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:
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.
Output:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 |