<?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/5242467#M1211356</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Binary search always use divide and conquer method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field1 Field2 Field3&lt;/P&gt;&lt;P&gt;ZX       BC      ZA&lt;/P&gt;&lt;P&gt;XY      DE      YH&lt;/P&gt;&lt;P&gt;ZA      AA       ZA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After Sort on Field1 Field2 Field3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;result will be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;XY    DE       YH&lt;/P&gt;&lt;P&gt;ZA    AA       ZA&lt;/P&gt;&lt;P&gt;ZX     BC      ZA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If we dont use Field on in read the result will not be accurate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF you want to use field2 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;USE :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort itab by field2 field3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab with key field2 field3 BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this resolves your query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Gurpreet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Feb 2009 17:11:57 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-02-18T17:11:57Z</dc:date>
    <item>
      <title>Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242465#M1211354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Would the following binary search produce correct results?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Internal table IT is sorted by field1 field2 field3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table IT with key field2 = 'X' field3  = 'Y'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure this is correct since the read statement makes no  &lt;/P&gt;&lt;P&gt;reference to field1.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Feb 2009 17:00:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242465#M1211354</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-18T17:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242466#M1211355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;use all the fields you used to sort , to read as well&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this will:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;read table IT with key field1 =  'X' field2 = 'X' field3 = 'Y'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Feb 2009 17:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242466#M1211355</guid>
      <dc:creator>former_member156446</dc:creator>
      <dc:date>2009-02-18T17:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242467#M1211356</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Binary search always use divide and conquer method:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Field1 Field2 Field3&lt;/P&gt;&lt;P&gt;ZX       BC      ZA&lt;/P&gt;&lt;P&gt;XY      DE      YH&lt;/P&gt;&lt;P&gt;ZA      AA       ZA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After Sort on Field1 Field2 Field3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;result will be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;XY    DE       YH&lt;/P&gt;&lt;P&gt;ZA    AA       ZA&lt;/P&gt;&lt;P&gt;ZX     BC      ZA&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If we dont use Field on in read the result will not be accurate.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IF you want to use field2 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;USE :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sort itab by field2 field3.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Read table itab with key field2 field3 BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this resolves your query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Gurpreet&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Feb 2009 17:11:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242467#M1211356</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-18T17:11: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/5242468#M1211357</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It depends on what you mean by "correct". Why not try it and see if you get the results you want?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Feb 2009 17:12:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242468#M1211357</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-18T17:12:43Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242469#M1211358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could determine the result by running this.  You'll see that it returns the first row.  It is not, by the way, a binary search.  And there is no way to make it binary unless you provide the entire key.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES:  BEGIN OF _ty_1,
        field1(1)  TYPE c,
        field2(1)  TYPE c,
        field3(1)  TYPE c.
TYPES:  END   OF _ty_1.


DATA:
  g_t_tab TYPE TABLE OF _ty_1,
  g_s_line TYPE _ty_1.

g_s_line-field1 = 'A'.
g_s_line-field2 = 'X'.
g_s_line-field3 = 'Y'.
APPEND g_s_line TO g_t_tab.

g_s_line-field1 = 'B'.
g_s_line-field2 = 'X'.
g_s_line-field3 = 'Y'.
APPEND g_s_line TO g_t_tab.

g_s_line-field1 = 'C'.
g_s_line-field2 = 'X'.
g_s_line-field3 = 'Y'.
APPEND g_s_line TO g_t_tab.

SORT g_t_tab BY field1 field2 field3.

READ TABLE g_t_tab WITH KEY field2 = 'X' field3 = 'Y' into g_s_line.

WRITE:/ g_s_line-field1,sy-subrc.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Feb 2009 17:26:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242469#M1211358</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-18T17:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242470#M1211359</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;there is thumb rule when using a BINARY SEARCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;when ever you are using a Binary Search for a read SORT the table before read with what ever fields you want, and use the same fields in sequence what you used for sorting ,&lt;/P&gt;&lt;P&gt;if you use different keys Binary search Fails but it works sometimes not always...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort IT by field1 field2 field3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table IT with key field1 = 'X'  field2 = 'X' field3 = 'Y'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you are using only field2 and field3 as key then sort internal table by field2 and field3 only.&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;vinayaka&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Feb 2009 19:00:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5242470#M1211359</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-02-18T19:00:59Z</dc:date>
    </item>
  </channel>
</rss>

