22
Requirement: Retrieving the table data s dynamically. Input: 1.Table name with three buttons To select the Where condition of table = "Where Condition" To select the list of field name s to be displayed = "O/P Field names" To reset the values = "Reset" Where Condition: When You click on Where Condition button, It should pop up the list of fields in the particular table. After the selection of the fields,it should take you to the selection screen of the fields selected .After providing the where condition details,Clicking on Save should navigate to main screen to select the list of fields to be displayed in the output screen O/P Field names : When You click on Where Condition button, It should pop up the list of fields in the particular table. After the selection of the fields,it should navigate to main screen Reset : Clicking on that will reset the values of where condition and O/P field names selection. Output: Clicking on F8 or Run will display the list of field names selected in the output with the given where condition in ALV Format Screens: Where Condition

Dynamic Table

Embed Size (px)

Citation preview

Page 1: Dynamic Table

Requirement:

Retrieving the table data s dynamically.

Input:

1.Table name with  three  buttons

To select the Where condition of table = "Where Condition" To select the list of field name s to be displayed = "O/P Field names"

To reset the values = "Reset"

Where Condition:

When You click on Where Condition button, It should pop up the list of fields in the particular table. After the selection of the fields,it should take you to the selection screen of the fields selected .After providing the where condition details,Clicking on Save should navigate to main screen to select the list of fields to be displayed in the output screen

O/P Field names   :

When You click on Where Condition button, It should pop up the list of fields in the particular table. After the selection of the fields,it should navigate to main screen

Reset :

Clicking on that will reset the values of where condition and O/P field names selection.

Output:

Clicking on F8 or Run will display the list of field names selected in the output with the given where condition in ALV Format

Screens:

Where Condition

Page 2: Dynamic Table

After Clicking on Continue button

After Clicking on Save button Select the field names to be displayed

Final Output

Page 3: Dynamic Table

Program :

Create a Executable ABAP program.

Create three Screens

200 -  Normal Screen

300-Create Custom Control in layout as below

400-Normal Screen

Page 4: Dynamic Table

GUI Status for three Screens

GUI STATUS:13317

Page 5: Dynamic Table

GUI STATUS:DIALOG

GUI STATUS : DIALOG 1

Page 6: Dynamic Table

Program Code:

*&---------------------------------------------------------------------**& Report  ZDYNAMIC_SELECT*&*&---------------------------------------------------------------------**&*&*&---------------------------------------------------------------------*

REPORT  ZDYNAMIC_SELECT LINE-SIZE 80  LINE-COUNT 64MESSAGE-ID zzNO STANDARD PAGE HEADING..*REPORT z_13317_code LINE-SIZE 80* LINE-COUNT 64* MESSAGE-ID zz* NO STANDARD PAGE HEADING.* ----------------------------------------------------------------------*•Tables ** ----------------------------------------------------------------------TABLES : sscrfields, "Fields on selection screensdd03l. "Table Fields* ----------------------------------------------------------------------*•Type Pools ** ----------------------------------------------------------------------TYPE-POOLS:rsds.* ----------------------------------------------------------------------*•Selection Screen ** ----------------------------------------------------------------------SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001,SKIP,BEGIN OF LINE,COMMENT 1(5) text-002.PARAMETERS : p_tab LIKE dd03l-tabname OBLIGATORY. "Table nameSELECTION-SCREEN : PUSHBUTTON 45(15) p_btn1 USER-COMMAND Where_cond, "Select-options

Page 7: Dynamic Table

