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

Table Determination

Former Member
0 Likes
725

Hi All,

I need to determine a particular table (CO-PA) based on the particular orgn unit.

And accordingly I will determine the table name from where I need to get the values.

Now once I determine, the name of the table willl be in a string.

How can I write a select query making use of the table name which is in the string.

Awaiting ur help.

Thanks,

DP

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
684

check this code...

*-----

For dynamic table name....

REPORT demo_select_dynamic_database .

DATA wa TYPE scarr.

DATA name(10) TYPE c VALUE 'SCARR'.

SELECT *

INTO wa

FROM (name) CLIENT SPECIFIED

WHERE mandt = '000'.

WRITE: / wa-carrid, wa-carrname.

ENDSELECT.

*-----

For dynamic field list

REPORT demo_select_dynamic_columns .

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

line = ' CITYFROM CITYTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

WRITE: / wa-cityfrom, wa-cityto.

ENDLOOP.

ENDIF.

Regards

Shashi

6 REPLIES 6
Read only

keerthy_k
Product and Topic Expert
Product and Topic Expert
0 Likes
684

Hi,

u can use the field TABNAME of the table DD02L for the variable in the progam insead of string.

DATA : l_tabname type DD02L-TABNAME value 'SPFLI',

wa type spfli.

*Now in select u can use this variable..like:

Select single * from (l_tabname) into wa where carrid = 'AA' .

write:/ wa-connid.

This is working....pls try..

Keerthi

Edited by: Keerthy K on Mar 10, 2009 10:48 AM

Read only

Former Member
0 Likes
685

check this code...

*-----

For dynamic table name....

REPORT demo_select_dynamic_database .

DATA wa TYPE scarr.

DATA name(10) TYPE c VALUE 'SCARR'.

SELECT *

INTO wa

FROM (name) CLIENT SPECIFIED

WHERE mandt = '000'.

WRITE: / wa-carrid, wa-carrname.

ENDSELECT.

*-----

For dynamic field list

REPORT demo_select_dynamic_columns .

DATA: itab TYPE STANDARD TABLE OF spfli,

wa LIKE LINE OF itab.

DATA: line(72) TYPE c,

list LIKE TABLE OF line(72).

line = ' CITYFROM CITYTO '.

APPEND line TO list.

SELECT DISTINCT (list)

INTO CORRESPONDING FIELDS OF TABLE itab

FROM spfli.

IF sy-subrc EQ 0.

LOOP AT itab INTO wa.

WRITE: / wa-cityfrom, wa-cityto.

ENDLOOP.

ENDIF.

Regards

Shashi

Read only

Former Member
0 Likes
684

hi,

passing the table name dynamically via a string variable can be done as follows:

assuming that u have assigned the table name to a string variable ie

string_variable = tablename .

select * from (string_variable) into wa.

write: wa.

try this...

thanks

Read only

Former Member
0 Likes
684

hi,

Try using the string directly in the Select query where u need to give the Table name.

Select * from (string)............

Thanks and Regards

Suraj S. Nair.

Read only

Former Member
0 Likes
684

Hi;

have a look

[Link|http://help.sap.com/saphelp_nw70/helpdata/en/67/93b80914a911d2953c0000e8353423/content.htm]

Regards

Shashi

Read only

Former Member
0 Likes
684

Thanks for everyone help.