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:
Leave A Comment?
You must be logged in to post a comment.