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
27,030

The purpose of this sample code is to generate select-options dynamically.

The selection-screen takes the table name as input and generates the select-options for the fields selected dynamically.

1.Selection screen:

2.Creating dynamic selection screen

Interface to read a table from the ABAP Dictionary

for example: iv_kotab = A549
CALL FUNCTION 'DDIF_TABL_GET'
EXPORTING
NAME
= IV_KOTAB
TABLES
DD03P_TAB
= GT_DD03P.

Build dynamic selection:

  •   Build Selections
    S_SELOPT
    -SIGN = 'I'.
    S_SELOPT
    -OPTION = 'EQ'.

LOOP AT GT_DD03P.
CASE GT_DD03P-FIELDNAME.
WHEN 'MANDT'
OR 'KAPPL'
OR 'KSCHL'
OR 'KNUMH'.
* Do nothing
WHEN OTHERS.
* Insert other selection
CONCATENATE
GT_DD03P
-TABNAME '-' GT_DD03P-FIELDNAME
INTO S_SELOPT-LOW.
APPEND S_SELOPT.
ENDCASE.
ENDCASE.
ENDLOOP.

Looping the seleopt table to generate the selection code

CONCATENATE 'SELECT-OPTIONS:' W_PARAMNAME INTO W_SRC
SEPARATED BY SPACE.
CONCATENATE W_SRC 'FOR' W_TABNAME INTO W_SRC
SEPARATED BY SPACE.
CONCATENATE W_SRC '-' W_FIELDNAME '.' INTO W_SRC.

* add field description at offset 42 - if possible
W_STRLEN
= STRLEN( W_SRC ).
IF W_STRLEN < 42.
WRITE: '"' TO W_SRC+42.
WRITE: W_FIELDTEXT TO W_SRC+43.
ELSE.
CONCATENATE W_SRC '"' W_FIELDTEXT INTO W_SRC.
ENDIF.

APPEND_LINE I_SELSCR_SRC W_SRC
.

* generate a text element for this select-option
CLEAR I_TEXTS.
I_TEXTS-
ID = 'S'.
I_TEXTS-
KEY = W_PARAMNAME.
I_TEXTS-ENTRY
= 'D'. "=take DDIC text if available
WRITE: W_FIELDTEXT TO I_TEXTS-ENTRY+8.
APPEND I_TEXTS.

* *****************************************
* Build some Types that reflects the Selection fields.
APPEND_EMPTY I_TYPES_SRC
.
CONCATENATE
'TYPES: BEGIN OF TP_' W_PARAMNAME+2(6) '.' INTO W_SRC.
APPEND_LINE I_TYPES_SRC W_SRC
.

CONCATENATE
'INCLUDE STRUCTURE' W_PARAMNAME '.' INTO W_SRC
SEPARATED BY SPACE.
APPEND_LINE I_TYPES_SRC W_SRC
.

CONCATENATE
'TYPES: END OF TP_' W_PARAMNAME+2(6) '.' INTO W_SRC.
APPEND_LINE I_TYPES_SRC W_SRC
.

  •   Combine all statements for selection include

    * Table declaration
    CONCATENATE
    'TABLES:' GV_KOTAB '.'
    INTO W_SRC SEPARATED BY SPACE.
    APPEND W_SRC TO L_SOURCE.

    * Frame start
    W_SRC =
    'SELECTION-SCREEN BEGIN OF BLOCK B0 WITH FRAME.'.
    APPEND W_SRC TO L_SOURCE.

    * Selection options
    APPEND LINES OF I_SELSCR_SRC TO L_SOURCE.

    * Frame end
    W_SRC =
    'SELECTION-SCREEN END OF BLOCK B0.'.
    APPEND W_SRC TO L_SOURCE.

    * Types
    APPEND LINES OF I_TYPES_SRC TO L_SOURCE.
    REFRESH I_TYPES_SRC.

    * ********************************
    * Add report title and change selection texts as text elements
    CLEAR I_TEXTS.
    I_TEXTS
    -ID = 'R'.
    I_TEXTS
    -ENTRY = 'Selection for Conversion of Condition Records'.
    APPEND I_TEXTS.
    SORT I_TEXTS BY ID KEY.

    * Create text elements
    DELETE TEXTPOOL C_DYN_REPID LANGUAGE SY-LANGU.
    INSERT TEXTPOOL C_DYN_REPID FROM I_TEXTS LANGUAGE SY-LANGU.

    * ********************************
    * Rebuild the selection include
    * program code inserted into ABAP repository
    INSERT REPORT C_DYN_REPID_SELECTION FROM L_SOURCE
    KEEPING DIRECTORY ENTRY.

Output:

5 Comments
SuhaSaha
Advisor
Advisor
0 Kudos

There was no need to re-invent the wheel. Dynamic selection screens have been there in ABAP since ages & there was no need for you to reinvent the wheel.

http://help.sap.com/abapdocu_740/en/abenfree_selections.htm

RieSe
Contributor
0 Kudos

... please update the link ...

matt
Active Contributor
0 Kudos

Just search: dynamic selections site:help.sap.com

raymond_giuseppi
Active Contributor

Why not use a function module such as FREE_SELECTIONS_DIALOG (and other modules in the SSEL function group)?

RieSe
Contributor
0 Kudos

Your're right: DEMO_FREE_SELECTIONS is the right answer. A link with 20 possible results is not useful 🙂

Labels in this area