FM: I_CHANGE_STATUS
代码样例:
FUNCTION zjkdms003.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(I_VBELN) TYPE VBELN_VA OPTIONAL
*" EXPORTING
*" VALUE(E_MSG) TYPE BAPIRET2
*"----------------------------------------------------------------------
DATA: lv_objnr TYPE vbak-objnr,
lv_objnr_t TYPE jsto-objnr,
lv_obtyp TYPE jsto-obtyp,
lv_stsma TYPE jsto-stsma,
lv_stonr TYPE tj30-stonr,
lt_status TYPE TABLE OF jstat,
ls_status TYPE jstat,
lt_tj30 TYPE TABLE OF tj30,
ls_tj30 TYPE tj30,
lv_estat1 TYPE tj30-estat,
lv_estat2 TYPE tj30-estat,
lv_estat3 TYPE tj30-estat,
ieinfo TYPE einfo.
CLEAR: lv_objnr,
lv_objnr_t,
lv_obtyp,
lv_stsma,
lv_stonr,
lt_status,
ls_status,
lt_tj30,
ls_tj30,
lv_estat1,
lv_estat2,
lv_estat3,
ieinfo.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_vbeln
IMPORTING
output = i_vbeln.
SELECT SINGLE objnr INTO lv_objnr
FROM vbak
WHERE vbeln = i_vbeln.
IF lv_objnr IS NOT INITIAL.
lv_objnr_t = lv_objnr.
CALL FUNCTION 'STATUS_READ'
EXPORTING
* CLIENT = SY-MANDT
objnr = lv_objnr_t
* ONLY_ACTIVE = ' '
IMPORTING
obtyp = lv_obtyp
stsma = lv_stsma
stonr = lv_stonr
TABLES
status = lt_status
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF lt_status IS NOT INITIAL.
SELECT * INTO TABLE lt_tj30
FROM tj30
WHERE stsma = lv_stsma.
SORT lt_tj30 BY estat.
CLEAR: ls_tj30.
READ TABLE lt_tj30 INTO ls_tj30 INDEX 1.
IF sy-subrc = 0.
lv_estat1 = ls_tj30-estat.
ENDIF.
CLEAR: ls_tj30.
READ TABLE lt_tj30 INTO ls_tj30 INDEX 2.
IF sy-subrc = 0.
lv_estat2 = ls_tj30-estat.
ENDIF.
CLEAR: ls_tj30.
READ TABLE lt_tj30 INTO ls_tj30 INDEX 3.
IF sy-subrc = 0.
lv_estat3 = ls_tj30-estat.
ENDIF.
CALL FUNCTION 'I_CHANGE_STATUS'
EXPORTING
objnr = lv_objnr_t
estat_inactive = lv_estat1
estat_active = lv_estat2
stsma = lv_stsma
EXCEPTIONS
cannot_update = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF sy-msgty = 'E' OR sy-msgty = 'A'.
e_msg-type = sy-msgty.
e_msg-id = sy-msgid.
e_msg-number = sy-msgno.
ieinfo-msgid = sy-msgid.
ieinfo-msgty = sy-msgty.
ieinfo-msgno = sy-msgno.
CALL FUNCTION 'MESSAGE_GET_TEXT'
EXPORTING
ieinfo = ieinfo
ilangu = '1'
IMPORTING
etext = e_msg-message
EXCEPTIONS
no_t100_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ELSE.
e_msg-type = 'S'.
e_msg-message = '审批成功'.
ENDIF.
CALL FUNCTION 'I_CHANGE_STATUS'
EXPORTING
objnr = lv_objnr_t
estat_inactive = lv_estat2
estat_active = lv_estat3
stsma = lv_stsma
EXCEPTIONS
cannot_update = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
IF sy-msgty = 'E' OR sy-msgty = 'A'.
e_msg-type = sy-msgty.
e_msg-id = sy-msgid.
e_msg-number = sy-msgno.
ieinfo-msgid = sy-msgid.
ieinfo-msgty = sy-msgty.
ieinfo-msgno = sy-msgno.
CALL FUNCTION 'MESSAGE_GET_TEXT'
EXPORTING
ieinfo = ieinfo
ilangu = '1'
IMPORTING
etext = e_msg-message
EXCEPTIONS
no_t100_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ELSE.
e_msg-type = 'S'.
e_msg-message = '审批成功'.
ENDIF.
ENDIF.
ENDIF.
ENDFUNCTION.