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

Dynamic SQL Statement with table name

Former Member
0 Likes
4,874

Dear all

i like to have a SQL statement with a dynamic tablename. Is this possible? If yes, how?

should be something like "select * from <mytablename>"

Thank you

Herbert

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,763

Yes this is possible. use the below reference code for this.

data: g_tablename type w_tabname,

gv_dref TYPE REF TO data.

FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.

gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)

CREATE DATA gv_dref TYPE TABLE OF (g_tabname).

ASSIGN gv_dref->* TO <g_itab>.

now use the below select query to fetch the data

SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.

Hope this will help

4 REPLIES 4
Read only

Former Member
0 Likes
1,763

Hi,

It's possible.

Ex;

w_tabname = 'MARA'.

select * from (w_tabname) into table ...

Read only

Former Member
0 Likes
1,763

Hi,

U can try like this,

  • Select

select * from zcostfreq

where (where_tab).

endselect.

regards,

Neelima.

Read only

Former Member
0 Likes
1,763

You can have dynamic statement .

select * from (sname)

into table

Read only

Former Member
0 Likes
1,764

Yes this is possible. use the below reference code for this.

data: g_tablename type w_tabname,

gv_dref TYPE REF TO data.

FIELD-SYMBOLS: <g_itab> TYPE STANDARD TABLE.

gv_tabname = p_tablename (take table name form selection screen or as per ur requirement)

CREATE DATA gv_dref TYPE TABLE OF (g_tabname).

ASSIGN gv_dref->* TO <g_itab>.

now use the below select query to fetch the data

SELECT * FROM (gv_tabname) INTO TABLE <g_itab>.

Hope this will help