How to grey out fields on ME21N/ME22N/ME23N
For certain Purchase orders, based on some condition, we need to grey out the fields NETPR & KBETR.
In order to do this, we need to find the right BADI or the right user exit to code our functionality. For this debug tool is a must to know where and how these fields are populated on the purchase order screen.
This functionality can be achieved by following the below steps.
For the PO creation/change screen below is the solution to gray out the required fields (NETPR & KBETR)
1. for NETPR:
The field catalog that fills NETPR is TC_1211 Actually in standard program SAPLMEGUI, there is a call to the FM MEGUI_BUILD_PO_ITEMOV_PLUGIN.. Inside that, in line 44, TC_1211 gets populated. This contains all field catalog values. So in BADI, code to disable field NETPR by reading values using field symbols.
Create Implementation — > Classic BADI –> ME_ACTV_CANCEL_PO –> Implementation name ZCL_IM_TEST
In method CHECK_ACTIVITY code the following:
FIELD-SYMBOLS :<fs> TYPE ANY TABLE,
<ls> TYPE ANY,
<lr_screen> TYPE screen.
ASSIGN (‘(SAPLMEGUI)TC_1211-COLS’) TO <fs>.
IF sy-subrc IS INITIAL.
LOOP AT <fs> ASSIGNING <ls>.
ASSIGN COMPONENT ’SCREEN’ OF STRUCTURE <ls> TO <lr_screen>.
IF <lr_screen>-name = ’MEPO1211-NETPR’.
<lr_screen>-input = 0.
Activate the implementation. NETPR will be disabled in the header when u try to create or change purchase order.
2. for KBETR
In Screen 6201 of program SAPLV69A -> LV69AO03à Module FELDAUSWAHL, there is a User Exit: PERFORM userexit_field_modification.
Inside this EXIT, change the contents of TCTRL_KONDITIONEN-COLS -SCREEN-INPUT to 0. KBETR will get grayed out.