<?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 FOR ALL ENTRIES sorted. in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105580#M439345</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The resulting list is not necessarily sorted even if the FOR ALL ENTRIES itab is sorted. How can make sure the optimizer will process the FOR ALL ENTRIES in the itab's sorted order?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, I would like to get the 10 most recently created sales orders' PO #:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;sort itab by vbeln descending.  " has 100 entries sorted to the most recent
select bstnk up to 10 rows
  from vbak
  into table itab_bstnk
   for all entries in itab
  where vbeln = itab-vbeln.
*-- the resulting list in itab_bstnk is not the same order as their corresponding vbelns
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot use ORDER BY clause because of FOR ALL ENTRIES. Would declaring the itab as a sorted internal table help? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 03 Apr 2007 22:12:08 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-04-03T22:12:08Z</dc:date>
    <item>
      <title>FOR ALL ENTRIES sorted.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105580#M439345</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The resulting list is not necessarily sorted even if the FOR ALL ENTRIES itab is sorted. How can make sure the optimizer will process the FOR ALL ENTRIES in the itab's sorted order?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, I would like to get the 10 most recently created sales orders' PO #:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;sort itab by vbeln descending.  " has 100 entries sorted to the most recent
select bstnk up to 10 rows
  from vbak
  into table itab_bstnk
   for all entries in itab
  where vbeln = itab-vbeln.
*-- the resulting list in itab_bstnk is not the same order as their corresponding vbelns
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I cannot use ORDER BY clause because of FOR ALL ENTRIES. Would declaring the itab as a sorted internal table help? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot,&lt;/P&gt;&lt;P&gt;John&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2007 22:12:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105580#M439345</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-03T22:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: FOR ALL ENTRIES sorted.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105581#M439346</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Unfortunately without an 'ORDER BY', SAP will have the internal table just as they are ordered in the database table that you are accessing from. So in your case, it will be in the order of VBELN ascending as that is the key and it is sorted ascending in the VBAK table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead of sorting your itab, add VBELN to your select and extend your internal table itab_bstnk to include VBELN and then sort itab_bstnk by VBELN descending.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT VBELN BSTNK UP TO 10 ROWS FROM vbak&lt;/P&gt;&lt;P&gt;INTO TABLE itab_bstnk FOR ALL ENTRIES IN itab&lt;/P&gt;&lt;P&gt;WHERE vbeln = itab-vbeln.&lt;/P&gt;&lt;P&gt;SORT itab_bstnk BY vbeln DESCENDING.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2007 22:29:28 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105581#M439346</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-03T22:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: FOR ALL ENTRIES sorted.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105582#M439347</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My problem is that since the UP TO 10 ROWS will pick only 10 out of 100, the SELECT doesn't necessarily picks the 1st 10 entries of itab_vbeln, therefore the resulting list is not the most recent sales orders.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAP will not even pick up the records in ascending order or the database order in VBAK. Thus this question.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2007 22:44:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105582#M439347</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-03T22:44:24Z</dc:date>
    </item>
    <item>
      <title>Re: FOR ALL ENTRIES sorted.</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105583#M439348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So is your ultimate requirement is to get the most recent 10 sales orders from out of the 100 sales orders in that itab? In that case, you have to get all the 100 sales orders, sort them and then delete the rest 90. I am not sure if you will be able achieve all this with just the SELECT statement alone.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2007 22:50:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/for-all-entries-sorted/m-p/2105583#M439348</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-04-03T22:50:40Z</dc:date>
    </item>
  </channel>
</rss>

