‎2008 Feb 14 4:37 PM
Hello,
I need to do a dynamic where condition on a loop for example:
DATA dyn_cond TYPE STRING.
dyn_cond = 'field = 123'.
LOOP AT itab WHERE dyn_cond.
...
ENDLOOP.
The compiler throw me a compiler error.
Thanks for your help.
‎2008 Feb 14 4:42 PM
DATA dyn_cond TYPE STRING.
dyn_cond = 'field = 123'.
LOOP AT itab WHERE ( dyn_cond ).
...
ENDLOOP.
Greetings,
Blag.
‎2008 Feb 14 4:43 PM
I don't think you can use dynamic WHEREs in a LOOP AT statement. But you can use ranges and fill them dynamically.
Rob
‎2008 Feb 14 4:48 PM
as said, not possible for LOOP, only for SELECT.
So dump your internal table contents into a Z-table and do a SELECT
But seriously, other than dynamically generating a temporary program I don't see a way to do this.
Greetings
Thomas
‎2008 Feb 14 5:15 PM
This is what i get F1 on LOOP
Addition 3
... WHERE log_exp
Effect
WHERE can be specified with all table-types. After WHERE, you can specify any logical expression log_exp in which the first operand of any singular comparison is a component of the internal table. For this reason, all logical expressions are possible except for IS ASSIGNED, IS REQUESTED and IS SUPPLIED. Dynamic specification of a component through bracketed character-type data objects is not possible Loops at sorted tables must have compatible operands of the logical expression. All rows are read for which the logical expression is true.
a®
‎2008 Feb 14 7:48 PM
‎2008 Feb 14 7:49 PM
‎2008 Feb 14 8:53 PM
‎2008 Feb 15 9:05 AM
however with ranges, you can only prepare the check values dynamically, but not the fields to be checked.
My answer to the OP is: there is no way to do this, except the very last and complex alternative, generate ABAP code on the fly and executing that.
‎2008 Feb 15 2:11 PM
Well - you would have to set up ranges for all fields that might be checked. This wouldn't be a lot different that setting up a dynamic WHERE.
Rob