业务场景:​在执行跨公司冲销时(FBU8),当我们在使用BAPI去冲销时候需要去检查是否允许冲销,就像MIGO过账前的检查一样,但是BAPI ​TB_FI_DOCUMENT_REVERSE​ 虽然有模拟运行标识,但并没有什么用,而且这个BAPI必须将所有的单子都冲一次(BAPI自带commit)。业务要求是要么都冲,要么都不冲,所以需要在冲之前校验一下。


解决办法:​GOOGLE了也没找到什么好的解决办法,只说这个BAPI可以用,后面实在没招,DEBUG了FBU8的程序,将校验的逻辑copy了出来,以下是完整的校验逻辑,只需改动很少即可运行。最后校验没问题的话直接调用BDC,模拟FBU8输入跨公司号去冲销,问题得以解决!

*&---------------------------------------------------------------------*
*& FORM CHECK_BEFORE_REVERSE
*&---------------------------------------------------------------------*
*& TEXT
*&---------------------------------------------------------------------*
*& <-- L_ERROR
*&---------------------------------------------------------------------*
FORM CHECK_BEFORE_REVERSE USING P_FW_OUTPUT STRUCTURE GS_OUTPUT
CHANGING P_L_ERROR P_MESSAGE.

DATA COMPANYCODE TYPE BUKRS.
DATA DOCUMENT TYPE BELNR_D.
DATA DOCUMENT2 TYPE BELNR_D.
DATA YEAR TYPE GJAHR.
DATA OBJ_KEY TYPE AWKEY.
DATA DATE_OF_REVERSAL TYPE BUDAT.
DATA PERIOD_OF_REVERSAL TYPE MONAT.
DATA REASON_FOR_REVERSAL TYPE STGRD.
DATA FLOW_IN TYPE VTBFHAPO.
DATA SIMULATION TYPE BOOLE_D.
DATA L_MESSAGE TYPE STRING.

SELECT *
INTO TABLE @DATA(LT_BKPF)
FROM BKPF
WHERE BVORG EQ @P_FW_OUTPUT-BVORG.

LOOP AT LT_BKPF ASSIGNING FIELD-SYMBOL(<FW_BKPF>).


* ------ PREPARE BATCH-INPUT DATA

REFRESH BDCDATA.
CLEAR BDCDATA.
BDCDATA-PROGRAM = 'SAPMF05A'.
BDCDATA-DYNPRO = '0105'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.

PERFORM FILL_BDCDATA USING 'RF05A-BELNS' <FW_BKPF>-BELNR.
PERFORM FILL_BDCDATA USING 'BKPF-BUKRS' <FW_BKPF>-BUKRS.
PERFORM FILL_BDCDATA USING 'RF05A-GJAHS' <FW_BKPF>-GJAHR.
PERFORM FILL_BDCDATA USING 'UF05A-STGRD' P_STGRD.
IF NOT P_BUDAT IS INITIAL.
PERFORM FILL_BDCDATA USING 'BSIS-BUDAT' P_BUDAT.
PERFORM FILL_BDCDATA USING 'BSIS-MONAT' P_BUDAT+4(2).
ENDIF.
* IF NOT RF05U-VATDATE IS INITIAL. "N1660511
* PERFORM FILL_BDCDATA USING 'VBKPF-VATDATE' RF05U-VATDATE."N1660511
* ENDIF. "N1660511
* TRANSFER BARCODE TO ALL PARTICIPATING DOCUMENTS (NOTE 0390492)

* PERFORM FILL_BDCDATA USING 'FS006-DOCID' DOCID.
* PERFORM FILL_BDCDATA USING 'FS006-BARCD' BARCODE_ID.
* SUPRESS CHECKING OF BARCODE IN TRANSACTION FB08 (NOTE 440553)
PERFORM FILL_BDCDATA USING 'FS006-XNOCHECK' 'X'.

PERFORM FILL_BDCDATA USING 'BDC_OKCODE' '/11'.

