<?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: sort table and binary search in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431198#M1845515</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are absolutely correct. I'd forgotten that. &lt;SPAN __jive_emoticon_name="shocked" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_macro jive_emote" src="https://community.sap.com/906/images/emoticons/shocked.gif"&gt;&lt;/SPAN&gt; So really, there is really very little reason to use BINARY SEARCH. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 29 Jun 2014 11:40:41 GMT</pubDate>
    <dc:creator>matt</dc:creator>
    <dc:date>2014-06-29T11:40:41Z</dc:date>
    <item>
      <title>sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431188#M1845505</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I just need to READ TABLE &lt;SPAN style="color: #ff0000;"&gt;once&lt;/SPAN&gt; for searching in an internal table.&lt;/P&gt;&lt;P&gt;Do I need to sort it first and then do binary search. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Someone told me that sort a table also takes time so that it is equal to READ TABLE directly if you just need to search once. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 01:35:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431188#M1845505</guid>
      <dc:creator>raffinkira</dc:creator>
      <dc:date>2014-06-27T01:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431189#M1845506</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, Ming&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It Depends on your Internal table contents, if content is more its better to use hashed Internal table&lt;/P&gt;&lt;P&gt;if content is less you can you sorted table.&lt;/P&gt;&lt;P&gt;if you need to use read table for checking ?&amp;nbsp; you can you transporting no fields, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Binary search is fastest way to find the record exits in itab then without binary search.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Venkat.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 01:52:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431189#M1845506</guid>
      <dc:creator>VenkatRamesh_V</dc:creator>
      <dc:date>2014-06-27T01:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431190#M1845507</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if you know the unique keys then declare internal table as hashed then use keys to search. otherwise, sort then read.. binary search is best practice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or if you're populating the table from SELECT then you may try to consider SELECT SINGLE or SELECT.. UP TO n ROWS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 03:34:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431190#M1845507</guid>
      <dc:creator>former_member730258</dc:creator>
      <dc:date>2014-06-27T03:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431191#M1845508</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;It not required to SORT and BINARY SEARCH for a single READ of an internal table.&lt;/P&gt;&lt;P&gt;But if you are using READ statement inside a LOOP , then its preferred.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyways for your satisfaction you can put TIMESTAMP for SORT &amp;amp; SEARCH with READ, and TIMESTAMP for only READ, then you may get a better clarification of your answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bishwajit&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 04:46:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431191#M1845508</guid>
      <dc:creator>bishwajit_das</dc:creator>
      <dc:date>2014-06-27T04:46:11Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431192#M1845509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you read a table just once it realy doesnt matter what kind of read you use...&lt;/P&gt;&lt;P&gt;Maybe the question is how often you read it per day and not how often its read in your programm.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;the performance depends on&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;how many records you have&lt;/LI&gt;&lt;LI&gt;how you insert the rows&lt;/LI&gt;&lt;LI&gt;what type of table you use&lt;/LI&gt;&lt;LI&gt;if you got duplicates in your table&lt;/LI&gt;&lt;LI&gt;how you read your table&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;check this blog &lt;A __default_attr="107077" __jive_macro_name="blogpost" class="jive_macro jive_macro_blogpost" data-orig-content="How does table record numbers influence performance" href="https://community.sap.com/"&gt;&lt;/A&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;Stefan Seeburger&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jun 2014 07:27:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431192#M1845509</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-06-27T07:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431193#M1845510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all, a &lt;STRONG&gt;SORT&lt;/STRONG&gt; is a very fast algorithm. A read of a &lt;STRONG&gt;STANDARD&lt;/STRONG&gt; table is always sequential. Therefore &lt;STRONG&gt;SORT&lt;/STRONG&gt;, followed by &lt;STRONG&gt;BINARY SEARCH&lt;/STRONG&gt; may be quicker than a simple &lt;STRONG&gt;READ&lt;/STRONG&gt;, depending on where the record is in the table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Second, define the table as &lt;STRONG&gt;HASHED&lt;/STRONG&gt; or &lt;STRONG&gt;SORTED&lt;/STRONG&gt;. Don't use&lt;STRONG&gt; READ/BINARY SEARCH&lt;/STRONG&gt; at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do &lt;STRONG style="text-decoration: underline;"&gt;not&lt;/STRONG&gt; use a single &lt;STRONG&gt;READ&lt;/STRONG&gt;. The reason is that while using a &lt;STRONG&gt;HASHED&lt;/STRONG&gt; or &lt;STRONG&gt;SORTED&lt;/STRONG&gt; table has an overhead, after that you get performance gains. If the table is only read once, then the overhead isn't going to affect the overall run time of the program. But programs change. While now it only does one read, in the future it may do many. So future proof your program now by defining the table properly, with the correct key.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 05:56:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431193#M1845510</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2014-06-29T05:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431194#M1845511</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That blog relates to database reads - not to internal table reads.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 05:58:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431194#M1845511</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2014-06-29T05:58:38Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431195#M1845512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Close. If you know the unique keys then declare the internal tables as hashed then use keys to search. Otherwise &lt;STRONG&gt;use a SORTED TABLE&lt;/STRONG&gt; is best practice.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The &lt;STRONG&gt;only&lt;/STRONG&gt; time to use SORT/READ/BINARY SEARCH is if the sort order is descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, UP TO 1 ROWS and SELECT SINGLE produce identical SQL on the database. Therefore use the latter (SELECT SINGLE) as it is clearer and simpler.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 06:00:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431195#M1845512</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2014-06-29T06:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431196#M1845513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No. The fastest way to read tables is to define them correctly, as HASHED or SORTED with the right key in the first place. Then use READ... TABLE KEY...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 06:02:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431196#M1845513</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2014-06-29T06:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431197#M1845514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;
