Skip to Content
0
Jan 20, 2021 at 01:49 PM

Remove batch number on delivery. Maybe using BAPI_OUTB_DELIVERY_CHANGE / WS_DELIVERY_UPDATE_2

217 Views

I need to remove the batch number (LIPS-CHARG) on the delivery item and tried with BAPI_OUTB_DELIVERY_CHANGE without success. I can change the delivery quantity (LIPS-LFIMG) correctly with this BAPI and change the picking number (LIPS-PKIMG) with WS_DELIVERY_UPDATE_2, but can't remove the batch number.

Does someone already remove the batch number? Don't need to use this BAPI, can be another one. I just need to remove the batch in any way.

The following code works to change the delivery quantity and picking quantity. At a certain moment, I change picking quantity to zero and at this moment I need to remove the batch number.

"&**** Begin structures BAPI_OUTB_DELIVERY_CHANGE *******
ls_header_data-deliv_numb     = p_vbeln.
ls_header_control-deliv_numb  = p_vbeln.
  
APPEND INITIAL LINE TO lt_item_data ASSIGNING FIELD-SYMBOL(<ls_item_data>).

<ls_item_data>-deliv_numb       = p_vbeln.
<ls_item_data>-deliv_item       = lv_posnn.
<ls_item_data>-material         = <ls_alv>-matnr. 
<ls_item_data>-batch            = <ls_alv>-charg. 
<ls_item_data>-hieraritem       = <ls_lips>-posnr.
<ls_item_data>-usehieritm       = '1'. 
<ls_item_data>-dlv_qty          = lv_delivery_qtd. "my delivery quantity
<ls_item_data>-dlv_qty_imunit   = lv_delivery_qtd. "my delivery quantity
<ls_item_data>-fact_unit_nom    = <ls_lips>-umvkz.
<ls_item_data>-fact_unit_denom  = <ls_lips>-umvkn.
<ls_item_data>-sales_unit       = <ls_lips>-vrkme.

APPEND INITIAL LINE TO lt_item_control ASSIGNING FIELD-SYMBOL(<ls_item_control>).

<ls_item_control>-deliv_numb = p_vbeln.
<ls_item_control>-deliv_item = lv_posnn.
<ls_item_control>-chg_delqty = 'X'.
"&**** End structures BAPI_OUTB_DELIVERY_CHANGE *******

CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
EXPORTING
  header_data    = ls_header_data
  header_control = ls_header_control
  delivery       = p_vbeln
TABLES
  item_data      = lt_item_data
  item_control   = lt_item_control
  return         = lt_return.
 
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. 

  
"&**** Begin structures WS_DELIVERY_UPDATE_2 *******
APPEND INITIAL LINE TO lt_vbpok ASSIGNING FIELD-SYMBOL(<ls_vbpok>).
<ls_vbpok>-vbeln_vl = <ls_lips>-vbeln.                
<ls_vbpok>-posnr_vl = <ls_lips>-posnr.                
<ls_vbpok>-vbeln    = <ls_lips>-vgbel.                
<ls_vbpok>-posnn    = <ls_lips>-vgpos.                
<ls_vbpok>-matnr    = <ls_lips>-matnr.
<ls_vbpok>-werks    = <ls_lips>-werks.
<ls_vbpok>-umvkz    = <ls_lips>-umvkz.                
<ls_vbpok>-umvkn    = <ls_lips>-umvkn.                
<ls_vbpok>-gewei    = <ls_lips>-gewei.
<ls_vbpok>-charg    = <ls_alv>-charg.
<ls_vbpok>-pikmg    = lv_picking_qtd.   "my picking quantity

ls_vbkok-vbeln_vl = <ls_lips>-vbeln.               
ls_vbkok-vbtyp_vl = 'J'.                           
ls_vbkok-komue    = 'X'.                           
ls_vbkok-gewei    = <ls_lips>-gewei.
ls_vbkok-anzpk    = lv_anzpk.
ls_vbkok-kzapk    = 'X'.
"&**** End structures WS_DELIVERY_UPDATE_2 *******

CALL FUNCTION 'WS_DELIVERY_UPDATE_2'
EXPORTING
    vbkok_wa                  = ls_vbkok
    delivery                  = p_vbeln
    synchron                  = abap_true
    update_picking            = abap_true
    nicht_sperren_1           = abap_true
    commit                    = abap_false
    if_error_messages_send    = abap_false
IMPORTING
    ef_error_any              = ls_error-any
    ef_error_in_item_deletion = ls_error-in_item_deletion
    ef_error_in_pod_update    = ls_error-in_pod_update
    ef_error_in_interface     = ls_error-in_interface
    ef_error_in_goods_issue   = ls_error-in_goods_issue
    ef_error_in_final_check   = ls_error-in_final_check
    ef_error_partner_update   = ls_error-partner_update
    ef_error_sernr_update     = ls_error-sernr_update
TABLES
    vbpok_tab                 = lt_vbpok.
    
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.