MIGO收货冲销BAPI
FUNCTION zsdfu014. *"---------------------------------------------------------------------- *"*"本地接口: *" IMPORTING *" VALUE(I_ID) TYPE ZRFC_LOGID OPTIONAL *" VALUE(I_CANUM) TYPE CANUM OPTIONAL *" EXPORTING *" VALUE(E_CODE) TYPE MSGTY *" VALUE(E_MSG) TYPE MSGTXT *" VALUE(E_FLOW_END) TYPE CHAR01 *" TABLES *" ET_RETURN STRUCTURE ZRFCT005 OPTIONAL *"---------------------------------------------------------------------- DATA:ls_zsdt022 TYPE zsdt022. DATA:ls_zsdt013_1 TYPE zsdt013, lt_zsdt013 TYPE TABLE OF zsdt013, ls_zsdt013_2 TYPE zsdt013. SELECT * INTO TABLE @DATA(lt_zsdt022) FROM zsdt022 WHERE zrfc_logid = @i_id. IF lt_zsdt022 IS INITIAL. e_code = 'E'. e_msg = '无可执行数据'. RETURN. ENDIF. DATA:ls_head TYPE bapi2017_gm_head_02, ls_head_ret TYPE bapi2017_gm_head_ret, lt_return TYPE TABLE OF bapiret2, ls_return TYPE bapiret2. DATA:message TYPE c LENGTH 200. DATA:ls_zrfct002 TYPE zrfct002, ls_zsdt013 TYPE zsdt013, ls_zrfct005 TYPE zrfct005. DATA:ls_head_im TYPE bapi2017_gm_head_01, ls_head_ex TYPE bapi2017_gm_head_ret, lt_item TYPE TABLE OF bapi2017_gm_item_create, ls_item TYPE bapi2017_gm_item_create. DATA:lv_mblnr TYPE bapi2017_gm_serialnumber. LOOP AT lt_zsdt022 INTO ls_zsdt022. ls_head_im-pstng_date = ls_zsdt022-budat. ls_head_im-ref_doc_no = ls_zsdt022-xblnr. ls_head_im-doc_date = ls_zsdt022-budat. ls_head_im-pr_uname = sy-uname. ls_item-material = ls_zsdt022-matnr. ls_item-plant = ls_zsdt022-werks. ls_item-stge_loc = ls_zsdt022-lgort. ls_item-batch = ls_zsdt022-charg. ls_item-move_type = ls_zsdt022-bwart. ls_item-entry_qnt = ls_zsdt022-menge. ls_item-mvt_ind = 'B'. ls_item-po_number = ls_zsdt022-ebeln. ls_item-po_item = ls_zsdt022-ebelp. ls_item-ref_doc = ls_zsdt022-zmblnr. ls_item-ref_doc_it = ls_zsdt022-zeile. ls_item-move_reas = ls_zsdt022-grund. APPEND ls_item TO lt_item. SELECT SINGLE * INTO ls_zsdt013_1 FROM zsdt013 WHERE zmblnr = ls_zsdt022-zmblnr. ls_zsdt013-zrfc_logid = i_id. ls_zsdt013-canum = i_canum. ls_zsdt013-zzrfc_logid = ls_zsdt013_1-zrfc_logid. ls_zsdt013-zcanum = ls_zsdt013_1-canum. ls_zsdt013-mblnr = ls_zsdt022-mblnr. ls_zsdt013-mjahr = ls_zsdt022-mjahr. ls_zsdt013-zrfc_logid_2 = ls_zsdt013_1-zrfc_logid. ls_zsdt013-canum_2 = ls_zsdt013_1-canum. ls_zsdt013-zzrfc_logid_2 = ls_zsdt013_1-zzrfc_logid. ls_zsdt013-zcanum_2 = ls_zsdt013_1-zcanum. ls_zsdt013-objtype = 'GS'. ls_zsdt013-objkey = ls_zsdt013_1-objkey. ls_zsdt013-zobjtype = 'PO'. ls_zsdt013-zobjkey = ls_zsdt013_1-zobjkey. ls_zsdt013-zrfcid = ls_zsdt013_1-zrfcid. APPEND ls_zsdt013 TO lt_zsdt013. CLEAR:ls_zsdt022,ls_item,ls_zsdt013,ls_zsdt013_1. ENDLOOP. CALL FUNCTION 'BAPI_GOODSMVT_CREATE' EXPORTING goodsmvt_header = ls_head_im goodsmvt_code = '01' IMPORTING goodsmvt_headret = ls_head_ex TABLES goodsmvt_item = lt_item return = lt_return. LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'. CONCATENATE message ls_return-message INTO message SEPARATED BY '/'. ENDLOOP. IF sy-subrc NE 0. CALL METHOD zcl_rfc=>get_source EXPORTING i_id = i_id i_canum = i_canum IMPORTING e_zrfct002 = ls_zrfct002. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X'. e_code = 'S'. CONCATENATE ls_head-mat_doc '冲销成功' INTO e_msg. CLEAR:ls_zrfct005. ls_zrfct005-status = '53'. ls_zrfct005-msgty = e_code. ls_zrfct005-msgid = '00'. ls_zrfct005-msgno = '001'. ls_zrfct005-msgv1 = e_msg. ls_zrfct005-msgv4 = ls_head_ex-mat_doc. APPEND ls_zrfct005 TO et_return. ls_zsdt013_2-zmblnr = ls_head_ex-mat_doc. ls_zsdt013_2-fkstol = 'X'. MODIFY lt_zsdt013 FROM ls_zsdt013_2 TRANSPORTING zmblnr fkstol WHERE zmblnr IS INITIAL. MODIFY zsdt013 FROM TABLE lt_zsdt013. ELSE. CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. e_code = 'E'. e_msg = message. ENDIF. ENDFUNCTION.
标签:BAPI,zsdt013,MIGO,head,zsdt022,item,ABAP,ls,TYPE From: https://www.cnblogs.com/ap-ad-java-abap/p/16991726.html