Skip to Content
Technical Articles

Easy Handling of Complex Selection Screen

Introduction

Most of us have faced this problem when designing a selection screen with a lot of fields. For example consider the scenario where you have to design selection screen for an ABAP Report which includes multiple Radio Buttons and accordingly the selection criteria i.e., select option or parameter should be made visible and hidden and also some radio can have authority object attached to it.

So in this blog post you will learn how you can reduce the complexity of Selection Screen Field visiblility inside the statement LOOP AT SCREEN .

The Concept used for Designing Solution

    1. Comparision operator (CS) for more detail, go to ABAP CS Pattern Documentation
    2. MODIF ID
    3. Basic ABAP Coding 😛

Program Requirement

Lets Assume that DISPLAY_DELM EXCEL_UPLOAD & EXECUTE are Authority objects

Need to design selection screen with following fields:

  • Table Maintenance (Radio Button)
    • Table Display/Delete (Radio Button) [Should be disabled if the user does not have DISPLAY_DEL authorization ]
      • Plant (Select Option)
    • Excel Upload (Radio Button) [Should be disabled if the user does not have EXCEL_UPLOAD authorization ]
      • Filepath (parameter)
      • Excel Guidance (Push Button)
      • Excel Format (Push Button)
  • SNP Log and Deployment (Radio Button)
    • SNP Optimizer Log (Radio Button)
      • Generate Report Data [Should be disabled if the user does not have EXECUTE authorization ]
        • SNP Log Name (Parameter)
        • Division (Select Option)
        • Calendar Month (Select Option)
      • Base Table Display
        • SNP Log Name (Parameter)
        • Division (Select Option)
        • Calendar Month (Select Option)
      • Region Level Display
        • SNP Log Name (Parameter)
        • Division (Select Option)
        • Calendar Month (Select Option)
        • Bucket Number (Select Option)
      • Transporation Zone Display
        • SNP Log Name (Parameter)
        • Division (Select Option)
        • Calendar Month (Select Option)
        • Bucket Number (Select Option)
    • Deployment Data (Radio Button)
      • Generate Report Data [Should be disabled if the user does not have EXECUTE authorization ]
        • Division (Select Option)
        • Calendar Month (Select Option)
      • Base Table Display
        • Division (Select Option)
        • Calendar Month (Select Option)
      • Region Level Display
        • Division (Select Option)
        • Calendar Month (Select Option)
        • Bucket Number (Select Option)
      • Transporation Zone Display
        • Division (Select Option)
        • Calendar Month (Select Option)
        • Bucket Number (Select Option)

Part 0: Data Declaration

TYPES:
  BEGIN OF gty_scn_field_auth,
    excel_upd   type boolean,
    display_del TYPE boolean,
    execute     TYPE boolean,
  END OF gty_scn_field_auth.

DATA gs_scn_field_auth TYPE gty_scn_field_auth.

DATA:
  gv_div    TYPE spart,
  gv_month  TYPE /bi0/oicalmonth,
  gv_bucket TYPE /sapapo/snpbucke,
  gv_date   TYPE d,
  gv_plant  TYPE werks_d.

 

Part 1: INITIALIZATION Event

Fetching Authorization information of Radio button for the selected user

  btn_guid = 'Excel File Guidence' .
  btn_frmt = 'Download File Format'.

**********************************************************************
** for demonstration purpose I have set the values manually
** in real program you must have set the fields using 
** AUTHORITY CHECK object, if the user has authorization
**********************************************************************
  
*  gs_scn_field_auth-excel_upd = abap_true.
  gs_scn_field_auth-display_del = abap_true.
  gs_scn_field_auth-execute     = abap_true.

 

Part 2: Declaring Selection Screen

Lets Start Designing Selection Screen

DATA:
  gv_div    TYPE spart,
  gv_month  TYPE /bi0/oicalmonth,
  gv_bucket TYPE /sapapo/snpbucke,
  gv_date   TYPE d,
  gv_plant  TYPE werks_d.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-s01.
PARAMETERS:
  r_s_mstr RADIOBUTTON GROUP g1 MODIF ID r1 USER-COMMAND rad1 DEFAULT 'X', "Table Maintence
  r_log_rp RADIOBUTTON GROUP g1 MODIF ID r1. "SNP Log and Deployment
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-s02.
PARAMETERS:
  r_s_dsp RADIOBUTTON GROUP g2 MODIF ID r6 USER-COMMAND rad2 DEFAULT 'X',
  r_s_upd RADIOBUTTON GROUP g2 MODIF ID r2. "excel upload
SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-s03.PARAMETER:
  p_file TYPE char1024 MODIF ID f1. "file path
SELECTION-SCREEN PUSHBUTTON:
  /1(25) btn_guid USER-COMMAND btn_guide MODIF ID f1, "excel guide
  53(25) btn_frmt USER-COMMAND btn_format MODIF ID f1. "Excel format
SELECTION-SCREEN END OF BLOCK b3.

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE TEXT-s04.
PARAMETERS:
  r_snplog RADIOBUTTON GROUP g3 MODIF ID r3 USER-COMMAND rad2 DEFAULT 'X', "SNP Optimizer Log
  r_deploy RADIOBUTTON GROUP g3 MODIF ID r3. "Deployment Data
SELECTION-SCREEN END OF BLOCK b4.

SELECTION-SCREEN BEGIN OF BLOCK b5 WITH FRAME TITLE TEXT-s05.
PARAMETERS:
  r_gnrt   RADIOBUTTON GROUP g4 MODIF ID r4 USER-COMMAND rad3, "generate report
  r_dp_bas RADIOBUTTON GROUP g4 MODIF ID r5, "Base data display
  r_dp_r   RADIOBUTTON GROUP g4 MODIF ID r5, "RO wise report
  r_dp_tzn RADIOBUTTON GROUP g4 MODIF ID r5. "TZone Wise dispaly
SELECTION-SCREEN END OF BLOCK b5.

SELECTION-SCREEN BEGIN OF BLOCK b6 WITH FRAME TITLE TEXT-s06.
PARAMETERS:
  p_log TYPE /sapapo/sessionname MODIF ID m1.
SELECT-OPTIONS:
  s_div FOR gv_div MODIF ID m2,
  s_plant FOR gv_plant MODIF ID m3,
  s_month FOR gv_month MODIF ID m2 NO-EXTENSION,
  s_cal_dt FOR gv_date MODIF ID m4,
  s_bucket FOR gv_bucket MODIF ID m5,
  s_date FOR gv_date NO-DISPLAY.
SELECTION-SCREEN END OF BLOCK b6.

 

Part 3: AT SELECTION SCREEN OUTPUT

Coding Selection Screen Toggle Fields based on Selected Radio Button

  • Creating a String variable for each radio button.
  • Initializing the String variable with a list of MODIF ID’s which are needed to be hidden.
  • Setting the respective string variable to the main LV_SELECTED variable so that the Selection screen elements could be set as active  = 0.
  • Similarly, the string variable LV_AUTH is being set based on the user’s authorization. and the respective screen elements are being set as inactive = 0.
  DATA:
*    radio button selection variable: to hold list of modif ids to be visible 
*      for selected ratio button
    lv_selected        TYPE string,

*    radio button selection variable: variable to hold list of modif ids 
*      for not authorized fields
    lv_auth            TYPE string,

*    radio button selection variable: table maintenance
    lv_r_tab_maint     TYPE string VALUE 'R3,R4,R5,M1,M2,M5,M4',

*    radio button selection variable: excel upload
    lv_r_tab_maint_upd TYPE string VALUE 'M3',

*    radio button selection variable: table display/delete
    lv_r_tab_maint_dsp TYPE string VALUE 'F1',

*    radio button selection variable: data source selection
    lv_r_data_src      TYPE string VALUE 'F1,R2,R6,M3,',
*    radio button selection variable: snp optimizer log
    lv_r_snplog        TYPE string VALUE 'M4,',
*    radio button selection variable: snp deployment
    lv_r_deployment    TYPE string VALUE 'M1,M5,'.

  IF gs_scn_field_auth-display_del = abap_false.
    CONCATENATE lv_auth 'R6' INTO lv_auth SEPARATED BY ','.
*    CONCATENATE lv_auth 'R2' INTO lv_auth SEPARATED BY ','.
  ENDIF.


  IF gs_scn_field_auth-execute = abap_false.
    lv_auth = 'R4'.
  ENDIF.

  IF gs_scn_field_auth-excel_upd = abap_false.
    CONCATENATE lv_auth 'R2' INTO lv_auth SEPARATED BY ','.
  ENDIF.

