Skip to Content
author's profile photo Former Member
Former Member

dynamic where clause in loop


I know dynamic clause works for SELECT.....


I built where_clause using concatenate... based on when key fields are available. So sometime where_clause has: A = X-1 and B = X-2. and another time where_clause can have A = X-1 and C = X-5 and D = X-6.....

SELECT * from db into table int_tab where (where_clause)

However I use the same way to build this dynamic where_clause, then used on the loop at statement :

LOOP AT int_tab into int_line

where (where_clause)

I got syntax error : Statement Concluding with ".... (where_clause)" ended unexpectedly.

Any idea to make where clause dynamicly for LOOP?


Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 08, 2008 at 11:23 AM

    Hi yi-wen,

    this is not possible since the LOOP statement wants to know the static type of the fields used in the WHERE clause.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 08, 2008 at 12:09 PM

    You should be aware that a LOOP AT ... WHERE is not an optimized access .

    + because on a standard table there is not sort order,

    so the loop goes over the whole table and does

    something when the condition is fulfilled

    + it is optimzed for sorted tables, but only for one key!

    => so your idea must have bad performance!

    If this is not a problem, then you can solve the problem

    in the following way:

    loop at table

    if ( dynamic condition )



    But maybe is dynamic condition is not necessary, but

    a some fixed if-conditions are also o.k.


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member


      Thanks for your response.

      I did try IF ( dynamic_condition).

      some logic...


      but I got syntax error : Relational operator ")" is not supported.

      Did I spill wrong?


      the dynamic_condition will contain A-A1 = B-A1 and A-A2 = B-A2, A-A4 = B-A4...... whatever the combination when A-Ax is available.

      Thanks so much.

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.