‎2009 Mar 10 9:06 AM
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
‎2009 Mar 10 9:48 AM
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
‎2009 Mar 10 9:12 AM
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
‎2009 Mar 10 9:48 AM
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
‎2009 Mar 11 4:25 AM
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
‎2009 Mar 11 8:36 AM
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.
‎2009 Mar 12 11:44 AM
Hi;
have a look
[Link|http://help.sap.com/saphelp_nw70/helpdata/en/67/93b80914a911d2953c0000e8353423/content.htm]
Regards
Shashi
‎2009 Apr 02 3:03 PM