写了一个简单单的调用 BAPI 冲销凭证的例子,这样的代码会经常用的上,贴在这里,方便我那天过来找。
DATA: wa_bapidochdrr TYPE bapiacrev,
bus_act TYPE bapiache09-bus_act.
DATA:obj_type TYPE bapiache09-obj_type,
obj_key TYPE bapiache09-obj_key,
obj_sys TYPE bapiache09-obj_sys.
DATA: l_msg(255).
DATA: l_error TYPE c.
DATA:gw_return TYPE bapiret2,
gt_return LIKE gw_return OCCURS 0.
SELECT
SINGLE *
INTO @DATA(gw_bkpf)
FROM bkpf
WHERE belnr = '9800000009'
AND bukrs = '1000'
AND gjahr = '2023'.
CLEAR wa_bapidochdrr.
wa_bapidochdrr-obj_type = gw_bkpf-awtyp.
wa_bapidochdrr-obj_key = gw_bkpf-awkey.
wa_bapidochdrr-obj_sys = gw_bkpf-awsys.
wa_bapidochdrr-obj_key_r = gw_bkpf-awkey.
* wa_bapidochdrr-ac_doc_no = gw_bkpf-belnr.
wa_bapidochdrr-pstng_date = sy-datum.
wa_bapidochdrr-reason_rev = '04'.
bus_act = 'RFBU'.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
EXPORTING
reversal = wa_bapidochdrr
bus_act = bus_act
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
return = gt_return.
LOOP AT gt_return INTO gw_return WHERE type = 'E' OR type = 'A'.
CONCATENATE gw_return-message l_msg INTO l_msg.
l_error = 'X'.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
IF sy-subrc = 0..
ENDIF.