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 multiple field values

Former Member
0 Likes
5,431

Hi All,

I want to sort internal table single field but based on this fields values preioritised.

fields priority are:

Field = 'aabb'

Field = 'aaaa'

Field = 'aacc'

Field = 'ddgg'.

interbale table should sort accoring to above values coming

. please suggest how to achive this.

Thanks,

Abaper

8 REPLIES 8
Read only

Former Member
0 Likes
2,189

In the past I have built a sort field that I concatenated the fields that I wanted to sort on into.  I think a variation on this theme would work fine.  Please note, in this case, concatenate is a euphamism.  So, say that field 1 was at max 10 characters long.  then field 2 started in the 11th character.

Read only

0 Likes
2,189

Hi neal,

But I have internal table with 50 fields but want to sort table based on only one fields values menationed above.

Read only

0 Likes
2,189

So,

If condition 1

Sort itab by fieldx

elseif condition2

Sort itab by fieldy

elseif condition3

Sort itab by fieldz

...

That meets the explanations by the others.

or mine

Loop at itab

  move itab[filed chosen] to itab-sortfield

  modify

endloop.

sort itab by sortfield.

Mine then has you using field symbols to assign which field you are sorting on

I've never tried a field symbol in a sort, so I didn't suggest

sort itab by <fs>

It might work, but again I've never tried it.

Neal

Read only

former_member156446
Active Contributor
0 Likes
2,189

Sort itab by field.

Read only

former_member1716
Active Contributor
0 Likes
2,189

Use the below code,

SORT Internal_table BY aabb aaaa aacc ddgg.

Regards,

Satish

Read only

Former Member
0 Likes
2,189

Hi

is your field a field of the internal table or a separate field?

also what is the difference between 'aabb' and 'aacc'

both are ascending. or did you want to explain sort by value1, value2, value3?

or for "aacc" you dont want "bb" to be part of the result?

it sounds like you want a sort that cant be done by "sort"-command.

easiest way is to add a field to the tab named "prio" (or something like that)

that you fill with "int"-values ond sort by them.

regards

Stefan Seeburger

Read only

Former Member
0 Likes
2,189

Abaper G,

Field values are not in order as per your priority. It is better you do it as per Mr.

Read only

philipdavy
Contributor
0 Likes
2,189
  • I doubt whether I got your question correctly, but you could try to build one sort order using some concatenate statements, and adding a sort alphabet.

Something like aaabb - First sort value, a in third position

                      aabaa - Second sort value b in third position

                      aadcc - Third sort value d in third position

                      ddegg - Fourth sort value e in third positon.


  • Then you could use something like Sort As Text , Sort As Text and later delete the extra alphabet used for sorting.

PS: 1) The idea all depends on assuming that your values (ie aabb, aaaa, aacc, ddgg) will be fixed.