05-18-2006 11:10 AM
In select Statement i want to put table name and field name as variables
please reply
05-18-2006 11:21 AM
Hi Umesh,
check this sample..
REPORT ZTEST_DYNAMIC no standard page heading .
parameters: tabl type DD03L-tabname,
fld type dd03l-FIELDNAME.
data: begin of itab occurs 0,
char(20),
end of itab.
start-of-selection.
select (fld)
into table itab
from (tabl).
if sy-subrc = 0.
endif.
end-of-selection.
write: tabl.
write:/ fld.
loop at itab.
write: / ITAB-char.
endloop.
Regards
vijay
05-18-2006 11:12 AM
try
select (fld1) (fld2) from (table)
into (w_fld1,w_fld2).
Regards,
Suresh Datti
I could pass the table name to the variable but the field names had to be specified.. the above statement did not work..
Message was edited by: Suresh Datti
05-18-2006 11:14 AM
Hi umesh,
1. we can do like this for table name.
2.
report abc.
data : tabname(30) type c.
data : itab like table of t001 with header line.
*----
tabname = 'T001'.
select *
from (tabname)
into table itab.
break-point.
regards,
amit m.
05-18-2006 11:18 AM
Hi Umesh,
Please check the below select :
SELECT * FROM (V_TABLE) INTO WORK WHERE (OPTIONS).
Concatenate where condition into options.
Thanks&Regards,
Siri.
05-18-2006 11:19 AM
chk this prog
REPORT ychatest.
PARAMETERS : p_tabnam LIKE dd03l-tabname.
DATA : v_tbname LIKE dd03l-tabname.
SELECT tabname FROM (p_tabnam) INTO v_tbname UP TO 1 ROWS.
ENDSELECT.
WRITE : v_tbname.
05-18-2006 11:19 AM
Hai Umesh
Check with the link
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/select.htm
select field1
field2
from table1
into internal Table
where <Condition>.
Regards
Sreeni
05-18-2006 11:21 AM
Hi Umesh,
check this sample..
REPORT ZTEST_DYNAMIC no standard page heading .
parameters: tabl type DD03L-tabname,
fld type dd03l-FIELDNAME.
data: begin of itab occurs 0,
char(20),
end of itab.
start-of-selection.
select (fld)
into table itab
from (tabl).
if sy-subrc = 0.
endif.
end-of-selection.
write: tabl.
write:/ fld.
loop at itab.
write: / ITAB-char.
endloop.
Regards
vijay
05-18-2006 11:21 AM
I agree with Amit, but want to make slight changes..
The code should be like this
tables: MARA.
data: v_fields(100) type c,
v_ftable(30) type c,
v_ttable(30) type c,
v_where(255) type c.
Data: begin of i_makt occurs 0,
matnr like mara-matnr,
maktx like makt-maktx,
end of i_makt.
SELECT-OPTIONS S_MATNR for MARA-MATNR.
v_fields = 'MATNR MAKTX'.
V_FTABLE = 'MAKT'.
V_TTABLE = 'I_MAKT'.
V_WHERE = 'MATNR in S_MATNR'.
select (v_fields)
into table (v_ttable)
from (v_ftable)
where (v_where).
Regds
Sandip
Message was edited by: Sandip Kamdar
05-18-2006 11:22 AM
05-18-2006 11:22 AM
Hi Umesh,
Welcome to SDN...........
Select statement with table name and field name as variables is possible. This is nothing but dynamic nature providing to field names and table name.
The dynamic naturre is provided with the help of <b>( )</b> [braces). The select statement will intrepet the values in () are of field names and table name. You can query select statement with dynamic fields or with dynamic tables or with both.
The syntax for this as follows::
<b>select (field1) (field2) (field3)
from (table name)
into <internal table>.</b>
Plz be careful while passing values to these field names and table name otherwise it will gives improper results.
Thanks,
Vinay
Note: plz award points to all helpful answers and close the thread if it is solved.