Dec 17, 2020

Batch Split in IBD via BAPI_INB_DELIVERY_CHANGE

 Stolen from answers.sap.com

REPORT z_delivery_batch_split.

DATA:header_data LIKE bapiibdlvhdrchg,
     header_control LIKE bapiibdlvhdrctrlchg,
     delivery LIKE bapiibdlvhdrchg-deliv_numb,
     ls_return LIKE bapiret2,
     item_data TYPE TABLE OF bapiibdlvitemchg,
     item_control TYPE TABLE OF bapiibdlvitemctrlchg,
     ls_item_data LIKE bapiibdlvitemchg,
     ls_item_control LIKE bapiibdlvitemctrlchg,
     return TYPE TABLE OF bapiret2 WITH NON-UNIQUE KEY type.

header_data-deliv_numb = '1800005005'.
header_control-deliv_numb = '1800005005'.
delivery = '1800005005'.
ls_item_data-deliv_numb = '1800005005'.
ls_item_data-deliv_item = '900001'.
ls_item_data-material = '000000000020067722'.
ls_item_data-batch = <NEW_BATCH_NUMBER>.
ls_item_data-hieraritem = '000010'.
ls_item_data-usehieritm = '1'.
ls_item_data-dlv_qty = 80.
ls_item_data-dlv_qty_imunit = 80.
ls_item_data-fact_unit_nom = '1'.
ls_item_data-fact_unit_denom = '1'.
ls_item_data-sales_unit = 'EA'.
ls_item_data-base_uom = 'EA'.

APPEND ls_item_data TO item_data.
ls_item_data-deliv_numb = '1800005005'.
ls_item_data-deliv_item = '900002'.
ls_item_data-material = '000000000020067722'.
ls_item_data-batch = <NEW_BATCH_NUMBER>.
ls_item_data-hieraritem = '000010'.
ls_item_data-usehieritm = '1'.
ls_item_data-dlv_qty = 60.
ls_item_data-dlv_qty_imunit = 60.
ls_item_data-fact_unit_nom = '1'.
ls_item_data-fact_unit_denom = '1'.
ls_item_data-sales_unit = 'EA'.
ls_item_data-base_uom = 'EA'.

APPEND ls_item_data TO item_data.
ls_item_control-deliv_numb = '1800005005'.
ls_item_control-deliv_item = '900001'.
ls_item_control-chg_delqty = 'X'.

APPEND ls_item_control TO item_control.
ls_item_control-deliv_numb = '1800005005'.
ls_item_control-deliv_item = '900002'.
ls_item_control-chg_delqty = 'X'.
APPEND ls_item_control TO item_control.

CALL FUNCTION 'BAPI_INB_DELIVERY_CHANGE'
EXPORTING
    header_data = header_data
    header_control = header_control
    delivery = delivery
   * TECHN_CONTROL = TECHN_CONTROL
TABLES
* HEADER_PARTNER = HEADER_PARTNER
* HEADER_PARTNER_ADDR = HEADER_PARTNER_ADDR
* HEADER_DEADLINES = HEADER_DEADLINES
    item_data = item_data
    item_control = item_control
* ITEM_SERIAL_NO = ITEM_SERIAL_NO
* EXTENSION1 = EXTENSION1
* EXTENSION2 = EXTENSION2
    return = return
* TOKENREFERENCE = TOKENREFERENCE
* HANDLING_UNIT_HEADER = HANDLING_UNIT_HEADER
* HANDLING_UNIT_ITEM = HANDLING_UNIT_ITEM
* PARTIAL_GR_OBJECTS = PARTIAL_GR_OBJECTS
.

READ TABLE return
INTO ls_return
WITH TABLE KEY type = 'E'.
IF sy-subrc = 0.
MESSAGE ID ls_return-id TYPE ls_return-type NUMBER ls_return-number WITH s_return-message_v1 ls_return-message_v2
ls_return-message_v3 s_return-message_v4.
ENDIF.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

Dec 12, 2020

How to place Equipment serial numbers into BAPI_PO_CREATE1 from internal number range

For some reasons business requires Material SNs related to equal Equipment number.

In this case you have to make some customizings:

Create new Equipment Category in OIET t-code (SPRO -- Plant Maintenance and Customer Service -- Master Data in Plant Maintenance and Customer Service -- Technical Objects -- Equipment -- Equipment Categories -- Define Number Ranges):


.. then in OIEN (or SPRO: Plant Maintenance and Customer Service -- Master Data in Plant Maintenance and Customer Service -- Technical Objects -- Equipment -- Equipment Categories -- Define Number Ranges) define group and NR for group:

.. assign group with NR to Equipment category:

.. create new serial number profile with equipment category X without warnings in t-code OIS2 (SPRO: Plant Maintenance and Customer Service -- Master Data in Plant Maintenance and Customer Service -- Technical Objects -- Serial Number Management -- Define Serial Number Profiles):

.. then inside the newly created profile define Serialization procedures, where you will generate SN,  with Equipment Requirement = 02 always with equipment: 


Create new material master with SN profile Z001, Serialization Level = 1 Keep equipment number and serial number synchronous:

From now you can assign SN to material numbers in ME21n by clocking the button 

The only problem is you are unable to use the same NR in BAPI_PO_CREATE1 function module.
Because you have to put serial numbers to SERIALNUMBER table parameter from EXTERNAL number range using NUMBER_GET_NEXT fm with EQUI_NR number range object. Else BAPI fals with error:
Equipment number XXXXXXXXXXXX not in external number interval

To resolve the issue you have to create another one Number Range Object (e.g. ZEQUI_NR) and create new EXTERNAL number range with the same values as it's for EQUI_NR internal number range.
Use ZEQUI_NR internal NR in 
NUMBER_GET_NEXT parameters.
For BAPI it will be proper external number.





Batch Split in IBD via BAPI_INB_DELIVERY_CHANGE

 Stolen from answers.sap.com REPORT z_delivery_batch_split. DATA :header_data LIKE bapiibdlvhdrchg,      header_control LIKE bapiibdlvhdr...