‎2008 Jan 08 11:09 AM
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.
‎2008 Jan 08 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.
‎2008 Jan 08 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 )
endif.
endloop.
But maybe is dynamic condition is not necessary, but
a some fixed if-conditions are also o.k.
Siegfried
‎2008 Jan 08 3:26 PM
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.