PUSHBUTTON 62(15) p_btn2 USER-COMMAND field_opt, "Select-optionsPUSHBUTTON 79(15) p_btn3 USER-COMMAND reset,END OF LINE,END OF BLOCK b1.* ----------------------------------------------------------------------*•Types ** ----------------------------------------------------------------------TYPES: BEGIN OF t_dd03l,tabname LIKE dd03l-tabname, "Table Namefieldname LIKE dd03l-fieldname, "Field Namekeyflag LIKE dd03l-keyflag, "Key Flagrollname LIKE dd03l-rollname, "Roll Nameposition LIKE dd03l-position, "Positionddtext(30), "DescriptionEND OF t_dd03l,BEGIN OF t_fields.INCLUDE STRUCTURE dd03l.TYPES: END OF t_fields.TYPES : BEGIN OF t_tabs. "To hold the table namesINCLUDE STRUCTURE rsdstabs.TYPES : END OF t_tabs.TYPES : BEGIN OF t_flds. "To hold the field namesINCLUDE STRUCTURE rsdsfields.TYPES : END OF t_flds.TYPES : BEGIN OF t_fname, "To hold the field namesfld LIKE dd03l-fieldname,END OF t_fname.* ----------------------------------------------------------------------*•Internal Tables ** ----------------------------------------------------------------------DATA : it_dd03l TYPE TABLE OF t_dd03l, "To hold the field namesit_tabs TYPE TABLE OF t_tabs, "To hold the table namesit_flds TYPE TABLE OF t_flds, "To hold the field names** Changeit_flds1 TYPE TABLE OF t_flds with header line, "To hold the field names** Changeit_temp TYPE TABLE OF t_flds, "Temp. table to hold field namesit_fields TYPE TABLE OF t_fields, "To hold the field namesit_cat TYPE TABLE OF lvc_s_fcat,"To hold Field Catalogit_fname TYPE TABLE OF t_fname.* ----------------------------------------------------------------------*•Work areas ** ----------------------------------------------------------------------DATA: d_ref TYPE REF TO data , "Data referencewa_dd03l LIKE LINE OF it_dd03l, "Workarea for IT_DD03Lwa_tabs LIKE LINE OF it_tabs, "Workarea for IT_TABSwa_flds LIKE LINE OF it_flds, "Workarea for IT_FLDSwa_temp LIKE LINE OF it_temp, "Workarea for IT_TEMP

Page 8: Dynamic Table

wa_fields LIKE LINE OF it_fields, "Workarea for IT_FIELDSwa_cat LIKE LINE OF it_cat , "Workarea for IT_CATwa_fname LIKE LINE OF it_fname. "Workarea for IT_FNAME* ----------------------------------------------------------------------*•Field Symbols ** ----------------------------------------------------------------------FIELD-SYMBOLS : <f_fs> TYPE table. "FieldSymbol for holding fields* ----------------------------------------------------------------------*•Variables ** ----------------------------------------------------------------------DATA: gx_texpr TYPE rsds_texpr, "Variable to hold Expressiongx_twhere TYPE rsds_twhere, "Variable to hold Where Clausegv_selid LIKE rsdynsel-selid, "Variable to hold Selidgv_actnum LIKE sy-tfill, "Variable to hold no of fieldsgv_title LIKE sy-title, "Variable to hold Titlegv_where_cl(100) TYPE c, "Variable to hold Where clausegv_tbname LIKE dd03l-tabname,gv_temp.

SELECT-OPTIONS:s_fld FOR dd03l-fieldname NO-DISPLAY, "To hold fields selecteds_selop FOR dd03l-fieldname NO-DISPLAY, "To hold fields for creating dyn. select-optionss_where FOR gv_where_cl NO-DISPLAY. "To hold where conditionPARAMETERS: gv_t_old LIKE dd03l-tabname NO-DISPLAY. "Earlier Table nameDATA : gt_grid TYPE REF TO cl_gui_alv_grid,gt_cust TYPE REF TO cl_gui_custom_container, "Custom Containercust TYPE scrfname VALUE 'CC_OUTPUT'. "Custom controller* ----------------------------------------------------------------------*•Constants ** ----------------------------------------------------------------------CONSTANTS: gc_i TYPE c VALUE 'I',gc_eq(2) TYPE c VALUE 'EQ'.* ----------------------------------------------------------------------*•Initialization ** ----------------------------------------------------------------------INITIALIZATION.* **--Initialize valuesPERFORM initialize.* ----------------------------------------------------------------------*•At Selection Screen ** ----------------------------------------------------------------------AT SELECTION-SCREEN.* **--Select the fields of the input tablePERFORM select_flds.* ----------------------------------------------------------------------*•Start Of Selection ** ----------------------------------------------------------------------

