Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Showing field dynamically based on dropdown value

kwiznix90
Newcomer
0 Likes
1,256

Goodmorning,

I am new to SAP and ABAP programming and I am trying to make field visible dynamically, but only when a dropdown menu has a certain value, but I cant get it to work.

So first i set the field inactive in the PBO:

LOOP AT SCREEN.
  CASE SCREEN-NAME.
     WHEN 'FIELD A'.
        SCREEN-INPUT = 0.
        MODIFY SCREEN.
     WHEN 'FIELD B'.
       SCREEN-ACTIVE = 0.
       MODIFY SCREEN.
    ENDCASE.
  ENDLOOP.

And then in the PAI i read the value of the dropdown and if its the correct value, set them to active again.

IF dropdown-field = 1.
    LOOP AT SCREEN.
      CASE SCREEN-NAME.
        WHEN 'FIELD A'.
          SCREEN-INPUT = 1.
          MODIFY SCREEN.
        WHEN 'FIELD B'.
          SCREEN-ACTIVE = 1.
          MODIFY SCREEN.
      ENDCASE.
    ENDLOOP.
  ENDIF.

I tried with a error message, and that shows perfectly, but the fields just won't show up, what am I doing wrong??

Thanks in advance!

2 REPLIES 2
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,157

Let's start with a reproducible example, you can see that FIELD_A is changed into an input field:

PARAMETERS p_number TYPE i.
PARAMETERS field_a TYPE i.
PARAMETERS field_b TYPE i.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    CASE screen-name.
      WHEN 'FIELD_A'.
        screen-input = 0.
        MODIFY SCREEN.
      WHEN 'FIELD_B'.
        screen-active = 0.
        MODIFY SCREEN.
    ENDCASE.
  ENDLOOP.

AT SELECTION-SCREEN.
  IF p_number = 1.
    LOOP AT SCREEN.
      CASE screen-name.
        WHEN 'FIELD_A'.
          screen-input = 1.
          MODIFY SCREEN.
        WHEN 'FIELD_B'.
          screen-active = 1.
          MODIFY SCREEN.
      ENDCASE.
    ENDLOOP.
    MESSAGE 'error' TYPE 'E'.
  ENDIF.
Read only

0 Likes
1,157

Hi,

kwiznix

1. So first you need to add your code(which you have written in PBO) in AT SELECTION-SCREEN OUTPUT event. This will help you see FIELD_A read only and FIELD_B as active on selection screen.2. When you want to modify the screen dynamically you will write your code(written by you in PAI) into AT SELECTION-SCREEN event. Here you can dynamically show fields based on whatever your dropdown value is.Regards,Anurag