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 where clause in select query

prabhu_s2
Active Contributor
0 Likes
1,227

Hi

I'm trying for a dynamic query and in the dynamic where clause i'm checking a field for constant.....for instance if i wanna to use WERKS EQ '0478' how to declare it in dync where clause. i tried for the following:

SELECT (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE (CONDI).

heree CONDI = 'werks eq 0287' . in this case the query fails as the werks shud be equal to '0287' and not just 0287. How to handle this? i tried for the following

CONDI = 'werks eq " '0287' " ' but no luck as it is not a valid stmt as i knew.

1 ACCEPTED SOLUTION
Read only

JozsefSzikszai
Active Contributor
0 Likes
1,021

hi Prabhu,

do:

condi = 'werks EQ ''0287'''.

double ' before 0287 and triple ' after 0287

ec

Hi

I'm trying for a dynamic query and in the dynamic where clause i'm checking a field for constant.....for instance if i wanna to use WERKS EQ '0478' how to declare it in dync where clause. i tried for the following:

SELECT (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE (CONDI).

heree CONDI = 'werks eq 0287' . in this case the query fails as the werks shud be equal to '0287' and not just 0287. How to handle this? i tried for the following

CONDI = 'werks eq " '0287' " ' but no luck as it is not a valid stmt as i knew.

6 REPLIES 6
Read only

former_member386202
Active Contributor
0 Likes
1,021

Hi,

SELECT (TAB_FIELD) INTO TABLE DITAB UP TO 10 ROWS FROM (TAB_NAME) WHERE werks eq '0287'.

Regards,

Prashant

Read only

0 Likes
1,021

dear prashant

i'm totaly aware of how to write a where clause but my question is how to use it in dynamic where clause.

Read only

Former Member
0 Likes
1,021

concatenate text-001 '0287' text-001 into condi.

concatenate 'WERKS = ' l_value into condi separated by space.

set text-001 to '

Albert

Read only

JozsefSzikszai
Active Contributor
0 Likes
1,022

hi Prabhu,

do:

condi = 'werks EQ ''0287'''.

double ' before 0287 and triple ' after 0287

ec

Read only

Former Member
0 Likes
1,021

hi prabhu,

this is how u select dynamically...

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.

regards,

sohi

Read only

former_member195698
Active Contributor
0 Likes
1,021

Use,

<b>CONDI = ' werks eq ''0287'' '.</b>

Regards,

Abhishek