Page 9: Dynamic Table

START-OF-SELECTION.* **--Fetch data to display outputPERFORM fetch_data.* ----------------------------------------------------------------------*•End Of Selection ** ----------------------------------------------------------------------END-OF-SELECTION.CALL SCREEN '0300'.* ----------------------------------------------------------------------*•At User Command ** ----------------------------------------------------------------------AT USER-COMMAND.CASE sy-ucomm.WHEN 'OK'.REFRESH it_temp.CLEAR it_temp.MOVE 'S' TO wa_temp-type.MOVE gv_tbname TO wa_temp-tablename.DO.READ LINE sy-index FIELD VALUE gv_temp INTO gv_temp.IF sy-subrc NE 0.EXIT.ENDIF.IF gv_temp EQ 'X'.sy-index = sy-index - 1.READ TABLE it_dd03l INTO wa_dd03l INDEX sy-index.IF sy-subrc = 0.MOVE wa_dd03l-fieldname TO wa_temp-fieldname.APPEND wa_temp TO it_temp.CLEAR gv_temp.ENDIF.ENDIF.ENDDO.DESCRIBE TABLE it_temp.IF sy-tfill GT 70.* **--More than 70 fields can not be selectedMESSAGE i001 WITH 'Cannot select more than 70 Parameters'(006).REFRESH it_temp[]. CLEAR it_temp.ELSE.LEAVE LIST-PROCESSING.ENDIF.WHEN 'CANCEL'.LEAVE LIST-PROCESSING.WHEN 'SELALL'.* **--Select all fieldsCLEAR wa_dd03l-fieldname.DO.READ LINE sy-index.

Page 10: Dynamic Table

IF sy-subrc EQ 0 ANDwa_dd03l-fieldname NE space.gv_temp = 'X'.MODIFY LINE sy-index INDEX 0 FIELD VALUE gv_temp.HIDE gv_temp.CLEAR wa_dd03l-fieldname.ELSEIF sy-subrc NE 0.EXIT.ENDIF.ENDDO.WHEN 'DSELALL'.* **--Deselect all fieldsCLEAR gv_temp.DO.READ LINE sy-index.IF sy-subrc EQ 0.CLEAR gv_temp.MODIFY LINE sy-index INDEX 0 FIELD VALUE gv_temp FROM gv_temp.HIDE gv_temp.ELSEIF sy-subrc NE 0.EXIT.ENDIF.ENDDO.ENDCASE.sy-lsind = 0.* &---------------------------------------------------------------------* *& Form INITIALIZE** &---------------------------------------------------------------------* * Initialize values on selection-screen* ----------------------------------------------------------------------FORM initialize .p_btn1 = 'Where Condition'(003).p_btn2 = 'Field Options'(003).p_btn3 = 'Reset'(003).ENDFORM. " INITIALIZE* &---------------------------------------------------------------------* *& Form SELECT_FLDS* &---------------------------------------------------------------------* * Select fields from the table* ----------------------------------------------------------------------FORM select_flds .CASE sscrfields-ucomm.WHEN 'WHERE_COND'.* **--Display Screen with the list of fieldsPERFORM genr_scr.WHEN 'FIELD_OPT'.* **--Display Screen with the list of fieldsPERFORM genr_scr_field.

Page 11: Dynamic Table

