<?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: Speed improvement at Loop-Statement in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596592#M1275593</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;that is true.... collect will not work correctly if the values are not same and I had mentioned it in earlier post also...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so is mandatory that you require all the fields in the summed table... can't you do the other way that once you get the summed records you can use both the tables taking the entries from the first table and finding if the record exist in another using read statement and getting the summed value from the summed table and then proceeding further&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;otherwise you can do it this way also....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at gt_output....&lt;/P&gt;&lt;P&gt;read from gs_summed with key....&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;  add 1 to count_field in the gs_summed table&lt;/P&gt;&lt;P&gt;  add other required fields...&lt;/P&gt;&lt;P&gt;  modify the record in the table.....&lt;/P&gt;&lt;P&gt;else.&lt;/P&gt;&lt;P&gt;  append the record in the table.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in this case you need not write loop within a loop.... just a read statement and your issue will be much better than what it was earlier with loop inside a loop....&lt;/P&gt;&lt;P&gt;Siddarth&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 May 2009 12:40:42 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-05-05T12:40:42Z</dc:date>
    <item>
      <title>Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596566#M1275567</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've got a problem with a short loop-statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First of my programm, an internal table have been filled (with about 50000 entries). Then I have to do a loop at this internal table to find all entries which I can sum (depends on 4 criteria). &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FORM sum_gleiche_positionen.

  DATA: ls_output  TYPE STANDARD TABLE OF gs_out WITH HEADER LINE,
        ls_table   TYPE STANDARD TABLE OF gs_out WITH HEADER LINE,
        lt_table   TYPE STANDARD TABLE OF gs_out WITH HEADER LINE,
        lt_results TYPE match_result_tab,
        l_netwr    TYPE netwr,
        l_kwmeng   TYPE p DECIMALS 0,
        l_counter  TYPE i..


  SORT gt_output BY vbeln matnr zzwldat abgru ASCENDING.

  LOOP AT gt_output INTO gs_output.

    CLEAR: l_netwr, l_kwmeng, l_counter.


    READ TABLE gt_sumtable  INTO lt_table
                            WITH KEY vbeln   = gs_output-vbeln
                                 matnr   = gs_output-matnr
                                 zzwldat = gs_output-zzwldat
                                 abgru   = gs_output-abgru.
    IF sy-subrc = 0. "Beleg schon verarbeitet
      CONTINUE.
    ENDIF.



    LOOP AT gt_output INTO ls_output WHERE vbeln   = gs_output-vbeln   AND
                                           matnr   = gs_output-matnr   AND
                                           zzwldat = gs_output-zzwldat AND
                                           abgru   = gs_output-abgru.

      l_netwr  = l_netwr + ls_output-netwr.
      l_kwmeng = l_kwmeng + ls_output-kwmeng.

      ADD 1 TO l_counter.


    ENDLOOP.
    ls_table = ls_output.
    IF l_counter &amp;gt; 1.
      CLEAR: ls_table-pstyv, ls_table-posnr.
      ls_table-netwr = l_netwr.
      ls_table-kwmeng = l_kwmeng.
    ENDIF.
    APPEND ls_table TO gt_sumtable.

  ENDLOOP.

ENDFORM.                    "sum_gleiche_positionen&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this needs to much time -&amp;gt; Time out!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What can I do to improve speed in this statement?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 07:51:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596566#M1275567</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T07:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596567#M1275568</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do not use loop within a loop. Here is what you can do:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, remove the unecessary entries then do the computation you want:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT gt_output
     READ TABLE gt_sumtable 
          IF sy-subrc EQ 0.
               gs_output-flag = X.
               MODIFY gt_output FROM gs_output TRANSPORTING flag.
          ENDIF.
ENDLOOP.
DELETE gt_output[] WHERE flag = 'X'.

IF gt_output[] IS NOT INITIAL.
     LOOP AT gt_output.
" Do your calculation logic
     ENDLOOP.
