Almost every ABAP developer comes to a point where they require obligatory parameters along with user command logic in their selection screens. As you might already know, that’s a problem. Because obligatory parameters demand input on every action of user and interfere with user command logic, which results in a broken selection screen. Let’s see an example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
PARAMETERS p_bukrs TYPE t001-bukrs OBLIGATORY. PARAMETERS p_sum RADIOBUTTON GROUP r01 DEFAULT 'X' USER-COMMAND r01. PARAMETERS p_det RADIOBUTTON GROUP r01. PARAMETERS p_sub AS CHECKBOX. AT SELECTION-SCREEN OUTPUT. IF p_det = space. LOOP AT SCREEN. IF screen-name = 'P_SUB'. screen-input = 0. MODIFY SCREEN. ENDIF. ENDLOOP. ENDIF. |
As soon as we run the report, we see P_SUB parameter as input-disabled and we expect it to be enabled when we click P_DET radiobutton. But no…
“Company Code” field demands input and “Display subtotal” field is still disabled although “Detail” radiobutton is already selected, which means our selection screen is broken. This certainly is not desired. The outcome gets even funnier if you use OBLIGATORY addition for a select option. We are not allowed to click extension button to enter an interval to the very same select option!
Most likely, SAP intended to make things easier for us by automating required field validation with a simple OBLIGATORY addition. But almost every time, this validation is only required after executing the report, not on every user action. Fortunately SAP also provided us with a workaround: the “recommended” field. If we assign value 2 to the REQUIRED attribute of screen, the field becomes “recommended”, which means we still see the checkmark in field which indicates the field expects an entry but no automated validation will run. So it is up to us when and how the required field validation would take place. In order to fix our previous code, we need an assignment to a selection screen field attribute, plus the validation code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
PARAMETERS p_bukrs TYPE t001-bukrs. PARAMETERS p_sum RADIOBUTTON GROUP r01 DEFAULT 'X' USER-COMMAND r01. PARAMETERS p_det RADIOBUTTON GROUP r01. PARAMETERS p_sub AS CHECKBOX. AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN. CASE screen-name. WHEN 'P_BUKRS'. screen-required = '2'. WHEN 'P_SUB'. IF p_det = space. screen-input = 0. ENDIF. ENDCASE. MODIFY SCREEN. ENDLOOP. AT SELECTION-SCREEN ON p_bukrs. IF sy-ucomm = 'ONLI'. IF p_bukrs IS INITIAL. MESSAGE e055(00). ENDIF. ENDIF. |
With this code, we won’t see any error messages until we hit the execute button, but still have the obligatory checkmark. This feature is also available in classical dynpro screens.