<?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: ABAP - Sort in loop or  read w/o binary search in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828411#M43394</link>
    <description>&lt;P&gt;&lt;STRONG&gt;Don't use BINARY SEARCH. Use a sorted or hashed table. See Tomas Buryanek's answer below.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Binary search should not appear in modern programs. It isn't needed.&lt;/P&gt;</description>
    <pubDate>Sat, 09 Feb 2019 08:28:08 GMT</pubDate>
    <dc:creator>matt</dc:creator>
    <dc:date>2019-02-09T08:28:08Z</dc:date>
    <item>
      <title>ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828405#M43388</link>
      <description>&lt;P&gt;Hi Expert,&lt;/P&gt;
  &lt;P&gt;I need your advice on using a SORT statement inside a loop or using read without Binary search inside loop.&lt;/P&gt;
  &lt;P&gt;i.e. Loop IT_TAB. SORT IT_TAB2 (IT_TAB2 table is populated with data inside same loop) . Read IT_TAB2 using Binary search. Endloop,&lt;/P&gt;
  &lt;P&gt;OR Loop IT_TAB. Read IT_TAB2 without Binary search. Endloop.&lt;/P&gt;
  &lt;P&gt;Which one is better?&lt;/P&gt;
  &lt;P&gt;Regards,&lt;/P&gt;
  &lt;P&gt;Raj&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 14:20:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828405#M43388</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2019-02-08T14:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828406#M43389</link>
      <description>&lt;P&gt;You say "IT_TAB2 table is populated with data inside same loop"&lt;/P&gt;&lt;P&gt;So I suggest 3rd approach:&lt;/P&gt;&lt;P&gt;- sort IT_TAB2 prior to Loop IT_TAB (in case there are entries already)&lt;/P&gt;&lt;P&gt;- within Loop IT_TAB add new entries to IT_TAB2 so it is sorted &lt;/P&gt;&lt;P&gt;- you may now Read IT_TAB2 with Binary search without necessity to sort again  &lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 15:09:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828406#M43389</guid>
      <dc:creator>harald_lesche-holzbecher</dc:creator>
      <dc:date>2019-02-08T15:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828407#M43390</link>
      <description>&lt;P&gt;Do not use SORT + BINARY SEARCH method! &lt;/P&gt;&lt;P&gt;There are much better options for fast internal table access / processing. Try SORTED or HASHED tables or at least use secondary table keys (SORTED or HASH).&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 15:26:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828407#M43390</guid>
      <dc:creator>Tomas_Buryanek</dc:creator>
      <dc:date>2019-02-08T15:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828408#M43391</link>
      <description>&lt;P&gt;If I understand your question well, IT_TAB2 is populated inside the loop in both cases, and you ask which of solution 1 (SORT + READ binary search) or solution 2 (READ without binary search) is the best.&lt;/P&gt;&lt;P&gt;First of all, the question is the same if there's no loop at all.&lt;/P&gt;&lt;P&gt;Let's calculate the "order":&lt;/P&gt;&lt;P&gt;Solution 1: SORT will read ALL the lines of a table (N)&lt;/P&gt;&lt;P&gt;Solution 2: READ without binary search will statistically tend to read half the lines if values are distributed equally and the searched value is random (N/2).&lt;/P&gt;&lt;P&gt;Answer: solution 2.&lt;/P&gt;&lt;P&gt;PS: I didn't even count the additional time needed for solution 1, to rebuild the index of lines, and to do a binary search.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 17:10:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828408#M43391</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-02-08T17:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828409#M43392</link>
      <description>&lt;P&gt;Is IT_TAB2 cleared &amp;amp; populated in each loop, or some lines are just added or removed?&lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 17:33:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828409#M43392</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2019-02-08T17:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828410#M43393</link>
      <description>&lt;P&gt;If IT_TAB2 is type of a sorted table, we don’t have to sort it again and we can use binary search. &lt;/P&gt;</description>
      <pubDate>Fri, 08 Feb 2019 23:56:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828410#M43393</guid>
      <dc:creator>s1252</dc:creator>
      <dc:date>2019-02-08T23:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828411#M43394</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Don't use BINARY SEARCH. Use a sorted or hashed table. See Tomas Buryanek's answer below.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Binary search should not appear in modern programs. It isn't needed.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Feb 2019 08:28:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828411#M43394</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2019-02-09T08:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP - Sort in loop or  read w/o binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828412#M43395</link>
      <description>&lt;P&gt; &lt;SPAN class="mention-scrubbed"&gt;s1252&lt;/SPAN&gt; If it's a SORTED table, then you don't need the addition BINARY SEARCH. It will be done automatically (assuming you're using the table key). &lt;/P&gt;</description>
      <pubDate>Sat, 09 Feb 2019 08:29:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-in-loop-or-read-w-o-binary-search/m-p/828412#M43395</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2019-02-09T08:29:22Z</dc:date>
    </item>
  </channel>
</rss>

