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

variable table in SQL select

Former Member
0 Likes
1,167

Hello,

In various SQL versions it is possible to define a variable that will hold the name of the table and then use that variable in the FROM clause instead the actual table name.

something like this:

var_table(4) type c.

var_table = 'tab1'

select * from &var_table&... etc

var_table = 'tab2'

select * from &var_table&... etc

It is possible something like this in ABAP SQL?

Thank you.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
953

Hi,

yes, you can use the dynamic table for the SQL selection.

SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>.

Regards,

Chris Gu

5 REPLIES 5
Read only

Former Member
0 Likes
953

yes, search using Dynamic Select, and you will find 1000s of threads

Read only

0 Likes
953

...or just press F1 on SELECT FROM.

Rob

Read only

Former Member
0 Likes
953

Check this :

https://www.sdn.sap.com/irj/scn/advancedsearch?query=dynamicSelect&cat=sdn_all

Regards

Neha

Read only

Former Member
0 Likes
954

Hi,

yes, you can use the dynamic table for the SQL selection.

SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>.

Regards,

Chris Gu

Read only

Former Member
0 Likes
953

Hi,

Check the foll code:

PARAMETERS: P_TABLE LIKE DD03L-TABNAME.

DATA: XTABLE TYPE REF TO DATA.
FIELD-SYMBOLS: <FS_TABLE>  TYPE TABLE,
               <WA_TABLE> TYPE ANY.


CREATE DATA XTABLE type TABLE OF (p_table).
assign xtable->* to <fs_table>.

SELECT * FROM (P_TABLE) INTO TABLE <fs_table> ORDER BY PRIMARY KEY.

loop at <fs_table> ASSIGNING <wa_table>.
ENDLOOP.

Thanks & Regards,

Navneeth K.