‎2009 Mar 17 1:15 PM
Hello!
I have a question concerning sorting internal tables. I have a table with two components of type char:
A B
space space
248 BA
273 space
I tried to sort the table by 'SORT itab BY a b DESCENDING' - the result I expected is ...
A B
273 space
248 BA
space space
... but the computed result is ...
A B
space space
248 BA
273 space
I assume that the computed result is due to the initial char-values (space). How are initial char-values (space) handled by the sort statement?
I appreciate any advice!
Greetings
Wolfgang
‎2009 Mar 17 1:32 PM
To get the expected result..........
what you have to do is...
'SORT itab BY a DESCENDING b DESCENDING'
because the above statement sort itab by a 's descending order first then if two row contain same valu for a then column b help to take the decision which one come first. if row one has smaller value in B than that of row two.then row one come next to row two.
thanks.
‎2009 Mar 17 1:22 PM
hi,
would you please explain your requirement elaborately?
Regards.
Sarbajit.
‎2009 Mar 17 1:24 PM
Sorry, I accidently hit the post button before having finished g.
‎2009 Mar 17 1:32 PM
To get the expected result..........
what you have to do is...
'SORT itab BY a DESCENDING b DESCENDING'
because the above statement sort itab by a 's descending order first then if two row contain same valu for a then column b help to take the decision which one come first. if row one has smaller value in B than that of row two.then row one come next to row two.
thanks.
‎2009 Mar 17 1:33 PM
Hi,
Test the Code Bellow it is working as per you requirement
data: BEGIN OF it OCCURS 1,
a(10),
b(10),
END OF it.
it-a = '273'. it-b = ' '. APPEND it.
it-a = '248'. it-b = 'BA'. APPEND it.
it-a = ' '. it-b = ' '. APPEND it.
SORT it by a DESCENDING b DESCENDING.Best Regards,
Faisal
‎2009 Mar 17 1:38 PM
‎2009 Mar 17 1:43 PM
Hello,
Dont use coloum having property of charactor.
if you sort internal table based on field having charactor then you will get result as per your computed result.
change your field properties from char to n. then you will get you expected answer.
example if you have internal table with one coloum 'A'.
let us assume value of that coloum is 1,6,12,7,14,7,19
if you sort result will be 1,12,14,6,7,19. so in this case you have to define coloum with numeric property.
Regards,
Peranandam