Skip to Content

dynamic where clause in select query

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Dec 04, 2007 at 10:42 AM

    hi Prabhu,

    do:

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

    double ' before 0287 and triple ' after 0287

    ec

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 10:38 AM

    Hi,

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

    Regards,

    Prashant

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 10:39 AM

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

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

    set text-001 to '

    Albert

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 10:46 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 04, 2007 at 10:47 AM

    Use,

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

    Regards,

    Abhishek

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.