WHEN 'RESET'.CLEAR: IT_FLDS[],IT_FLDS1[].ENDCASE.ENDFORM. " SELECT_FLDS*&---------------------------------------------------------------------**&      Form  genr_scr_field*&---------------------------------------------------------------------**       text*----------------------------------------------------------------------*form genr_scr_field.** **--If table in the parameter is not the same as the old table and** **--old table is not blank, then initialise all the variables associated* IF p_tab NE gv_t_old AND gv_t_old IS NOT INITIAL.* REFRESH: it_tabs, it_flds,* gx_texpr, gx_twhere,* s_where, s_selop.* CLEAR: gv_selid.** **--Pass current table parameter value to Old table parameter* gv_t_old = p_tab.* ENDIF.** **--Pass the current table name to old table variable* IF gv_t_old EQ space.* gv_t_old = p_tab.* ENDIF.* **--Check if table name is given before clicking the buttonIF p_tab IS INITIAL.MESSAGE e001 WITH 'Enter the Table name'(004).ENDIF.* **--Get the list of ,fields of a given table* PERFORM get_selections_field.* **--If none of the fields, provide the list of fields for selectingIF it_flds1[] IS INITIAL.CLEAR gv_selid.** Change* **--Display Screen with the list of fieldsPERFORM select_fieldlist_display.IF it_flds1[] IS INITIAL.MESSAGE s001 WITH 'No parameters selected for Field Options'(005).EXIT.ENDIF.

* ** ChangeENDIF.* **--Show message if none of the fields are selectedendform.                    "genr_scr_field* &---------------------------------------------------------------------* *& Form genr_scr* &---------------------------------------------------------------------

Page 12: Dynamic Table

* * Display a screen with list of fields* ----------------------------------------------------------------------FORM genr_scr.** **--If table in the parameter is not the same as the old table and** **--old table is not blank, then initialise all the variables associated* IF p_tab NE gv_t_old AND gv_t_old IS NOT INITIAL.* REFRESH: it_tabs, it_flds,* gx_texpr, gx_twhere,* s_where, s_selop.* CLEAR: gv_selid.** **--Pass current table parameter value to Old table parameter* gv_t_old = p_tab.* ENDIF.** **--Pass the current table name to old table variable* IF gv_t_old EQ space.* gv_t_old = p_tab.* ENDIF.* **--Check if table name is given before clicking the buttonIF p_tab IS INITIAL.MESSAGE e001 WITH 'Enter the Table name'(004).ENDIF.* **--Get the list of ,fields of a given tablePERFORM get_selections.* **--If none of the fields, provide the list of fields for selectingIF it_flds[] IS INITIAL.CLEAR gv_selid.** Change* CASE sscrfields-ucomm.* WHEN 'WHERE_COND'.* **--Display Screen with the list of fieldsPERFORM select_fieldlist.IF it_flds[] IS INITIAL.MESSAGE s001 WITH 'No parameters selected for Where Condition '(005).EXIT.ENDIF.* **--Generate dynamic select-optionsREFRESH it_tabs.CLEAR : it_tabs, wa_tabs.wa_tabs-prim_tab = p_tab.APPEND wa_tabs TO it_tabs.PERFORM set_values.* **--Generate Expression from Where clauseCALL FUNCTION 'FREE_SELECTIONS_WHERE_2_EX'EXPORTINGwhere_clauses        = gx_twhereIMPORTINGexpressions          = gx_texprEXCEPTIONS

Page 13: Dynamic Table

