05-09-2007 1:45 PM
Dear Friends,
I need your opinion about a query I have to write.
I need to input the name of the table in a variable and retrieve data
from that particular table.
e.g. <b>var</b> = 'MARA'.
Select * from <b>var</b> into table itab .
Somebody advised me to use Field Symbol for this purpose.
I have never used field symbols and am not aware about it's usage.
Please help.......
05-09-2007 1:48 PM
Hi,
for this u don't need to go for field symbols.
try like this.
Select * from (var) into table itab .
field symnols will be useful some special cases like example shown below.
data:var1(10) value 'var2'.
data:var2(10) value 'output'.
field-symbols:<fs> type any.
assign (var1) to <fs>.
write:/ <fs>.
rgds,
bharat.
Message was edited by:
Bharat Kalagara
05-09-2007 1:48 PM
Hi,
for this u don't need to go for field symbols.
try like this.
Select * from (var) into table itab .
field symnols will be useful some special cases like example shown below.
data:var1(10) value 'var2'.
data:var2(10) value 'output'.
field-symbols:<fs> type any.
assign (var1) to <fs>.
write:/ <fs>.
rgds,
bharat.
Message was edited by:
Bharat Kalagara
05-09-2007 1:50 PM
parameters : p_tab like dd03l-tabname.
select * from (p_tab) into table itab.
05-09-2007 1:54 PM
Yes, u have to use field symbols, as u have no idea, what the table name is going to be, and hence u cannot declare an internal table with a pre defined structure.
u have to generate an internal table of the structure of the table which u are going to select data from.
here is sample code.
DATA: wa_fldcat TYPE LVC_S_FCAT.
DATA: it_fldcat TYPE LVC_T_FCAT.
DATA: it TYPE REF TO DATA.
*parameters : p_week type kweek.
parameters : p_tabnm type TABNAME16.
FIELD-SYMBOLS: <fs_table> TYPE TABLE.
FIELD-SYMBOLS: <fs_temp> TYPE ANY.
data : t_dd03 like dd03l occurs 0 with header line.
select * from dd03l into corresponding fields of table t_dd03
where tabname = p_tabnm.
loop at t_dd03.
wa_fldcat-fieldname = t_dd03-fieldname.
wa_fldcat-tabname = 'IT'.
wa_fldcat-datatype = t_dd03-rollname.
append wa_fldcat to it_fldcat.
endloop.
*CREATE THE DYNAMIC INTERNAL TABLE
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat[]
IMPORTING
EP_TABLE = it.
ASSIGN it->* TO <fs_table>.
so now fs_table has structure of ur table.
now u can select data from ur tabe to fs_table.
05-09-2007 2:49 PM
Dear Sujamol,
The code you sent to me ......I could not understand some part of it.
loop at t_dd03.
wa_fldcat-fieldname = t_dd03-fieldname.
wa_fldcat-tabname = <b>'IT'</b> . WHY 'IT' ??
wa_fldcat-datatype = t_dd03-rollname.
append wa_fldcat to it_fldcat.
endloop.
Actually I already have two different internal tables, having two different tablname
and fields, and I need to check the common fields these two tables have.
Any suggestions???