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

Effective Loop

Former Member
0 Likes
670

Hi Guys,

can you please let me know which is less time consuming LOOP selection?

LOOP at BKPF where belnr = ws-Belnr.

IF i_bkpf-blart = 'A1'. ...........................check the condition and enter in loop ITAB

loop at itab into ws_itab where a = b.

delete record.

endloop.

ELSEIF i_bkpf-blart = 'B1' . check the condition and enter in loop ITAB

loop at itab into ws_itab where a = b.

delere record.

endloop.

ENDIF.

ENDLOOP.

OR**************************************************************************

LOOP at BKPF where belnr = ws-Belnr.

loop at itab . -


Enter the LOOP ITAB and then check condtion

IF i_bkpf-blart = 'A1'.

delete record.

elseif i_bkpf-blart = 'B1' .

delere record.

endif.

endloop.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
636

Both are bad. You should use READs with BINARY SEARCH instead. Please see:

[Performance of Nested Loops|]

Rob

6 REPLIES 6
Read only

Former Member
0 Likes
636

Hi,

The second loop is more efficient.

Thanks,

Preetham S

Read only

0 Likes
636

Hi ,

But the second loop LOOPs across all the records of ITAB and then check condition.

And first one just LOOPs when condition is met.

What do you say?

Regards,

Yogita

Read only

0 Likes
636

LOOP at BKPF where belnr = ws-Belnr.

IF i_bkpf-blart = 'A1'. ...........................check the condition and enter in loop ITAB

loop at itab into ws_itab where a = b.

delete record.

endloop.

ELSEIF i_bkpf-blart = 'B1' . check the condition and enter in loop ITAB

loop at itab into ws_itab where a = b.

delere record.

endloop.

ENDIF.

ENDLOOP.

**************************************OR*************************************************************************

LOOP at BKPF where belnr = ws-Belnr.

loop at itab . Enter the LOOP ITAB and then check condtion

IF i_bkpf-blart = 'A1'.

delete record.

elseif i_bkpf-blart = 'B1' .

delere record.

endif.

endloop.

ENDLOOP.

Read only

Former Member
0 Likes
637

Both are bad. You should use READs with BINARY SEARCH instead. Please see:

[Performance of Nested Loops|]

Rob

Read only

0 Likes
636

Hi Rob,

But as per the requirement, I need to select multiple records and hence I need to use LOOP instead of READ which selects single record.

Please advice.

Regards,

Yogita

Read only

0 Likes
636

The blog shows one way to do exactly that.

Rob