incorrect_expression = 1OTHERS               = 2.IF sy-subrc NE 0.MESSAGE i001 WITH 'Error in Dynamic screen generation'(009).EXIT.ENDIF.IF gx_texpr IS NOT INITIAL.* **--Populate values to select-options from expressionPERFORM set_values.ENDIF.* **--Display screen with the fields listedIF gv_selid IS NOT INITIAL.PERFORM call_screen.ENDIF.* WHEN 'FIELD_OPT'.** **--Display Screen with the list of fields*  PERFORM select_fieldlist_display.*  IF it_flds1[] IS INITIAL.* MESSAGE s001 WITH 'No parameters selected for Field Options'(005).* EXIT.* ENDIF.* ENDCASE.* ** ChangeENDIF.* **--Show message if none of the fields are selectedENDFORM. " genr_scr* &---------------------------------------------------------------------* *& Form GET_SELECTIONS* &---------------------------------------------------------------------* * Fetch the fields in the table given* ----------------------------------------------------------------------FORM get_selections.DATA : wa_where LIKE LINE OF gx_twhere.REFRESH: it_flds, gx_twhere.CLEAR : wa_flds.wa_flds-tablename = p_tab.wa_flds-type = 'S'.LOOP AT s_selop.* **--Populate all the fields selected that are previously selectedwa_flds-fieldname = s_selop-low.APPEND wa_flds TO it_flds.ENDLOOP.CLEAR S_SELOP[].IF s_where[] IS NOT INITIAL.* **--Populate values to where condition if any data is previously given* **--to the dynamic select-optionswa_where-tablename = p_tab.LOOP AT s_where.

Page 14: Dynamic Table

APPEND s_where-low TO wa_where-where_tab.ENDLOOP.APPEND wa_where TO gx_twhere.ENDIF.ENDFORM. " GET_SELECTIONS

*&---------------------------------------------------------------------**&      Form  get_selections_field*&---------------------------------------------------------------------**       text*----------------------------------------------------------------------*FORM get_selections_field.DATA : wa_where LIKE LINE OF gx_twhere.REFRESH: it_flds1, gx_twhere.CLEAR : wa_flds.wa_flds-tablename = p_tab.wa_flds-type = 'S'.

LOOP AT s_selop.* **--Populate all the fields selected that are previously selectedwa_flds-fieldname = s_selop-low.APPEND wa_flds TO it_flds1.ENDLOOP.

IF s_where[] IS NOT INITIAL.* **--Populate values to where condition if any data is previously given* **--to the dynamic select-optionswa_where-tablename = p_tab.LOOP AT s_where.APPEND s_where-low TO wa_where-where_tab.ENDLOOP.APPEND wa_where TO gx_twhere.ENDIF.ENDFORM. " GET_SELE* &---------------------------------------------------------------------* *& Form SELECT_FIELDLIST* &---------------------------------------------------------------------* * Display the list of fields* ----------------------------------------------------------------------FORM select_fieldlist.perform field_select.* **--Display screen with the fields listed for the given tableCALL SCREEN 200 STARTING AT 10 2ENDING AT 70 22.* **--Clear all the fields selectedCLEAR : it_flds, it_flds[], gv_tbname.* **--Populate the newly selected fieldsit_flds[] = it_temp[].* **--Clear temporary table with the fields selected

Page 15: Dynamic Table

CLEAR : it_temp, it_temp[].ENDFORM. " SELECT_FIELDLIST**Changeform field_select.CLEAR: it_dd03l[], it_dd03l,gv_tbname.* **--Get field names for given tableSELECT tabnamefieldnamekeyflagrollnamepositionFROM dd03lINTO TABLE it_dd03lWHERE tabname EQ p_tabAND fieldname NE 'MANDT'.IF sy-subrc = 0.SORT it_dd03l BY position.DELETE it_dd03l WHERE fieldname CP '.INCLU*'.ENDIF.* **--Get the description of the fieldsLOOP AT it_dd03l INTO wa_dd03l.IF NOT wa_dd03l-rollname IS INITIAL.SELECT SINGLE ddtextFROM dd04tINTO wa_dd03l-ddtextWHERE rollname EQ wa_dd03l-rollnameAND ddlanguage = sy-languAND as4local = 'A'.MODIFY it_dd03l FROM wa_dd03l.ELSE.SELECT SINGLE ddtextFROM dd03tINTO wa_dd03l-ddtextWHERE tabname EQ wa_dd03l-tabnameAND ddlanguage = sy-languAND as4local = 'A'AND fieldname = wa_dd03l-fieldname.MODIFY it_dd03l FROM wa_dd03l.ENDIF.ENDLOOP.gv_tbname = p_tab.endform.                    "field_select** ChangeFORM select_fieldlist_display.perform field_select.* **--Display screen with the fields listed for the given tableCALL SCREEN 400 STARTING AT 10 2

