‎2007 Aug 01 11:30 AM
Hi,
Do nested if statements result in performance issues ?
I have a subroutine which has the following codes within its body.
DATA: l_date_high TYPE datum,
l_date_low TYPE datum,
l_time_high TYPE uzeit,
l_time_low TYPE uzeit.
CLEAR: l_date_high, l_date_low.
IF so_date IS INITIAL.
l_date_high = sy-datlo.
CLEAR: l_date_low.
l_time_high = sy-uzeit.
CLEAR: l_time_low.
ELSEIF so_date-high IS INITIAL AND NOT so_date-low IS INITIAL.
l_date_high = so_date-low.
IF l_date_high = sy-datlo.
l_time_high = sy-uzeit.
ELSE.
l_time_high = '235959'.
ENDIF.
l_date_low = so_date-low.
CLEAR: l_time_low.
ELSE.
l_date_high = so_date-high.
l_date_low = so_date-low.
IF l_date_high = sy-datlo.
l_time_high = sy-uzeit.
ELSE.
l_time_high = '235959'.
ENDIF.
CLEAR: l_time_low.
ENDIF.
IF so_time IS INITIAL.
l_time_high = '235959'.
CLEAR: l_time_low.
ELSEIF so_time-high IS INITIAL AND NOT so_time-low IS INITIAL.
l_time_low = so_time-low.
l_time_high = '235959'.
ELSEIF NOT so_time-high IS INITIAL AND so_time-low IS INITIAL.
CLEAR: so_time-low.
l_time_high = so_time-high.
ELSE.
l_time_low = so_time-low.
l_time_high = so_time-high.
ENDIF.
CALL FUNCTION 'CHANGE_POINTERS_READ'
EXPORTING
activation_date_high = l_date_high
activation_date_low = l_date_low
activation_time_high = l_time_high
activation_time_low = l_time_low
creation_date_high = l_date_high
creation_date_low = l_date_low
creation_time_high = l_time_high
creation_time_low = l_time_low
message_type = p_mestyp
read_not_processed_pointers = 'X'
TABLES
change_pointers = t_bp
EXCEPTIONS
error_in_date_interval = 1
error_in_time_interval = 2
OTHERS = 3.
IF sy-subrc <> 0.
ELSE.
SORT t_bp BY cdchgid usrname.
t_bp_orig[] = t_bp[]. "keep track of pulled documents
DELETE t_bp WHERE cdchgid = 'D'
OR cdchgid = 'E'.
please suggest to make necessary changes.
Thanks.
Binay.
‎2007 Aug 01 3:14 PM
sorry, the last comment is incorrect. With your 3, 4, 5 conditions there is absolutely nb need to think about a change (if you have a problem then it is somewhere completely different).
Case ... endscase can help slightly, if you have different value for a certain variable, and 10s oder 100s of branches.
Siegfried
‎2007 Aug 01 11:34 AM
Hi,
If possible try and use CASE instead of IF ELSEIF ELSE ENDIF.
Else this should not be a big problem with respect to Performance.
Since these days the application servers are good in performance this hould not be a big problem.
Concentrate more on reducing the Database statements to improve the performance instead.
Regards,
Sesh
‎2007 Aug 01 11:45 AM
there is no problem in using multiple if..else statements... performance wont hit a much... but the better way is if u have more than 3 if statement try using Case...Endcase statement.
ur code is fine and will work properly as at any time it will check only one if statement and performance won't hit a long...
‎2007 Aug 01 11:48 AM
Hi,
generally, it should not affect the performance. in this important is that which cotrol structure is suitable for ur logic. Say CASE...ENDCASE is used to tackle diffrent values of a single variable. and IF is used to tackle logic of expression condition.
Jogdand M B
‎2007 Aug 01 1:56 PM
hi
CASE AND ENDCASE I VERY GOOD AT THIS POINT OF TIME
WITH NESTED IF YES U WILL GET PERFORMANCE PROBLEM
REWARD IF USEFULL
‎2007 Aug 01 3:14 PM
sorry, the last comment is incorrect. With your 3, 4, 5 conditions there is absolutely nb need to think about a change (if you have a problem then it is somewhere completely different).
Case ... endscase can help slightly, if you have different value for a certain variable, and 10s oder 100s of branches.
Siegfried
‎2007 Aug 01 3:36 PM
I agree completely. I'd be surprised if you found a user who was able to detect a performance difference between CASE and IF ... ELSEIF ... ENDIF, even if there was a thousand ELSEIF lines. Computers compute fast, humans interact slowly.
The main advantage (in my opinion) of CASE statements is that the program is easier to read.
‎2007 Aug 01 7:07 PM
Absolutely no problem from performance point of view.
The programs with nested if statements are difficult to read. In this case you cant avoid if statements as you dont have fixed value to use case statements.
So the above listed code is perfect.
Thanks
Praveen