&lt;P&gt;The &lt;STRONG&gt;only&lt;/STRONG&gt; time to use SORT/READ/BINARY SEARCH is if the sort order is descending.&lt;/P&gt;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Afaik the prerequisite for BINARY SEARCH is that the key-fields should be sorted in &lt;SPAN style="text-decoration: underline;"&gt;ascending&lt;/SPAN&gt; order.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 08:54:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431197#M1845514</guid>
      <dc:creator>SuhaSaha</dc:creator>
      <dc:date>2014-06-29T08:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431198#M1845515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are absolutely correct. I'd forgotten that. &lt;SPAN __jive_emoticon_name="shocked" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_macro jive_emote" src="https://community.sap.com/906/images/emoticons/shocked.gif"&gt;&lt;/SPAN&gt; So really, there is really very little reason to use BINARY SEARCH. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Jun 2014 11:40:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431198#M1845515</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2014-06-29T11:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431199#M1845516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Matthew,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree with all of the architecture points you've made in this thread.&amp;nbsp; Always better to set yourself up and future proof your code by designing with hashed or sorted tables in mind.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One small thing: in my thinking, a SORT plus a BINARY SEARCH can never be faster than a sequential READ of a table.&amp;nbsp; The worst case for a READ (no found record) is O(n), whereas the best case for any SORT (data is already sorted) algorithm is O(n), and then you have a leftover best case of O(1) for BINARY SEARCH (you hit the data you want on the first binary operation).&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think if someone is absolutely stuck in not being able to use hashed or sorted tables, then for one READ operation it's quicker just to do the sequential read.&amp;nbsp; But that should be a pretty rare case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paul&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 07:14:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431199#M1845516</guid>
      <dc:creator>former_member187859</dc:creator>
      <dc:date>2014-06-30T07:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431200#M1845517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I create a class in Java that behaves like an internal table, and I implement quicksort (or whatever) in a method just using Java and no other libraries, and a "read binary search" method, then you're right. However, sorting is so useful, that on many architectures it's implemented at a very low level - even chip level. It's also a readily parallelisable algorithm. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, all things being equal, of course you are right. But in practice, it may turn out somewhat different. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, the reason to use the correct data structures is that while today it's just one read, you never know when it's going to be a million reads. And if it's just one read, the additional overhead of a HASHED table is not going to affect overall performance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd also say that if a developer is stuck and unable to work out how to use HASHED and SORTED tables, that maybe they should consider another career? &lt;SPAN __jive_emoticon_name="happy" __jive_macro_name="emoticon" class="jive_macro_emoticon jive_macro jive_emote" src="https://community.sap.com/906/images/emoticons/happy.gif"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 07:26:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431200#M1845517</guid>
      <dc:creator>matt</dc:creator>
      <dc:date>2014-06-30T07:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: sort table and binary search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431201#M1845518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mathew,&lt;/P&gt;&lt;P&gt;i do almost, but not quite, agree with your statements.&lt;/P&gt;&lt;P&gt;I's absolutely true when we're talking about programming from scratch.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are of course, especially when you venture into the abyss of existing HR-reports and their descendants, loads of szenarios, where you have to deal with predefined tables (e.g. infotype-tables), which, although ancient and outdated, do have their benefits.&lt;/P&gt;&lt;P&gt;And sometimes you don't need to redesign a complete program, but just readjust a tiny bit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In these cases, when you're not free to declare a table hashed or sorted, sort and binary search are valuable language constructs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't imagine any scenario, where you would populate an internal table, that is big enough to even consider the use of sort/binary search and then only have one single read access. Thus i have to assume, that the table in question is populated and used somewhere else and therfore the table-type is not free to alter for the read acces here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the answer to the original question depends on the number of entries in said table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You would need a lot of entries to gain a substantial benefit in run-time by sorting and reading with binary search. On the other hand, considering a potential scenario, where the table is "owned" by other program parts, you could risk unwanted side effects.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As long as i'm not in posession of all the facts and unless we talk about big numbers, i'd opt for the sequential access. Don't change, just read.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards - Jörg&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jun 2014 08:16:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-table-and-binary-search/m-p/10431201#M1845518</guid>
      <dc:creator>jrg_wulf</dc:creator>
      <dc:date>2014-06-30T08:16:24Z</dc:date>
    </item>
  </channel>
</rss>

