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

Sorting an internal table!

Former Member
0 Likes
788

Dear ABAPers,

In the program there is a statement

SORT nbseg BY txgrp.

Even though the table is already sorted by tax group, that is in my case, the first item of the invoice ahs tax group 000 and all the rest have 001.

As soon as the sort statemet is executed, the first item remains as it is, but the rest of the items change positions. item number 329 comes second, 170 comes 3rd etc even though they have same tax group.

Any idea how the sort statement works when the field has identical values?

Would be glad to award points for helpful answers.

Regards

Veena

7 REPLIES 7
Read only

Former Member
0 Likes
758

try sort itab by field1 ascending

Read only

0 Likes
758

Thank you, but I am not developing the program and trying to resolve the issue in an existing program. Because of this sorting pattern we do not have the last item of the invoice being read last.

Read only

0 Likes
758

sorry.. i was trying to edit my last post to reflect your real question..

it probably has something to do with the columns to the left of the field you are sorting. if you are particular about those other fields, you should sort them in sequence as well.

sort itab by txgrp field2 field3 .... ascending.

Read only

0 Likes
758

Thanks so much for the answers, but i still have one question.

If the 3 records in the internal table look like below

Tax group

1 2133 1800002056 000 001 D S

2 2133 1800002056 001 002 S S

3 2133 1800002056 001 003 S S

4 2133 1800002056 001 004 S S

5 2133 1800002056 001 005 S S

Then ideally after sorting by tax group, the records should remain as they are right? Wierdly, in some cases the records remain as they are but for some invoices they get shifted, any thoughts?

Read only

0 Likes
758

Sorry in my previous post, tax group column is the one with

000

001

001

001

001

Read only

former_member156446
Active Contributor
0 Likes
758

hi there try sorting using item number as well

SORT nbseg BY item_no txgrp.

is notthing is mention in sort its ascending by default.

Read only

Former Member
0 Likes
758

try stable sort.