I was trying to give an access to one block of selection screen that should only a few people see. For the rest of SAP users, it should be invisible but I've made some mistakes.
Declaration of the block that I want to hide:
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-004.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN PUSHBUTTON 3(45) TEXT-ba5 USER-COMMAND x.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN PUSHBUTTON 3(45) TEXT-bb3 USER-COMMAND y.
SELECTION-SCREEN SKIP 2.
SELECTION-SCREEN END OF BLOCK b3.
Fragment of code that should've done the job:
DATA: lt_authorized_users TYPE STANDARD TABLE OF sy-uname,
ls_user TYPE sy-uname.
lt_authorized_users = VALUE #( ( 'USER 1' )
( 'USER 2' ).
LOOP AT lt_authorized_users INTO ls_user.
ENDLOOP.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'BLK'.
IF sy-uname = ls_user.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
You are on the right track with
LOOP AT SCREENinAT SELECTION-SCREEN OUTPUT. But forIF screen-group1 = 'BLK'to work, you actually have to state which elements of the selection screen belong to the group "BLK". You do that with the additionMODIF ID idthat is available for most selection screen elements:And then there is another problem in your code that isn't really a technical problem but really, really bad practice: Building your own authorization system! SAP already has an authorization system. It is built around roles defined in tcode
PFCG, which contain authorizations for authorization objects defined in tcodeSU21and get assigned to users with tcodeSU01. You can check if a user is authorized to do something with the ABAP instructionAUTHORITY-CHECK. Whenever you deal with user authorizations, you should be building on this system. Homebrewed authorization systems are a nightmare for maintenance, administration, troubleshooting and compliance. Only build them when you have a really good reason why the SAP standard system doesn't work for you.You might wonder what's about the
BLOCKand theSKIP. Don't they need a modifier ID, too? No, they don't. They can't have one. But they don't need one either, because when a block contains no visible elements, then the whole block disappears without taking up any space on the selection-screen.