*&---------------------------------------------------------------------*
*& Report ZTEST_PROGRAM_2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest_program_2.
*--- Radio Buttons
PARAMETERS: r_opt1 RADIOBUTTON GROUP grp DEFAULT 'X' USER-COMMAND rad,
r_opt2 RADIOBUTTON GROUP grp,
r_opt3 RADIOBUTTON GROUP grp.
*--- Fields controlled by radio buttons
PARAMETERS: p_field1 TYPE char20,
p_field2 TYPE char20,
p_field3 TYPE char20.
*--- Screen Modification
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CASE screen-name.
WHEN 'P_FIELD1'.
screen-active = COND #( WHEN r_opt1 = 'X' THEN 1 ELSE 0 ).
WHEN 'P_FIELD2'.
screen-active = COND #( WHEN r_opt2 = 'X' THEN 1 ELSE 0 ).
WHEN 'P_FIELD3'.
screen-active = COND #( WHEN r_opt3 = 'X' THEN 1 ELSE 0 ).
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
*--- Output
START-OF-SELECTION.
WRITE: / 'Option 1:', r_opt1,
/ 'Option 2:', r_opt2,
/ 'Option 3:', r_opt3,
/ 'Field1:', p_field1,
/ 'Field2:', p_field2,
/ 'Field3:', p_field3.
Output:
This ABAP program ZRADIO_DEMO
demonstrates how to create a dynamic selection screen using radio buttons. It defines three radio buttons, where only one can be selected at a time, and three corresponding input fields (p_field1
, p_field2
, p_field3
). The logic inside the AT SELECTION-SCREEN OUTPUT
event uses a LOOP AT SCREEN
to check which radio button is active and then enable or disable the related input field accordingly, making the other fields invisible. This ensures that only the field relevant to the selected option is shown to the user. Finally, in the START-OF-SELECTION
block, the program outputs the selected option and the entered values. Overall, the code provides a simple but effective example of how to use radio buttons to control screen modifications in SAP reports, making the user interface more interactive and user-friendly.