Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Just google for it and you may not find a simple solution to it… Sometimes seemingly simple coding requirements are perhaps not so simple, and many developers (mostly new learners) struggle to get it right in their code. One of such problems is to code a simple dynamic selection screen, where the requirement is as follows:

  1. I need a simple screen with just a couple of elements:
    1. A dropdown of values
    2. A selection option to select some values
  2. I need a Check box on the screen that should control the above elements’ visibility on the screen. If the checkbox is not selected, the above elements should not be visible to the user, and vise-versa.
  3. Also, from the dropdown, only for a specific value selected, the selection option should be available to the user, otherwise not.

Now seeing such a requirement, you can ofcourse create a normal screen (like screen 100) in a module pool program, and have all the above dynamic (visible/invisible) behaviors controlled very well, using PBO, PAI, UCOMM, etc. However, for such a simple requirement as above, a module pool with a screen seems overkill, doesn’t it? If a simple selection screen with a few lines of code can achieve this, why do the heavy coding?

But as I figured, quite a few developers (new and moderately experienced alike) struggled with the idea of how to achieve such a dynamic behavior with Selection Screens in a Report program!
So I thought even seemingly simple problems like these are also might be a gap in the vast knowledge base of the Internet… So here you go, the solution is
here…

I’ll begin with the end result of how the screen looks like finally:

Nothing Selected

Checkbox Selected, and values in the dropdown

'Value 2' Selected in the dropdown, showing the Selection Option

Having seen the beautiful screens let’s dive in to the dirty stuff.

First off, to keep things simple, I created a domain with fixed values, for the dropdown above. So it looks like this:

Then, created a data element with this domain to use in the report. Speaking of the report, here’s the code for your kind perusal:

*&---------------------------------------------------------------------*
*& Report  ZDYN_SELSCREEN
*&
*&---------------------------------------------------------------------*
*& Dynamic screen Programming for Selection Screens
*& Using understanding of Selection Screen Flow
*&---------------------------------------------------------------------*
REPORT zdyn_selscreen.
DATA: myrange TYPE boolean.
SELECTION-SCREEN BEGIN OF BLOCK hiding.
PARAMETERS: p_ctl AS CHECKBOX
                  USER-COMMAND hde1,
            p_list TYPE zvals
                   AS LISTBOX VISIBLE LENGTH 20
                   MODIF ID hd1
                   USER-COMMAND hde2.
SELECT-OPTIONS: p_sel FOR myrange
                      MODIF ID hd2.
SELECTION-SCREEN END OF BLOCK hiding.
AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF p_ctl EQ abap_true AND screen-group1 = 'HD1'.
      screen-active = '1'.
      screen-invisible = '0'.
    ELSEIF screen-group1 = 'HD2' AND p_list = 'CD'.
      screen-active = '1'.
      screen-invisible = '0'.
    ELSEIF screen-group1 = 'HD1' OR screen-group1 = 'HD2'.
      screen-active = '0'.
      screen-invisible = '1'.
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.
START-OF-SELECTION.
*Start doing something

And ofcourse the texts you see in the above screenshots are maintained here:

Now let me delve into the explanation of the code, and why this works…

First off, I hope you’ve gone through the general flow of a selection screen here.

Now having a knowledge of the selection screen flow, the code above should be straight-forward to understand.

AT SELECTION-SCREEN OUTPUT.” is the PBO event for a selection screen. So every time the screen is loaded, this event is fired (Not the INITIALIZATION event). And we make sure the screen is re-loaded when we define the “USER-COMMAND” for any of the “PARAMETERS”.

So, as the screen gets loaded the “LOOP AT SCREEN” runs and depending upon the value of the checkbox or the Lisbox, sets the screen properties (in this case invisibility) for the screen elements that has a specific “MODIF ID” set.

Finally “MODIFY SCREEN.” seals the deal and the change is done for the screen.

Do feel free to copy this code and try it out on your machine… All the best!

PS: In case you’re wondering why my SAP GUI screens look different from yours, this is SAP GUI 7.3 using the new “Corbu Theme”.

4 Comments