Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Dynamic selection

Former Member
0 Likes
569

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
521

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

4 REPLIES 4
Read only

Former Member
0 Likes
522

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

Read only

Former Member
0 Likes
521

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

Read only

Former Member
0 Likes
521
Read only

Former Member
0 Likes
521

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