FUNCTION zrfc_dn_post2.
*“----------------------------------------------------------------------
"“本地接口:
*” IMPORTING
*” VALUE(P_VBELN) TYPE LIKP-VBELN OPTIONAL
*" VALUE(P_DATE) TYPE WADAT_IST OPTIONAL
*" EXPORTING
*" VALUE(V_SUBRC) TYPE CHAR01
*" VALUE(V_MESSAGE) TYPE CHAR200
*" VALUE(V_MBLNR) TYPE MKPF-MBLNR
*" VALUE(V_MJAHR) TYPE MKPF-MJAHR
*"----------------------------------------------------------------------
DATA:ls_vbkok TYPE vbkok.
DATA:lt_vbpok_tab TYPE TABLE OF vbpok .
DATA:ls_vbpok_tab TYPE vbpok.
DATA lt_prot LIKE TABLE OF prott .
DATA ls_prot LIKE LINE OF lt_prot.
DATA:ls_likp LIKE likp.
DATA:lt_lips LIKE TABLE OF lips.
DATA:ls_lips LIKE LINE OF lt_lips.
DATA: l_message TYPE char100.
DATA: lv_error.
DATA: e_rvbeln TYPE mkpf-mblnr.
DATA: e_mjahr TYPE mkpf-mjahr.
CLEAR:ls_vbkok,ls_likp,lt_lips,lt_vbpok_tab,lt_prot,lv_error,e_rvbeln,e_mjahr.
SELECT SINGLE * INTO ls_likp FROM likp WHERE vbeln = p_vbeln.
ls_vbkok-vbeln_vl = ls_likp-vbeln.
ls_vbkok-vbeln = ls_likp-vbeln.
ls_vbkok-wadat_ist = p_date."过账日期
ls_vbkok-wabuc = ‘X’. "过账标识
SELECT * INTO TABLE lt_lips FROM lips WHERE vbeln = p_vbeln.
LOOP AT lt_lips INTO ls_lips.
CLEAR:ls_vbpok_tab.
ls_vbpok_tab-vbeln_vl = ls_lips-vbeln. "Delivery number
ls_vbpok_tab-posnr_vl = ls_lips-posnr.
ls_vbpok_tab-vbeln = ls_lips-vbeln . "DN
ls_vbpok_tab-posnn = ls_lips-posnr. "DN-item
ls_vbpok_tab-matnr = ls_lips-matnr.
ls_vbpok_tab-sobkz = ls_lips-sobkz."如果测试有问题,可以不考虑特殊库存标识 E库存标识
ls_vbpok_tab-lfimg = ls_lips-lfimg.
ls_vbpok_tab-pikmg = ls_lips-lfimg.
ls_vbpok_tab-lgmng = ls_lips-lfimg.
APPEND ls_vbpok_tab TO lt_vbpok_tab.
ENDLOOP.
CALL FUNCTION ‘WS_DELIVERY_UPDATE’
EXPORTING
vbkok_wa = ls_vbkok
delivery = p_vbeln
-
update_picking = 'X' if_error_messages_send_0 = 'X' commit = 'X' if_database_update = '1' synchron = 'X' if_wmpp = 'X'
TABLES
vbpok_tab = lt_vbpok_tab
prot = lt_prot
EXCEPTIONS
error_message = 1
OTHERS = 2.LOOP AT lt_prot INTO ls_prot WHERE msgty CA ‘AE’.
CLEAR:l_message.CALL FUNCTION ‘MESSAGE_TEXT_BUILD’
EXPORTING
msgid = ls_prot-msgid
msgnr = ls_prot-msgno
msgv1 = ls_prot-msgv1
msgv2 = ls_prot-msgv2
msgv3 = ls_prot-msgv3
msgv4 = ls_prot-msgv4
IMPORTING
message_text_output = l_message.v_message = v_message && ‘/’ && l_message.
lv_error = ‘X’.
ENDLOOP.IF lv_error = ‘’.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
wait = ‘X’.SELECT SINGLE vbeln mjahr
INTO (e_rvbeln,e_MJAHR)
FROM vbfa
WHERE vbelv = p_vbeln AND vbtyp_n = ‘R’ AND bwart NE ‘’ AND rfmng NE 0 "R 货物移动(过账物料凭证)
AND NOT EXISTS
( SELECT *
FROM m_mbmps "视图比MSEG多条件
WHERE smbln = vbfa~vbeln OR mblnr = vbfa~vbeln ). "非冲销和被冲销v_subrc = ‘S’.
CONCATENATE ‘交货单’ p_vbeln ‘已过帐完成’ INTO v_message.
v_mblnr = e_rvbeln.
v_mjahr = e_mjahr.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’.v_subrc = ‘E’.
v_message = p_vbeln && ‘过账失败,详情:’ && v_message.
ENDIF.
ENDFUNCTION.