货铺QQ群号:834508274
TABLES:LIKP,LIPS.
PARAMETERS:P_VBELN TYPE VBELN_VL.PARAMETERS:P_SERNR TYPE OBJK-SERNR.
DATA:LS_HEADER_DATA LIKE BAPIOBDLVHDRCHG,LS_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCHG,LV_DELIVERY LIKE BAPIOBDLVHDRCHG-DELIV_NUMB.DATA:LT_ITEM_DATA LIKE TABLE OF BAPIOBDLVITEMCHG,LT_ITEM_CONTROL LIKE TABLE OF BAPIOBDLVITEMCTRLCHG,LT_ITEM_SERIAL_NO LIKE TABLE OF BAPIDLVITMSERNO.DATA:LS_ITEM_DATA LIKE BAPIOBDLVITEMCHG,LS_ITEM_CONTROL LIKE BAPIOBDLVITEMCTRLCHG,LS_ITEM_SERIAL_NO LIKE BAPIDLVITMSERNO.
DATA:LT_RETURN TYPE TABLE OF BAPIRET2.DATA:LT_LIPS TYPE TABLE OF LIPS.DATA:LS_LIPS TYPE LIPS.DATA:LT_SER01 TYPE TABLE OF SER01.DATA:LS_SER01 TYPE SER01.DATA:LT_OBJK TYPE TABLE OF OBJK.DATA:LS_OBJK TYPE OBJK.
"交货单信息SELECT * FROM LIPS INTO TABLE LT_LIPS WHERE VBELN = P_VBELN.
"交货单系列号的凭证抬头SELECT * FROM SER01 INTO TABLE LT_SER01 WHERE LIEF_NR = P_VBELN.
"交货单对应的物料+序列号IF LT_SER01[] IS NOT INITIAL.SELECT * FROM OBJK INTO TABLE LT_OBJK FOR ALL ENTRIES IN LT_SER01WHERE OBKNR = LT_SER01-OBKNR.ENDIF.
CLEAR LT_ITEM_SERIAL_NO[].
"填写物料+序列号LOOP AT LT_LIPS INTO LS_LIPS.
READ TABLE LT_SER01 INTO LS_SER01WITH KEY LIEF_NR = LS_LIPS-VBELNPOSNR = LS_LIPS-POSNR.
CHECK SY-SUBRC = 0.
LOOP AT LT_OBJK INTO LS_OBJK WHERE OBKNR = LS_SER01-OBKNR.
CLEAR LS_ITEM_SERIAL_NO.LS_ITEM_SERIAL_NO-DELIV_NUMB = LS_LIPS-VBELN.LS_ITEM_SERIAL_NO-ITM_NUMBER = LS_LIPS-POSNR.LS_ITEM_SERIAL_NO-SERIALNO = LS_OBJK-SERNR.
APPEND LS_ITEM_SERIAL_NO TO LT_ITEM_SERIAL_NO[].ENDLOOP.
ENDLOOP.
*&最后一个行项目上 数量加一,加一个物料 和序列号LS_ITEM_SERIAL_NO-DELIV_NUMB = LS_LIPS-VBELN.LS_ITEM_SERIAL_NO-ITM_NUMBER = LS_LIPS-POSNR.LS_ITEM_SERIAL_NO-SERIALNO = P_SERNR.
APPEND LS_ITEM_SERIAL_NO TO LT_ITEM_SERIAL_NO[].
"修改交货单数量CLEAR LS_ITEM_DATA.CLEAR LT_ITEM_DATA[].LS_LIPS-LFIMG = LS_LIPS-LFIMG + 1.
LS_ITEM_DATA-DELIV_NUMB = LS_LIPS-VBELN.LS_ITEM_DATA-DELIV_ITEM = LS_LIPS-POSNR .LS_ITEM_DATA-MATERIAL = LS_LIPS-MATNR .LS_ITEM_DATA-DLV_QTY = LS_LIPS-LFIMG .LS_ITEM_DATA-DLV_QTY_IMUNIT = LS_LIPS-LFIMG.LS_ITEM_DATA-FACT_UNIT_DENOM = 1.LS_ITEM_DATA-FACT_UNIT_NOM = 1.LS_ITEM_DATA-SALES_UNIT = 'EA'.LS_ITEM_DATA-BASE_UOM = 'EA'.
APPEND LS_ITEM_DATA TO LT_ITEM_DATA.
CLEAR LS_ITEM_CONTROL.CLEAR LT_ITEM_CONTROL[].LS_ITEM_CONTROL-DELIV_NUMB = LS_LIPS-VBELN..LS_ITEM_CONTROL-DELIV_ITEM = LS_ITEM_DATA-DELIV_ITEM.LS_ITEM_CONTROL-CHG_DELQTY = 'X'.
APPEND LS_ITEM_CONTROL TO LT_ITEM_CONTROL.
LV_DELIVERY = P_VBELN.LS_HEADER_DATA-DELIV_NUMB = P_VBELN.LS_HEADER_CONTROL-DELIV_NUMB = P_VBELN.
CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'EXPORTINGHEADER_DATA = LS_HEADER_DATAHEADER_CONTROL = LS_HEADER_CONTROLDELIVERY = LV_DELIVERYTABLES ITEM_DATA = LT_ITEM_DATAITEM_CONTROL = LT_ITEM_CONTROLITEM_SERIAL_NO = LT_ITEM_SERIAL_NO RETURN = LT_RETURN .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGWAIT = 'X'.