SAP 憑證沖銷可以使用BAPI_ACC_DOCUMENT_REV_POST或者BDC錄製FB08來做
憑證沖銷可以使用BAPI_ACC_DOCUMENT_REV_POST或者BDC錄製FB08來做,效果相同
本文介紹使用BAPI_ACC_DOCUMENT_REV_POST做沖銷憑證
部分程式碼實現:
@---------------------------------------------------------------------
*@ BAPI函式用到的變數
DATA: wa_bapidochdrr TYPE bapiacrev,
gt_return TYPE TABLE OF bapiret2 WITH HEADER LINE.
LOOP AT gt_bkpf ASSIGNING <fs_bkpf> WHERE xreversal = ‘’.
-
給 BAPI 函式相應的引數賦值
wa_bapidochdrr-obj_type = <fs_bkpf>-awtyp.
wa_bapidochdrr-obj_key = <fs_bkpf>-awkey.
wa_bapidochdrr-obj_key_r = <fs_bkpf>-awkey.
wa_bapidochdrr-pstng_date = <fs_bkpf>-budat.
wa_bapidochdrr-fis_period = <fs_bkpf>-monat.
wa_bapidochdrr-comp_code = <fs_bkpf>-bukrs.
wa_bapidochdrr-ac_doc_no = <fs_bkpf>-belnr.
wa_bapidochdrr-reason_rev = ‘03’. -
取得系統 LOGICAL SYSTEM
CALL FUNCTION ‘OWN_LOGICAL_SYSTEM_GET’
IMPORTING
own_logical_system = wa_bapidochdrr-obj_sys. -
呼叫 BAPI 函式,沖銷會計憑證
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_REV_POST’ -
EXPORTING
-
obj_type = gv_glvor EXPORTING reversal = wa_bapidochdrr bus_act = <fs_bkpf>-glvor TABLES return = gt_return.
READ TABLE gt_return WITH KEY type = ‘E’.
IF sy-subrc NE 0. -
提交憑證過賬 CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' IMPORTING return = i_return. IF i_return IS INITIAL. APPEND LINES OF gt_return TO gt_info. MESSAGE '會計憑證過賬成功' TYPE 'S'. ELSE. APPEND i_return TO gt_info. CLEAR: i_return-number, i_return-id. i_return-type = 'E'. i_return-message = '過賬失敗,請用事務程式碼ST22檢視詳細資訊'. APPEND i_return TO gt_info. MESSAGE '會計憑證過賬失敗' TYPE 'E'. ENDIF.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK’. -
將返回資訊新增到結果資訊內表
APPEND LINES OF gt_return TO gt_info.
ENDIF.