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

IF Statement Peformance Question

Former Member
0 Likes
382

I have an abap program that performs 20% better with a simple change in the structure of the if statement. Anyone got any explaination why this would be so? I would really appreciate any insight into this.

This code:

IF sy-tcode IN r_order_tcodes.

...some logic #1....

ELSEIF sy-batch EQ 'X' OR

( sy-cprog = 'ZSR_ECAT_GENERATE_V3' ).

...some logic #1....

ENDIF.

executes 20% faster than this code:

IF sy-tcode IN r_order_tcodes OR

sy-tcode IN r_ecat_tcodes OR

( sy-batch EQ 'X' AND

( sy-cprog EQ 'ZSR_GENERATE_ECAT_V3' OR

sy-cprog EQ 'ZSR_ECAT_SINGLE_CONFIG'

)

).

...some logic #1...

endif.

Thanks.

Scott

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
346

hi,

it's giving 20% more performance because in this case it's checking only one condition at a time. i.e. IF sy-tcode IN r_order_tcodes,if this is satisfied then it won't check else condition.

In the second case it has to check all the conditions.

IF sy-tcode IN r_order_tcodes OR

sy-tcode IN r_ecat_tcodes OR

( sy-batch EQ 'X' AND

( sy-cprog EQ 'ZSR_GENERATE_ECAT_V3' OR

sy-cprog EQ 'ZSR_ECAT_SINGLE_CONFIG'

)

).her it has to check all the conditions specified in the if.

so performance will be decreased

if helpful reward points

2 REPLIES 2
Read only

Former Member
0 Likes
346

Hi,

I believe the tcodes in r_order_tcodes and r_ecat_tcodes will have the same programs given in the else condition...

Looks like This following simple IF statement will work for all the scenarios..

Try this..

IF SY-CPROG = 'ZSR_GENERATE_ECAT_V3' OR

SY-CPROG = 'ZSR_ECAT_SINGLE_CONFIG'.

...some logic #1....

ENDIF.

Thanks,

Naren

Read only

Former Member
0 Likes
347

hi,

it's giving 20% more performance because in this case it's checking only one condition at a time. i.e. IF sy-tcode IN r_order_tcodes,if this is satisfied then it won't check else condition.

In the second case it has to check all the conditions.

IF sy-tcode IN r_order_tcodes OR

sy-tcode IN r_ecat_tcodes OR

( sy-batch EQ 'X' AND

( sy-cprog EQ 'ZSR_GENERATE_ECAT_V3' OR

sy-cprog EQ 'ZSR_ECAT_SINGLE_CONFIG'

)

).her it has to check all the conditions specified in the if.

so performance will be decreased

if helpful reward points