Page 16: Dynamic Table

ENDING AT 70 22.* **--Clear all the fields selectedCLEAR : it_flds1, it_flds1[], gv_tbname.* **--Populate the newly selected fieldsit_flds1[] = it_temp[].* **--Clear temporary table with the fields selectedCLEAR : it_temp, it_temp[].ENDFORM. " SELECT_FIELDLIST* &---------------------------------------------------------------------* *& Form INITIALIZE_SCREEN* &---------------------------------------------------------------------* * text* ----------------------------------------------------------------------FORM initialize_screen.CALL FUNCTION 'FREE_SELECTIONS_INIT'EXPORTINGkind                     = 'T'expressions              = gx_texprIMPORTINGselection_id             = gv_selidnumber_of_active_fields  = gv_actnumTABLEStables_tab               = it_tabsfields_tab               = it_fldsEXCEPTIONSfields_incomplete        = 01fields_no_join           = 02field_not_found          = 03no_tables                = 04table_not_found          = 05expression_not_supported = 06incorrect_expression     = 07illegal_kind             = 08area_not_found           = 09inconsistent_area        = 10kind_f_no_fields_left    = 11kind_f_no_fields         = 12too_many_fields          = 13.ENDFORM. " INITIALIZE_SCREEN* &---------------------------------------------------------------------* *& Form SET_VALUES* &---------------------------------------------------------------------* * Set the values to the select-options* ----------------------------------------------------------------------FORM set_values.CALL FUNCTION 'FREE_SELECTIONS_INIT'EXPORTINGkind                     = 'T'

Page 17: Dynamic Table

expressions              = gx_texprIMPORTINGselection_id             = gv_selidnumber_of_active_fields  = gv_actnumTABLEStables_tab               = it_tabsfields_tab               = it_fldsEXCEPTIONSfields_incomplete        = 01fields_no_join           = 02field_not_found          = 03no_tables                = 04table_not_found          = 05expression_not_supported = 06incorrect_expression     = 07illegal_kind             = 08area_not_found           = 09inconsistent_area        = 10kind_f_no_fields_left    = 11kind_f_no_fields         = 12too_many_fields          = 13.ENDFORM. " SET_VALUES* &---------------------------------------------------------------------* *& Form CALL_SCREEN* &---------------------------------------------------------------------* * Call the screen to display the fields* ----------------------------------------------------------------------FORM call_screen.DATA : wa_where LIKE LINE OF gx_twhere,lv_txt TYPE string.lv_txt = 'Dynamic Selections Parameters for'(007).CONCATENATE lv_txt p_tabINTO gv_title SEPARATED BY space.CALL FUNCTION 'FREE_SELECTIONS_DIALOG'EXPORTINGselection_id            = gv_selidtitle                   = gv_titletree_visible            = ' 'IMPORTINGwhere_clauses           = gx_twhereexpressions             = gx_texprnumber_of_active_fields = gv_actnumTABLESfields_tab              = it_fldsEXCEPTIONSinternal_error          = 01no_action               = 02no_fields_selected      = 03

Page 18: Dynamic Table

