Application Development 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: 

How to improve performance incase of unavoidable nested loops

Former Member
0 Kudos

Hi Experts,

How to improve performance incase of unavoidable nested loops?

Any body pls explain the PARALLEL CURSOR approach to improve the performance incase of nested loops?

I got this approach from Tips&Tricks of SE30.

pls explain how to implement this approach.

Thanks in Advance

5 REPLIES 5

Former Member
0 Kudos

Refer this code.


REPORT  zpt_parallel_cursor1.

TABLES:
  likp,
  lips.

DATA:
  t_likp  TYPE TABLE OF likp,
  t_lips  TYPE TABLE OF lips.

DATA:
  w_runtime1 TYPE i,
  w_runtime2 TYPE i,
  w_index LIKE sy-index.

START-OF-SELECTION.
  SELECT *
    FROM likp
    INTO TABLE t_likp.

  SELECT *
    FROM lips
    INTO TABLE t_lips.

  GET RUN TIME FIELD w_runtime1.
  SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.
  DATA : w_cnt TYPE i.
  LOOP AT t_likp INTO likp.
    w_index = sy-tabix.
    READ  TABLE  t_lips INTO lips WITH KEY vbeln = likp-vbeln
                                           binary search.

      LOOP AT t_lips INTO lips FROM sy-index.
      IF likp-vbeln NE lips-vbeln.

        EXIT.
      ENDIF.
        w_cnt = w_cnt + 1.
      ENDLOOP.
  ENDLOOP.

  WRITE : w_cnt.
  GET RUN TIME FIELD w_runtime2.

  w_runtime2 = w_runtime2 - w_runtime1.

  WRITE 😕  w_runtime2.

regards,

Jinson

0 Kudos

Hi jinson,

How much performance is improved by using parallel cursor method?

In case i have 3 nested loops. How can i implement this method?

please find below my problem...

i have BATCH..

BATCH have multiple CYCLES....Again each cycle has multiple SEGMENTS..again each SEGMENT has multiple SENDER and RECEIVERS..

I need to handle all Dependencies with good performance..

For dependency handling

i wrote nested loops upto 3. it gave less performance..i need to improve performance...i think by using PARALLEL CURSOR methos..

Thanks

Jinson

Former Member
0 Kudos

Hi siva,

http://learnabap.blogspot.com/2007/05/performance-tuning-using-parallel.html

google it there is one more link from saptechnical from which above code is copied ...

i cant post it here

regards

vivek

Edited by: vivek jain on Jan 16, 2009 1:02 PM

former_member194613
Active Contributor
0 Kudos

I would not recommend the parallel cursor method, it is minimally better than the others but much much more complicated.

The recommended solutions are use SORTED or HASHED Tables!

For 1:1 Relations you can use


LOOP AT itab INTO wa.
   READ itab2 WITH KEY f = wa-f ...
ENDLOOP:

itab2: Sorted table, Hashed table or standard table with binray search!

For 1:c Relations you can use


LOOP AT itab INTO wa.
   LOOP AT itab2 WHERE f = wa-f 
ENDLOOP:

itab2: Sorted table, or standard table with binray search, LOOP from index, exit (see above)!

or see here

Measurements on internal tables: Reads and Loops:

/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables

These solutions a all fine, they will never be a performance problem!

Parallel cursor, works with indexes, which you must add or subtract etc.

It become alreay in the 1:1 case complicated, if your tables can differ

+ lines with same key but different content

+ additional lines in itab1

+ additional lines in itab2.

In the 1:c relation I have no general solution, it is even more complicated.

Performance advantage little, we are taking abut internal tables not selects.

AND in the case of parallel cursors both tables itab1 and itab2 must be sorted, in the other

case only itab2 !!!!

So if itab1 is not already correctly sorted, then you will loose even the last advantage

of the parallel cursor! So it is not recommended any more, even if it appears in the Tipps and

Tricks of the SE30.

This is in short the content of blog, which will probably never be published !

Siegfried

uwe_schieferstein
Active Contributor
0 Kudos

Hello Siva

Do not miss the blog by Rob Burbank:

[SAP Network Blog: Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]

Regards

Uwe