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

Sort internal table with the sequence

Former Member
2,452

Hello Experts,

wanted to sort my internal table in sequence. for example

Sno Mat id Rec_id Sequence no

  1. BOG6C210F 5857FB1D 2
  2. BOG6C210F 5857FB20 1
  3. BOG6C210F BOG6C210F 3
  4. BOG6C2166 584232BF 2
  5. BOG6C2166 584232C0 1
  6. BOG6C2166 584232A2 3

The above mentioned is my internal table data. i wanted to sort my internal table as below.

  1. BOG6C210F 5857FB20 1
  2. BOG6C210F 5857FB1D 2
  3. BOG6C210F BOG6C210F 3
  4. BOG6C2166 584232C0 1
  5. BOG6C2166 584232BF 2
  6. BOG6C2166 584232A2 3

Can any one provide me the idea, how to achieve this sort based on sequence no. this is small example, i have more than 100 records are available in my internal table.

<inappropriate comment removed by moderator>

Thanks,

Srikanth.

10 REPLIES 10
Read only

Dominik_Tylczynski
SAP Champion
SAP Champion
2,154
SORT <internal table> BY <sequence no> ASCENDING <mat id> ASCENDING <rec_id> DESCENDING.

should do the trick. Just replace <...> by actual field names of your internal table.

Also take a look at SORT key word ABAP documentation.

Read only

0 Likes
2,154

+1

Read only

2,154

Instead of writing +1, why not press the arrow above the zero, and upvote the answer you like?

Read only

2,154

I did upvote to bring the value from -1 to 0.

Read only

matt
Active Contributor
0 Likes
2,154

You've given inconsistent information as the records in your first set of data do not match any in the second. You really need to be clear exactly how you expect the data to be sorted, which columns, ascending or descending etc. But most of all you probably need to read the ABAP keyword documentation of SORT.

Read only

Dominik_Tylczynski
SAP Champion
SAP Champion
0 Likes
2,154

Would you explain where you see inconsistency?

The second set is just as the first one but in another order. Or am I missing something?

Read only

tom_wan
Product and Topic Expert
Product and Topic Expert
0 Likes
2,154

Hi Srikanth

For me, it is not 100% clear about what kind of sort sequence do you want.

Feels like you want to sort the table by "Mat id" and "Sequence no"

If yes, try this:

sort <internal table> by <Mat id> <Sequence no> ascending.

Read only

matt
Active Contributor
0 Likes
2,154

Sure. First data order is this:

Sno Mat id    Rec_id   Sequence no
1   BOG6C210F 5857FB1D    2
2   BOG6C210F 5857FB20    1
3   BOG6C210F BOG6C210F   3 
4   BOG6C2166 584232BF    2
5   BOG6C2166 584232C0    1
6   BOG6C2166 584232A2    3
<br>

Second is this

Sno Mat id    Rec_id   Sequence no
1   BOG6C210F 5857FB20    1
2   BOG6C210F 5857FB1D    2
3   BOG6C210F BOG6C210F   3
4   BOG6C2166 584232C0    1
5   BOG6C2166 584232BF    2
6   BOG6C2166 584232A2    3

The record 1 BOG6C210F 5857FB1D 2 in the first set does not exist in the second data set.

Of course, you've made the assumption that the Sno column should be ignored, which is probably true, but the point I was making is that it's really important when people ask questions to be as clear as possible.

And that it would be nice if people would put in a little effort to resolve issues themselves before posting here. I mean, how hard is it to read the keyword documentation? If this question had not received some answers already, I'd have deleted the question on the grounds of RTM.

Read only

Dominik_Tylczynski
SAP Champion
SAP Champion
2,154

I couldn’t agree more with your remarks on questions quality.

I did assume Sno is superfluous and based my answer on that assumption.

Best reg

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
2,154

"how hard is it to read the keyword documentation?"

Hopefully, not as hard as writing it 😉