<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Performance enhancement for parallel loops in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646810#M878227</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
   lv_wa_final-afnam = lv_wa_ekpo-afnam.

LOOP at xt_git_ekkn 
          into lv_wa_ekkn 
          where ebeln = lv_wa_ekpo-ebeln
             and ebelp = lv_wa_ekpo-ebelp.

       lv_wa_final-meins = lv_wa_ekpo-meins.

       READ TABLE xt_git_ekko INTO lv_wa_ekko
                 WITH KEY ebeln = lv_wa_ekpo-ebeln
                 BINARY SEARCH.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must use a sorted table for xt_git_ekkn or use trick with standard tables,&lt;/P&gt;&lt;P&gt;see&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Measurements on internal tables: Reads and Loops:&lt;/P&gt;&lt;P&gt;/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Last section (read binary search / Loop from index and EXIT !!!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Apr 2008 08:23:02 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-04-15T08:23:02Z</dc:date>
    <item>
      <title>Performance enhancement for parallel loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646809#M878226</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;  I have performance problem for the following parallel loops.Please help me solve this to improve performance of report,urgently.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LOOP AT xt_git_ekpo INTO lv_wa_ekpo.&lt;/P&gt;&lt;P&gt;lv_wa_final-afnam     = lv_wa_ekpo-afnam.&lt;/P&gt;&lt;P&gt;LOOP at xt_git_ekkn into lv_wa_ekkn  where ebeln = lv_wa_ekpo-ebeln&lt;/P&gt;&lt;P&gt;and ebelp = lv_wa_ekpo-ebelp.&lt;/P&gt;&lt;P&gt;lv_wa_final-meins     = lv_wa_ekpo-meins.&lt;/P&gt;&lt;P&gt;READ TABLE xt_git_ekko INTO lv_wa_ekko&lt;/P&gt;&lt;P&gt;                                WITH KEY ebeln = lv_wa_ekpo-ebeln&lt;/P&gt;&lt;P&gt;                                BINARY SEARCH.&lt;/P&gt;&lt;P&gt;      IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;        lv_wa_final-ebeln     = lv_wa_ekko-ebeln.&lt;/P&gt;&lt;P&gt;        lv_wa_final-ebelp     = lv_wa_ekpo-ebelp.&lt;/P&gt;&lt;P&gt;        lv_wa_final-txz01     = lv_wa_ekpo-txz01.&lt;/P&gt;&lt;P&gt;        lv_wa_final-aedat     = lv_wa_ekko-aedat.&lt;/P&gt;&lt;P&gt; READ TABLE xt_git_lfa1 INTO lv_wa_lfa1&lt;/P&gt;&lt;P&gt;                                      WITH KEY lifnr = lv_wa_ekko-lifnr&lt;/P&gt;&lt;P&gt;                                      BINARY SEARCH.&lt;/P&gt;&lt;P&gt;        IF sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;          lv_wa_final-lifnr = lv_wa_lfa1-lifnr.&lt;/P&gt;&lt;P&gt;          lv_wa_final-name1 = lv_wa_lfa1-name1.&lt;/P&gt;&lt;P&gt;        ENDIF.&lt;/P&gt;&lt;P&gt;       &lt;/P&gt;&lt;P&gt;     LOOP AT xt_git_ekbe INTO lv_wa_ekbe WHERE   ebeln      =   lv_wa_ekpo-ebeln&lt;/P&gt;&lt;P&gt;AND  ebelp = lv_wa_ekpo-ebelp.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;waiting for quick reply.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2008 07:27:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646809#M878226</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-15T07:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Performance enhancement for parallel loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646810#M878227</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
   lv_wa_final-afnam = lv_wa_ekpo-afnam.

LOOP at xt_git_ekkn 
          into lv_wa_ekkn 
          where ebeln = lv_wa_ekpo-ebeln
             and ebelp = lv_wa_ekpo-ebelp.

       lv_wa_final-meins = lv_wa_ekpo-meins.

       READ TABLE xt_git_ekko INTO lv_wa_ekko
                 WITH KEY ebeln = lv_wa_ekpo-ebeln
                 BINARY SEARCH.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must use a sorted table for xt_git_ekkn or use trick with standard tables,&lt;/P&gt;&lt;P&gt;see&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Measurements on internal tables: Reads and Loops:&lt;/P&gt;&lt;P&gt;/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Last section (read binary search / Loop from index and EXIT !!!)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2008 08:23:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646810#M878227</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-15T08:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Performance enhancement for parallel loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646811#M878228</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if u have Nested loops then its better to use &lt;STRONG&gt;PARALLEL CURSOR&lt;/STRONG&gt; Method.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Nested Loops&lt;/STRONG&gt;&lt;/U&gt; &amp;#150; This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Program using Normal Nested Loop:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  ZNORMAL_NESTEDLOOP.

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.

START-OF-SELECTION.
select *
  from likp
  into table t_likp.

select *
  from lips
  into table t_lips.

get RUN TIME FIELD w_runtime1.

loop at t_likp into likp.
  loop at t_lips into lips where vbeln eq likp-vbeln.
  endloop.
endloop.

get RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

write w_runtime2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Nested Loop using Parallel Cursor:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  zparallel_cursor2.

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.

  LOOP AT t_likp INTO likp.

    LOOP AT t_lips INTO lips FROM w_index.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

  GET RUN TIME FIELD w_runtime2.

  w_runtime2 = w_runtime2 - w_runtime1.

  WRITE w_runtime2.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Analysis report&lt;/STRONG&gt;: Runtime in microseconds:  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Iteration No&lt;/U&gt;.... &lt;U&gt;Normal Nested Loop&lt;/U&gt;..._Using Parallel Cursor_ &lt;/P&gt;&lt;P&gt;  &lt;/P&gt;&lt;P&gt;1  ......................34,796,147.................  63,829 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;2 .......................38,534,583 ................. 56,894 &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;3 ......................34,103,426 .................. 50,510 &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please check this link &lt;/P&gt;&lt;P&gt;&lt;A href="http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm" target="test_blank"&gt;http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward if helpful&lt;/P&gt;&lt;P&gt;raam&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2008 15:38:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646811#M878228</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-04-15T15:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: Performance enhancement for parallel loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646812#M878229</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LOOP AT&lt;/P&gt;&lt;P&gt; xt_git_ekpo INTO lv_wa_ekpo.&lt;/P&gt;&lt;P&gt;lv_wa_final-afnam = lv_wa_ekpo-afnam.&lt;/P&gt;&lt;P&gt;LOOP at &lt;/P&gt;&lt;P&gt;xt_git_ekkn into lv_wa_ekkn where ebeln = lv_wa_ekpo-ebeln&lt;/P&gt;&lt;P&gt;and ebelp = lv_wa_ekpo-ebelp.&lt;/P&gt;&lt;P&gt;lv_wa_final-meins = lv_wa_ekpo-meins.&lt;/P&gt;&lt;P&gt;READ TABLE xt_git_ekko INTO lv_wa_ekko&lt;/P&gt;&lt;P&gt;WITH KEY ebeln = lv_wa_ekpo-ebeln&lt;/P&gt;&lt;P&gt;BINARY SEARCH.&lt;/P&gt;&lt;P&gt;IF &lt;/P&gt;&lt;P&gt;sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;lv_wa_final-ebeln = lv_wa_ekko-ebeln.&lt;/P&gt;&lt;P&gt;lv_wa_final-ebelp = lv_wa_ekpo-ebelp.&lt;/P&gt;&lt;P&gt;lv_wa_final-txz01 = lv_wa_ekpo-txz01.&lt;/P&gt;&lt;P&gt;lv_wa_final-aedat = lv_wa_ekko-aedat.&lt;/P&gt;&lt;P&gt;READ TABLE xt_git_lfa1 INTO lv_wa_lfa1&lt;/P&gt;&lt;P&gt;WITH KEY lifnr = lv_wa_ekko-lifnr&lt;/P&gt;&lt;P&gt;BINARY SEARCH.&lt;/P&gt;&lt;P&gt;IF &lt;/P&gt;&lt;P&gt;sy-subrc IS INITIAL.&lt;/P&gt;&lt;P&gt;lv_wa_final-lifnr = lv_wa_lfa1-lifnr.&lt;/P&gt;&lt;P&gt;lv_wa_final-name1 = lv_wa_lfa1-name1.&lt;/P&gt;&lt;P&gt;ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jul 2008 11:17:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646812#M878229</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-08T11:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Performance enhancement for parallel loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646813#M878230</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Forget the parallel cursor stuff it is much to complicated in your case, for loop and read. And it is not better the a solution with binary searches.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read my answer again if you don't understand it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A loop if really necessary can not be replaced by a read so the third solution is also not applicable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read the last section of the blog, then you will get the solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2008 08:10:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646813#M878230</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-09T08:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Performance enhancement for parallel loops</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646814#M878231</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;U can use SORTED TABLE instead of STANDARD TABLE:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;DATA: xt_git_ekkn TYPE SORTED TABLE OF EKKN WITH NON-UNIQUE KEY EBELN EBELP,
          xt_git_ekbe  TYPE SORTED TABLE OF EKBE WITH NON-UNIQUE KEY EBELN EBELP.


LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
    lv_wa_final-afnam = lv_wa_ekpo-afnam.
    LOOP at xt_git_ekkn into lv_wa_ekkn where ebeln = lv_wa_ekpo-ebeln
                                                              and ebelp = lv_wa_ekpo-ebelp.
        lv_wa_final-meins = lv_wa_ekpo-meins.
        READ TABLE xt_git_ekko INTO lv_wa_ekko WITH KEY ebeln = lv_wa_ekpo-ebeln
                                                                                BINARY SEARCH.
        IF sy-subrc IS INITIAL.
          lv_wa_final-ebeln = lv_wa_ekko-ebeln.
          lv_wa_final-ebelp = lv_wa_ekpo-ebelp.
          lv_wa_final-txz01 = lv_wa_ekpo-txz01.
          lv_wa_final-aedat = lv_wa_ekko-aedat.
          READ TABLE xt_git_lfa1 INTO lv_wa_lfa1 WITH KEY lifnr = lv_wa_ekko-lifnr
                                                                                BINARY SEARCH.
          IF sy-subrc IS INITIAL.
             lv_wa_final-lifnr = lv_wa_lfa1-lifnr.
             lv_wa_final-name1 = lv_wa_lfa1-name1.
         ENDIF.

         LOOP AT xt_git_ekbe INTO lv_wa_ekbe WHERE ebeln = lv_wa_ekpo-ebeln
                                                                         AND ebelp = lv_wa_ekpo-ebelp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway u should considere to upload in the internal table only the record of the current document, in this case u need to insert the SELECT into the loop:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT  xt_git_ekpo by EBELN EBELP.

LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
    lv_wa_final-afnam = lv_wa_ekpo-afnam.

   IF lv_wa_ekkn-EBELN &amp;lt;&amp;gt;  lv_wa_ekpo-EBELN.
     SELECT * FROM EKKN INTO TABLE xt_git_ekkn WHERE EBELN = lv_wa_ekpo-EBELN.
     SELECT * FROM EKBE INTO TABLE xt_git_ekbe WHERE EBELN = lv_wa_ekpo-EBELN.
   ENDIF.

    LOOP at xt_git_ekkn into lv_wa_ekkn where ebelp = lv_wa_ekpo-ebelp.
        lv_wa_final-meins = lv_wa_ekpo-meins.
        READ TABLE xt_git_ekko INTO lv_wa_ekko WITH KEY ebeln = lv_wa_ekpo-ebeln
                                                                                BINARY SEARCH.
        IF sy-subrc IS INITIAL.
          lv_wa_final-ebeln = lv_wa_ekko-ebeln.
          lv_wa_final-ebelp = lv_wa_ekpo-ebelp.
          lv_wa_final-txz01 = lv_wa_ekpo-txz01.
          lv_wa_final-aedat = lv_wa_ekko-aedat.
          READ TABLE xt_git_lfa1 INTO lv_wa_lfa1 WITH KEY lifnr = lv_wa_ekko-lifnr
                                                                                BINARY SEARCH.
          IF sy-subrc IS INITIAL.
             lv_wa_final-lifnr = lv_wa_lfa1-lifnr.
             lv_wa_final-name1 = lv_wa_lfa1-name1.
         ENDIF.

         LOOP AT xt_git_ekbe INTO lv_wa_ekbe WHERE ebelp = lv_wa_ekpo-ebelp.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my experience (for a very large number of records) this second solution was faster than the first one:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;- Using the first solution (upload all data in internal table and use sorted table): my job takes 2/3 days&lt;/P&gt;&lt;P&gt;- Using the second solution: my job takes 1 hour. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Max&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jul 2008 08:29:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/performance-enhancement-for-parallel-loops/m-p/3646814#M878231</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-07-09T08:29:12Z</dc:date>
    </item>
  </channel>
</rss>

