Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Strange Problem in sorting an internal table

Former Member
0 Likes
2,431

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,143

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

5 REPLIES 5
Read only

Former Member
0 Likes
1,144

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

Read only

0 Likes
1,143

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??

Read only

former_member1716
Active Contributor
0 Likes
1,143

Hi B M,

Your code must as given below,

SORT itab STABLE BY lifnr.

Hope this helps.

Regards,

Satish

Read only

Former Member
0 Likes
1,143

Please note the date of the OP.

Rob

Read only

0 Likes
1,143

Ohh sorry..


Dint notice that