<?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/5439127#M1247532</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Alok,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must Sort your Internal Table in &lt;STRONG&gt;ASCENDING&lt;/STRONG&gt; order for &lt;STRONG&gt;BINARY SEARCH&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Faisal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 08 Apr 2009 05:58:11 GMT</pubDate>
    <dc:creator>faisalatsap</dc:creator>
    <dc:date>2009-04-08T05:58:11Z</dc:date>
    <item>
      <title>Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439123#M1247528</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a small query , its regarding read table with binary search.&lt;/P&gt;&lt;P&gt;My query is can we use read table with binary search on an internal table that has been sorted in descending order?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Alok.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:42:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439123#M1247528</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T05:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439124#M1247529</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It can be used....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But it would cause extremely Severe performance issues...better to avoid... &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:44:00 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439124#M1247529</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T05:44: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/5439125#M1247530</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi SubZero,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried using it with descending ,  but it doesnt give the same results, is it that only ascending works?&lt;/P&gt;&lt;P&gt;and what would be the kind of performance issues incase of descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Alok.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Alok Navare on Apr 8, 2009 7:47 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:47:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439125#M1247530</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T05:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439126#M1247531</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;yes, the fields you are using with key addition in read statement shoud be in sort (it must be sorted in ascending order)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you need to sort fiels which are using with key addition&lt;/P&gt;&lt;P&gt;ex.&lt;/P&gt;&lt;P&gt;itab having fiels a, b,c ,d, e , f, g.&lt;/P&gt;&lt;P&gt;here you are goint to read based on three fieds a, b, c.&lt;/P&gt;&lt;P&gt;sort itab by a b c.&lt;/P&gt;&lt;P&gt;read table itab with key a = 'aaa'&lt;/P&gt;&lt;P&gt;                                  b = 'bbbb'&lt;/P&gt;&lt;P&gt;                                  c = 'ccc'&lt;/P&gt;&lt;P&gt;                                 binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Peranandam&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: peranandam chinnathambi on Apr 8, 2009 7:49 AM&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: peranandam chinnathambi on Apr 8, 2009 8:21 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:48:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439126#M1247531</guid>
      <dc:creator>Peranandam</dc:creator>
      <dc:date>2009-04-08T05:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439127#M1247532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Alok,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You must Sort your Internal Table in &lt;STRONG&gt;ASCENDING&lt;/STRONG&gt; order for &lt;STRONG&gt;BINARY SEARCH&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Faisal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:58:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439127#M1247532</guid>
      <dc:creator>faisalatsap</dc:creator>
      <dc:date>2009-04-08T05:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439128#M1247533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Alok &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Well the binary search algorithm itself asks for the keys to be sorted in ascending order... So it doesnt necessarily depend whether its ABAP or C or java..whatever....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure how it affects .. but i think when sorted in ascending order, performance is O(n) and when in descending order its of O(n square )......&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But if its not working when its sorted in descending , then no point in using it buddy &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:59:15 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439128#M1247533</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T05:59: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/5439129#M1247534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;We can use for ascending and decending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if u r getting different values means, The internal table may have multiple records with the key u r passing , If the table has only one record then the result will be same..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Performwnce is also same in both the cases..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kiran&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: kiran vempati on Apr 8, 2009 8:00 AM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 05:59:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439129#M1247534</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T05:59: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/5439130#M1247535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;data: itab like standard table of spfli,
      fs type spfli.

      select * from spfli into table itab.

sort itab by carrid descending .        

read table itab into fs with key carrid = 'AA' binary search.

write : fs-connid.

sort itab by carrid.        

read table itab into fs with key carrid = 'AA' binary search.

write : fs-connid.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Check the difference of the result beacuse binary search will only work with ascending sort order.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Binary search works on Divide and Rule methods. after dividing It will check with the middle value if its lesser than the searched element than it goes to right half else it goes to left half.&lt;/P&gt;&lt;P&gt;Hence its mandt that the search filed of the table should be in Ascending order.&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, 08 Apr 2009 06:02:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439130#M1247535</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T06:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439131#M1247536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, Kiran&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It must be ascending order test the following code it is not working with DESCENDING but will work when Chang to ASCENDING.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;TYPES: BEGIN OF ty_test,
  no TYPE i,
  END OF ty_test.
DATA: it TYPE STANDARD TABLE OF ty_test WITH HEADER LINE.

DO 1000 TIMES.
  it-no = sy-index.
  APPEND it.
ENDDO.

SORT it BY no DESCENDING.

READ TABLE it WITH KEY no = 838 BINARY SEARCH.
IF sy-subrc EQ 0.
  WRITE: it-no.
ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Faisal&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 06:03:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439131#M1247536</guid>
      <dc:creator>faisalatsap</dc:creator>
      <dc:date>2009-04-08T06:03:12Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439132#M1247537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Faisal,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;U r correct... Sorry for my wrong answer...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 06:07:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439132#M1247537</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T06:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Binary Search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439133#M1247538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are using the Binary search in Read statement you should sort the internal table before read statement. Otherwise it won't give correct answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Joan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Apr 2009 06:11:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search/m-p/5439133#M1247538</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-04-08T06:11:02Z</dc:date>
    </item>
  </channel>
</rss>

