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: 

variable table in SQL select

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

...or just press F1 on SELECT FROM.

Rob

Former Member
0 Kudos

Check this :

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

Regards

Neha

Former Member
0 Kudos

Hi,

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

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

Regards,

Chris Gu

Former Member
0 Kudos

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.