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 in select statement - Is it possible!

Former Member
0 Likes
6,606

Hello All,

I have a internal table with one column containing table names

Field

-


RSAABAP

RSATABLE

RSAFGA

.....

..

I need to read this internal table and write the content of each table on the screen.. like select * from...

My question here is

Is it possible for me to use a statement like

select * from tabname where this tabname is variable which could accomodate the table names like RSAABAP & so on..

Thanks in advance!

Karthik

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,530

Hi karthik,

1. yes we can give the table name as variable.

2. just copy paste to get a taste of it.

3.

report abc.

*----


DATA : T001 LIKE TABLE OF T001 WITH HEADER LINE.

DATA : TABNAME(30) TYPE C.

TABNAME = 'T001'.

SELECT * FROM <b>(TABNAME)</b>

INTO TABLE T001.

BREAK-POINT.

4. The only thing is that

the INTO TABLE

should be defined accordingly.

regards,

amit m.

5 REPLIES 5
Read only

Former Member
0 Likes
2,530

Yes it is possible:

select *

from ( v_tabname )

into table itab.

where..

Refer the following example:

<i><b>Example

Dynamic specification of the inner joins. The column specification after SELECT is also dynamic.

PARAMETERS: p_cityfr TYPE spfli-cityfrom,

p_cityto TYPE spfli-cityto.

DATA: BEGIN OF wa,

fldate TYPE sflight-fldate,

carrname TYPE scarr-carrname,

connid TYPE spfli-connid,

END OF wa.

DATA itab LIKE SORTED TABLE OF wa

WITH UNIQUE KEY fldate carrname connid.

DATA: column_syntax TYPE string,

dbtab_syntax TYPE string.

column_syntax = `ccarrname pconnid f~fldate`.

dbtab_syntax = `( ( scarr AS c `

& ` INNER JOIN spfli AS p ON pcarrid = ccarrid`

& ` AND p~cityfrom = p_cityfr`

& ` AND p~cityto = p_cityto )`

& ` INNER JOIN sflight AS f ON fcarrid = pcarrid `

& ` AND fconnid = pconnid )`.

SELECT (column_syntax)

FROM (dbtab_syntax)

INTO CORRESPONDING FIELDS OF TABLE itab.

LOOP AT itab INTO wa.

WRITE: / wa-fldate, wa-carrname, wa-connid.

ENDLOOP.</b></i>

Regards,

ravi

Read only

Former Member
0 Likes
2,531

Hi karthik,

1. yes we can give the table name as variable.

2. just copy paste to get a taste of it.

3.

report abc.

*----


DATA : T001 LIKE TABLE OF T001 WITH HEADER LINE.

DATA : TABNAME(30) TYPE C.

TABNAME = 'T001'.

SELECT * FROM <b>(TABNAME)</b>

INTO TABLE T001.

BREAK-POINT.

4. The only thing is that

the INTO TABLE

should be defined accordingly.

regards,

amit m.

Read only

Former Member
0 Likes
2,530

Hai

Check the following Code

REPORT ZDYNAMIC_SELECT .

TABLES: VBAK.

DATA: CONDITION TYPE STRING.

DATA: BEGIN OF ITAB OCCURS 0,

VBELN LIKE VBAK-VBELN,

POSNR LIKE VBAP-POSNR,

END OF ITAB.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.

CONCATENATE 'VBELN' 'IN' 'S_VBELN.'

INTO CONDITION SEPARATED BY SPACE.

SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB

WHERE (CONDITION).

LOOP AT ITAB.

WRITE 'hello'.

ENDLOOP.

Thanks & regards

Sreenivasulu P

Read only

Former Member
0 Likes
2,530

Hi

Yes u can:

PARAMETERS P_TABLE(30) TYPE C.

DATA: WA TYPE STRING.

DATA: T_WA LIKE TABLE OF WA.

SELECT * FROM (P_TABLE) INTO T_WA.

Max

Read only

Former Member
0 Likes
2,530

Hi Karthik Krishna ,

suppose ur internal table 'itab 'containing table names is defined like..

data: begin of itab occurs 0,

RSAABAP like tadir-obj_name,

RSATABLE like tadir-obj_name,

RSAFGA like tadir-obj_name,

end of itab.

After populating itab,

Select * from (itab-RSAABAP) into itab1.

Thanks ,

Kiran