<?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: binary search in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051986#M423128</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you read entries from standard tables using a key other than the default key, you can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE &amp;lt;itab&amp;gt; WITH KEY &amp;lt;k1&amp;gt; = &amp;lt;f1&amp;gt;... &amp;lt;kn&amp;gt; = &amp;lt;fn&amp;gt; BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The standard table &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;must be sorted in ascending order&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BINARY SEARCH approaches the middle entry in the table, decides if it matches, or lexically greater than or equal to the key being searched. It accordingly skips either the top or bottom part of the internal table and searches the other half. It repeats this process till it finds the row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using BINARY SEARCH with READ is the most efficient way to read standard internal tables which are sorted by the key used to search them&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BINARY SEARCH addition when reading a sorted table is not required, as it happens by default. It makes a good difference in performance if you are reading a large standard internal table without sorting and reading by BINARY SEARCH&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Vishnu T&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 11 Mar 2007 17:47:57 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-03-11T17:47:57Z</dc:date>
    <item>
      <title>binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051984#M423126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI&lt;/P&gt;&lt;P&gt;     can anyone explain abt binary search?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Mar 2007 17:19:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051984#M423126</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-11T17:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051985#M423127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Let us say u have an internal table with the following records..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Carrier ID  Destination Airport&lt;/P&gt;&lt;P&gt;AU           Australia&lt;/P&gt;&lt;P&gt;LH            USA&lt;/P&gt;&lt;P&gt;LH            Frankfurt&lt;/P&gt;&lt;P&gt;LH            Australia&lt;/P&gt;&lt;P&gt;SQ           Singapore&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suppose you have stored these records in a standard table then when you are processing the record through LOOP AT or READ TABLE statement then the system will use the table scan ie. searching the table line by line for the requested record...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For instance if you are using LOOP AT itab INTO wa WHERE carrid = 'LH'.&lt;/P&gt;&lt;P&gt;If your table is a standard table then system will first search first record to check whether the Carrier id is equal to LH if not it proceed with the next reoord.&lt;/P&gt;&lt;P&gt;If your table is a sorted table then the system will use the binary search ie it will search only the below records..&lt;/P&gt;&lt;P&gt;LH            USA&lt;/P&gt;&lt;P&gt;LH            Frankfurt&lt;/P&gt;&lt;P&gt;LH            Australia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note you could also achive the BINARY SEARCH effect in the standard table..For that sort your standard table based on the search key and use BINARY SEARCH addition to your READ statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this clear your doubt..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hakim&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mark all useful answers..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Mar 2007 17:46:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051985#M423127</guid>
      <dc:creator>abdul_hakim</dc:creator>
      <dc:date>2007-03-11T17:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051986#M423128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you read entries from standard tables using a key other than the default key, you can use a binary search instead of the normal linear search. To do this, include the addition BINARY SEARCH in the corresponding READ statements.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;READ TABLE &amp;lt;itab&amp;gt; WITH KEY &amp;lt;k1&amp;gt; = &amp;lt;f1&amp;gt;... &amp;lt;kn&amp;gt; = &amp;lt;fn&amp;gt; BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The standard table &amp;lt;u&amp;gt;&amp;lt;b&amp;gt;must be sorted in ascending order&amp;lt;/b&amp;gt;&amp;lt;/u&amp;gt; by the specified search key. The BINARY SEARCH addition means that you can access an entry in a standard table by its key as quickly as you would be able to in a sorted table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BINARY SEARCH approaches the middle entry in the table, decides if it matches, or lexically greater than or equal to the key being searched. It accordingly skips either the top or bottom part of the internal table and searches the other half. It repeats this process till it finds the row.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Using BINARY SEARCH with READ is the most efficient way to read standard internal tables which are sorted by the key used to search them&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BINARY SEARCH addition when reading a sorted table is not required, as it happens by default. It makes a good difference in performance if you are reading a large standard internal table without sorting and reading by BINARY SEARCH&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;Vishnu T&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 11 Mar 2007 17:47:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051986#M423128</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-11T17:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051987#M423129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Chaitanya,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will try to put it in a simple way.&lt;/P&gt;&lt;P&gt;for ex:-&lt;/P&gt;&lt;P&gt;if we have the following numbers &lt;/P&gt;&lt;P&gt;10,20,30,40,50,60,70.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now think that we are searching for a number  30.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when we use a binary search it will split the entire data into two halfs and first search in the first half.&lt;/P&gt;&lt;P&gt;I mean to say it will for 30 among 10,20,30,40.&lt;/P&gt;&lt;P&gt;So it will find the number we are searching for and thus avoids the unnecessary search in the remaining half.Thus it improves performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the number is not found in that then it will continue with searching the 2nd half.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;K.Kiran&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Mar 2007 03:39:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051987#M423129</guid>
      <dc:creator>kiran_k8</dc:creator>
      <dc:date>2007-03-12T03:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051988#M423130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;some morte additional info......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;standard tables are subject to a linear search. If the addition BINARY SEARCH is specified, the search is binary instead of linear. This considerably reduces the runtime of the search for larger tables (from approximately 100 entries upwards). For the binary search, the table must be sorted by the specified search key in ascending order. Otherwise the search will not find the correct row. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sorted tables are subject to a binary search if the specified search key is or includes a starting field of the table key. Otherwise it is linear. The addition BINARY SEARCH can be specified for sorted tables, but has no effect. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For hashed tables, the hash algorithm is used if the specified search key includes the table key. Otherwise the search is linear. The addition BINARY SEARCH is not permitted for hashed tables.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Mar 2007 03:45:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051988#M423130</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-12T03:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051989#M423131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;good&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use of binary search option&lt;/P&gt;&lt;P&gt;When a programmer uses the read command, the table is sequentially searched. This slows down the processing. Instead of this, use the binary search addition. The binary search algorithm helps faster search of a value in an internal table. It is advisable to sort the internal table before doing a binary search. Binary search repeatedly divides the search interval in half. If the value to be searched is less than the item in the middle of the interval, the search is narrowed to the lower half, otherwise the search is narrowed to the upper half. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Not Recommended&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;            Read table int_fligh with key  airln = &amp;#145;LF&amp;#146;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Recommended&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;            Read table int_fligh with key  airln = &amp;#145;LF&amp;#146; binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;mrutyun^&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Mar 2007 03:46:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051989#M423131</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-12T03:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051990#M423132</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;Binary serach is a quicker way to read record in an internal table .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please note that when ever you use BINARY SERACH..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort the table based on the requirement and while using BINARY SERACH use with the keys on ehich table is sorted .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Mar 2007 04:52:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051990#M423132</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-12T04:52:41Z</dc:date>
    </item>
    <item>
      <title>Re: binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051991#M423133</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;In addition to our forumates info... I am here adding a bit to that.&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt; b4 you use binery search.. dont forget to sort the internal table&amp;lt;/b&amp;gt;.&lt;/P&gt;&lt;P&gt;if not sorted and used binary search mens.. &amp;lt;b&amp;gt;u will not find the specified record in most of the cases, even its present in the table.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sujatha.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 12 Mar 2007 05:14:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2051991#M423133</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-03-12T05:14:13Z</dc:date>
    </item>
  </channel>
</rss>

