‎2008 Feb 19 6:59 AM
hi experts,
can any body tell me how can a loop with in loop effect the performance of the abap program.
can we use like that .
‎2008 Feb 19 7:07 AM
Usually "loop in loop" looks like
LOOP AT header_itab.
LOOP AT item_itab WHERE num = header_itab-num.
ENDLOOP.
ENDLOOP.With standard (eg index) tables the item_tab can be fully read to select records at each pass. Only way to optimize is to have declared this table as a SORTED TABLE with the header number as a key. In this case the internal loop is optimized. - This is written in online abap documentation.
Regards
‎2008 Feb 19 7:17 AM
‎2008 Feb 19 7:08 AM
loop at itab1. ( n records)
loop at itab2. (m records)
endloop.
endloop.
for each record of itab1. entire itab2 is looping so finally inner loop is going to run n * m times.
so it is very poor performance
to avoid this u need to use read statement
‎2008 Feb 19 7:16 AM
‎2008 Feb 19 9:02 AM
If the question is already answered then you forgot to give points!
There is general assumption that you have either
loop at itab1. ( n records)
loop at itab2. ( a records, a constant)
or
loop at itab1
loop at itab2 where key = (m records in itab2, where m grows if n grows)
In the first case you have no performance problem, it scales with n.
In the second case, you have a performance problem if itab2 is standard table. But you can avoid it, if you use sorted tables.
You can also avoid it for standard tables by a workaround
read binary search, loop from index, exit
For details on the workaround see
Measurements on internal tables: Reads and Loops:
/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables
For background information on nonlinearity see
/people/siegfried.boes/blog/2007/02/12/performance-problems-caused-by-nonlinear-coding
Siegfried