*  checking for which radion button has been selected
  CASE abap_true.

    WHEN r_s_mstr. "Table Maintence

      CASE abap_true.
        WHEN r_s_upd. "Excel Upload
          CONCATENATE lv_r_tab_maint lv_r_tab_maint_upd INTO lv_selected SEPARATED BY ','.
        WHEN r_s_dsp. "table display/change/delete
          CONCATENATE lv_r_tab_maint lv_r_tab_maint_dsp INTO lv_selected SEPARATED BY ','.
      ENDCASE.

    WHEN r_log_rp. "SNP Log and Deployment

      CASE abap_true.
        WHEN r_snplog. "snp optimizer log data
          CONCATENATE lv_r_data_src lv_r_snplog INTO lv_selected SEPARATED BY ','.
          IF r_gnrt = abap_true OR r_dp_bas = abap_true.
            CONCATENATE lv_selected 'M5' INTO lv_selected SEPARATED BY ','.
          ENDIF.
        WHEN r_deploy. "deployment data
          CONCATENATE lv_r_data_src lv_r_deployment
            INTO lv_selected SEPARATED BY ','.
          IF r_gnrt = abap_true OR r_dp_bas = abap_true.
            CONCATENATE lv_selected 'M4' INTO lv_selected SEPARATED BY ','.
          ENDIF.
      ENDCASE.
  ENDCASE.

  LOOP AT SCREEN.
    IF screen-group1 IS NOT INITIAL.
*      hide the fields which are not required for selected ratio button
      IF lv_selected CS screen-group1.
        screen-active = 0. "hide field
        MODIFY SCREEN.
      ENDIF.

*      disable radio button for which the user does not have the authorization
      IF lv_auth CS screen-group1.
        screen-input = 0. "gray out field
        MODIFY SCREEN.
      ENDIF.
    ENDIF.
  ENDLOOP.

 

Part 4: START-OF-SELECTION

Use your own logic based on the selected radio button.

Output

Selection%20Screen%20Output

Selection Screen Output: With a multiple Selection Fields & Radio Button

Selection%20Screen%20Output%3A

Selection Screen Output: User doesnot have EXCEL_UPLOAD authorization, so the Excel Upload Radio Button has been disabled


Conclusion

Advantages of Using this Approach

  • The If else branch inside LOOP AT SCREEN gets reduced.
  • For future changes in the selection screen, one has to add the MODIF ID in the respective radio button selection variable.
  • Easy Code Maintainaibility.

The Complete Source code is available in the GitHub Repository


