Material Batch Determination
In this example, we are trying to find the batch for a material that can be used for a movement. FM used here – VB_BATCH_DETERMINATION.
Points to note:
Movement type is important. So please fill in.
KAPPL and KALSM – These fields make up the rule which will be used to fetch the batch based on quantity.
NODIA – Check this field or you will get a pop-up with the relevant batch info.
E_BDBATCH contains the records of batches to be used. It depends on quantity. So assume if you are using 100 KGs of material and in the system that quantity cannot be met from a single batch, then multiple rows will come. Ideally, you should get the quantity equal to what you entered or less (if there are not enough batched quantities available). If you are getting the list of all available batches then tweak the value of KZVBP.
DATA: ls_komph TYPE komph, ls_bdcom TYPE bdcom, lt_bdbatch TYPE STANDARD TABLE OF bdbatch INITIAL SIZE 0. ls_komph-matnr = material_number ls_komph-werks = plant ls_komph-lgort = storage_location ls_komph-bwart = movement_type ls_bdcom-kappl = 'ME'. ls_bdcom-kalsm = 'YE0001'. ls_bdcom-meins = base_uom ls_bdcom-erfmg = quantity ls_bdcom-erfme = quantity_unit ls_bdcom-mbdat = sy-datum. ls_bdcom-kzvbp = 'L'. ls_bdcom-nolck = abap_true. ls_bdcom-nodia = abap_true. CALL FUNCTION 'VB_BATCH_DETERMINATION' EXPORTING i_komph = ls_komph x_bdcom = ls_bdcom TABLES e_bdbatch = lt_bdbatch EXCEPTIONS no_material = 1 no_plant = 2 no_application = 3 function_not_possible = 4 condition_not_found = 5 classtype_not_found = 6 classtype_not_active = 7 no_base_unit = 8 no_unit = 9 conversion_not_found = 10 conversion_overflow = 11 missing_entry_t156c = 12 conversion_type_invalid = 13 division_by_zero = 14 data_mismatch = 15 material_not_found = 16 no_quantity = 17 invalid_duplicate_batch = 18 OTHERS = 19. IF sy-subrc <> 0. ENDIF.