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 use a table name in the select statement using a variable?

Former Member
0 Kudos

Hi Everybody,

I got a internal table which has a field or a variable that gets me some tables names. Now I need to retrieve the data from all these tables in that field dynamically at runtime. So could you suggest me a way out to use the select query which uses this variable as a table ?

Regards,

Mallik.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi all,

Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?

for ex : select * from (tab_name) where....?

Can we do inner join on such select statements? If so how?

Thanks & Regards,

Mallik.

9 REPLIES 9

former_member181962
Active Contributor
0 Kudos

select * from (v_table_name) into table itab where ....

Regards,

Ravi

Former Member
0 Kudos

Hello,

LV_TABNAME = 'MARA'.
Select * from ( LV_TABNAME ) ....

Vasanth

Former Member
0 Kudos

Hi Malli,

Dynamic values to the SELECT query are passed with in brackets.

DATA V_TABNAME TYPE DD02L-TABNAME.

V_TABNAME = 'VBAK'.

SELECT * FROM (V_TABNAME) INTO TABLE ITAB.

Thanks,

Vinay

Former Member
0 Kudos

Hi all,

Thanks a lot.

Former Member
0 Kudos

Hi alik,

Parameters: Tab_name TYPE DD02L-TABNAME.

SELECT * FROM (Tab_name) INTO TABLE ITAB where ____

Regards

Sudheer

Former Member
0 Kudos

Hi all,

Actually i need some more clarification. How to use the same select statement, if i've to use the tabname in the where clause too?

for ex : select * from (tab_name) where....?

Can we do inner join on such select statements? If so how?

Thanks & Regards,

Mallik.

0 Kudos
tables: mara.
DATA  TABNAME(10).
SELECT-options: s_matnr FOR MARA-matnr.
TABNAME = 'MARA'.
SELECT * INTO TABLE ITAB FROM (TABNAME)
 WHERE matnr IN s_matnr.

0 Kudos

Hi judith,

Thanks for the reply, But can we use inner join or for all entries in such select statements which use variable in place of table name? if so how?

Best Regards,

Mallik

0 Kudos

I tried and it gave an error, I gues no.

Reward if this solves ur query.