‎2006 Jun 26 12:28 PM
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
‎2006 Jun 26 12:30 PM
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.
‎2006 Jun 26 12:30 PM
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
‎2006 Jun 26 12:30 PM
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.
‎2006 Jun 26 12:31 PM
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
‎2006 Jun 26 12:32 PM
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
‎2006 Jun 26 12:38 PM
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