上文我们总结了创建会计凭证的函数,今天我们来学习总结怎么冲销掉会计凭证。
即FB08的冲销逻辑和字段。在S4HANA中亲测有效,放心使用。希望您喜欢~
这也是50个常用BAPI例子的第二个。希望上海早日解封~
相对于会计凭证创建,
会计凭证冲销要简单一些。参数要少很多。
参数名称 | 关联类型 | 可选的 | 说明 |
REVERSAL | BAPIACREV | 必选 | 冲销的参考信息 |
BUS_ACT | BAPIACHE09-BUS_ACT | 必选 | 业务事务 |
好了。言归正传。我们分享我们的核心DEMO示例代码:
TYPES: BEGIN OF TY_BELNR,
BELNR TYPE BKPF-BELNR,
END OF TY_BELNR.
DATA: LV_SYS TYPE TBDLS-LOGSYS,
LV_KEY TYPE BAPIACREV-OBJ_KEY,
LS_REV TYPE BAPIACREV,
LV_BUS_ACT TYPE BAPIACHE09-BUS_ACT,
LT_RETURN TYPE TABLE OF BAPIRET2,
LS_RETURN TYPE BAPIRET2,
LT_BELNR TYPE TABLE OF TY_BELNR,
LS_BELNR TYPE TY_BELNR,
LV_TABIX TYPE SY-TABIX,
LT_ZFI0008 TYPE TABLE OF ZFI0008,
LS_ZFI0008 TYPE ZFI0008,
LV_ZCXND TYPE ZFI0008-ZCXND,
LV_ZCXYD TYPE ZFI0008-ZCXND,
LV_BUDAT TYPE BKPF-BUDAT.
LV_ZCXND = I_WADAT_IST(4).
LV_ZCXYD = I_WADAT_IST+4(2).
*取数逻辑
SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_ZFI0008
FROM ZFI0008
WHERE VBELN_VL = I_VBELN
AND ZFLAG = ”.
READ TABLE LT_ZFI0008 INTO LS_ZFI0008 INDEX 1.
IF SY-SUBRC EQ 0.
IF LS_ZFI0008-BELNR1 IS NOT INITIAL.
LS_BELNR-BELNR = LS_ZFI0008-BELNR1.
APPEND LS_BELNR TO LT_BELNR.
ELSE.
CLEAR LS_BELNR.
APPEND LS_BELNR TO LT_BELNR.
ENDIF.
IF LS_ZFI0008-BELNR2 IS NOT INITIAL.
LS_BELNR-BELNR = LS_ZFI0008-BELNR2.
APPEND LS_BELNR TO LT_BELNR.
ELSE.
CLEAR LS_BELNR.
APPEND LS_BELNR TO LT_BELNR.
ENDIF.
LOOP AT LT_BELNR INTO LS_BELNR.
LV_TABIX = SY-TABIX.
CHECK LS_BELNR-BELNR IS NOT INITIAL.
CLEAR: LS_REV, LV_BUS_ACT, LV_KEY.
*给REVERSAL和BUS_ACT赋值
SELECT SINGLE AWTYP AWKEY GLVOR BUDAT FROM BKPF
INTO (LS_REV-OBJ_TYPE, LS_REV-OBJ_KEY, LV_BUS_ACT, LV_BUDAT )
WHERE BUKRS EQ LS_ZFI0008-BUKRS
AND GJAHR EQ LS_ZFI0008-GJAHR
AND BELNR EQ LS_BELNR-BELNR.
MOVE: “LS_BELNR-BELNR TO LS_REV-AC_DOC_NO,
I_WADAT_IST TO LS_REV-PSTNG_DATE,
LS_ZFI0008-BUKRS TO LS_REV-COMP_CODE.
IF LV_ZCXND EQ LS_ZFI0008-GJAHR AND LV_ZCXYD EQ LS_ZFI0008-MONAT.
MOVE: ’01’ TO LS_REV-REASON_REV.
LS_REV-PSTNG_DATE = LV_BUDAT.
ELSE.
MOVE: ’02’ TO LS_REV-REASON_REV.
ENDIF.
*获取 LS_REV-OBJ_SYS的值
CALL FUNCTION ‘OWN_LOGICAL_SYSTEM_GET’
IMPORTING
OWN_LOGICAL_SYSTEM = LV_SYS
EXCEPTIONS
OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
MOVE LV_SYS TO LS_REV-OBJ_SYS.
MOVE LS_REV-OBJ_KEY TO LS_REV-OBJ_KEY_R.
REFRESH LT_RETURN .
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_REV_CHECK’
EXPORTING
REVERSAL = LS_REV
BUS_ACT = LV_BUS_ACT
TABLES
RETURN = LT_RETURN.
READ TABLE LT_RETURN WITH KEY TYPE = ‘E’ TRANSPORTING NO FIELDS.
IF SY-SUBRC EQ 0.
CONTINUE.
ENDIF.
REFRESH LT_RETURN .
CALL FUNCTION ‘BAPI_ACC_DOCUMENT_REV_POST’
EXPORTING
REVERSAL = LS_REV
BUS_ACT = LV_BUS_ACT
IMPORTING
OBJ_KEY = LV_KEY
TABLES
RETURN = LT_RETURN.
READ TABLE LT_RETURN WITH KEY TYPE = ‘E’ TRANSPORTING NO FIELDS.
IF SY-SUBRC EQ 0.
CONTINUE.
ELSE.
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
EXPORTING
WAIT = ‘X’.
ENDIF.
ENDIF.
本文链接http://www.hot583.com/2022/03/30/bapi_acc_document_rev_post/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
我的微信公众号hot583或者在这个链接联系我
微信原文《全文完》