<?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: Read table and binary search in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576476#M1271935</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Posting to performance forum&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 May 2009 07:53:03 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-05-15T07:53:03Z</dc:date>
    <item>
      <title>Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576466#M1271925</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;I have a simple query regarding read int_tab with binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why reading  internal table with binary search fails if it is sorted in descending order table must be sorted in ascending order?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I check fo the algorithm of binary search, it does not talk about sort order. As far as my understanding goes binary search only require sorted table but while reading table in SAP it has to be sorted in ascending order!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:07:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576466#M1271925</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576467#M1271926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Helo, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Table must be in sorted order it might be in Asc OR Desc.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:09:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576467#M1271926</guid>
      <dc:creator>shishupalreddy</dc:creator>
      <dc:date>2009-05-15T07:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576468#M1271927</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;When using Binary search in read statement, sort internal table in ascending order of the keys used in read statement&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:09:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576468#M1271927</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576469#M1271928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;in binary search it split the table and check the extreme values.&lt;/P&gt;&lt;P&gt;so upper most value is the low value and the lower most is the high value&lt;/P&gt;&lt;P&gt;so u need to short the table in decending order&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:11:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576469#M1271928</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576470#M1271929</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;before reading itab using binary search...with key conditions..&lt;/P&gt;&lt;P&gt;you must sort it...ascen/desc with order of the keys given in the read statment ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;please send the code..now.. if you face the problem again...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;safel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:12:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576470#M1271929</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576471#M1271930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No surprise:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt; The table must be sorted by the specified search key in ascending order. Otherwise the wrong row will be found.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Source: &lt;A href="http://help.sap.com/abapdocu/en/ABAPREAD_TABLE_FREE.htm#!ABAP_ONE_ADD@1@" target="test_blank"&gt;http://help.sap.com/abapdocu/en/ABAPREAD_TABLE_FREE.htm#!ABAP_ONE_ADD@1@&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:16:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576471#M1271930</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2009-05-15T07:16:59Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576472#M1271931</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If sorted in descending order then the read with binary search will fail .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try reading any table sorted in descending order with binary search, then the read will fail. Table must be sorted in ascending order and this is the issue , why it do not work if table is sorted in descending order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try writing a simple query and check!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:19:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576472#M1271931</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576473#M1271932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Thomas you are write and this is my question, why ascending order is necessary, binary search algo does not put any such restriction!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:31:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576473#M1271932</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576474#M1271933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, the ABAP binary search algorithm has this restriction, and as for the "why", I have asked to have your question moved to the "ABAP performance" forum, I'm sure somebody will have a good answer there, as I could only make assumptions.&lt;/P&gt;&lt;P&gt;Thomas&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:45:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576474#M1271933</guid>
      <dc:creator>ThomasZloch</dc:creator>
      <dc:date>2009-05-15T07:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576475#M1271934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you thomas &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:46:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576475#M1271934</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576476#M1271935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Posting to performance forum&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 May 2009 07:53:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576476#M1271935</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-15T07:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Read table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576477#M1271936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;By default binary search assumes that the sort order is ASCENDING.&lt;/P&gt;&lt;P&gt;If you sort the list in descending and then try to binary search your quires will fail. Look at an example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;P&gt;Let the descending order internal table as:&lt;/P&gt;&lt;P&gt;Field1      Field2&lt;/P&gt;&lt;P&gt;Sam        50000&lt;/P&gt;&lt;P&gt;John       34786&lt;/P&gt;&lt;P&gt;Boob      54321&lt;/P&gt;&lt;P&gt;Alice       12345&lt;/P&gt;&lt;P&gt;-&lt;/P&gt;&lt;HR originaltext="-------" /&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you do binary search with key = 'Sam' then it will directly go to 2nd and 3rd records for comparision. The binary search algorithm compares 'Sam' with 'John' and it concludes that 'Sam' is greater than 'John' and it will continue to look downward into the internal table. And when it reaches the end of the internal table then the value of SY-TABIX = 5 and SY-SUBRC = 8 (Key is greater than the all).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And if you do binary search with key = 'Alice' then the binary search algorithm compares 'Alice' with 'John' and it concludes that 'Alice' is lower than 'John' and it will continue to look upward into the internal table. And when it reaches above the first record in internal table then the value of SY-TABIX = 1 and SY-SUBRC = 4 (points to the next largest entry).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only correct result you will get is when you execute statement with key='John' (In this particular case) . SY-TABIX = 2 and SY-SUBRC = 0. I think you got this binary search algorithm.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Jul 2010 10:28:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/read-table-and-binary-search/m-p/5576477#M1271936</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-07-20T10:28:18Z</dc:date>
    </item>
  </channel>
</rss>

