Skip to Content

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:

/wp-content/uploads/2012/08/sel1_129889.png

Nothing Selected

/wp-content/uploads/2012/08/sel2_129908.png

Checkbox Selected, and values in the dropdown

/wp-content/uploads/2012/08/sel3_129909.png

‘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:

/wp-content/uploads/2012/08/sel6_129910.png

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:

/wp-content/uploads/2012/08/sel4_129911.png

/wp-content/uploads/2012/08/sel5_129912.png

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”.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

    1. Mithun Kumar Post author

      Thanks a lot for your feedback, Jelena.

      I rectified and rephrased it in my opening line 🙂

      The reason I wrote this blog is that my experience with interviewing many ABAP beginners (typically 0 to 3 years exp.), showed that they did not understand the basics of this simple technique. I did google for it, and found really long codes for this everywhere, but mostly nowhere was there an explanation about why that works, so that developers could modify the code to suit their specific requirements.

      I don’t intend to discredit anyone’s efforts, but my intention is just to give a bit of simplicity in explanation of the solution.

      (0) 
      1. Kesavadas Thekkillath

        Hi,

        In the example you have referred  “p_sel” as predefined which you are hiding & displaying in the event. So the term dynamic is not much related here 🙂 .May be term “changing screen properties during run time” would be alright.

        The functions like FREE_SELECTIONS_DIALOG,FREE_SELECTIONS_INIT etc does the dynamic screen generation for example

        It is very bad that candidates having 0 to 3 years of exp does not know this 😛 .

        Kesav

        (0) 
        1. Mithun Kumar Post author

          Thanks for your feedback, Kesav.

          Yes, I do agree with you about the term ‘Dynamic’ here. A title rephrase should make it clearer, I guess 🙂

          However, taking the ‘dynamic generation’ as the technical aspect, I prefered to call this the dynamic selection screen from a user’s perspective, wherein the screen elements change behavior dynamically. 🙂

          Regarding those candidates, if I’d have asked them about dynamic generation of selection screen, probably we’d have required to call the medics to take the unconcious ones from the room 😛 (just kidding)!

          (0) 

Leave a Reply