Application Development and Automation 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: 
Read only

Select data from multiple tables using only one select query

Former Member
0 Likes
1,914

Hi All,

I am making a report where the user chooses the names of tables he wants to select data from. I have to fetch data from these tables and upload the data as flat files to application server.

When writing the report, 2 things are unknown : name and number of tables. As the internal table also depends on the table, the structure will be unknown too.

Is there a way in which I can only write one select statement and it can be reused.

Something like:

Select * from [table name] into table [internal table name of same format].

where I can update the table name and internal table (which should be of the same format as the table) .

Thanks,

Samriddhi

1 ACCEPTED SOLUTION
Read only

s1252
Product and Topic Expert
Product and Topic Expert
0 Likes
1,470
you can write something like this 

SELECT * FROM (p_table) INTO TABLE @DATA(lt_table) UP TO p_rows ROWS.

*lt_table will be dynamically created based on select output. 
2 REPLIES 2
Read only

DoanManhQuynh
Active Contributor
1,470

Take a look at program: DEMO_DYNAMIC_SQL, you will know how to build a dynamic SQL.

Read only

s1252
Product and Topic Expert
Product and Topic Expert
0 Likes
1,471
you can write something like this 

SELECT * FROM (p_table) INTO TABLE @DATA(lt_table) UP TO p_rows ROWS.

*lt_table will be dynamically created based on select output.