2012 May 03 5:14 PM
Hi Experts,
I am really confused with how the below sorting is working:
Simple statement: SORT ITAB by LIFNR.
1st Scenario:
I have around 13-14 records in my internal table
1.Vendor 2000000029 Company Code 1176 EKORG 1176 Name1 Test
2.Vendor 2000000021 Company Code 1176 EKORG 1176 Name1 test2
3.Vendor 2000000029 Company Code 1176 EKORG 1176 Name1 BLANK
Now when i sort the above results i get the 3rd record at second place where name1 is blank i dnt know why this happened, i was expecting
2nd record then 1st then 3rd
Then i increased the range of my selection it worked , strange how sort mechanism is working?
Should i add more keys here i mean i wanted to know what is wrong here.
2012 May 03 5:22 PM
If you want to maintain the original order where the sort field has the same value, you have to add the keyword STABLE to the SORT command.
Rob
2012 May 03 5:22 PM
If you want to maintain the original order where the sort field has the same value, you have to add the keyword STABLE to the SORT command.
Rob
2012 May 03 5:27 PM
Ok i will try with stable and look into it.
One more question i have is in debugging i skipped the sort statement on internal table
and since i am displaying the data in ALV i am sorting my output using method Add_SOrt on lfinr.
When i skip the sort statement and let the method do it , its giving correct results.
So is the sort in Add_sort do the stable sorting and not the sort statement??
2016 Jan 05 5:11 PM
Hi B M,
Your code must as given below,
SORT itab STABLE BY lifnr.
Hope this helps.
Regards,
Satish
2016 Jan 05 6:20 PM
2016 Jan 05 6:28 PM