<?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 problem in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978521#M71401</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;Not sure whether this will work. But worth trying...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The order of fields given in SORT and READ TABLE is different. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by custsa salorg divs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_pio_custsa with key&lt;/P&gt;&lt;P&gt;CUSTSA = COMM_STRUCTURE-/BIC/IO_CUSTSA&lt;/P&gt;&lt;P&gt;SALORG = COMM_STRUCTURE-/BIC/IO_SALORG&lt;/P&gt;&lt;P&gt;DIVS = COMM_STRUCTURE-/BIC/IO_DIVS&lt;/P&gt;&lt;P&gt;  binary search.&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;RESULT = it_pio_custsa-bussct.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Vinod&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Sep 2005 10:18:08 GMT</pubDate>
    <dc:creator>Vinod_Chandran</dc:creator>
    <dc:date>2005-09-05T10:18:08Z</dc:date>
    <item>
      <title>binary search problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978519#M71399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;a binary search see below is returning a sy-subrc code of 8 and not finding the record as i expect. anyone know why?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;in debug i can see the entry in the internal table. it just doesn't find it using the binary search. the values are correct in the select statement and i don't think there is a problem with formatting. there are approx 700,000 entries in the table. the dis_ch (result) field is empty and should be populated with the bussct field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;internal table declaration&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TYPES: BEGIN OF s_custsa,&lt;/P&gt;&lt;P&gt;         salorg type /BIC/PIO_CUSTSA-/BIC/IO_SALORG,&lt;/P&gt;&lt;P&gt;         dis_ch type /BIC/PIO_CUSTSA-/BIC/IO_DIS_CH,&lt;/P&gt;&lt;P&gt;         divs   type /BIC/PIO_CUSTSA-/BIC/IO_DIVS,&lt;/P&gt;&lt;P&gt;         custsa type /BIC/PIO_CUSTSA-/BIC/IO_CUSTSA,&lt;/P&gt;&lt;P&gt;         bussct type /BIC/PIO_CUSTSA-/BIC/IO_BUSSCT,&lt;/P&gt;&lt;P&gt;       END OF s_custsa.&lt;/P&gt;&lt;P&gt;DATA:  it_pio_custsa TYPE STANDARD TABLE OF s_custsa with header line&lt;/P&gt;&lt;P&gt;                     WITH NON-UNIQUE DEFAULT KEY INITIAL SIZE 10.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;filling the internal table with all active records.&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT  /BIC/IO_SALORG /BIC/IO_DIS_CH /BIC/IO_DIVS /BIC/IO_CUSTSA&lt;/P&gt;&lt;P&gt;        /BIC/IO_BUSSCT&lt;/P&gt;&lt;P&gt;  FROM  /BIC/PIO_CUSTSA&lt;/P&gt;&lt;P&gt;  INTO table it_pio_custsa&lt;/P&gt;&lt;P&gt;  WHERE  OBJVERS = 'A'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;delete it_pio_custsa where bussct = ''.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by custsa salorg divs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;b&amp;gt;now try to find the entry&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_pio_custsa with key&lt;/P&gt;&lt;P&gt;       SALORG  = COMM_STRUCTURE-/BIC/IO_SALORG&lt;/P&gt;&lt;P&gt;       DIVS    = COMM_STRUCTURE-/BIC/IO_DIVS&lt;/P&gt;&lt;P&gt;       CUSTSA  = COMM_STRUCTURE-/BIC/IO_CUSTSA binary search.&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;       RESULT =  it_pio_custsa-bussct.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2005 10:07:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978519#M71399</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-05T10:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: binary search problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978520#M71400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;read internal table as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_pio_custsa with key&lt;/P&gt;&lt;P&gt;CUSTSA = COMM_STRUCTURE-/BIC/IO_CUSTSA&lt;/P&gt;&lt;P&gt;SALORG = COMM_STRUCTURE-/BIC/IO_SALORG&lt;/P&gt;&lt;P&gt;DIVS = COMM_STRUCTURE-/BIC/IO_DIVS&lt;/P&gt;&lt;P&gt; binary search.&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;RESULT = it_pio_custsa-bussct.&lt;/P&gt;&lt;P&gt;endif. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;order should be same as in sort.&lt;/P&gt;&lt;P&gt;did you got it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2005 10:14:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978520#M71400</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-05T10:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: binary search problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978521#M71401</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;Not sure whether this will work. But worth trying...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The order of fields given in SORT and READ TABLE is different. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by custsa salorg divs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;read table it_pio_custsa with key&lt;/P&gt;&lt;P&gt;CUSTSA = COMM_STRUCTURE-/BIC/IO_CUSTSA&lt;/P&gt;&lt;P&gt;SALORG = COMM_STRUCTURE-/BIC/IO_SALORG&lt;/P&gt;&lt;P&gt;DIVS = COMM_STRUCTURE-/BIC/IO_DIVS&lt;/P&gt;&lt;P&gt;  binary search.&lt;/P&gt;&lt;P&gt;if sy-subrc = 0.&lt;/P&gt;&lt;P&gt;RESULT = it_pio_custsa-bussct.&lt;/P&gt;&lt;P&gt;endif.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Vinod&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2005 10:18:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978521#M71401</guid>
      <dc:creator>Vinod_Chandran</dc:creator>
      <dc:date>2005-09-05T10:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: binary search problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978522#M71402</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;If u want to retain the read statement as it is,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then sort the table by - &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by salorg divs custa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rather than - &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by custsa salorg divs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;it makes sense to change the sort sequence because data type for internal table is defined in the same order.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2005 10:20:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978522#M71402</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-05T10:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: binary search problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978523#M71403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks all for your comments. what i find strange is that out of a sample debug of 140 records only 3 fail to be found using the original code. why would this be the case?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i will amend the code as suggested keeping the internal table and read formats as they correspond to the master data table that is being read from. and just change the sort sequence.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i'll award some points tomorrow if it works!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2005 10:44:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978523#M71403</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-05T10:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: binary search problem</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978524#M71404</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;do the sorting as per in the read statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by custsa salorg divs&lt;/P&gt;&lt;P&gt;instead of the above statement change it like&lt;/P&gt;&lt;P&gt;sort it_pio_custsa by salorg divs custsa.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Sasi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Sep 2005 13:51:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/binary-search-problem/m-p/978524#M71404</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2005-09-05T13:51:16Z</dc:date>
    </item>
  </channel>
</rss>

