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

How to use a table name in the select statement using a variable?

Former Member
0 Likes
2,054

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
Read only

Former Member
0 Likes
1,802

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.

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.

9 REPLIES 9
Read only

Former Member
0 Likes
1,802

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

Regards,

Ravi

Read only

Former Member
0 Likes
1,802

Hello,

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

Vasanth

Read only

Former Member
0 Likes
1,802

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

Read only

Former Member
0 Likes
1,802

Hi all,

Thanks a lot.

Read only

Former Member
0 Likes
1,802

Hi alik,

Parameters: Tab_name TYPE DD02L-TABNAME.

SELECT * FROM (Tab_name) INTO TABLE ITAB where ____

Regards

Sudheer

Read only

Former Member
0 Likes
1,803

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.

Read only

0 Likes
1,802
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.
Read only

0 Likes
1,802

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

Read only

0 Likes
1,802

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

Reward if this solves ur query.