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 issue with IF statement

Former Member
0 Likes
1,286

Hi All,

I'm using below if condition , is their any way to avoid multiple IF conditions  ?

Constants : C_N(1) type C value 'N',

            C_S(1) type C value 'S',

            C_E(1) type C value 'E',

            C_A(1) type C value 'A',

            C_C(1) type C value 'C',

            C_R(1) type C value 'R',

            C_M(1) type C value 'M'.

if it_debit-status = C_N or

   it_debit-status = C_S or

it_debit-status = C_E or

it_debit-status = C_A or

it_debit-status = C_C or

it_debit-status = C_R or

it_debit-status = C_M.

10 REPLIES 10
Read only

JJosh
Active Participant
0 Likes
1,254

Hi Smitha,

Try the below codes..

1. Sort it_debit by status.

2. Try using Case.... End Case.

3. Delete it_debit where Status NOT IN (XXXX).

Read only

Former Member
0 Likes
1,254

Hi Smitha,

You can code like this:

LOOP AT IT_DEBIT INTO WA_DEBIT.

CASE STATUS.

WHEN C_N.

WHEN C_S.

WHEN C_E.

WHEN C_A

WHEN C_C.

WHEN C_R.

WHEN C_M.

WHEN OTHERS.

ENDCASE.

CLEAR WA_DEBIT.

ENDLOOP.

You do not have to add any logic for WHEN OTHERS. But it is a good practise to include that as well. Hope this helps!

Read only

Former Member
0 Likes
1,254

Hi Smitha,

If you are using if conditions in your program it will kill the performance.because it will check each and every condition ..but if you use case and endcase only it will trigger if the condition satisfies.

Thanks

Pavan.

Read only

Former Member
0 Likes
1,254

Can we use Check ?

Read only

0 Likes
1,254

Case...Endcase is always better than CHECK

Read only

kakshat
Product and Topic Expert
Product and Topic Expert
0 Likes
1,254

Hi Smitha,

Yes, you can use CHECK but even with that you will have to write all the conditions. And, that's the case with CASE too!

You can avoid multiple conditions in case there are very few (only a couple for example) values for which you don't want the logic to be executed. So, you have several values (N, S, E, A, C, R, M) for which you want to execute your logic. If the values for which you don't want to execute this logic are very few (let's say only one - Z), you can do with a single IF condition using the <> operator i.e. IF STATUS <> 'Z'.

Also, CHECK statement is generally used to exit a block of code if certain conditions are not met. So, it has a semantic significance attached to it. For cases where you want to perform different things based on different conditions, IF or CASE would be better.

Read only

Kartik2
Contributor
0 Likes
1,254

Hi,

Without using IF it can be acieved by using ranges or select options. Please use the following code:

   data char type char01.

select-options s_number for char no-display.

s_number-sign   = 'I'.
s_number-option = 'EQ'.
s_number-low    = 'A'.
append s_number to s_number.

s_number-sign   = 'I'.
s_number-option = 'EQ'.
s_number-low    = 'E'.
append s_number to s_number.

s_number-sign   = 'I'.
s_number-option = 'EQ'.
s_number-low    = 'C'.
append s_number to s_number.

char = 'D'.

if char in s_number.

endif.

You can change the names of variables accordingly. Thank you.

Regards,

Kartik

Read only

Former Member
0 Likes
1,254

Hi,

Make use of ranges.

Thanks,

Tooshar Bendale

Read only

Former Member
0 Likes
1,254

Hi,

The best option is to use CASE- ENDCASE statement, in this case.

BR

Nitin

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,254

Did SAT or SE30 raise actually any performance problem on this statement 

Else for maintenanbility (but not much for perfiormance) you could write

CASE  it_debit-status.

  WHEN c_n OR c_s OR c_e OR c_a OR c_c OR c_r OR c_m.

    " ...

  WHEN OTHERS.

    " ...

ENDCASE.

Regards,

Raymond