Skip to Content
Author's profile photo umar jawid ahmed syed

Creating Multiple batches for a Production order


The company uses production orders to convert industrial materials into commercial materials which are both handled in batches. Each batch represents a physical unit which usually contains (say) 100 PCE of a material.

A production order in this scenario should be able to create multiple batches (of commercial material), and number of batches (of commercial material) equal to the number of components used in the production order and it was also required to inherit the batch characteristics from the industrial materials batches (component material batches) to commercial materials batches.


Currently, SAP is not able to create multiple batches within a production order, but as a default setup the production order can create one batch for all the components used in the production order creation. And SAP is also not able to inherit the meterial batch characteristics into the new created batches.


Make sure the automatic batch creation setting in Production Scheduling profile has been turned-off so that the batch is created only through the enhancement framework. (this is customizing setting and is to be made by Functional consultant)

Solution proposed:

We can create batches for production order while creation/Change/Release/Confirmation of production order, the first step is to decide where to create the batches. The option for me was, to create the batches while production order confirmation because of the fact that the production order data ( like production order number and other related data) is almost correct and available in the tables at the point of confirmation.

The second step is to create a ztable in database to store these batches because there is no standard table in SAP that can accomodate multiple batches for a production order. Using this ztable we can relate the batches to their respective production orders.

So to begin with we will create table ‘ZPROD_BATCHES’ in SAP with the following fields.


Next we create an enhancement in CO15 to create multiple batches. CO15 is used for Production order confirmation. This T-code uses function module CO_ZV_ORDER_POST.

I used Implicit enhancement spot at the end of function module CO_ZV_ORDER_POST see below screenshot for reference. The idea behind using an implicit enhancement at the end of FM is to ensure that the batches are not created if something goes worng with the confirmation thus making sure that the multiple batches are created only once and that too if the production order confirmation is successful.


Note: This FM is also used by other production order transactions so make sure you build a check on SY-TCODE = ‘CO15’ and implementing this enhancement will effect globally so also make sure to add additional checks on Sales Org or Plant.

At this point the relevant production order data is available in structure “CAUFVD” but the component data is not available so using the field RSNUM in CAUFVD we fetch the relevant component data of the production order into an internal table ‘IT_RESB’ as below.

          SELECT * FROM resb INTO TABLE it_resb WHERE rsnum = caufvdrsnum.

Now the requirement is to create multiple commercial material batches and

     number of commercial material batches (Production order batches) = number of component batches.

so after the select from RESB we now have all the components of the production order and their relevant information in internal table IT_RESB. Looping on IT_RESB and creating one batch for every loop will gives us a batch for every component, thus satisfying the requirement number of commercial material batches (Production order batches) = number of component batches. while creating the production order batches also inherit the batch characteristics of the component batches. below is the pseudocode for the same.

The code can differ from one system to another, so i am not posting the exact code here. This will only be a pseudocode so please do your data declarations and error handling. Cannot answer to questions regarding the usage of the BAPI’s so please refer to the online documentation and examples on how to use the mentioned BAPI’s.

******Start of implementation********

LOOP AT it_resb INTO wa_resb.


* Relevant code handling for calling ‘BAPI_BATCH_CREATE’






                  batch                      = lv_batch.

* Once the batch is created keep adding (appending) the newly created batches (returned by Bapi_Batch_Create) along with the relevant production order and component information to an internal table ‘IT_ZPROD_BATCHES’ for every loop (as below).

     wa_zprod_batches-mandt = sy-mandt.

     wa_zprod_batches-aufnr = caufvd-aufnr.             ” Production order number

     wa_zprod_batches-rspos = wa_resb-rspos.           ” Component item number

     wa_zprod_batches-charg = lv_batch.                   ” New batch created

     wa_zprod_batches-werks = caufvd-werks.           “Production order plant

     wa_zprod_batches-matnr = caufvd-plnbez.          ” Production order material

     wa_zprod_batches-bdmng = wa_resb-bdmng.      ” Component quantity

     wa_zprod_batches-meins = wa_resb-meins.         ” Componenet UOM

     wa_zprod_batches-erdat = sy-datum.

     APPEND  wa_zprod_batches TO it_zprod_batches.



* Now Copy batch characteristics to the created batches.


* Relevant code handling for fetching the batch characteristics of component batches



* Relevant code handling for calling ‘BAPI_OBJCL_CREATE’


   CALL FUNCTION ‘BAPI_OBJCL_CREATE’. ” for creating batch characteristics of the new batch



* at the end of loop you have all the created batches in internal table ‘IT_ZPROD_BATCHES’, now insert them into the database table ZPROD_BATCHES as below.

   INSERT zprod_batches FROM TABLE it_zprod_batches.


********* End Of Implementation**********

At the end, if you can successfully implement this enhancement, you would have created multiple batches for a production order with all the entries stored in a ztable with each production order refering to its corresponding batches.

My next document ‘Automate distribution of quantity in MIGO‘ in specific deals with the process of automation of quantity distribution along with the newly created batch number assignment (to the distributed quantity) while doing Goods Receipt. But in general can be used to distribute the quantity automatically and eliminate the manual steps. Please refer the same to complete the process of implementing ‘Production order with a multiple batches in SAP’.


Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      nicely presented.