Get to know the detail analysis process of batch determination program.
The main Function Module of batch determination is VB_BATCH_DETERMINATION
1) Open Function Module VB_BATCH_DETERMINATION in SE37, press "SET/DELETE Breakpoint" button to set session breakpoint.
2) Manually do the batch determination or recreate the problem in cetain transaction code to trigger automatic batch determination.
PS: If you hope to analysis the problem on-line for the automatic background batch determination process, then you need to find out the following part in FM VB_BATCH_DETERMINATION:
*-- Hellsteuerung bei keinem Ergebnis
PERFORM check_dialog. <<<<<<< Set a breakpoint here.
*-- Ergebnistabelle im Dialog anzeigen
When the program runs to the form check_dialog press F5 to go into this form and you will see the following:
CHECK NOT no_dialog IS INITIAL.
Double click the parameter no_dialog to show its content, it should be X if the batch determination is called in background, you need to change it into BLANK during debug and press F8 to continue, then you will reach the main screen of batch determination to analysis the batch determination process on-line.
Main Program Analysis:
Main Program SAPLV01F Source code of LV01FU01
PERFORM get_kondition USING space
** This form is used to find out the batch determination condition record according to the importing data of the FUNCTION, that is the batch search strategy releated information.
** This form is used to decide the searching sequence of batch determination, it will change the the content of internal table 'xfs', normally the content of this internal table is like below:
1 DB <<<Select the batch which has stocks from the database according to the selection condition.
2 CL <<<Filter the selected batch according to the batch search strategy, delete the not qualified batch.
3 AC <<<ATP(Availability Check) is done for the batch that is picked out, delete the batch that has not enough stock.
LOOP AT xfs. *---- Klassenselektion
IF xfs-type EQ cl AND cl_done IS INITIAL.
cl_done = x.
last_flow = xfs-type.
** Select the batch according to the characteristic value in the selection class of the search strategy, return internal table 'ycl_mchb'.
IF xfs-type EQ db AND db_done IS INITIAL.
db_done = x.
last_flow = xfs-type.
** Direct pick up the corresponding batch from the database table, return internal table 'ydb_mchb'.
IF xfs-type EQ ac AND ac_done IS INITIAL.
ac_done = x. last_flow = xfs-type.
**Availability check for the selected batch, return internal table 'yac_mchb'
**Basic batch determination is carried out in these three forms, normally volumn of data entries in the internal tables is ydb_mchb>ycl_mchb>yac_mchb
*-- Ergebnistabelle sortieren IF sort_done IS INITIAL.
sort_done = x.
**Sorting of the selected batches is done in this form, it follows the sorting rule defined in the batch search strategy.
*-- Ergebnistabelle Menge verteilen
IF dist_done IS INITIAL.
PERFORM lock_atp_batch USING 0.
dist_done = x.
**Quantities are assigned to the selected and sorted batches here.
*-- Hellsteuerung bei keinem Ergebnis
**This form controls if the batch determination is run on-line or background, you can change the parameter inside to change the running mode of batch determination, I have mentioned this earlier above.
There are 3 main Subroutines (FORMS) that executes specific program functionalities:
1. FORM select_batch_cl - Sort and restrict according to the selection criteria;
2. FORM select_batch_db - Select all the available batches in stock;
3. FORM select_batch_ac - Check the stock according to the availability check settings.
If you check in the source code, you’ll see that the execution sequence is not exactly the same as showed above. It happens because internal table XFS is the one that stores the execution sequence. In specific scenarios, it is possible to execute select_batch_ac before select_batch_cl.
The program flow inside the forms is much more complex, but you can see which part is having problem base on the content in the returned internal table. After that you can check the settings and data foreground to find out where the problem is without debugging deeply to analysis the program flow. You need to aware that in FORM select_batch_cl, the system will check the status of the batch classification also except checking the selection class, if the sttus is locked or incompleted then the batch will be filtered also. (Batch classification status:Open the batch in MSC3N, goto classification tab, there is a button with a pencil and checkmark, click it, the status screen will popup.)
The first routine executed is to select the batches. It will select all batches available, it does not consider the batch stock but select all available batches according to the restrictions imposed by the business (sales order, process order, goods issue, etc). The parameters used to read the batches are mainly the material number (MATNR), plant (WERKS) and storage location (SLOC).
The internal function used to read the batches is VB_BATCH_READ.
If we check the source code in detail, we can see that there are many different SELECT statements for transparent table MCHB and also from V_CF_MCHB which is a view that contains three tables (MCHB, MCHA and MCH1).
It’s not difficult to conclude that performance issues can happen if table MCHB have a huge amount of data and the SELECT statements in VB_BATCH_READ do not use more parameters to restrict the selection.
This is the reason why we always recommend executing the archiving of the MCHB old records. It will improve the performance significantly. The object used to archive is MM_SPSTOCK (transaction SARA).
It’s also possible to create our own logic to select the batches. It can be achieved using BADI VB_BD_SELECTION. The methods PRESELECT_STOCKS and PRESELECT_BATCHES can be used to create a custom code to select only the batches wanted. It’s possible to suppress the VB_BATCH_READ if the BADI is active, it facilitate if a specific batch selection must be done.
The internal table that stores the result of the batch selection is YDB_MCHB.
After the batch selection, the batch search strategy should “decide” which batches are selected according to characteristics defined in the classification data. If the batch is not classified (classification tab in batch master), it won’t be selected. So, it is very important to classify the batches many users forgot to do it.
The function modules that select the class and the characteristics don’t belong to the Batch Determination (LO-BM) itself but belong to classification (CA-CL). There are 2 key functions, one select the class and characteristics assigned to a batch (CTMS_DDB_HAS_VALUES) and the other select the values (CUSL_BATCHES_SELECTION).
It’s also possible to create your own logic for the selection criteria using BADI VB_BD_SELECTION_CRITERIA or the userexit EXIT_SAPLV01F_001. I always recommend using BADIs as Userexits have some particular problems, specially because the “freedom” we have to change the variable and internal tables resulting, sometimes, in corrupt entries saved in the database and incorrect data displayed. In the following screen, you can see the source code where both can be chosen.
The internal table that stores the result of the batches after the selection criteria is YCL_MCHB.
If the Availability check is active, it will restrict the batches according to its customizing. If it’s not active, it will only exclude the batches with no stock and continue the VB_BATCH_DETERMINATION execution.
The Function module AVAILABILITY_CHECK_CONTROLER is the key for the availability check. If the function is executed, it means that availability check is active. We can check the result in internal table XATPCS, which stores the available quantity calculated inside of availability check. The field that must be checked is VMENG, if it’s zero, there is no available stock for a specific batch. It can also be checked in transaction CO09.
After the execution of AVAILABILITY_CHECK_CONTROLLER, the batches with stock zero will be excluded from the final result.
The table that stores the result of the batch selection after the availability check is YAC_MCHB. This internal table is the one that will contain the final result of the batch selection. It will not contain the batches sorted yet. The sort happens in Form SORT_BATCH.
Keep in mind that this document covers the most common batch determination scenarios, there are specific scenarios, for example, in Warehouse Management which uses specific routines and restrictions that are not covered by this document.
Batch Determination Syntax
The batch determination function is usually called using the following logic:
… call function ‘VB_BATCH_DETERMINATION’ exporting
i_komkh = komkh
i_komph = komph
x_bdcom = bdcom
x_bdcom = bdcom
i_bdbatch = ybdbatch
e_bdbatch = xbdbatch
i_mdva = ymdva
e_mdva = xmdva
i_atpcsx = yatpcs
e_atpcsx = xatpcs
* OTHERS = 0.
NO_MATERIAL = 1
NO_PLANT = 2
If the returned content in internal table 'xbdbatch' is correct, then it means the batch determination has been carried out successfully without problem, the problem should happen in the follow up process.
Batch determination may carried out together with Stock Determination:
Customizing for Stock Determination: OLMB
Function Module for Stock Determination: BF_STOCK_DETERMINATION
Stock determination is called within batch determination at: FORM select_batch_db
If the warehouse management is used, then the batch determination may happen in FUNCTION 'L_PPIM_BATCH_DETERMINATION_INT' but not in FUNCTION 'VB_BATCH_DETERMINATION'.