How to add customer-specific fields into MB52
It is the common requirement to extend standard reporting programs with additional information.
Here is the example of extending Transaction MB52 List of Warehouse Stocks on Hand ( Program RM07MLBS; Component MM-IM Inventory Management ) by a new field Supplier batch. The field is used as a unique identification number for tracking purposes and is usually received from a supplier before the Goods receipt step).
Important note: Based on the customizing the batch number can be unique at Client, Plant or Material level. Dependent on it, the source table to retrieve batch master attributes will be different.
To fulfill the requirement we can use the predefined enhancements spots inside the program RM07MLBS:
- Extend the field structure ( type structure bestand, RM07MLBS) with the new columns: ENHANCEMENT–POINT ehp604_rm07mlbs_03 SPOTS es_rm07mlbs STATIC .
- Extend the routing by adding a field into the field catalog and filling the newly added fields. Progam RM07MLBS, routine list_output. Use the ENHANCEMENT-SECTION rm07mlbs_09 SPOTS es_rm07mlbs.
TRY. * Adding a field into the Field catalog INSERT VALUE #( fieldname = 'LICHA' tabname = 'BESTAND' ref_fieldname = 'LICHA' ref_tabname = 'MCH1' col_pos = fieldcat[ fieldname = 'CHARG' ]-col_pos ) INTO TABLE fieldcat. * Selecting materials with batches DATA(lt_batches_query) = CORRESPONDING tt_mcha( bestand ). * Getting batch attributes SELECT matnr, charg, licha INTO TABLE @DATA(lt_batch_master) FROM mch1 FOR ALL ENTRIES IN @lt_batches_query WHERE matnr = @lt_batches_query-matnr AND charg = @lt_batches_query-charg and lvorm = ''. IF sy-subrc EQ 0. LOOP AT bestand ASSIGNING FIELD-SYMBOL(<lfs_output>) WHERE charg IS NOT INITIAL. TRY. * Assign the value to a an output line <lfs_output>-licha = lt_batch_master[ matnr = <lfs_output>-matnr charg = <lfs_output>-charg ]-licha. CATCH cx_sy_itab_line_not_found. CONTINUE. ENDTRY. ENDLOOP. ENDIF. CATCH cx_sy_itab_line_not_found. " No exception handling ENDTRY.
- Check the result by running the transaction MB52:
The new column is added and filled with a value ( Supplier batch for an internal batch number ).
Nice Blog, used something similar in MB52 to add batch informations.
Maybe you could add a check for parameter xmchb to your coding. If it is not set on selection screen, MB52 won't show batch informations, so no need to perform a SELECT on MCH1.
Also the batch field (CHARG) is set to technical within fieldcat. I would expect a ZBATCH_FIELD would also disappear from the fieldcat, if MB52 is not running on batch level.
Is there any reason to still use the "old style" LIST ALV instead of the "new style" GRID ALV?
Check customizing for view: V_MMIM_REP_PRINT. Just tick the checkbox for field GRIDCONTROL for program RM07MLBS. And MB52 is using the ALV GRID in future.
Dear Hendrik, thank you for your comments.
I am not aware of the customizing V_MMIM_REP_PRINT. Indeed, it switches to a ''fresher'' view 🙂
In addition, I have checked that the enhancement works in both cases independently on the checkbox in V_MMIM_REP_PRINT.
And you are right about the selection parameter 'Display batch stocks' (xmchb). This is the starting point. Nevertheless, it is the static part to fill the field catalog. When this checkbox is empty, the program will not find the field CHARG and goes directly to the CATCH section ( no query would be executed ).