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 condition on a loop

Former Member
0 Likes
3,173

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.

9 REPLIES 9
Read only

Former Member
1,279

DATA dyn_cond TYPE STRING.
 
dyn_cond = 'field = 123'.
 
LOOP AT itab WHERE ( dyn_cond ).
...
ENDLOOP.

Greetings,

Blag.

Read only

Former Member
0 Likes
1,279

I don't think you can use dynamic WHEREs in a LOOP AT statement. But you can use ranges and fill them dynamically.

Rob

Read only

ThomasZloch
Active Contributor
0 Likes
1,279

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

Read only

former_member194669
Active Contributor
0 Likes
1,279

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®

Read only

0 Likes
1,279

O.K.

But what is correct solution for this.

Best Regars.

Read only

0 Likes
1,279

O.K.

But what is correct solution for this?

Best Regars.

Read only

0 Likes
1,279

Check my earlier response - you can use ranges.

Rob

Read only

0 Likes
1,279

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.

Read only

0 Likes
1,279

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