简单demo,交货单数量 1,然后维护上序列号(有的公司没有启用序列号就不需要了)
REPORT zdemo_vl02n. |
TABLES:likp,lips. |
PARAMETERS:p_vbeln TYPE vbeln_vl. |
PARAMETER: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_ser01 |
WHERE obknr = lt_ser01-obknr. |
ENDIF. |
CLEAR lt_item_serial_no[]. |
"填写物料 序列号 |
LOOP AT lt_lips INTO ls_lips. |
READ TABLE lt_ser01 INTO ls_ser01 |
WITH KEY lief_nr = ls_lips-vbeln |
posnr = 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' |
EXPORTING |
header_data = ls_header_data |
header_control = ls_header_control |
delivery = lv_delivery |
TABLES |
* HEADER_PARTNER = |
* HEADER_PARTNER_ADDR = |
* HEADER_DEADLINES = |
item_data = lt_item_data |
item_control = lt_item_control |
item_serial_no = lt_item_serial_no |
* SUPPLIER_CONS_DATA = |
* EXTENSION1 = |
* EXTENSION2 = |
return = lt_return |
* TOKENREFERENCE = |
* ITEM_DATA_SPL = |
* COLLECTIVE_CHANGE_ITEMS = |
* NEW_ITEM_DATA = |
* NEW_ITEM_DATA_SPL = |
* NEW_ITEM_ORG = |
* ITEM_DATA_DOCU_BATCH = |
. |