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

sorting the internal table I'm getting ......

Former Member
0 Likes
769

While sorting the internal table I'm getting one of the columns not sorted .... why is that? for example

A B C

9 2 11

4 9 10

8 3 7

using ---> sort itab by A B C. gives me this

A B C

4 2 7

8 9 10

9 3 11

please help?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
735

are you sure ? because it gives me

4 | 9 | 10

8 | 3 | 7

9 | 2 | 11

like this and it is the correct one.

regards

shiba dutta

While sorting the internal table I'm getting one of the columns not sorted .... why is that? for example

A B C

9 2 11

4 9 10

8 3 7

using ---> sort itab by A B C. gives me this

A B C

4 2 7

8 9 10

9 3 11

please help?

5 REPLIES 5
Read only

Former Member
0 Likes
735

hi Essa,

It would be better if you could sort it with key fields .. and more over the order in which you might have used the sort statement is

sort ITAB by B A C.

Note : Please close your previous theread by marking helpful answers

Regards,

Santosh

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
735

Hi,

When you sort, sort operation will follow the order you give the columns if you give SORT by A B C that order will be taken if you give B A C then that order will be followed.

SO thats why you see that result.

Regards,

Sesh

Read only

Former Member
0 Likes
736

are you sure ? because it gives me

4 | 9 | 10

8 | 3 | 7

9 | 2 | 11

like this and it is the correct one.

regards

shiba dutta

Read only

Former Member
0 Likes
735

Hi,

check this code,

REPORT ZEX31 .

data : begin of itab occurs 0,

f1 type i,

f2 type i,

f3 type i,

end of itab.

itab-f1 = 9 .

itab-f2 = 2.

itab-f3 = 11 .

append itab.

clear itab.

itab-f1 = 4 .

itab-f2 = 9.

itab-f3 = 10 .

append itab.

clear itab.

itab-f1 = 8 .

itab-f2 = 3.

itab-f3 = 7 .

append itab.

clear itab.

loop at itab.

write : / itab-f1 , itab-f2 , itab-f3.

endloop.

sort itab by f1 f2 f3.

skip 2.

loop at itab.

write : / itab-f1 , itab-f2 , itab-f3.

endloop.

sorting will be based on the order u give,

if u give order f1 f2 f3 then first f1 will be checked and sorted in the order of it.

o/p will be

4 9 10

8 3 7

9 2 11

Read only

0 Likes
735

Thank you very much for this great explanation and now it's working.