Dynamic SELECT from arbitrary table

I have a Dropdown List in my Program in which I entered the names of different tables. So I worked with the IF-Statement. Basically:

if wa_list-key = '1'.
(replace name of table with the one choosen from the dropdown list)

I have this kind of selection:

select * from customer into table lt_customer.

Whats the syntax of replacing names of tables? I know replace-statements only work with strings but is there a way around?


  • You can dynamically select from a table:

    DATA: lv_table TYPE tabname.
        SELECT * 
               INTO TABLE lt_table
               FROM (lv_table).

    However the lt_table you select into, has to have the same structure like the database table you select from, otherwise it will dump. To overcome this you can use INTO COORESPONDING FIELDS OF lt_table (instead of INTO TABLE...). You can also declare the WHERE conditions dynamically: WHERE (lv_where) It all depends on your exact needs.