05-26-2011 8:59 PM
I have an internal table with character field which has data like this after I sort it. This is not what I expect from the sort.:
13A
15A
29A
30A
31A
33A
123A
125
62
76
94A
I expect this, which is sorted number first, then alpha. Any ideas how to get this sort?:
13A
15A
29A
30A
31A
33A
62
76
94A
123A
125
05-26-2011 9:18 PM
That isn't the order I would expect either, nor is the order you specified. What operating system and codepage is it? The 123A and 125 values should be at the top of the list in an ASCII based sort. If you use Rob's suggestion, you'll have to use an integer or other number type field for the number side; a CHAR field will still bubble the 123 and 125 values to the top in ASCII.
05-26-2011 9:01 PM
05-26-2011 9:18 PM
That isn't the order I would expect either, nor is the order you specified. What operating system and codepage is it? The 123A and 125 values should be at the top of the list in an ASCII based sort. If you use Rob's suggestion, you'll have to use an integer or other number type field for the number side; a CHAR field will still bubble the 123 and 125 values to the top in ASCII.
05-26-2011 9:27 PM
We are on Windows NT, but I'm doing this sort in ABAP in an internal table, so not sure why the operating system would effect it.
05-26-2011 9:32 PM
Excel sorting results into this:
123A
125
13A
15A
29A
30A
31A
33A
62
76
94A
As Rob has suggested, you need to have your own algorithm for sorting as your per your requirement.
Regards,
Naimesh Patel
05-26-2011 9:32 PM
Different operating systems can have different collating sequences (and I think in some you can specify your own).
But this does look wierd. I tried sorting it and got Brad's sequence, not yours (Linux).
@Naimesh - actually I got your sequence.
Rob
Edited by: Rob Burbank on May 26, 2011 4:36 PM
05-31-2011 4:14 PM
Thanks for the suggestions. After reading the suggestions and reviewing some other post threads, here's what I did to get the sort to work:
Add a dash - to the end of any record that did not have an alphabet character at the end. This way, all records have at least one non-numeric character at the end. Then I overlayed zeros '0000000' over each record. Then I sorted the table. Afterwards, I removed the dashes and zeros.
The long way around, but it worked for me. Since the internal table is processed in memory, it doesn't add much overhead to the run time.