8 Comments
You must be Logged on to comment or reply to a post.
  • Great blog Namasivayam. We usually face requirements where we want to have multiple options on Selection screen in a Report program. But we are not aware that we can achieve all possibilities through it or not.

    I would like to add one more point in it regarding use of ‘BEGIN OF LINE’. In some cases, where we want to display multiple Radio button in single line or we want to change the position of Radio button to align it with other input fields, we can use SELECTION SCREEN BEGIN OF LINE command.

    Through this syntax, we can give the position of each field like position for Radio button, different position for its text and so on.

    • Thanks :), Pankaj GUPTA !!!

      Yes, you can use this for the selection screen fields beginning with ‘BEGIN OF LINE’. When using this you need to give the same MODIF ID for each pair of PARAMETER and COMMENT field, as shown below:

      SELECTION-SCREEN BEGIN OF BLOCK b1.
        SELECTION-SCREEN BEGIN OF LINE. 
          PARAMETER: rb_1 RADIOBUTTON GROUP g1  MODIF ID m1 DEFAULT 'X'. 
          SELECTION-SCREEN : COMMENT 3(5) comm_rb1 FOR FIELD rb_1 MODIF ID m1. 
      
          PARAMETER: rb_2 RADIOBUTTON GROUP g1  MODIF ID m2. 
          SELECTION-SCREEN : COMMENT 10(5) comm_rb2 FOR FIELD rb_2 MODIF ID m2. 
        SELECTION-SCREEN END OF LINE.
      SELECTION-SCREEN END OF BLOCK b1.
      
      INITIALIZATION.
        comm_rb1 = 'RB 1'.
        comm_rb2 = 'RB 2'.
  • Nice to see all different ways of doing things

    There’s another option which could be developed based on Screen Breaker Project launched!, by Fabio Pagoti, on 2010/09/15, and extended. My idea is that your code could be more expressive/functional hereafter. Of course the class ZCL_SCREEN_BREAKER_2 does not exist yet, it’s just an idea that I think could work.

    Cheers.

    Sandra

    SELECTION-SCREEN BEGIN OF BLOCK report_selection WITH FRAME TITLE TEXT-s01. " meaningful instead of B01
    ...
    
    AT SELECTION-SCREEN OUTPUT.
      TYPES: BEGIN OF ENUM ty_blocks_1000 STRUCTURE blocks_1000,
        report_selection,
        table_update,
        upload_selections,
        data_source_selectns,
        display_type,
        selection_criteria,
      END OF ENUM blocks_1000 STRUCTURE blocks_1000.
    
      DATA(lo_screen) = NEW zcl_screen_breaker_2( ). " DOES NOT EXIST YET
      lo_screen->set_invisible_all( ).
      lo_screen->set_visible_block( blocks_1000-report_selection ).
      CASE abap_true.
        WHEN r_s_mstr. "Table Maintence
          lo_screen->set_visible_block( blocks_1000-table_update ).
          IF not authorized.
            lo_screen->set_output( 'R_S_UPD' ). " Gray out Excel Upload of TABLE_UPDATE block
          ENDIF.
          CASE abap_true.
            WHEN r_s_upd. "Excel Upload
              lo_screen->set_visible_block( blocks_1000-upload_selections ).
            WHEN r_s_dsp. "table display/change/delete
              lo_screen->set_input( 'S_PLANT' ). " Plant selection
          ENDCASE.
        WHEN r_log_rp. "SNP Log and Deployment
          ...
      ...
      lo_screen->activate_screen( ). " LOOP AT SCREEN and MODIFY SCREEN only occur here
    
    • Thanks. I wasn’t aware of this Screen Breaker Project. It’s a nice idea

      (Though in real-life scenarios, it is more common to modify selection screen elements by modification group and not by the parameter name).

      How did you plan to implement set_visible_block, BTW?

       

      • That could be developed by testing the element names of the blocks, they are prefixed with the block number which is automatically incremented by SAP based on the order (01, 02, etc.) It’s why an ENUM is a smart way of defining the same order as in the screen: if a block is added in the selection screen, one can just insert a line in the ENUM at the right place, all ENUM elements will be automatically renumbered. The algorithm may not be trivial because there may be some elements between the blocks, it might be difficult to know that they are not part of a block -maybe the only solution would be to use IMPORT DYNPRO then-.

        • To be honest, I wondered if you have any “hidden” API.

          1. Regarding element names, do you mean to manual naming convention or some internal naming (I’m not aware of)?
          2. Even with the (somehow forbidden) IMPORT DYNRPO, it would still require manual parsing of the block fields according to the explicitly defined ENUM (I couldn’t find any place where the block name itself is available).
          • Nothing very special.

            If we use this selection screen:

            SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE TEXT-001.
            PARAMETERS a.
            SELECTION-SCREEN END OF BLOCK b01.
            
            SELECTION-SCREEN BEGIN OF BLOCK b02 WITH FRAME TITLE TEXT-001.
            PARAMETERS b.
            SELECTION-SCREEN END OF BLOCK b02.
            
            PARAMETERS c.

            There are these field names:

            NAME                   Type   INPUT  OUTPUT  INVISIBLE  ACTIVE  REQUIRED  LENGTH  GROUP1  GROUP2  GROUP3  GROUP4
            SSCRFIELDS-UCOMM       OK     0      0       0          1       0         0                                  
            %B001000_BLOCK_1000    Frame  0      1       0          1       0         0                       BLK        
            %_A_%_APP_%-TEXT       I/O    0      1       0          1       0         30                      TXT     001
            A                      I/O    1      1       0          1       0         1                       PAR     001
            %B001003_BLOCK_1000    Frame  0      1       0          1       0         0                       BLK        
            %_B_%_APP_%-TEXT       I/O    0      1       0          1       0         30                      TXT     004
            B                      I/O    1      1       0          1       0         1                       PAR     004
            %_C_%_APP_%-TEXT       I/O    0      1       0          1       0         30                      TXT     006
            C                      I/O    1      1       0          1       0         1                       PAR     006
            %_17NNS0001323002_%_%  Text   0      0       0          1       0         0                               SRI

            So I guess it’s feasible (group3 = ‘BLK’, next lines with same group4 belong to same block?). But maybe it will be more complex than expected, who can know, without trying…

          • I see.

            That’s what I called “manual parsing”.

            Take into account that:

            1. The block element is available only for visible blocks (WITH FRAME).
            2. There may also be canonical blocks.