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 for two fields

mark_fryu
Participant
0 Likes
6,794

I need to sort the it_mseg internal table in ascending order for the bwart and mkpf_budat fields.

I am trying to use this statement:

ORDER it_mseg FOR budat_mkpf bwart.

but it doesn't work because it only sorts for one field I also tried like this:

order it_mseg by bwart.

order stable it_mseg of budat_mkpf.

how do i do it? thanks

1 ACCEPTED SOLUTION
Read only

Patrick_vN
Active Contributor
6,563

Normally the code should look like this:

SORT it_mseg BY field_a ASCENDING field_b DESCENDING.

Are you sure that you can modify the contents of your table [it_mseg]? If it is an import parameter, it might be protected against changes.

9 REPLIES 9
Read only

MateuszAdamus
Active Contributor
6,563

Hello mark.fryu

If you want to sort an internal table then what you're looking for is SORT keyword.

https://help.sap.com/doc/abapdocu_752_index_htm/7.52/en-US/abapsort_itab.htm

Kind regards,
Mateusz
Read only

0 Likes
6,563

I tried "sort" but it didn't work, can you give me an instruction with the sort to try?

Read only

6,563
mark.fryu Did you open and read the link? It's full of instructions and examples.
Read only

Patrick_vN
Active Contributor
6,564

Normally the code should look like this:

SORT it_mseg BY field_a ASCENDING field_b DESCENDING.

Are you sure that you can modify the contents of your table [it_mseg]? If it is an import parameter, it might be protected against changes.

Read only

0 Likes
6,563

yes I can modify the internal table, it's my report, I also tried this instruction but it sorts only for the first field, in this example of yours it sorts only for the field field_a

Read only

joltdx
Active Contributor
6,563

Patricks example should work. Please update your question with your exact code and we will be able to help. Also please show us your data before and after the sort, where we can see the data not sorted properly.

Read only

6,563
mark.fryu You're wrong, so please give details of values in your internal table + ABAP code so that we can explain what your error is.
Read only

joltdx
Active Contributor
6,563

Please show us your exact code.

Do you mean to use to SORT statement after there already is data in it_mseg? Or are you trying to use the ORDER BY to get the data sorted already from a SELECT query?

Read only

matt
Active Contributor
0 Likes
6,563

I'm guessing this question is the output of automated translation!