<?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: ABAP SORT Statement is strange in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444592#M1998975</link>
    <description>&lt;P&gt;I guess you missed screen shots with the data before and after sort. Showing the itab internal table definition would also help to help you.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Jul 2021 08:51:47 GMT</pubDate>
    <dc:creator>Dominik_Tylczynski</dc:creator>
    <dc:date>2021-07-09T08:51:47Z</dc:date>
    <item>
      <title>ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444591#M1998974</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
  &lt;P&gt;I am facing with a strange issue about sorting.&lt;/P&gt;
  &lt;P&gt;My data before sorting is below:&lt;/P&gt;
  &lt;P&gt;&lt;IMG alt="" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1954716-before.png" /&gt;&lt;/P&gt;
  &lt;P&gt;After using "SORT itab BY EBELP ETENR RSPOS, the output is strange:&lt;/P&gt;
  &lt;P&gt;&lt;IMG alt="" style="font-size: 15px; color: inherit;" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1954718-after.png" /&gt;&lt;/P&gt;
  &lt;P&gt;As you can see above, I don't know why "I" go before "D" in RSPOS item no 10.&lt;/P&gt;
  &lt;P&gt;Can everyone help me explain the reason why I &amp;gt; D?.&lt;/P&gt;
  &lt;P&gt;I think that it should be keep the original order in case of the sort key is the same.&lt;/P&gt;
  &lt;P&gt;(NOTE: The sort statement is in BAPI_PO_CHANGE)&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:40:19 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444591#M1998974</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T08:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444592#M1998975</link>
      <description>&lt;P&gt;I guess you missed screen shots with the data before and after sort. Showing the itab internal table definition would also help to help you.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:51:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444592#M1998975</guid>
      <dc:creator>Dominik_Tylczynski</dc:creator>
      <dc:date>2021-07-09T08:51:47Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444593#M1998976</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;These two example rows have same key on level EBELP+ETENR+RSPOS. So order in other columns will be random.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:54:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444593#M1998976</guid>
      <dc:creator>sergey_muratov</dc:creator>
      <dc:date>2021-07-09T08:54:24Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444594#M1998977</link>
      <description>&lt;P&gt; @&lt;SPAN class="mention-scrubbed"&gt;3a9e4ce873a94034b33dc62b0ce600ee&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I edited it from 5 minute ago. On my screen, the picture display correctly.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:55:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444594#M1998977</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T08:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444595#M1998978</link>
      <description>&lt;P&gt;Are you kiddin'?&lt;/P&gt;&lt;P&gt;If you are sorting by EBELP, ETENR and RSPOS, the data appears sorted by those three fields. The column you marked as "weird" is UPDKZ. It's not sorted (and must NOT be).&lt;/P&gt;&lt;P&gt;Check again your screenshots, and take a deeper look at the column RSPOS.&lt;/P&gt;&lt;P&gt;Before the SORT you have something like&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;10 - D&lt;/LI&gt;&lt;LI&gt;20 - D&lt;/LI&gt;&lt;LI&gt;10 - I&lt;/LI&gt;&lt;LI&gt;20 - I&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;and after the sort, the RSPOS are rearranged (and thus, the UPDKZ disordered)&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;10 - D&lt;/LI&gt;&lt;LI&gt;10 - I&lt;/LI&gt;&lt;LI&gt;20 - D&lt;/LI&gt;&lt;LI&gt;20 - I&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Nothing weird at all, mate.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:57:57 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444595#M1998978</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2021-07-09T08:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444596#M1998979</link>
      <description>&lt;P&gt;Mate, check my answer and once you get it, ask this post to be deleted to not be read again in the future (ie, when someone will search by "SORT").&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:59:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444596#M1998979</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2021-07-09T08:59:05Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444597#M1998980</link>
      <description>&lt;P&gt;Hello &lt;SPAN class="mention-scrubbed"&gt;kemdau&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;What you are see is perfectly normal - see SAP Help on &lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapsort_itab.htm" target="_blank"&gt;SORT itab&lt;/A&gt;. It reads:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Sorting is unstable by default, which means that the relative order of rows that do not have different sort keys is not preserved when they are sorted. The order can be different depending on the platform or when sorted multiple times. The addition STABLE can be used for stable sorting.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;If you need to preserve the relative order of rows after sorting, use STABLE.&lt;/P&gt;&lt;P&gt;Best regards&lt;/P&gt;&lt;P&gt;Dominik Tylczynski&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapsort_itab.htm" target="_blank"&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 08:59:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444597#M1998980</guid>
      <dc:creator>Dominik_Tylczynski</dc:creator>
      <dc:date>2021-07-09T08:59:59Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444598#M1998981</link>
      <description>&lt;P&gt;Thank for your answer,&lt;/P&gt;&lt;P&gt;But, why other lines alway keep the original order(D&amp;gt;I). Only item RSPOS 10 have I&amp;gt;D&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:00:18 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444598#M1998981</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T09:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444599#M1998982</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This behaviour can be considered normal in ABAP. That said, I think it poses an interesting question on the inner workings of SORT. To explain this behavior with 100% certainty, we would need to know the exact implementation of the SORT statement in ABAP.&lt;/P&gt;&lt;P&gt;My guess:&lt;BR /&gt;The 'plain' SORT statement uses the some kind of &lt;A href="https://en.wikipedia.org/wiki/Quicksort" target="_blank"&gt;quicksort &lt;/A&gt;algorithm. From Wikipedia: "Quicksort is a &lt;A href="https://en.wikipedia.org/wiki/Divide-and-conquer_algorithm"&gt;divide-and-conquer algorithm&lt;/A&gt;. It works by selecting a 'pivot' element from the array and partitioning the other elements into two sub-arrays, according to whether they are less than or greater than the pivot."&lt;BR /&gt;&lt;BR /&gt;So in your example, my assumption is the middle element, meaning line 12, is chosen as the first pivot. This explains the strange behavior that you see: the first element has UPKZ 'I', while all following rows occur in their 'original' order, with UPKZ 'D' before 'I'.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:02:05 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444599#M1998982</guid>
      <dc:creator>LaurensDeprost</dc:creator>
      <dc:date>2021-07-09T09:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444600#M1998983</link>
      <description>&lt;P&gt;Hi  @&lt;SPAN class="mention-scrubbed"&gt;vicen.lozano&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;The weird thing is :&lt;/P&gt;&lt;P&gt;10-I&lt;/P&gt;&lt;P&gt;10-D&lt;/P&gt;&lt;P&gt;20-D&lt;/P&gt;&lt;P&gt;20-I&lt;/P&gt;&lt;P&gt;Because I think SORT statement should keep the original order in case of the same key&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:05:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444600#M1998983</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T09:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444601#M1998984</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;dep&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank you so much,&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:11:24 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444601#M1998984</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T09:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444602#M1998985</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;vicen.lozano&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;I think this post should be keep. &lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:19:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444602#M1998985</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T09:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444603#M1998986</link>
      <description>&lt;P&gt;You are wrong by assuming things. That attitude lead a lot of developers to not use the ORDER BY in a lot of programs, and when their companies moved to HANA DB, all those programs stopped to work properly, because HANA gives the data unsorted.&lt;BR /&gt;NEVER EVER assume anything.&lt;/P&gt;&lt;P&gt;If you tell SAP to SORT BY col_list, do not expect for it to sort the other columns. Maybe it does, but it will stop doing it at any time.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:21:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444603#M1998986</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2021-07-09T09:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444604#M1998987</link>
      <description>&lt;P&gt;Never knew abot that STABLE thing.&lt;/P&gt;&lt;P&gt;I will try to forget ASAP (when I need any kind of sorting, I specify the whole sort and I don't care about the rest of the columns). Check my comment about assumptions in my answer.&lt;/P&gt;&lt;P&gt;But if some day I see that STABLE thing, I will not think about horses nor donkeys XD&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:23:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444604#M1998987</guid>
      <dc:creator>VXLozano</dc:creator>
      <dc:date>2021-07-09T09:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP SORT Statement is strange</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444605#M1998988</link>
      <description>&lt;P&gt;&lt;SPAN class="mention-scrubbed"&gt;vicen.lozano&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Thank for your information,&lt;/P&gt;&lt;P&gt;My purpose in this question is that I want to understand more about the logic in SORT statement to find solution because the sort statement above is in Standard program(Which I don't want to change).&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 09:42:13 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/abap-sort-statement-is-strange/m-p/12444605#M1998988</guid>
      <dc:creator>former_member591443</dc:creator>
      <dc:date>2021-07-09T09:42:13Z</dc:date>
    </item>
  </channel>
</rss>

