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 IF - if (lv_condition)

bruno_macedo
Explorer
0 Likes
4,474

Hi mates,

i have a configuration table where i'll read some values like Contains, Contains Any, Begins With, etc...

now i want to construct an if statement based on that table entries like:

CONCATENATE var_1 var_operator var_2

                   INTO lv_condition SEPARATED BY space.

and then use:

if (lv_condition)

in this case, somthing like "if (var_1 CA var_2)."

is it possible? Simple?

Maybe i'll have to quit this solution and try case/endcase...

any help would be great.

thanks!

1 ACCEPTED SOLUTION
Read only

Ashg1402
Contributor
2,380

Hi Bruno,

Unfortunately this dynamic condition will not work.

But what is your proper requirement.?

Regards

Ashish

7 REPLIES 7
Read only

Ashg1402
Contributor
2,381

Hi Bruno,

Unfortunately this dynamic condition will not work.

But what is your proper requirement.?

Regards

Ashish

Read only

0 Likes
2,380

Well, i have a ZTAB1 (transparent table) where i need to check some conditions (EQ, NE, CA, CS...) and some description/value in other field.

Depending on the selection to that table, i'll get different results so my if can be:
if var1 EQ '1' or if var_1 CS 'S103' etc etc

Anyway, i can manage to have the variables more or less dynamic but not the logic expressions... i cannot do if(lv_condition)

where the condition is, for instance, 'var_1 CS 'F409''...
I guess i'll have to hardcode a CASE condition with the logic expressions.

(sorry if it's not so clear, my english is not perfect) thanks a lot

Read only

0 Likes
2,380

hi,

As far as I have used, dynamic condition works in where condition for loop and select queries.

you can do a loop and inside it put the condition according to the your need.

Regards

Ashish

Read only

0 Likes
2,380

We'll maybe i can try and check if i can do a logic where i use a loop instead of an if.

I know that the WHERE statement let's you put a condition based on a concatenate. Thanks.

Read only

0 Likes
2,380

I've sorted it out with a CASE condition.

Not dynamic but it's working for now. In the meantime, maybe i could change this part of the code to be  dynamic.

Thanks mates!

Read only

Juwin
Active Contributor
0 Likes
2,380

Kindly search before posting.

Have a look at this discussion: http://scn.sap.com/community/abap/blog/2016/02/29/dynamic-if-condition

Thanks,

Juwin

Read only

0 Likes
2,380

Thanks mate. Will read. Seems a bit complex (for my experience). And i'll get it will be easier for me to do the CASE statement but it's always great to have such opinions and learn new stuff. thanks!