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 loop

Former Member
0 Likes
672

Hi,

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

e.g.

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?

Thanks.

3 REPLIES 3
Read only

Former Member
0 Likes
557

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.

Read only

Former Member
0 Likes
557

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 )

endif.

endloop.

But maybe is dynamic condition is not necessary, but

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

Siegfried

Read only

0 Likes
557

Siegfried,

Thanks for your response.

I did try IF ( dynamic_condition).

some logic...

ENDIF.

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

Did I spill wrong?

Note:

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.