<?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 sort before search in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989033#M1493726</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi gurus,&lt;/P&gt;&lt;P&gt;             What is the best way to use select statement to get most recently changed/created N number of documents from vbak.&lt;/P&gt;&lt;P&gt;I was wondering if there is a standard way to do this or else do a custom loop solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Jun 2010 18:33:43 GMT</pubDate>
    <dc:creator>sujay_ranjan3</dc:creator>
    <dc:date>2010-06-08T18:33:43Z</dc:date>
    <item>
      <title>sort before search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989033#M1493726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi gurus,&lt;/P&gt;&lt;P&gt;             What is the best way to use select statement to get most recently changed/created N number of documents from vbak.&lt;/P&gt;&lt;P&gt;I was wondering if there is a standard way to do this or else do a custom loop solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jun 2010 18:33:43 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989033#M1493726</guid>
      <dc:creator>sujay_ranjan3</dc:creator>
      <dc:date>2010-06-08T18:33:43Z</dc:date>
    </item>
    <item>
      <title>Re: sort before search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989034#M1493727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT * FROM VBAK UP TO n ROWS
  INTO ...
  ORDER BY erdat DESCENDING.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Performance will be an issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jun 2010 18:43:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989034#M1493727</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-08T18:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: sort before search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989035#M1493728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Rob. is the order by before selection or after. Also would creating index help in speeding the process?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jun 2010 18:45:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989035#M1493728</guid>
      <dc:creator>sujay_ranjan3</dc:creator>
      <dc:date>2010-06-08T18:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: sort before search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989036#M1493729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the "order by" is part of the SELECT, not before or after.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't see how an index would help; you're selecting all records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jun 2010 18:51:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989036#M1493729</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-08T18:51:25Z</dc:date>
    </item>
    <item>
      <title>Re: sort before search</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989037#M1493730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;CRM_2007 wrote:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;is the order by before selection or after&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Technically the ORDER BY is applied to the result set of the query (as part of the SELECT statement). Now [Open SQL|http://help.sap.com/abapdocu_70/en/ABENOPENSQL.htm] has the nice feature that your &lt;EM&gt;UP TO n ROWS&lt;/EM&gt; clause is actually applied &lt;EM&gt;after&lt;/EM&gt; executing &lt;EM&gt;ORDER BY&lt;/EM&gt;, see the help on [UP TO n ROWS|http://help.sap.com/abapdocu_70/en/ABAPFROM_CLAUSE.htm#!ABAP_ADDITION_1@1@]:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the addition ORDER BY is also specified, the rows of the hit list are sorted on the database server and only the number of sorted rows specified in n are passed to the result set. If the addition ORDER BY is not specified, n arbitrary rows that meet the WHERE condition are passed to the result set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In actual database SQL dialects (SAP calls this [native SQL|http://help.sap.com/abapdocu_70/en/ABENNATIVESQL.htm]) this can vary and then you would have to make sure to formulate your query in such a way that the result set is first sorted and &lt;EM&gt;then&lt;/EM&gt; the row limit is applied (e.g. see explanation for [Oracle rownum queries|http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/pseudocolumns009.htm], where the naive query with limiting row numbers along with an &lt;EM&gt;order by&lt;/EM&gt; clause does not work).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Rob wrote:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;I don't see how an index would help; you're selecting all records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Based on the requirement of the poster and your code example only the top &lt;EM&gt;N&lt;/EM&gt; records should be returned (not &amp;lt;em&amp;gt;all records&amp;lt;/em&amp;gt;). Thus ideally you want a query that does &lt;EM&gt;not&lt;/EM&gt; read all data. I.e. with an index on creation date ERDAT, it would be trivial to find the &lt;EM&gt;N&lt;/EM&gt; highest values (Oracle would do an &amp;lt;em&amp;gt;index range scan descending&amp;lt;/em&amp;gt;). Otherwise the database is forced to do a &lt;EM&gt;full table scan&lt;/EM&gt;. So index creation should improve your query (especially if you have lots of sales documents).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For retrieving the latest documents I'd also check out the other obvious alternative: Change documents stored in CDHDR (objectclas = 'VERKBELEG' for sales documents). However, you should check if CDHDR has an appropriate index supporting your query. Note that such an index is often (though for sure not always) present, because it's common feature among applications to be interested in the latest changes. However, even with an appropriate index it's worthwhile to run the statements through a SQL trace and compare the used resources (usually there's &lt;EM&gt;lots&lt;/EM&gt; of change documents).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers, harald&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Jun 2010 23:55:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/sort-before-search/m-p/6989037#M1493730</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2010-06-08T23:55:24Z</dc:date>
    </item>
  </channel>
</rss>

