程序如下:
DATA: LV_LGO_SYS TYPE TBDLS-LOGSYS,
LS_REVERSAL TYPE BAPIACREV,
LV_BUS_ACT TYPE BAPIACHE09-BUS_ACT,
LV_OBJ_KEY TYPE BAPIACREV-OBJ_KEY,
LT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
LV_ERROR_FLAG TYPE C.
"LOGICAL SYSYTEM
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = LV_LGO_SYS
EXCEPTIONS
OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1
OTHERS = 2.
LOOP AT GT_ROW INTO LS_ROW.
DATA(LS_OUT) = GT_OUT[ LS_ROW-ROW_ID ].
SELECT SINGLE
AWTYP,
AWKEY,
BUDAT,
MONAT,
GLVOR
INTO @DATA(LS_BKPF)
FROM BKPF
WHERE BUKRS = @LS_OUT-BUKRS
AND BELNR = @LS_OUT-BELNR_JT
AND GJAHR = @LS_OUT-GJAHR_JT.
LS_REVERSAL = VALUE #(
OBJ_TYPE = LS_BKPF-AWTYP
OBJ_KEY = LS_BKPF-AWKEY
OBJ_SYS = LV_LGO_SYS
OBJ_KEY_R = LS_BKPF-AWKEY
PSTNG_DATE = LS_BKPF-BUDAT
"FIS_PERIOD = LS_BKPF-MONAT
COMP_CODE = LS_OUT-BUKRS
AC_DOC_NO = LS_OUT-BELNR_JT
REASON_REV = '04' ).
LV_BUS_ACT = LS_BKPF-GLVOR.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
EXPORTING
REVERSAL = LS_REVERSAL
BUS_ACT = LV_BUS_ACT
IMPORTING
* OBJ_TYPE =
OBJ_KEY = LV_OBJ_KEY
* OBJ_SYS =
TABLES
RETURN = LT_RETURN.
LOOP AT LT_RETURN INTO DATA(LS_RETURN) WHERE TYPE CA 'AEX'.
LS_OUT-MESSAGE =
COND #( WHEN LS_OUT-MESSAGE = SPACE THEN LS_RETURN-MESSAGE
ELSE |{ LS_OUT-MESSAGE }/{ LS_RETURN-MESSAGE }| ).
ENDLOOP.
IF SY-SUBRC = 0.
LV_ERROR_FLAG = 'X'.
ELSE.
LS_OUT-BELNR_CX = LV_OBJ_KEY(10).
LS_OUT-GJAHR_CX = LV_OBJ_KEY+14(4).
ENDIF.
MODIFY GT_OUT FROM LS_OUT INDEX LS_ROW-ROW_ID.
CLEAR: LS_OUT.
ENDLOOP.
报错信息如下:
解决方法:
工作区 LS_REVERSAL中会计凭证字段 AC_DOC_NO 不用填入值即可
原因:OBJ_KEY字段已经包含了 需要冲销凭证编号