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

Building a dynamic IF condition

Former Member
0 Likes
5,994

Hi all,

Is there a way to check if a dynamically built logical expression is true or false? For example, I have two values val_1 and val_2 in a table, and a logical operator also stored in my table, how do I check ( val_1 <operator> val_2 ) at run time?

I tried to concatenate this into a string and check but it does not work. Any ideas?

Thanks,

Nithya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,011

I think the following thread will help you a lot:

Award if info is useful

Thanks, Ankur

6 REPLIES 6
Read only

Former Member
0 Likes
2,011

hI,

Move the same thing to the Field symbol instead of a string, then you can check this field symbol value to that table

Regards

Sudheer

Read only

0 Likes
2,011

Hi Sudheer,

In this case, the operator itself will be picked up from a table at runtime only. So the complete expression has to be built at run time. I have a table that has the operator and threshold value to check against. When the user enters a particular value, this check has to be done. Any input?

Regards

Nithya

Read only

0 Likes
2,011

Hi,

Is it an internal table or database table ?...and will the user make an entry in the selection screen or is it in the program excution that happens ?

Thanks..

Preetham S

Read only

0 Likes
2,011

Hi Nithya,

Are all the three variables in a single line of the internal table - in three different columns

LOOP AT <itab> INTO <wa>.

IF <wa>-fld1 <wa>-comp <wa>-fld2.

ENDIF.

CLEAR: <wa>.

ENDLOOP.

This works i think.

Read only

Former Member
0 Likes
2,012

I think the following thread will help you a lot:

Award if info is useful

Thanks, Ankur

Read only

Former Member
0 Likes
2,011

You can try Defining a Macro or do it by Ranges:

<b>If you want to use a Macro, Try something like this:</b>

DATA: t_t001 TYPE t001 OCCURS 0 WITH HEADER LINE.

DEFINE my_dynamic_check.

if &1 &2 &3.

write:/ 'Success'.

else.

write:/ 'Failed'.

endif.

END-OF-DEFINITION.

SELECT * FROM t001 INTO TABLE t_t001.

LOOP AT t_t001.

my_dynamic_check t_t001-bukrs eq 'US01'. "US01 can be replaced by a company code in table T001

ENDLOOP.

<b>Or if You want to use Ranges:</b>

ranges: r_datum for sy-datum.

r_datum-sign = 'I'.

r_datum-option = 'EQ'.

r_datum-low = sy-datum.

apppend r_datum.

If sy-datum in r_datum.

Endif.

Thanks, Ankur

Award if the info is useful

Message was edited by:

ankur malhotra