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

Performance : if-endif vs case-endcase.

Former Member
0 Likes
2,339

Hi,

Which is better in performance ? if endif or case endcase?

I have an if endif condition in which i am checking 20 values like

if wa-var1 = '1' OR wa-var = '2' OR

............................................

...........................................

wa-var1 = '19' OR wa-var = '20'.

molga = '26'

endif.

This code is in a userexit and the std application is taking a lot of time to complete.

Would a case endcase help ?

Thanks

Pranati.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,054

It is always advisable to use case … endcase as far as possible.

When testing fields "equal to" something, one can use either the nested IF or the CASE statement

The CASE is better for two reasons. It is easier to read and after about five nested IFs the performance of the CASE is more efficient.

2 REPLIES 2
Read only

Former Member
0 Likes
1,055

It is always advisable to use case … endcase as far as possible.

When testing fields "equal to" something, one can use either the nested IF or the CASE statement

The CASE is better for two reasons. It is easier to read and after about five nested IFs the performance of the CASE is more efficient.

Read only

Former Member
0 Likes
1,054

Using CASE will not help. When there are only two alternatives (as here) it might take longer.

This statement cannot possibly be the source of the problem.

Rob