ENDIF.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mawi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Mawi C. Ng on May 4, 2009 10:04 AM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Mawi C. Ng on May 4, 2009 10:04 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 08:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596567#M1275568</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-04T08:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596568#M1275569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi mawi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;first - thanks for your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I'm not sure if I understand you right:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your code, you do a loop on my itab (gt_output) and then delete all entries that matches my statement.&lt;/P&gt;&lt;P&gt;After that, I make a "new loop" on my itab and do the calculation. But this cannot work becuase all entries I want to calculate with are deleted...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I right?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 08:09:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596568#M1275569</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T08:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596569#M1275570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;At quick glance it seems that you should look into using the COLLECT statement to aggregate NETWR and KWMENG by VBELN, MATNR, ZZWLDAT and ABGRU. Maybe you can even do it already during data selection with the aggregate function SUM ().&lt;/P&gt;&lt;P&gt;Do you need GT_OUTPUT for further processing or is GT_SUMTABLE your final result?&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 08:14:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596569#M1275570</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2009-05-04T08:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596570#M1275571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Thomas,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gt_sumtable is my final result.&lt;/P&gt;&lt;P&gt;Unfortunatelly, I cannot sum NETWR and KWMENG during data selection because the user want to select if he needs the data summed or not.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will have a look at the collect statement - maybe this can help :9&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 08:19:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596570#M1275571</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T08:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596571#M1275572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And if COLLECT should not work, at least make sure that you access internal table data inside an outer loop always with binary search, either explicit (READ TABLE ... BINARY SEARCH) or implicit (READ or LOOP via key fields of tables declared as SORTED).&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S.&lt;/P&gt;&lt;P&gt;&amp;gt; the user want to select if he needs the data summed or not&lt;/P&gt;&lt;P&gt;this could also be handled via ALV-list layouts.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 08:26:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596571#M1275572</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2009-05-04T08:26:21Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596572#M1275573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have 2 performance problems, and they can both be solved by using binary search.&lt;/P&gt;&lt;P&gt;Since the table is not declared as SORTED, the easiest way to adapt your code would be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) For the LOOP inside the LOOP, make a READ first with BINARY SEARCH, and then LOOP FROM sy-tabix (with no WHERE, and EXIT when you find a record that does not match your criteria).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) For the READ inside the LOOP, add BINARY SEARCH (your results table is also sorted from what I see, so that should be ok).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope it is clear enough.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 08:41:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596572#M1275573</guid>
      <dc:creator>Rui_Dantas</dc:creator>
      <dc:date>2009-05-04T08:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596573#M1275574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hallo Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;your coding is a perfect example for quadratic coding and long long runtimes .... &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please read here:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nonlinearity: The problem and background&lt;/P&gt;&lt;P&gt;/people/siegfried.boes/blog/2007/02/12/performance-problems-caused-by-nonlinear-coding&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;The first will explain the problem, the second the main reason for nonlinearity.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use SORTED tables, whenever you do nested processing!&lt;/P&gt;&lt;P&gt;Or the more complciated standard tables, with binary search and LOOP ... see second blog&lt;/P&gt;&lt;P&gt;Sort the inner table not the outer table (that is waste of time!) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But your program has other problems:&lt;/P&gt;&lt;P&gt;The READ has not consequence, or? and it is INOT ls_table&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
