‎2014 Oct 08 8:38 PM
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
‎2014 Oct 08 8:55 PM
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.
‎2014 Oct 08 9:06 PM
Hi neal,
But I have internal table with 50 fields but want to sort table based on only one fields values menationed above.
‎2014 Oct 09 3:16 PM
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
‎2014 Oct 08 8:55 PM
‎2014 Oct 09 7:48 AM
Use the below code,
SORT Internal_table BY aabb aaaa aacc ddgg.
Regards,
Satish
‎2014 Oct 09 8:04 AM
Hi Abaper G
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
‎2014 Oct 09 8:15 AM
Abaper G,
Field values are not in order as per your priority. It is better you do it as per Mr. Stefan Seeburger comment.
‎2014 Oct 09 8:18 AM
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.
PS: 1) The idea all depends on assuming that your values (ie aabb, aaaa, aacc, ddgg) will be fixed.