‎2007 Sep 21 7:40 AM
Hi frnds,
In my selection screen I have threefields like tablename, fieldname and date.
For eg: mkpf in Tablename
budat in field(it can be bldat, cpudt anything)
10.09.2007 in date fileds
For this selection, I have to write a select query dynamically..(i.e) tablename and fieldname are dynamic parameters...
How to pass these in select query..
select * from (tabname)
into wa
where (fieldname) in date.
‎2007 Sep 21 7:45 AM
Check the fm <b>RH_DYNAMIC_WHERE_BUILD</b> to specify a WHERE clause dynamically
and the below extract from SAP help, helps to specify the database table dynamically
<b>Specifying Database Tables Dynamically</b>
To specify the name of a database table dynamically, use the following:
SELECT... FROM (<name>) <options> . ..
The field <name> must contain the name of a database table in the ABAP Dictionary. The table name must be written in uppercase. When you specify the name of a database table dynamically, you cannot use an empty INTO clause to read all of the columns into the work area <dbtab>. It is also not possible to use alternative table names.
Message was edited by:
Rajesh
‎2007 Sep 21 7:45 AM
Check the fm <b>RH_DYNAMIC_WHERE_BUILD</b> to specify a WHERE clause dynamically
and the below extract from SAP help, helps to specify the database table dynamically
<b>Specifying Database Tables Dynamically</b>
To specify the name of a database table dynamically, use the following:
SELECT... FROM (<name>) <options> . ..
The field <name> must contain the name of a database table in the ABAP Dictionary. The table name must be written in uppercase. When you specify the name of a database table dynamically, you cannot use an empty INTO clause to read all of the columns into the work area <dbtab>. It is also not possible to use alternative table names.
Message was edited by:
Rajesh
‎2007 Sep 21 7:47 AM
Hi nivetha
if your requirement is urgent , you could do this below way.
If conditon = '01'.
select x1 x2. ....from tab1..
elseif condtion = '02'.
select x3 x4 from tab2.
...
endif.
Regards
Wiboon
Regards
Wiboon
‎2007 Sep 21 8:19 AM
Hi,
Check the following link:
http://sap-img.com/abap/how-can-we-give-dynamic-table-name-in-select-statement.htm
Regards,
Bhaskar
‎2007 Sep 21 12:34 PM
tables mara.
data itab type table of mara with header line.
data table(4) type c value 'MARA' .
data wh_codn type string.
select-options s_date for mara-ersda.
parameter p_fname1(5) type c.
concatenate p_fname1
' in s_date'
into wh_codn.
select * from (table)
into table itab
where (wh_codn) .
Loop at itab.
WRITE: itab-mandt,
itab-matnr,
itab-ersda,
endloop.
This dynamic select query works well in 4.7..
But in 4.6 C it is throwing a syntax error " wa_cond" is not an inttable.
How to do this in 4.6C