Dynamically hiding parameters AND selection texts

Good afternoon!

I’m trying to hide a parameter based on the tcode the program is used in. The selection screen has several tabs with input parameters. When I tried the following code on the first tab, everything worked fine: Neither the input or the selection text of the parameter is shown.
However, on the next tab, for some reason it does hide the input fields, but it still shows the selection texts. 
With the shown code, the first case is what does work correctly. The second case (with screen2) doesnt work. I first tried only using the ‘active’ part and setting it to 0, which is how I had it in the first place for the parameters that do correctly get hidden. Then I tried setting ‘screen-invisible’ to 1, and to 0, and putting either ‘invisible’ first or ‘active’ first, but nothing works. 

Does anyone have any idea what might be going wrong here?

Thank you so much in advance!

 

AT SELECTION-SCREEN OUTPUT.
IF sy-tcode = ‘TCODE’.
LOOP AT SCREEN INTO DATA(ls_screen).
CASE ls_screen-name.
WHEN ‘P_NAME’.
ls_screen-active = ‘0’.
MODIFY SCREEN FROM ls_screen.
ENDCASE.
ENDLOOP.
ELSEIF sy-tcode <> ‘TCODE’.
LOOP AT SCREEN INTO DATA(ls_screen2).
CASE ls_screen2-name.
WHEN ‘P_NAME’.
ls_screen2-invisible = ‘1’.
ls_screen2-active = ‘0’.
MODIFY SCREEN FROM ls_screen2.
ENDCASE.
ENDLOOP.
ENDIF.

 

Scroll to Top