2013 Mar 14 5:57 AM
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.
2013 Mar 14 6:06 AM
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).
2013 Mar 14 6:12 AM
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!
2013 Mar 14 6:17 AM
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.
2013 Mar 14 6:26 AM
2013 Mar 14 6:29 AM
2013 Mar 14 6:57 AM
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.
2013 Mar 14 6:39 AM
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
2013 Mar 14 6:52 AM
2013 Mar 14 7:29 AM
Hi,
The best option is to use CASE- ENDCASE statement, in this case.
BR
Nitin
2013 Mar 14 8:08 AM