<?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/2125895#M446293</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;You have added name1 field in comapring keys in second eg.  but, immediatly before that while sorting you have not added that field into SORT. This may lead to erros sometimes. so write like:&lt;/P&gt;&lt;P&gt;sort t_kna1 by name1 kunnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After this it will improve performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jogdand M B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 10 Apr 2007 11:34:24 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-04-10T11:34:24Z</dc:date>
    <item>
      <title>Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125891#M446289</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;In general we code like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of t_kna1 occurs 0,&lt;/P&gt;&lt;P&gt;          kunnr like kna1-kunnr,&lt;/P&gt;&lt;P&gt;          name1 like kna1-name1,&lt;/P&gt;&lt;P&gt;        end of t_kna1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    select kunnr name1 from kna1 into table t_kna1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    sort t_kna1 by kunnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    loop at t_bseg. &lt;/P&gt;&lt;P&gt;      read table t_kna1 with key kunnr = t_bseg-kunnr binary search.&lt;/P&gt;&lt;P&gt;       ............&lt;/P&gt;&lt;P&gt;      endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Suppose if we put like this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of t_kna1 occurs 0,&lt;/P&gt;&lt;P&gt;          kunnr like kna1-kunnr,&lt;/P&gt;&lt;P&gt;          name1 like kna1-name1,&lt;/P&gt;&lt;P&gt;        end of t_kna1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    select kunnr name1 from kna1 into table t_kna1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    sort t_kna1 by kunnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;    loop at t_bseg. &lt;/P&gt;&lt;P&gt;      read table t_kna1 with key name1 = t_bseg-name1 kunnr = t_bseg-kunnr                                                                                &lt;/P&gt;&lt;P&gt;binary search.&lt;/P&gt;&lt;P&gt;    .............   &lt;/P&gt;&lt;P&gt;    endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is the difference in reading the table t_kna1 in both the sample code.&lt;/P&gt;&lt;P&gt;Is there any disadvantage in the second method.&lt;/P&gt;&lt;P&gt;Will it have any performance disadvantage.&lt;/P&gt;&lt;P&gt;Can anyone explain in detail.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2007 06:45:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125891#M446289</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T06:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125892#M446290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ram,&lt;/P&gt;&lt;P&gt; While using the binary search we should mention the proper kwys else performance will be down.&lt;/P&gt;&lt;P&gt;In the first method record can be fetch based on the primary key kunnr.&lt;/P&gt;&lt;P&gt;In the second method record can be fetch based on the primary as well as secondary key also. &lt;/P&gt;&lt;P&gt;Instead of this &lt;/P&gt;&lt;P&gt;read table t_kna1 with key name1 = t_bseg-name1 kunnr = t_bseg-kunnr &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try with this &lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;read table t_kna1 with key  kunnr = t_bseg-kunnr  name1 = t_bseg-name1&lt;/P&gt;&lt;P&gt;  binary search.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;It will improve the performance.&lt;/P&gt;&lt;P&gt;Hope this helps you, reply for queries, Shall post you the updates.&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;Kumar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2007 07:01:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125892#M446290</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T07:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125893#M446291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Shri Ram,&lt;/P&gt;&lt;P&gt;&lt;B&gt;&lt;/B&gt;&lt;/P&gt;&lt;P&gt;Use of binary search option&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&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;PRE&gt;&lt;CODE&gt;            Read table int_fligh with key  airln = &amp;#145;LF&amp;#146;.&lt;/CODE&gt;&lt;/PRE&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;PRE&gt;&lt;CODE&gt;            Read table int_fligh with key  airln = &amp;#145;LF&amp;#146; binary search.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Refer&lt;/P&gt;&lt;P&gt;&lt;A href="http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/content.htm" target="test_blank"&gt;http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb373d358411d1829f0000e829fbfe/content.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&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;Santosh&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2007 08:06:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125893#M446291</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T08:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125894#M446292</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;Note:&lt;/P&gt;&lt;P&gt;The standard table must be sorted in ascending order 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 usage is best when you use the keys that are sorted in the same order. it speeds up the retrieval. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort itab by A B.&lt;/P&gt;&lt;P&gt;Read table itab with key A = field1&lt;/P&gt;&lt;P&gt;                                    B = field2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this will give the much better performance compared to&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab with key B = field2&lt;/P&gt;&lt;P&gt;                                    A = field1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;madhu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2007 08:20:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125894#M446292</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T08:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125895#M446293</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;You have added name1 field in comapring keys in second eg.  but, immediatly before that while sorting you have not added that field into SORT. This may lead to erros sometimes. so write like:&lt;/P&gt;&lt;P&gt;sort t_kna1 by name1 kunnr.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After this it will improve performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jogdand M B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2007 11:34:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125895#M446293</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T11:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125896#M446294</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;due to the performance issues it would be better to read the particular tableusing the READ statment.&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>Tue, 10 Apr 2007 11:37:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125896#M446294</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T11:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125897#M446295</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As KUNNR is the primary key of KNA1, and therefore the internal table, you only need to sort or match on that field. Your second piece of code becomes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: begin of tY_kna1,
         kunnr like kna1-kunnr,
         name1 like kna1-name1,
       end of tY_kna1.
DATA : T_KNA1  TYPE SORTED TABLE OF TY_KNA1
                WITH UNIQUE KEY KUNNR.

select kunnr name1 from kna1 into table t_kna1.

sort t_kna1 by kunnr.

loop at t_bseg. 
  read table t_kna1 with TABLE key kunnr = t_bseg-kunnr.
  ............. 
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;MattG.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 10 Apr 2007 12:02:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125897#M446295</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-10T12:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125898#M446296</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ram,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think the question you are asking is regarding the Binary search.&lt;/P&gt;&lt;P&gt;In the second case as you are using binary search and the table is sorted . the read statement will be fast than the first one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;beware you need to sort the table in the ascending order of the search filed's or else you get unwanted results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 11 Apr 2007 14:13:37 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/2125898#M446296</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-11T14:13:37Z</dc:date>
    </item>
  </channel>
</rss>

