vl02n 批次拆分

*&---------------------------------------------------------------------*
*& Report  ZVL02N_CHARGE
*&
*&---------------------------------------------------------------------*
*&  先调用 BAPI_OUTB_DELIVERY_CHANGE 对批次进行拆分(前提是 要拆分的 外向交货单 行项目 批次为 空)
*&  然后 调用 WS_DELIVERY_UPDATE 更新 交货数量和拣配数量
*&---------------------------------------------------------------------*

REPORT ZVL02N_CHARGE.


DATA : I_HEADER_DATA LIKE BAPIOBDLVHDRCHG. "Delivery header
DATA : I_HEADER_CONTROL LIKE BAPIOBDLVHDRCTRLCHG. "delivery header control
DATA : I_DELIVERY_NO LIKE BAPIOBDLVHDRCHG-DELIV_NUMB. "deliver number
DATA : I_TECHN_CONTROL LIKE BAPIDLVCONTROL. "TECHN_CONTROL


DATA : I_ITEM_DATA LIKE BAPIOBDLVITEMCHG OCCURS 0 WITH HEADER LINE. "ITEM_DATA delivery item
DATA : I_ITEM_CONTROL LIKE BAPIOBDLVITEMCTRLCHG OCCURS 0 WITH HEADER LINE. "ITEM_CONTROL
DATA : I_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE. "Return



*Set Delivery Header data
I_DELIVERY_NO = '0080000066'.
I_HEADER_DATA-DELIV_NUMB = I_DELIVERY_NO.
I_TECHN_CONTROL-UPD_IND = 'U'.
I_HEADER_CONTROL-DELIV_NUMB = I_DELIVERY_NO.


I_ITEM_DATA-DELIV_NUMB = I_DELIVERY_NO.
I_ITEM_DATA-DELIV_ITEM = '900001'.
I_ITEM_DATA-HIERARITEM = '10'.            "The batch split record below delivery item hierary
I_ITEM_DATA-USEHIERITM = '1'.
I_ITEM_DATA-MATERIAL = 'WY-F-001'.
I_ITEM_DATA-BATCH = '0000000001'.
I_ITEM_DATA-DLV_QTY = 2.

*I_ITEM_DATA-DLV_QTY_IMUNIT = 1000.

I_ITEM_DATA-FACT_UNIT_NOM = 1.
I_ITEM_DATA-FACT_UNIT_DENOM = 1.
APPEND I_ITEM_DATA.
CLEAR I_ITEM_DATA.


I_ITEM_DATA-DELIV_NUMB = I_DELIVERY_NO.
I_ITEM_DATA-DELIV_ITEM = '900002'.       "The batch split record below delivery item hierary
I_ITEM_DATA-HIERARITEM = '10'.
I_ITEM_DATA-USEHIERITM = '1'.
I_ITEM_DATA-MATERIAL = 'WY-F-001'.
I_ITEM_DATA-BATCH = '0000000002'.
I_ITEM_DATA-DLV_QTY = 3.

I_ITEM_DATA-FACT_UNIT_NOM = 1.
I_ITEM_DATA-FACT_UNIT_DENOM = 1.
APPEND I_ITEM_DATA.

CLEAR I_ITEM_DATA.


I_ITEM_CONTROL-DELIV_NUMB = I_DELIVERY_NO.
I_ITEM_CONTROL-DELIV_ITEM = '10'.
I_ITEM_CONTROL-CHG_DELQTY = 'X'.
APPEND I_ITEM_CONTROL.
CLEAR I_ITEM_DATA.



I_ITEM_CONTROL-DELIV_NUMB = I_DELIVERY_NO.
I_ITEM_CONTROL-DELIV_ITEM = '900001'.
I_ITEM_CONTROL-CHG_DELQTY = 'X'.
APPEND I_ITEM_CONTROL.
CLEAR I_ITEM_DATA.



I_ITEM_CONTROL-DELIV_NUMB = I_DELIVERY_NO.
I_ITEM_CONTROL-DELIV_ITEM = '900002'.
I_ITEM_CONTROL-CHG_DELQTY = 'X'.
APPEND I_ITEM_CONTROL.
CLEAR I_ITEM_DATA.



CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
  EXPORTING
    HEADER_DATA    = I_HEADER_DATA
    HEADER_CONTROL = I_HEADER_CONTROL
    DELIVERY       = I_DELIVERY_NO
    TECHN_CONTROL  = I_TECHN_CONTROL
  TABLES
    ITEM_DATA      = I_ITEM_DATA
    ITEM_CONTROL   = I_ITEM_CONTROL
    RETURN         = I_RETURN.
IF SY-SUBRC EQ 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      WAIT = 'X'.
ENDIF.


DATA : I_VBKOK LIKE VBKOK. "Delivery header
DATA : I_VBPOK LIKE VBPOK  OCCURS 0 WITH HEADER LINE. "Delivery Picking
DATA : V_ERROR.


I_VBKOK-VBELN_VL = '0080000066'.
I_VBKOK-WABUC = 'X'. "Post Good Issue Automatic

I_VBPOK-VBELN_VL = I_VBKOK-VBELN_VL. "Delivery NO
I_VBPOK-POSNR_VL = '900001'. "Delivery Item
I_VBPOK-VBELN = '1000000325'. "Sales Order            "You must assign Sales order & Item number
I_VBPOK-POSNN = '10'.       "Sales Order item
I_VBPOK-MATNR = 'WY-F-001'.
I_VBPOK-CHARG =  '0000000001'.
I_VBPOK-LFIMG = 5.     "Actual quantity delivered (in sales units)
I_VBPOK-LGMNG = 5.     "Actual quantity delivered in stockkeeping units
APPEND I_VBPOK.


I_VBPOK-VBELN_VL = I_VBKOK-VBELN_VL. "Delivery NO
I_VBPOK-POSNR_VL = '900002'. "Delivery Item
I_VBPOK-VBELN = '1000000325'. "Sales Order
I_VBPOK-POSNN = '10'.       "Sales Order item
I_VBPOK-MATNR = 'WY-F-001'.
I_VBPOK-CHARG =  '0000000002'.
I_VBPOK-LFIMG = 5.     "Actual quantity delivered (in sales units)
I_VBPOK-LGMNG = 5.     "Actual quantity delivered in stockkeeping units

APPEND I_VBPOK.


CALL FUNCTION 'WS_DELIVERY_UPDATE'
  EXPORTING
    VBKOK_WA                  = I_VBKOK
    DELIVERY                  = I_VBKOK-VBELN_VL
    UPDATE_PICKING            = 'X'         "Update Picking data
  IMPORTING
    EF_ERROR_IN_GOODS_ISSUE_0 = V_ERROR
  TABLES
    VBPOK_TAB                 = I_VBPOK.


IF SY-SUBRC EQ 0.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

endif.

你可能感兴趣的:(SAP)