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

how to include dynamic where clause

Former Member
0 Likes
1,141

hai i want to write the dyanamic where clause to my select statments can any one suggest me how to do it

regards

afzak

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,098

hi... what do u want to do exactly?

SELECT * FROM <db table> into <wa> WHERE (<cond_syntax>).

you can build the cond_syntax programatically by using string operations like concatenate.

9 REPLIES 9
Read only

Former Member
0 Likes
1,099

hi... what do u want to do exactly?

Read only

0 Likes
1,098

hai the requierment is that i dont know the where clause till runtime i mean whcih fields i have to pass to select statment and what conditions like or and, so once i may get there fields and next time 4 fields and conditions may differ or and , so i want to build the where clause based on this

regards

afzal

Read only

0 Likes
1,098

hi... u can select dynamic fields as below..

data: str type table of string.

data: st type string.

(here u can append ur fields' name into str which u want to..

ex.

st = 'carrid'.

append st to str.

)

select (str) from spfli into corresponding fields of table it_spfli.

this way u can select dynamic fields int select query..

Read only

Former Member
0 Likes
1,098

See the below post

Read only

Former Member
0 Likes
1,098

Please go through this link.

http://www.sapfans.com/forums/viewtopic.php?t=74847

Regards

Vasu

Read only

Former Member
0 Likes
1,098

hi

u should create a screen in screen painter and put a button

where condition there and text boxes

and then u can create u r own

there is posibility in screen painter

Read only

Former Member
0 Likes
1,098

SELECT * FROM <db table> into <wa> WHERE (<cond_syntax>).

you can build the cond_syntax programatically by using string operations like concatenate.

Read only

Former Member
0 Likes
1,098

Hi,

Dynamic " where" can be achieved by the FM

CALL FUNCTION 'AIBZ_FILL_WHERE_CLAUSE'

EXPORTING

i_tabname =

it_select =

IMPORTING

es_where_clause = .

and pass all the exporting parameters.

Rvert back if any issues,

Reward with points if helpful.

Regards,

Naveen

Read only

Former Member
0 Likes
1,098

Hi Afzal,

REPORT demo_select_dynamic_conditions .

DATA: cond(72) TYPE c,

itab LIKE TABLE OF cond.

PARAMETERS: city1(10) TYPE c, city2(10) TYPE c.

DATA wa TYPE spfli-cityfrom.

CONCATENATE 'CITYFROM = ''' city1 '''' INTO cond.

APPEND cond TO itab.

CONCATENATE 'OR CITYFROM = ''' city2 '''' INTO cond.

APPEND cond TO itab.

CONCATENATE 'OR CITYFROM = ''' 'BERLIN' '''' INTO cond.

APPEND cond TO itab.

LOOP AT itab INTO cond.

WRITE cond.

ENDLOOP.

SKIP.

SELECT cityfrom

INTO wa

FROM spfli

WHERE (itab).

WRITE / wa.

ENDSELECT.

Thanks & Regards,

Sai