SAP 与WMS 集成之后,会出现这么一种情况,就是外向交货单发货过账之后,
WMS 端发起取消发货,那么接口需要将已经过账的外向交货单冲销,并将已经做了批次拆分的外向交货单,还原成未拆分的。
外向交货取消发货bapi: WS_REVERSE_GOODS_ISSUE
外向交货单删除批次拆分行:BAPI_OUTB_DELIVERY_CHANGE
但是再一个接口中同时调用这两个函数会有问题,报错VL216
经过debug发现,两个函数用了一些公用的变量,倒是内表的数据错误,所以校验出了问题
后来通过VL09的BDC + BAPI_OUTB_DELIVERY_CHANGE 实现需求
实例代码如下:
DATA: LT_MESG TYPE STANDARD TABLE OF MESG,
LS_MESG TYPE MESG,
LS_EMKPF TYPE EMKPF.
DATA: LV_MESSAGE TYPE STRING.
DATA: LV_ALL_MESSAGE TYPE STRING.
DATA: LV_FLAG TYPE CHAR01.
DATA: LV_VBELN TYPE LIPS-VBELN.
DATA LS_ZCA_URL TYPE ZCA_URL.
DATA LV_POSTDATE TYPE DATUM.
*to check if the date control is open BY FEI XUE 20211201
CLEAR LS_ZCA_URL.
SELECT SINGLE *
FROM ZCA_URL
INTO LS_ZCA_URL
WHERE INTERFACEID = 'I03'.
IF LS_ZCA_URL-ZDATECONTRL IS NOT INITIAL AND LS_ZCA_URL-ZPOSTDATE IS NOT INITIAL.
LV_POSTDATE = LS_ZCA_URL-ZPOSTDATE.
ELSE.
LV_POSTDATE = SY-DATUM.
ENDIF.
*to check if the date control is open BY FEI XUE 20211201
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_DATA-DN
IMPORTING
OUTPUT = LV_VBELN.
*如果通过BAPI进项过账,用VL09冲销需要更新VLSTK状态。
UPDATE LIKP SET VLSTK = SPACE
WHERE VBELN = LV_VBELN .
IF SY-SUBRC = 0 .
COMMIT WORK AND WAIT .
ENDIF .
DATA:LT_MESSAGE TYPE TABLE OF BDCMSGCOLL,
LS_MESSAGE TYPE BDCMSGCOLL.
DATA:LV_SUBRC TYPE SYST-SUBRC .
CALL FUNCTION 'ZFM_VL09_BDC'
EXPORTING
CTU = 'X'
MODE = 'N'
UPDATE = 'S'
* GROUP =
* USER =
* KEEP =
* HOLDDATE =
* NODATA =
LOW_001 = LV_VBELN
* LF_ANAUS_002 = 'X'
IMPORTING
SUBRC = LV_SUBRC
TABLES
MESSTAB = LT_MESSAGE.
LOOP AT LT_MESSAGE INTO LS_MESSAGE WHERE MSGTYP CA 'EAX'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_MESSAGE-MSGID
MSGNR = LS_MESSAGE-MSGNR
MSGV1 = LS_MESSAGE-MSGV1
MSGV2 = LS_MESSAGE-MSGV2
MSGV3 = LS_MESSAGE-MSGV3
MSGV4 = LS_MESSAGE-MSGV4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_MESSAGE.
CONCATENATE LV_ALL_MESSAGE LV_MESSAGE INTO LV_ALL_MESSAGE.
ENDLOOP.
* CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
* EXPORTING
* I_VBELN = LS_DATA-DN
* I_BUDAT = LV_POSTDATE
** I_COUNT =
** I_MBLNR =
* I_TCODE = 'VL09'
* I_VBTYP = 'J'
** I_MBLPO =
** I_MJAHR =
** I_POSNR =
** I_SIMULATE = ' '
** I_SPE_BUDAT_UHR =
** I_SPE_BUDAT_ZONE =
** I_SPE_MDNUM_EWM =
** I_SPE_LOGSYS =
** I_SPE_CONFIRM_CENTRAL = ' '
* IMPORTING
* ES_EMKPF = LS_EMKPF
* TABLES
* T_MESG = LT_MESG
* EXCEPTIONS
* ERROR_REVERSE_GOODS_ISSUE = 1
* ERROR_MESSAGE = 3
* OTHERS = 2.
* IF SY-SUBRC <> 0.
* LOOP AT LT_MESG INTO LS_MESG WHERE MSGTY EQ 'E' OR MSGTY EQ 'A'.
* CALL FUNCTION 'MESSAGE_TEXT_BUILD'
* EXPORTING
* MSGID = LS_MESG-MSGTY
* MSGNR = LS_MESG-TXTNR
* MSGV1 = LS_MESG-MSGV1
* MSGV2 = LS_MESG-MSGV2
* MSGV3 = LS_MESG-MSGV3
* MSGV4 = LS_MESG-MSGV4
* IMPORTING
* MESSAGE_TEXT_OUTPUT = LV_MESSAGE.
*
* CONCATENATE LV_ALL_MESSAGE LV_MESSAGE INTO LV_ALL_MESSAGE.
* ENDLOOP.
* ENDIF.
IF LV_ALL_MESSAGE IS INITIAL .
COMMIT WORK AND WAIT.
DATA: LS_HEADER_DATA TYPE BAPIOBDLVHDRCHG.
DATA: LS_HEADER_CONTROL TYPE BAPIOBDLVHDRCTRLCHG.
DATA: LT_BATCH_ITEM TYPE STANDARD TABLE OF BAPIOBDLVITEMCHG.
DATA: LS_BATCH_ITEM TYPE BAPIOBDLVITEMCHG.
DATA: LT_BATCH_CONTROL TYPE STANDARD TABLE OF BAPIOBDLVITEMCTRLCHG.
DATA: LS_BATCH_CONTROL TYPE BAPIOBDLVITEMCTRLCHG.
DATA : TECHN_CONTROL LIKE BAPIDLVCONTROL. "TECHN_CONTROL
DATA: LT_LIPS TYPE STANDARD TABLE OF LIPS.
DATA: LS_LIPS TYPE LIPS.
DATA: LT_LIPS_SPLIT TYPE STANDARD TABLE OF LIPS.
DATA: LS_LIPS_SPLIT TYPE LIPS.
DATA: LT_RETURN_TAB TYPE TABLE OF BAPIRET2,
LS_RETURN_TAB TYPE BAPIRET2.
"Header
LS_HEADER_DATA-DELIV_NUMB = LV_VBELN.
LS_HEADER_CONTROL-DELIV_NUMB = LV_VBELN.
TECHN_CONTROL-UPD_IND = 'U' .
CLEAR:LT_LIPS, LS_LIPS.
SELECT * INTO TABLE LT_LIPS
FROM LIPS
WHERE VBELN = LV_VBELN
AND UECHA EQ SPACE.
LOOP AT LT_LIPS INTO LS_LIPS.
CLEAR LS_BATCH_ITEM.
CLEAR LS_BATCH_CONTROL.
LS_BATCH_ITEM-DELIV_NUMB = LV_VBELN. "被拆分DN号
LS_BATCH_ITEM-DELIV_ITEM = LS_LIPS-POSNR. "被拆分DN Item
LS_BATCH_ITEM-MATERIAL = LS_LIPS-MATNR. "物料 "fei
LS_BATCH_ITEM-DLV_QTY = LS_LIPS-KCMENG. "交货数量 "fei
LS_BATCH_ITEM-DLV_QTY_IMUNIT = LS_LIPS-KCMENG. "交货数量 "fei
LS_BATCH_ITEM-BASE_UOM = LS_LIPS-VRKME. "被拆分DN销售单位 "fei
LS_BATCH_ITEM-SALES_UNIT = LS_LIPS-VRKME. "被拆分DN销售单位 "fei
LS_BATCH_ITEM-SALES_UNIT_ISO = LS_LIPS-MEINS. "被拆分DN基本单位 "fei
LS_BATCH_ITEM-FACT_UNIT_NOM = LS_LIPS-UMVKZ. "销售数量转换成SKU的分子(因子)
LS_BATCH_ITEM-FACT_UNIT_DENOM = LS_LIPS-UMVKN. "销售数量转换为 SKU 的值(分母)
APPEND LS_BATCH_ITEM TO LT_BATCH_ITEM.
LS_BATCH_CONTROL-DELIV_NUMB = LV_VBELN.
LS_BATCH_CONTROL-DELIV_ITEM = LS_LIPS-POSNR.
LS_BATCH_CONTROL-CHG_DELQTY = 'X'.
APPEND LS_BATCH_CONTROL TO LT_BATCH_CONTROL.
CLEAR:LT_LIPS_SPLIT, LS_LIPS_SPLIT.
SELECT * INTO TABLE LT_LIPS_SPLIT
FROM LIPS
WHERE VBELN = LV_VBELN
AND UECHA = LS_LIPS-POSNR
AND POSNR LIKE '9%'.
IF SY-SUBRC = 0.
"Header
LS_HEADER_DATA-DELIV_NUMB = LV_VBELN.
LS_HEADER_CONTROL-DELIV_NUMB = LV_VBELN.
LOOP AT LT_LIPS_SPLIT INTO LS_LIPS_SPLIT WHERE UECHA = LS_LIPS-POSNR.
CLEAR LS_BATCH_ITEM.
CLEAR LS_BATCH_CONTROL.
LS_BATCH_ITEM-DELIV_NUMB = LV_VBELN. "被拆分DN号
LS_BATCH_ITEM-DELIV_ITEM = LS_LIPS_SPLIT-POSNR. "被拆分DN Item
LS_BATCH_ITEM-HIERARITEM = LS_LIPS-POSNR . "fei
LS_BATCH_ITEM-USEHIERITM = '1' . "fei
LS_BATCH_ITEM-MATERIAL = LS_LIPS_SPLIT-MATNR. "物料 "fei
LS_BATCH_ITEM-DLV_QTY = LS_LIPS_SPLIT-LFIMG. "交货数量 "fei
LS_BATCH_ITEM-SALES_UNIT = LS_LIPS_SPLIT-VRKME. "被拆分DN销售单位 "fei
LS_BATCH_ITEM-SALES_UNIT_ISO = LS_LIPS_SPLIT-MEINS. "被拆分DN基本单位 "fei
LS_BATCH_ITEM-FACT_UNIT_NOM = LS_LIPS_SPLIT-UMVKZ. "销售数量转换成SKU的分子(因子)
LS_BATCH_ITEM-FACT_UNIT_DENOM = LS_LIPS_SPLIT-UMVKN. "销售数量转换为 SKU 的值(分母)
APPEND LS_BATCH_ITEM TO LT_BATCH_ITEM.
LS_BATCH_CONTROL-DELIV_NUMB = LV_VBELN.
LS_BATCH_CONTROL-DELIV_ITEM = LS_LIPS_SPLIT-POSNR.
LS_BATCH_CONTROL-DEL_ITEM = 'X'.
APPEND LS_BATCH_CONTROL TO LT_BATCH_CONTROL.
ENDLOOP.
ENDIF.
ENDLOOP.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
HEADER_DATA = LS_HEADER_DATA
HEADER_CONTROL = LS_HEADER_CONTROL
DELIVERY = LV_VBELN
TECHN_CONTROL = TECHN_CONTROL
TABLES
ITEM_DATA = LT_BATCH_ITEM
ITEM_CONTROL = LT_BATCH_CONTROL
RETURN = LT_RETURN_TAB
EXCEPTIONS
ERROR_MESSAGE = 1
OTHERS = 2.
LOOP AT LT_RETURN_TAB INTO LS_RETURN_TAB WHERE TYPE CA 'EAX'.
LV_FLAG = 'X'.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
MSGID = LS_RETURN_TAB-ID
MSGNR = LS_RETURN_TAB-NUMBER
MSGV1 = LS_RETURN_TAB-MESSAGE_V1
MSGV2 = LS_RETURN_TAB-MESSAGE_V2
MSGV3 = LS_RETURN_TAB-MESSAGE_V3
MSGV4 = LS_RETURN_TAB-MESSAGE_V4
IMPORTING
MESSAGE_TEXT_OUTPUT = LV_MESSAGE.
CONCATENATE LV_ALL_MESSAGE LV_MESSAGE INTO LV_ALL_MESSAGE.
ENDLOOP.
IF LV_ALL_MESSAGE IS NOT INITIAL .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
IF_STATU = '02'.
IFMSG = LV_ALL_MESSAGE.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ENDIF.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
IF_STATU = '02'.
IFMSG = LV_ALL_MESSAGE.
LV_FLAG = 'X'.
ENDIF.
IF LV_FLAG IS INITIAL .
IF_STATU = '01'.
IFMSG = 'success'.
ENDIF.