no_tables_selected      = 04selid_not_found         = 05.IF sy-subrc EQ 0.REFRESH: s_where, s_selop.* **--Populate the Where clause with selected valuess_where-sign = gc_i.s_where-option = gc_eq.CLEAR wa_where.READ TABLE gx_twhere INDEX 1 INTO wa_where.LOOP AT wa_where-where_tab INTO s_where-low.APPEND s_where.ENDLOOP.* **--Populate all the fieldss_selop-sign = gc_i.s_selop-option = gc_eq.CLEAR : wa_flds.LOOP AT it_flds INTO wa_flds.s_selop-low = wa_flds-fieldname.APPEND s_selop.ENDLOOP.ENDIF.ENDFORM. " CALL_SCREEN* &---------------------------------------------------------------------* *& Module STATUS_0200 OUTPUT* &---------------------------------------------------------------------* * Display screen with select-options* ----------------------------------------------------------------------MODULE status_0200 OUTPUT.DATA: lv_txt TYPE string.lv_txt = 'Selection Paramters List'(008).SET PF-STATUS 'DIALOG'.LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.SUPPRESS DIALOG.MOVE lv_txt TO sy-title.* **--display list of fields that can be selected for creating dynamic select-optionsLOOP AT it_dd03l INTO wa_dd03l.AT FIRST.WRITE: (60) sy-uline.ENDAT.READ TABLE it_flds INTO wa_flds WITH KEY fieldname = wa_dd03l-fieldname.IF sy-subrc NE 0.CLEAR gv_temp.ELSE.gv_temp = 'X'.ENDIF.WRITE:/ '|' ,gv_temp AS CHECKBOX.WRITE: (20) wa_dd03l-fieldname,'|', wa_dd03l-ddtext, AT 60 '|'.HIDE: gv_temp, wa_dd03l-fieldname, wa_dd03l-keyflag.

Page 19: Dynamic Table

AT LAST.WRITE: (60) sy-uline.ENDAT.ENDLOOP.ENDMODULE. " STATUS_0200 OUTPUT**ChangeMODULE status_0400 OUTPUT.DATA: lv_txt1 TYPE string.lv_txt1 = 'Selection Paramters List'(008).SET PF-STATUS 'DIALOG1'.LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.SUPPRESS DIALOG.MOVE lv_txt TO sy-title.* **--display list of fields that can be selected for creating dynamic select-optionsLOOP AT it_dd03l INTO wa_dd03l.AT FIRST.WRITE: (60) sy-uline.ENDAT.READ TABLE it_flds1 INTO wa_flds WITH KEY fieldname = wa_dd03l-fieldname.IF sy-subrc NE 0.CLEAR gv_temp.ELSE.gv_temp = 'X'.ENDIF.WRITE:/ '|' ,gv_temp AS CHECKBOX.WRITE: (20) wa_dd03l-fieldname,'|', wa_dd03l-ddtext, AT 60 '|'.HIDE: gv_temp, wa_dd03l-fieldname, wa_dd03l-keyflag.AT LAST.WRITE: (60) sy-uline.ENDAT.ENDLOOP.ENDMODULE. " STATUS_0200 OUTPUT** Change* &---------------------------------------------------------------------* *& Form FETCH_DATA* &---------------------------------------------------------------------* * Fetch data from table* ----------------------------------------------------------------------FORM fetch_data .DATA: lv_where TYPE string,lv_cnt TYPE i.* **--Check for the existance of the table

SELECT *FROM dd03lINTO TABLE it_fieldsWHERE tabname = p_tab.*   and fieldname = it_flds1-fieldname.

Page 20: Dynamic Table

