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 condition

Former Member
0 Likes
1,034

Hi Forum!

I want to know if it's possible to build a dynamic logical expression for IF or CASE instructions and get it evaluated.

For example:

data: LogExp type string.

LogExp = 'Sy-subrc eq 0'.

IF (LogExp).

Endif.

Or

data: Var type string,

LogExp type i.

LogExp1 = 0.

LogExp2 = 4.

Var = 'Sy-subrc'.

Case (Var).

When (LogExp1).

When (LogExp2).

...

When others.

Endcase.

Thanks in advance.

John.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
671

Hi John,

in general your idea of dynamic logical expression is not possible in ABAP.

But you can use the operator IN in combination with range tables. You have define all variables in your statement. Empty range tables will be treated as true.

See this example:

data lt_r_subrc type range of sy-subrc.
data ls_r_subrc like line of lt_r_subrc.

ls_r_subrc-sign = 'I'.
ls_r_subrc-option = 'EQ'.
ls_r_subrc-low  = 0.
insert ls_r_subrc into table lt_r_subrc.

if sy-subrc in lt_r_subrc.
" do something
endif.

Just modify the range tables for different conditons.

Regards,

Axel

2 REPLIES 2
Read only

Former Member
0 Likes
671

hi,

Dynamic If conditions are not possible.

Try with subroutine pools instead..

Regards,

Sailaja.

Read only

Former Member
0 Likes
672

Hi John,

in general your idea of dynamic logical expression is not possible in ABAP.

But you can use the operator IN in combination with range tables. You have define all variables in your statement. Empty range tables will be treated as true.

See this example:

data lt_r_subrc type range of sy-subrc.
data ls_r_subrc like line of lt_r_subrc.

ls_r_subrc-sign = 'I'.
ls_r_subrc-option = 'EQ'.
ls_r_subrc-low  = 0.
insert ls_r_subrc into table lt_r_subrc.

if sy-subrc in lt_r_subrc.
" do something
endif.

Just modify the range tables for different conditons.

Regards,

Axel