Application Development 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: 

Building a dynamic IF condition

Former Member
0 Kudos

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

Former Member
0 Kudos

I think the following thread will help you a lot:

Award if info is useful

Thanks, Ankur

6 REPLIES 6

Former Member
0 Kudos

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

0 Kudos

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

0 Kudos

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

0 Kudos

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.

Former Member
0 Kudos

I think the following thread will help you a lot:

Award if info is useful

Thanks, Ankur

Former Member
0 Kudos

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