SORT it_fields BY position.* **--Delete the fields starting with .INCLUDELETE it_fields WHERE fieldname CP '.INCLU*'.** Changesort it_fields[] by fieldname.** Changeloop at it_flds1 into wa_flds.* **--Display the first 150 fields of the table* LOOP AT it_fields INTO wa_fields TO 150.LOOP AT it_fields INTO wa_fields where fieldname = wa_flds-fieldname.lv_cnt = lv_cnt + 1.wa_cat-tabname = p_tab.wa_cat-fieldname = wa_fields-fieldname.wa_cat-col_pos = lv_cnt.wa_cat-inttype = wa_fields-inttype.wa_cat-datatype = wa_fields-datatype.wa_cat-intlen = wa_fields-intlen.wa_cat-seltext = wa_fields-fieldname.wa_cat-decimals = wa_fields-decimals.wa_cat-ref_field = wa_fields-fieldname.wa_cat-ref_table = p_tab.APPEND wa_cat TO it_cat.CLEAR wa_cat.wa_fname-fld = wa_fields-fieldname.APPEND wa_fname TO it_fname.CLEAR wa_fname.ENDLOOP.clear wa_flds.endloop.* **--Create a dynamic internal table with the 150 fieldsCALL METHOD cl_alv_table_create=>create_dynamic_tableEXPORTINGit_fieldcatalog = it_catIMPORTINGep_table        = d_ref.ASSIGN d_ref->* TO <f_fs>.* **--Populate the Where clause as a stringLOOP AT s_where.CONCATENATE lv_where s_where-low INTO lv_where SEPARATED BY space.ENDLOOP.* **--Select the data from the table given as input and populate* **--it into the dynamic internal table created based on the where conditionSELECT (it_fname)FROM (p_tab)INTO CORRESPONDING FIELDS OF TABLE <f_fs>WHERE (lv_where).* **--If no entries are found that satisfies the selection criteriaIF sy-subrc <> 0.

Page 21: Dynamic Table

MESSAGE i000(zz) WITH 'No data found'(010).ENDIF.ENDFORM. " FETCH_DATA* &---------------------------------------------------------------------* *& Form DISPLAY_DATA* &---------------------------------------------------------------------* * Display data in the grid control* ----------------------------------------------------------------------FORM display_data .IF gt_cust IS INITIAL.CREATE OBJECT gt_custEXPORTINGcontainer_name = cust.CREATE OBJECT gt_gridEXPORTINGi_parent = gt_cust.* **--Display the data in the grid controlCALL METHOD gt_grid->set_table_for_first_displayEXPORTINGi_buffer_active = 'X'i_bypassing_buffer = ' '* * I_CONSISTENCY_CHECK =* * I_STRUCTURE_NAME =* * IS_VARIANT =* * I_SAVE =* * I_DEFAULT = 'X'* * IS_LAYOUT =* * IS_PRINT =* * IT_SPECIAL_GROUPS =* * IT_TOOLBAR_EXCLUDING =* * IT_HYPERLINK =* * IT_ALV_GRAPHICS =* * IT_EXCEPT_QINFO =* * IR_SALV_ADAPTER =CHANGINGit_outtab = <f_fs>it_fieldcatalog = it_cat* * IT_SORT =* * IT_FILTER =EXCEPTIONSinvalid_parameter_combination = 1program_error = 2too_many_lines = 3OTHERS = 4.IF sy-subrc <> 0.ENDIF.ENDIF.

Page 22: Dynamic Table

ENDFORM. " DISPLAY_DATA* &---------------------------------------------------------------------* *& Module DISPLAY_DATA OUTPUT* &---------------------------------------------------------------------* * Dispaly data in the output* ----------------------------------------------------------------------MODULE display_data OUTPUT.PERFORM display_data.ENDMODULE. " DISPLAY_DATA OUTPUT* &---------------------------------------------------------------------* *& Module STATUS_0300 OUTPUT* &---------------------------------------------------------------------* * Pf-status for the screen* ----------------------------------------------------------------------MODULE status_0300 OUTPUT.SET PF-STATUS '13317'.ENDMODULE. " STATUS_0300 OUTPUT* &---------------------------------------------------------------------* *& Module USER_COMMAND_0300 INPUT* &---------------------------------------------------------------------* * Handling the button clicks* ----------------------------------------------------------------------MODULE user_command_0300 INPUT.CASE sy-ucomm.* **--Go to the previous screenWHEN 'BACK'.LEAVE TO SCREEN 0.* **--Come out of the programWHEN 'EXIT'.LEAVE PROGRAM.ENDCASE.ENDMODULE. " USER_COMMAND_0300 INPUT