ABAP Dynamic Selection Screen using Tabbed Selection Screen

By | March 13, 2013 | Classical | 3,365 | 4

ABAP Dynamic Selection Screen using Tabbed selection screen to avoid activating each and every field. You would find tabbed selection screen at its best in this article.

Preface

Recently, I needed to display separate fields for selection on selection screen based on various options. These options would be dynamic as well. There would be separate logic for validation, actual data selection etc but that I would cover some other day.

Traditional Approach

Simplest way is to create these options – lets call them Object Type as a radio button group. Create parameter fields using the MOD ID to tag the selection parameters and select-options for specific Object Type. I would need to add additional logic in the AT SELECTION-SCREEN OUTPUT to hide the fields based on the selection.

Drawback of the traditional Approach

This design based on the MOD ID using the MODIFY SCREEN is not as dynamic it could be

  • Dynamic logic is too embedded – You need to define MOD ID for each field.
  • High maintenance
  • Less flexibility – You need to have logic to suppress the fields which are needed based on the Object Type
  • Have to have a default option selected

Solution using Tabbed Selection Screen

To make things more clean, neat, straight forward; I designed this approach.

  • Create a Tabbed Selection screen with ONLY one Tab
  • Create a Empty Selection Screen – This would be dummy screen for blank option.
  • Create Selection screen for each various set of selection screen
  • Set the Value of the Screen within the tabbed selection screen using the screen number
  • Maintain the config table for the Object Type, its description and its selection screen

In this approach, I have a flexibility to create a separate selection screen for newly added Object Type. I can easily point it to use the Selection Screen using the Config entries. Most importantly, you are not touching the existing selection screen fields. Which would reduce the testing.

Advertisement

Code Lines

Here is the program to achieve this:

 
REPORT  ztest_np_dynamic_sel_screen.
*&---------------------------------------------------------------------*
*& Purpose - Dynamic Selection Screen using the Tabbed Selected Screen
*& Author  - Naimesh Patel
*& URL     -
*&---------------------------------------------------------------------*
*
CLASS lcl_main DEFINITION.
  PUBLIC SECTION.
    TYPES:
      BEGIN OF ty_vrm_values,
        key  TYPE char40,
        text TYPE char80,
      END   OF ty_vrm_values.
    TYPES: tt_vrm_values TYPE STANDARD TABLE OF ty_vrm_values 
             WITH DEFAULT KEY.
    TYPES:
      BEGIN OF ty_config,
        key  TYPE char10,
        desc TYPE char50,
        dynnr TYPE sy-dynnr,
      END   OF ty_config.
    DATA: t_config TYPE STANDARD TABLE OF ty_config.
    METHODS:
      get_vrm_values
        RETURNING value(rt_values) TYPE tt_vrm_values,
      get_dynnr
        IMPORTING iv_objtype TYPE char10
        RETURNING value(rv_dynnr) TYPE sy-dynnr.
ENDCLASS.                    "lcl_main DEFINITION
*
DATA: t_objtypes TYPE lcl_main=>tt_vrm_values.
DATA: o_main TYPE REF TO lcl_main.
 
*
DATA: v_vbeln TYPE vbak-vbeln,
      v_erdat TYPE vbak-erdat,
      v_vkorg TYPE vbak-vkorg,
      v_vtweg TYPE vbak-vtweg,
      v_spart TYPE vbak-spart.
 
* Object type Selector
PARAMETER: p_objtyp TYPE char10 AS LISTBOX 
             VISIBLE LENGTH 30 USER-COMMAND v_obj .
*
* TABBED Selection screen for displaying the screen
SELECTION-SCREEN: BEGIN OF TABBED BLOCK mytab FOR 7 LINES,
                  TAB (20) seltab USER-COMMAND push1,
                  END OF BLOCK mytab.
*
* Default screen
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
SELECTION-SCREEN END OF SCREEN 100.
*
* for SO
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
SELECT-OPTIONS: so_vbeln FOR v_vbeln,
                so_erdat FOR v_erdat,
                so_vkorg FOR v_vkorg,
                so_vtweg FOR v_vtweg,
                so_spart FOR v_spart.
