FM: ZF_FI_ACC_DOC_REV_POST
FUNCTION ZF_FI_ACC_DOC_REV_POST.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IV_BUKRS) TYPE BKPF-BUKRS
*" REFERENCE(IV_BELNR) TYPE BKPF-BELNR
*" REFERENCE(IV_GJAHR) TYPE BKPF-GJAHR
*" REFERENCE(IV_STGRD) TYPE BKPF-STGRD DEFAULT '04'
*" EXPORTING
*" REFERENCE(OV_BELNR_CX) TYPE BKPF-BELNR
*" REFERENCE(OV_GJAHR_CX) TYPE BKPF-GJAHR
*" REFERENCE(OV_MESSAGE) TYPE STRING
*"----------------------------------------------------------------------
DATA: LV_LGO_SYS TYPE TBDLS-LOGSYS.
DATA: 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.
"Get logical system
CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
IMPORTING
OWN_LOGICAL_SYSTEM = LV_LGO_SYS
EXCEPTIONS
OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1
OTHERS = 2.
SELECT SINGLE
AWTYP,
AWKEY,
BUDAT,
MONAT,
GLVOR
INTO @DATA(LS_BKPF)
FROM BKPF
WHERE BUKRS = @IV_BUKRS
AND BELNR = @IV_BELNR
AND GJAHR = @IV_GJAHR.
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 = IV_BUKRS
"AC_DOC_NO = LS_OUT-BELNR
REASON_REV = IV_STGRD ).
LV_BUS_ACT = LS_BKPF-GLVOR.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_CHECK'
EXPORTING
REVERSAL = LS_REVERSAL
BUS_ACT = LV_BUS_ACT
TABLES
RETURN = LT_RETURN.
LOOP AT LT_RETURN INTO DATA(LS_RETURN) WHERE TYPE CA 'AEX'.
OV_MESSAGE =
COND #( WHEN OV_MESSAGE = SPACE THEN LS_RETURN-MESSAGE
ELSE |{ OV_MESSAGE }/{ LS_RETURN-MESSAGE }| ).
ENDLOOP.
IF OV_MESSAGE IS NOT INITIAL.
RETURN.
ENDIF.
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 LS_RETURN WHERE TYPE CA 'AEX'.
OV_MESSAGE =
COND #( WHEN OV_MESSAGE = SPACE THEN LS_RETURN-MESSAGE
ELSE |{ OV_MESSAGE }/{ LS_RETURN-MESSAGE }| ).
ENDLOOP.
IF SY-SUBRC NE 0.
OV_BELNR_CX = LV_OBJ_KEY(10).
OV_GJAHR_CX = LV_OBJ_KEY+14(4).
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
ENDFUNCTION.