拣配 :WS_DELIVERY_UPDATE
发货过账:BAPI_OUTB_DELIVERY_CONFIRM_DEC,过账后无法使用VL09冲销,冲销时报错,分散系统无法冲销。解决方法是BAPI过账后,清空LIKP-VLSTK 。
发货过账VL02N,冲销:VL09
FUNCTION ZSNSDFM_WMS001.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IT_INPUT) TYPE ZSNSDTWMS001
*" EXPORTING
*" REFERENCE(ET_OUTMESSAGE) TYPE ZSNSDTWMOUT
*"----------------------------------------------------------------------
DATA: LS_VBKOK TYPE VBKOK,
LV_DELIVERY TYPE LIKP-VBELN,
LV_VBELN TYPE LIKP-VBELN,
LV_ZPOSNR TYPE LIPS-POSNR,
LV_MENGE TYPE EKPO-MENGE,
LS_VBPOK TYPE VBPOK,
LT_VBPOK TYPE TABLE OF VBPOK,
LS_PROT TYPE PROTT,
LT_PROT TYPE TABLE OF PROTT.
DATA LT_RETURN TYPE BAPIRET2 .
DATA LV_MATNR TYPE N LENGTH 18 .
DATA ES_OUTMESSAGE TYPE ZSNSDSWMOUT .
LOOP AT IT_INPUT INTO DATA(LS_ITEMS).
SELECT SINGLE * FROM LIKP INTO @DATA(LS_LIKP) WHERE VBELN = @LS_ITEMS-ZDELIVERY-VBELN .
CLEAR ES_OUTMESSAGE .
ES_OUTMESSAGE-VBELN = LS_ITEMS-ZDELIVERY-VBELN .
"检查发货单是否已过账
IF LS_LIKP-WBSTK = 'C'.
ES_OUTMESSAGE-TYPE = 'E'.
ES_OUTMESSAGE-MESSAGE = '交货单已过账,请检查!'.
APPEND ES_OUTMESSAGE TO ET_OUTMESSAGE .
ENDIF.
CHECK LS_LIKP-WBSTK NE 'C' .
"交货单拣配
CLEAR:LV_MENGE,LV_ZPOSNR,LV_VBELN .
LV_VBELN = LS_ITEMS-ZDELIVERY-VBELN .
LV_DELIVERY = LV_VBELN.
LOOP AT LS_ITEMS-ZITEM INTO DATA(LS_ITEM).
LS_VBKOK = VALUE #( VBELN_VL = LV_VBELN
WADAT_IST = SY-DATUM
KZWAD = 'X' ).
LV_DELIVERY = LV_VBELN.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = LS_ITEM-MATNR
IMPORTING
OUTPUT = LV_MATNR.
LS_VBPOK = VALUE #( VBELN_VL = LV_VBELN
POSNR_VL = LS_ITEM-POSNR
VBELN = LV_VBELN
POSNN = LS_ITEM-POSNR
CHARG = LS_ITEM-CHARG
LGORT = LS_ITEM-LGORT
MATNR = LV_MATNR
TAQUI = 'X'
LIANP = 'X'
* LFIMG = LS_ITEM-LFIMG
* LGMNG = LS_ITEM-LFIMG
PIKMG = LS_ITEM-LFIMG )
.
APPEND LS_VBPOK TO LT_VBPOK.
ENDLOOP.
TRY .
"拣配
CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
VBKOK_WA = LS_VBKOK
DELIVERY = LV_DELIVERY
UPDATE_PICKING = 'X'
* commit = 'X'
* IMPORTING
* EF_ERROR_ANY_0 = LV_XFELD
TABLES
VBPOK_TAB = LT_VBPOK[]
PROT = LT_PROT.
CATCH CX_ROOT INTO DATA(LO_ROOT).
ENDTRY.
DELETE LT_PROT WHERE MSGTY <> 'E'
AND MSGTY <> 'A'.
IF LT_PROT[] IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
"交货单过账
PERFORM VL02N_POST TABLES LS_ITEMS-ZITEM
USING LV_VBELN
CHANGING ES_OUTMESSAGE .
APPEND ES_OUTMESSAGE TO ET_OUTMESSAGE .
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT LT_PROT INTO LS_PROT.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
INTO DATA(LV_MSGTX).
ES_OUTMESSAGE-MESSAGE = ES_OUTMESSAGE-MESSAGE && LV_MSGTX.
ENDLOOP.
ES_OUTMESSAGE-TYPE = 'E'.
APPEND ES_OUTMESSAGE TO ET_OUTMESSAGE .
ENDIF.
ENDLOOP.
ENDFUNCTION.
FORM VL02N_POST TABLES LT_ITEMS TYPE ZSNSDTWMS001_M
USING PV_VBELN
CHANGING ES_OUTMESSAGE TYPE ZSNSDSWMOUT .
DATA: LS_HEADER_DATA TYPE BAPIOBDLVHDRCON,
LS_HEADER_CONTROL TYPE BAPIOBDLVHDRCTRLCON,
LV_DELIVERY TYPE BAPIOBDLVHDRCON-DELIV_NUMB,
LS_RETURN TYPE BAPIRET2,
LT_RETURN TYPE TABLE OF BAPIRET2,
LS_EXTENSION2 TYPE BAPIEXT,
LT_EXTENSION2 TYPE TABLE OF BAPIEXT.
DATA: LT_IPK LIKE TABLE OF /SPE/BAPIOBDLVITEMCONF WITH HEADER LINE,
LT_HDL LIKE TABLE OF BAPIDLVDEADLN WITH HEADER LINE.
DATA LT_BAPIDLVHDUNSERNO TYPE STANDARD TABLE OF /SPE/BAPIOBDLVITEM_SKU WITH HEADER LINE.
LS_HEADER_DATA-DELIV_NUMB = PV_VBELN.
LS_HEADER_CONTROL-DELIV_NUMB = PV_VBELN.
LS_HEADER_CONTROL-POST_GI_FLG = 'X'.
LS_HEADER_CONTROL-DELIV_DATE_FLG = 'X'.
LS_HEADER_CONTROL-GDSI_DATE_FLG = 'X'.
LV_DELIVERY = PV_VBELN.
"指定库存地点
LOOP AT LT_ITEMS INTO DATA(LS_ITEM).
CLEAR LT_IPK .
LT_IPK-DELIV_NUMB = PV_VBELN.
LT_IPK-DELIV_ITEM = LS_ITEM-POSNR.
LT_IPK-STGE_LOC = LS_ITEM-LGORT.
APPEND LT_IPK.
ENDLOOP.
"查 HEADER_DEADLINES 说明得到下面提示
*- WSHDRLFDAT Delivery date
*- WSHDRWADAT Goods issue date (planned)
*- WSHDRWADTI Goods issue date (actual)
*- WSHDRLDDAT Loading date
*- WSHDRTDDAT Transportation planning date
*- WSHDRKODAT Picking date
CLEAR LT_HDL .
LT_HDL-DELIV_NUMB = PV_VBELN.
LT_HDL-TIMETYPE = 'WSHDRWADTI'. "实际过账日期
LT_HDL-TIMESTAMP_UTC = SY-DATUM .
APPEND LT_HDL.
CLEAR LT_HDL .
LT_HDL-DELIV_NUMB = PV_VBELN.
LT_HDL-TIMETYPE = 'WSHDRWADAT'. "计划日期
LT_HDL-TIMESTAMP_UTC = SY-DATUM .
APPEND LT_HDL.
CLEAR: LS_EXTENSION2.
LS_EXTENSION2-FIELD = 'BUDAT'.
LS_EXTENSION2-VALUE = SY-DATUM.
LS_EXTENSION2-TYPE = 'DATS'.
LS_EXTENSION2-LENGTH = 8.
APPEND LS_EXTENSION2 TO LT_EXTENSION2.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CONFIRM_DEC'
EXPORTING
HEADER_DATA = LS_HEADER_DATA
HEADER_CONTROL = LS_HEADER_CONTROL
DELIVERY = LV_DELIVERY
TABLES
ITEM_DATA_SPL = LT_IPK[]
HEADER_DEADLINES = LT_HDL
EXTENSION2 = LT_EXTENSION2
RETURN = LT_RETURN.
DELETE LT_RETURN WHERE TYPE <> 'E'
AND TYPE <> 'A'.
IF LT_RETURN IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
WAIT UP TO 1 SECONDS.
UPDATE LIKP SET VLSTK = ''
ANZPK = '0'
WHERE VBELN = PV_VBELN.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ES_OUTMESSAGE-VBELN = PV_VBELN .
ES_OUTMESSAGE-TYPE = 'S'.
ES_OUTMESSAGE-MESSAGE = '交货单过账成功'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ES_OUTMESSAGE-VBELN = PV_VBELN .
LOOP AT LT_RETURN INTO LS_RETURN.
ES_OUTMESSAGE-MESSAGE = ES_OUTMESSAGE-MESSAGE && LS_RETURN-MESSAGE.
ENDLOOP.
ES_OUTMESSAGE-TYPE = 'E'.
ENDIF.
ENDFORM .
过账后无法冲销增强实施
增强点:LE_SHP_DELIVERY_PROC
method:CHANGE_DELIVERY_HEADER
* 交货单过账时,需要通过增强清空LIKP-VLSTK字段,否则无法冲销
EXPORT p1 = PV_VBELN TO MEMORY ID 'ZYKSDFM015'.
IMPORT p1 = lv_vbeln FROM MEMORY ID 'ZYKSDFM015'.
IF cs_likp-vbeln EQ lv_vbeln.
CLEAR: cs_likp-vlstk.
ENDIF.