_MODE = 'N'.

CALL TRANSACTION 'FB08' USING BDCDATA MODE _MODE.
* IF SY-SUBRC = 0.
* <FW_BKPF>-XBUOK = 'X'.
* ELSE.
* CLEAR <FW_BKPF>-XBUOK.
* ENDIF.
SELECT SINGLE * FROM T100
WHERE SPRSL = SY-LANGU
AND ARBGB = SY-MSGID
AND MSGNR = SY-MSGNO .
IF SY-SUBRC = 0.
F160 = T100-TEXT.
ELSE.
F160 = SY-MSGID.
F160+3(3) = SY-MSGNO.
* (DEL) F160+7(10) = ': & & & &'. "NOTE455782
F160+7(14) = ': &1 &2 &3 &4'. "NOTE455782
ENDIF.
* ERROR? NOTE 413469
IF SY-MSGID NE 'F5' OR SY-MSGNO NE '530'.
ERROR = 'X'.
ENDIF.

* CLEAR BELEG_TABLE-XBSTATB. "NOTE2375208
DATA: L_BSTAT LIKE BKPF-BSTAT. "NOTE2375208
IF SY-MSGID = 'F5' AND SY-MSGNO = '360'. "NOTE2375208
SELECT SINGLE BSTAT INTO L_BSTAT "NOTE2375208
FROM BKPF "NOTE2375208
WHERE BUKRS = <FW_BKPF>-BUKRS "NOTE2375208
AND BELNR = <FW_BKPF>-BELNR "NOTE2375208
AND GJAHR = <FW_BKPF>-GJAHR. "NOTE2375208
IF L_BSTAT = 'B' OR L_BSTAT = 'A'. "NOTE2375208
* BELEG_TABLE-XBSTATB = 'X'. "NOTE2375208
ENDIF. "NOTE2375208
ENDIF. "NOTE2375208

REPLACE '&1' WITH SY-MSGV1 INTO F160. "NOTE455782
IF SY-SUBRC NE 0. "NOTE455782
REPLACE '&' WITH SY-MSGV1 INTO F160.
ENDIF. "NOTE455782
CONDENSE F160.
REPLACE '&2' WITH SY-MSGV2 INTO F160. "NOTE455782
IF SY-SUBRC NE 0. "NOTE455782
REPLACE '&' WITH SY-MSGV2 INTO F160.
ENDIF. "NOTE455782
CONDENSE F160.
REPLACE '&3' WITH SY-MSGV3 INTO F160. "NOTE455782
IF SY-SUBRC NE 0. "NOTE455782
REPLACE '&' WITH SY-MSGV3 INTO F160.
ENDIF. "NOTE455782
CONDENSE F160.
REPLACE '&4' WITH SY-MSGV4 INTO F160. "NOTE455782
IF SY-SUBRC NE 0. "NOTE455782
REPLACE '&' WITH SY-MSGV4 INTO F160.
ENDIF. "NOTE455782
CONDENSE F160.
REPLACE '$' WITH SY-MSGV1 INTO F160.
CONDENSE F160.
REPLACE '$' WITH SY-MSGV2 INTO F160.
CONDENSE F160.
REPLACE '$' WITH SY-MSGV3 INTO F160.
CONDENSE F160.
REPLACE '$' WITH SY-MSGV4 INTO F160.
CONDENSE F160.
IF SY-MSGTY EQ 'E'.
P_L_ERROR = 'X'.
P_MESSAGE = F160.
LOOP AT GT_OUTPUT INTO GS_OUTPUT WHERE HKTID = P_FW_OUTPUT-HKTID AND LIFNR = P_FW_OUTPUT-LIFNR AND ZBVTY = P_FW_OUTPUT-ZBVTY.
GS_OUTPUT-STATUS = GC_LIGHT_R.
GS_OUTPUT-MESSAGE1 = P_MESSAGE.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDIF.


ENDLOOP.