Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to generate a dynamic selection-screen

0 Kudos
2,362

Hi folks,

I have a itab with all fields and descriptions of a database-table. Now i want to generate a selection screen dynamically. I want to create a select-option for every field of the table.

First I read all fields of a database table into my intern table:

CALL FUNCTION 'DDIF_FIELDINFO_GET'

EXPORTING

tabname = 'database_tabname'

TABLES

dfies_tab = it_tabname_fields.

Then I tried to generate a dynamic selection-screen with a select-options statement per field of the itab, but it doesn't work:

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 NO INTERVALS.

LOOP AT it_tabname_fields INTO s_tabname_fields. "should be 14 loops and 14 lines

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT (25) s_tabname_fields-SCRTEXT_S FOR FIELD var1. "the name of the field should be set dynamically from the itab

SELECT-OPTIONS var1 FOR tabname-s_tabname_fields-fieldname. "s_tabname_fields-fieldname should be set dynamically for each line

SELECTION-SCREEN END OF LINE.

ENDLOOP.

SELECTION-SCREEN END OF BLOCK b2.

I know that this doesn't work but it should help you to understand what i want to do. It doesn't create more than one select-option (it should be 14 because there are 14 lines in the table) and it doesn't get the values from the table.

I hope you can help me...

Regards,

Sebastian

1 ACCEPTED SOLUTION

Former Member
0 Kudos
273

HI,

enter any data base table name in the parameters field and execute.

it will show u key fields as select-options if u want remaining field select SETTINGS->FIELDS FOR SELECTION there select required fields and press enter.

PARAMETERS:TABNAME(30).

CALL FUNCTION 'RS_TABLE_LIST_CREATE'

EXPORTING

TABLE_NAME = TABNAME.

rgds,

bharat.

3 REPLIES 3

Former Member
0 Kudos
273

hi Koehler

Refer to this code sample ... might be of some help

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abapProgramtogenerateselect-options+dynamically&

Former Member
0 Kudos
273

hi

Firstly, have a look at the following code to see how this can be implemented -


REPORT ZTEST.
 
perform test.
 
 
class test definition.
  public section.
    methods: create_screen.
endclass.
 
class test implementation.
  method create_screen.
    data:  report_line(72),
           report_source like table of report_line.
 
    data: err_message(240),
          err_line type i,
          err_word(100).
 
    report_line = 'REPORT TEST.'.
    append report_line to report_source.
 
    report_line = 'PARAMETERS: P_TEST TYPE I.'.
    append report_line to report_source.
 
    report_line = 'START-OF-SELECTION.'.
    append report_line to report_source.
 
    report_line = 'WRITE : P_TEST.'.
    append report_line to report_source.
 
    syntax-check for report_source message err_message
                                   line    err_line
                                   word    err_word.
    if err_message is initial.
      INSERT REPORT 'ZZZTESTZZZ' FROM REPORT_SOURCE.
      SUBMIT ZZZTESTZZZ VIA SELECTION-SCREEN AND RETURN.
    endif.
  endmethod.
endclass.
 
form test.
  data test type ref to test.
  CREATE OBJECT TEST.
  call method test->create_screen.
endform.


As you can see, the report is being written dynamically. Once the INSERT REPORT statement is executed, the program is available. you can you external subroutine calls to pass the data between the programs now.

Regards,

ravish

<b>plz dont forget to reward points if helpful</b>

Former Member
0 Kudos
274

HI,

enter any data base table name in the parameters field and execute.

it will show u key fields as select-options if u want remaining field select SETTINGS->FIELDS FOR SELECTION there select required fields and press enter.

PARAMETERS:TABNAME(30).

CALL FUNCTION 'RS_TABLE_LIST_CREATE'

EXPORTING

TABLE_NAME = TABNAME.

rgds,

bharat.