Skip to Content
author's profile photo Former Member
Former Member

How to improve performance incase of unavoidable nested loops

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2009 at 12:00 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • author's profile photo Former Member
    Former Member
    Posted on Jan 16, 2009 at 12:02 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 16, 2009 at 01:08 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 16, 2009 at 01:51 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.