READ TABLE gt_sumtable  INTO lt_table
                            WITH KEY vbeln   = gs_output-vbeln
                                 matnr   = gs_output-matnr
                                 zzwldat = gs_output-zzwldat
                                 abgru   = gs_output-abgru.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The loop can stop if the counter is larger than 1, there are no other consequences.&lt;/P&gt;&lt;P&gt;I don't think that your LOOP inside the LOOP makes sense, it is on the same table,&lt;/P&gt;&lt;P&gt;If the inner loop finds two records or more, than it is also executed identically&lt;/P&gt;&lt;P&gt;two times or more, because the outer loop has the same records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the actual task?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 09:05:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596573#M1275574</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-04T09:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596574#M1275575</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;hope I can response to all your relies &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Thomas: Sure, I can manage it with ALV - but not all requirements. I will check the collect statement asap.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Rui: Yes, I unserstand your idea! I'm not sure if this can help me improve speed (is it faster to make a loop with "loop at xy into i_xy from 1" than making it with "loop at xy into &lt;U&gt;i&lt;/U&gt;xy where..."?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;@Siegfried: You are right - it's not a nice coding. I will read your links asap! And sure, my read statement has a consequence: if the actual data has already been read (and so been written in table gt_sumtable), the next record will been read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code I have at the moment:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FORM sum_gleiche_positionen.

  DATA: ls_output  TYPE STANDARD TABLE OF gs_out WITH HEADER LINE,
        ls_table   TYPE STANDARD TABLE OF gs_out WITH HEADER LINE,
        lt_table   TYPE STANDARD TABLE OF gs_out WITH HEADER LINE,
        lt_results TYPE match_result_tab,
        l_netwr    TYPE netwr,
        l_kwmeng   TYPE p DECIMALS 0,
        l_counter  TYPE i,
        l_tabix    TYPE i.


  SORT gt_output BY vbeln matnr zzwldat abgru ASCENDING.

  LOOP AT gt_output INTO gs_output.
    l_tabix = sy-tabix.

    CLEAR: l_netwr, l_kwmeng, l_counter.


    READ TABLE gt_sumtable  INTO lt_table
                            WITH KEY vbeln   = gs_output-vbeln
                                 matnr   = gs_output-matnr
                                 zzwldat = gs_output-zzwldat
                                 abgru   = gs_output-abgru.
    IF sy-subrc = 0. "Beleg schon verarbeitet
      CONTINUE.
    ENDIF.

    LOOP AT gt_output INTO ls_output FROM l_tabix.

      IF ls_output-vbeln   NE gs_output-vbeln   OR
         ls_output-matnr   NE gs_output-matnr   OR
         ls_output-zzwldat NE gs_output-zzwldat OR
         ls_output-abgru   NE gs_output-abgru.
        EXIT.
      ENDIF.

      l_netwr  = l_netwr + ls_output-netwr.
      l_kwmeng = l_kwmeng + ls_output-kwmeng.

      ADD 1 TO l_counter.

    ENDLOOP.


    ls_table = gs_output.
    IF l_counter &amp;gt; 1.
      CLEAR: ls_table-pstyv, ls_table-posnr.
      ls_table-netwr = l_netwr.
      ls_table-kwmeng = l_kwmeng.
    ENDIF.
    APPEND ls_table TO gt_sumtable.

  ENDLOOP.

ENDFORM.                    "sum_gleiche_positionen&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 09:45:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596574#M1275575</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T09:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596575#M1275576</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, you can believe it will be MUCH faster. Just try it and you will be amazed at the wonders of binary search.. &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;What you have now is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP.
   LOOP WHERE.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second LOOP will go throught all the 50,000 entries to find the ones that match (and you do this second LOOP 50,000 times!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can easily change that to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP.
      "you can use binary search because the table was sorted in advance
      "it will be quite fast
      READ ... WITH KEY... BINARY SEARCH. 

      "now, no need to go through all entries; just start by the first one found by READ
      "this access is pretty much immediate
      LOOP ... FROM sy-tabix.       

           "you have to make sure you quit the LOOP when a non-matching entry is found
           IF   ... &amp;lt;&amp;gt; ... OR .... &amp;lt;&amp;gt; .... OR ... .
                  EXIT.
           ENDIF.
    
           ......
       ENDLOOP.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rui Pedro Dantas on May 4, 2009 12:07 PM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Rui Pedro Dantas on May 4, 2009 12:08 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 10:07:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596575#M1275576</guid>
      <dc:creator>Rui_Dantas</dc:creator>
      <dc:date>2009-05-04T10:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596576#M1275577</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Rui,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OK, when you say it will be faster, than it will be faster &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I don't need the Read-Statement!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;LOOP.&lt;/P&gt;&lt;P&gt;"you can use binary search because the table was sorted in advance&lt;/P&gt;&lt;P&gt;"it will be quite fast&lt;/P&gt;&lt;P&gt;READ ... WITH KEY... BINARY SEARCH.&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I already know from which line I have to start (the line, in qhich my Outer Loop is):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_output INTO gs_output.
    l_tabix = sy-tabix.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I can the inner Loop this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_output INTO ls_output FROM l_tabix.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will test this in our Test system - hope it will improve speed a little bit&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you Rui!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 10:11:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596576#M1275577</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T10:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596577#M1275578</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;but you need the BINARY SEARCH .... in your first READ! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also sort that table, actually not I think it is created, in the loop, so just add BINARY SEARCH.&lt;/P&gt;&lt;P&gt;also the append is then o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second is o.k.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Overall it is still hard to understand, there is still improvement possible.&lt;/P&gt;&lt;P&gt;Start also the first LOOP from tabix,  and use the tabix where the second loop was when &lt;/P&gt;&lt;P&gt;the exit happened, then also the read is not necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I must say, Thomas was right with his statement, your program is not more then a complicated way to programm a COLLECT, please do that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*  no sort !! SORT gt_output BY vbeln matnr zzwldat abgru ASCENDING.
 
  LOOP AT gt_output INTO gs_output.
     COLLECT gs_output  INTO TABLE gt_sumtable.

   ENDLOOP..
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gt_sumtable is hashed table with UNIQUE KEY&lt;/P&gt;&lt;P&gt;     vbeln   = gs_output-vbeln&lt;/P&gt;&lt;P&gt;      matnr   = gs_output-matnr&lt;/P&gt;&lt;P&gt;       zzwldat = gs_output-zzwldat&lt;/P&gt;&lt;P&gt;       abgru   = gs_output-abgru.&lt;/P&gt;&lt;P&gt;plus these 2 fields&lt;/P&gt;&lt;P&gt;       l_netwr  = l_netwr + ls_output-netwr.&lt;/P&gt;&lt;P&gt;      l_kwmeng = l_kwmeng + ls_output-kwmeng.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Better use a hashed table, but standard is also possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 10:57:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596577#M1275578</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-04T10:57:02Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596578#M1275579</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Siegfried,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you very much for your reply!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just one question:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP AT gt_output INTO gs_output.
     COLLECT gs_output  INTO TABLE gt_sumtable.
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I understand the SAp-Help right, then a collect can be used sum all entries that are not key-fields. Problem is, that gt_output has also other fields. Maybe I have to make a new itab just with this special fields I want to sum...I have to test it...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 11:12:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596578#M1275579</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T11:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596579#M1275580</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;just move the six fields explicitly inside the loop before you do the COLLECT.&lt;/P&gt;&lt;P&gt;The definition refers to the gt_sumtable&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Siegfried&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 13:02:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596579#M1275580</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-04T13:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596580#M1275581</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You won't believe it - I made the statement "completely" new - now it works in about 5 seconds!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Made it this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SORT gt_output BY vbeln matnr zzwldat abgru ASCENDING.

  l_tabix = 1.
  DESCRIBE TABLE gt_output LINES l_rows.
  DO.
    IF l_rows = l_tabix. l_ende = 'X'. ENDIF.
    CLEAR: l_netwr, l_kwmeng, l_counter.
    READ TABLE gt_output INTO gs_output INDEX l_tabix.
    LOOP AT gt_output INTO ls_output FROM l_tabix.

      IF ls_output-vbeln   NE gs_output-vbeln   OR
         ls_output-matnr   NE gs_output-matnr   OR
         ls_output-zzwldat NE gs_output-zzwldat OR
         ls_output-abgru   NE gs_output-abgru.
        l_tabix = sy-tabix.
        EXIT.
      ENDIF.

      l_netwr  = l_netwr + ls_output-netwr.
      l_kwmeng = l_kwmeng + ls_output-kwmeng.

      ADD 1 TO l_counter.

    ENDLOOP.
    ls_table = gs_output.
    IF l_counter &amp;gt; 1.
      CLEAR: ls_table-pstyv, ls_table-posnr.
      ls_table-netwr = l_netwr.
      ls_table-kwmeng = l_kwmeng.
    ENDIF.
    APPEND ls_table TO gt_sumtable.
    IF l_ende = 'X'. EXIT. ENDIF.
  ENDDO.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you all vor your input!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 13:51:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596580#M1275581</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T13:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596581#M1275582</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Might be fast, but will you understand this code part yourself four weeks later, let alone a third person? &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 14:09:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596581#M1275582</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2009-05-04T14:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596582#M1275583</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;it is much faster, but it is not really fast.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The recommeded solution was the COLLECT which would be faster by factors and much shorter coding.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP

move 6 fields

COLLECT

ENDLOOP.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Collecting 50.000 records can not take seconds, with good hardware about 1microsecond per record,&lt;/P&gt;&lt;P&gt;gives, 50ms, there is a factor of 100 still left in your 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>Mon, 04 May 2009 14:30:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596582#M1275583</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-04T14:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596583#M1275584</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ok, tomorrow I will do a test with the collect, but for today it's enough &lt;SPAN __jive_emoticon_name="wink"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 May 2009 18:39:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596583#M1275584</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-04T18:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596584#M1275585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Siegfried,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sorry for the new question - but I'm not sure how to make the whole statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;LOOP
 
move 6 fields
 
COLLECT
 
ENDLOOP.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to do the move? Do I need a new table?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2009 06:40:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596584#M1275585</guid>
      <dc:creator>michael_fallenbchel</dc:creator>
      <dc:date>2009-05-05T06:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Speed improvement at Loop-Statement</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596585#M1275586</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Michael,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;attached code should be enough. For gt_sumtable use a hashed table with key vbeln, matnr, zzwldat, abgru.&lt;/P&gt;&lt;P&gt;If you use standard table don't make any other change (besides the collect) to gt_sumtable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hermann&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
LOOP AT gt_output INTO ls_output .
 
 gt_sumtable-vbeln =  ls_output-vbeln.   
 gt_sumtable-matnr =    ls_output-matnr.  
 gt_sumtable-zzwldat =  ls_output-zzwldat.
 gt_sumtable-abgru =  ls_output-abgru.
 gt_sumtable-netwr = ls_output-netwr.
 gt_sumtable-kwmeng = ls_output-kwmeng.
 
      collect gt_sumtable.
 
 ENDLOOP.
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 May 2009 06:50:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/speed-improvement-at-loop-statement/m-p/5596585#M1275586</guid>
      <dc:creator>HermannGahm</dc:creator>
      <dc:date>2009-05-05T06:50:11Z</dc:date>
    </item>
  </channel>
</rss>

