前言:在SAP系统中有很多时候 我们需要记录单据的当前状态 以下以检验批状态举例
当我们需要获取他的状态时有以下两种方式
1、STATUS_TEXT_EDIT:
当我们使用此BAPI获取状态 是从JEST获取当前对象ID在JEST-INACT = ABAP_FALSE 的值去取对应语言的状态文本(TJ02T-TXT04)予以展示
2、STATUS_READ
当我们使用此BAPI获取状态 是从JEST直接获取当前对象ID在JEST中的值予以展示 当然可以在ONLY_ACTIVE里限定 获取未激活还是已激活的
3、STATUS_UPDATE 状态的新增
当我们要新增状态时 首先要明确当前对象ID的类型 可在JSTO表内查看
对应代码如下:
//1、STATUS_TEXT_EDIT
DATA:ls_status TYPE bsvx-sttxt,
lt_status TYPE TABLE OF bsvx-sttxt.
CLEAR:e_text.
CALL FUNCTION 'STATUS_TEXT_EDIT' "订单状态文本
EXPORTING
objnr = i_objnr "对象ID号
"spras = sy-langu "语言标识
client = sy-mandt "客户端
"objnr = p_objnr "对象编号
only_active = abap_true "激活标志
bypass_buffer = abap_true "这个标记上就可以取最新的状态了
IMPORTING
line = ls_status
EXCEPTIONS
object_not_found = 01
OTHERS = 02.
e_text = ls_status.
//2、STATUS_READ
DATA:ls_status TYPE jstat,
lt_status TYPE TABLE OF jstat. " WITH HEADER LINE.
CALL FUNCTION 'STATUS_READ'
EXPORTING
client = sy-mandt
objnr = i_objnr
TABLES
status = lt_status
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
SORT lt_status BY stat inact.
//3、新增状态
DATA:lt_obj_del TYPE TABLE OF onr00,
lt_jsto_ins TYPE TABLE OF jsto,
lt_jsto_updt TYPE TABLE OF jsto_upd,
lt_jest_ins TYPE TABLE OF jest_upd,
lt_jest_updt TYPE TABLE OF jest_upd.
SELECT SINGLE FROM qals
FIELDS objnr
WHERE prueflos = @i_insplot-prueflos
INTO @DATA(l_objnr).
lt_jest_ins = VALUE #( ( mandt = sy-mandt
objnr = l_objnr
stat = 'I0230'
chgnr = '001'
obtyp = 'QL1'
chgkz = abap_true
) ).
CALL FUNCTION 'STATUS_UPDATE' " IN UPDATE TASK
TABLES
obj_del = lt_obj_del
jsto_ins = lt_jsto_ins
jsto_upd = lt_jsto_updt
jest_ins = lt_jest_ins
jest_upd = lt_jest_updt.
IF sy-subrc = 0.
COMMIT WORK AND WAIT.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.