SELECTION-SCREEN END OF SCREEN 200.
*
* for Billing
SELECTION-SCREEN BEGIN OF SCREEN 300 AS SUBSCREEN.
SELECT-OPTIONS: bi_vbeln FOR v_vbeln,
                bi_erdat FOR v_erdat,
                bi_vkorg FOR v_vkorg,
                bi_vtweg FOR v_vtweg,
                bi_spart FOR v_spart.
SELECTION-SCREEN END OF SCREEN 300.
*
INITIALIZATION.
  CREATE OBJECT o_main.
  t_objtypes = o_main->get_vrm_values( ).
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'P_OBJTYP'
      values = t_objtypes.
*
  mytab-dynnr = o_main->get_dynnr( p_objtyp ).
  mytab-prog = sy-repid.
  mytab-activetab = 'PUSH1'.
*
  seltab = 'Selection Criteria'.
*
* dynamic text for objec type
  %_p_objtyp_%_app_%-text = 'Object Type'.
*
*
AT SELECTION-SCREEN OUTPUT.
* Set the selection screen based on the object type
  mytab-dynnr = o_main->get_dynnr( p_objtyp ).
*
*
START-OF-SELECTION.
*
*
CLASS lcl_main IMPLEMENTATION.
  METHOD get_vrm_values.
    DATA: ls_config LIKE LINE OF me->t_config.
* ---- Config entries, in real time it comes from table
*
    ls_config-key   = ".             " Default
    ls_config-desc  = ".
    ls_config-dynnr = '0100'.
    APPEND ls_config TO me->t_config.
*
    ls_config-key   = 'ORDER'.
    ls_config-desc  = 'Sales Order'.
    ls_config-dynnr = '0200'.
    APPEND ls_config TO me->t_config.
*
    ls_config-key   = 'BILLING'.
    ls_config-desc  = 'Billing Document'.
    ls_config-dynnr = '0300'.
    APPEND ls_config TO me->t_config.
*
*   vrm set values
    DATA: ls_vrm LIKE LINE OF rt_values.
    LOOP AT me->t_config INTO ls_config.
      ls_vrm-key = ls_config-key.
      ls_vrm-text = ls_config-desc.
      APPEND ls_vrm TO rt_values.
    ENDLOOP.
 
  ENDMETHOD.                    "get_vrm_values
  METHOD get_dynnr.
*   get the screen number
    DATA: ls_config LIKE LINE OF me->t_config.
    READ TABLE me->t_config INTO ls_config
      WITH KEY key = iv_objtype.
    IF sy-subrc EQ 0.
      rv_dynnr = ls_config-dynnr.
    ELSE.
*     fallback - if default is not maintained in config
      rv_dynnr = '0100'.
    ENDIF.
  ENDMETHOD.                    "get_dynnr
 
ENDCLASS.                    "lcl_main IMPLEMENTATION
 

Certainly, I could have displayed selection screen text using FM SELECTION_TEXTS_MODIFY as per my old article Dynamic Parameter Texts in Selection Screen – 2, but I left it as this not the intent of this article.

Output

On screen at first, you would see a blank selection screen, which is in fact screen number 100.

Based on object type selection, you would notice fields are changing. In fact, they being handled nicely by tabbed selection screen.

Nice & clean, huh :)

Like It? Share!!

Don't miss an Update

Naimesh Patel{220 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 220 articles.

Load comments

4 Comments

  • Vamshi

    Whatever be the drawbacks… the output rocks !! :)

  • NorthernGuy

    Hi Naimesh,

    This looks really interesting. I had a similar problem few weeks ago. I tried to solve it with Screen-Badi’s. In general it worked, but I couldn’t save the selection criterias from the subscreen that was replaced by the Screen-Badi. Therefore we couldn’t plan it into background, which was a no-go.

    Does your solution save the selection criterias to report variant in any case?

    Thanks & regards,
    Tapio

  • NorthernGuy

    edit:

    I have created test report and it works. *Thumbs up*

    Thanks & regards

  • Hello Tapio,

    As you mentioned in your edit, it would work with Variants, in Scheduling Jobs etc. Thanks for checking it.

    Regards,
    Naimesh Patel

Comments on this Post are now closed. If you have something important to share, you can always contact me.