Application Development 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: 

SORT in ABAP

0 Kudos

Hello All,

I have an Internal with a Character field and i need to sort that table.

Can I SORT the internal table irrespective of their ASCII value.

For example: if the internal table contains value ABD and ABc.

on Sorting the table i wanted it to be in the order of ABc, ABD and not ABD, Abc.

Is it possible to do so ?

Thanks in advance.

Best Regards,

Kasi Raaman.R

1 ACCEPTED SOLUTION

former_member585060
Active Contributor
0 Kudos

Hi,

Try this syntax

SORT ITAB AS TEXT.

Regards

Bala Krishna

11 REPLIES 11

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

yes this is possible.

Regards,

Sandeep

0 Kudos

Hi Sandeep,

Thanks for the information.

Bt how do i do that ?

Thanks,

Kasi

Sandeep_Kumar
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi ,

There is no additional effort needed here .

For example:

DATA : lt_mara TYPE TABLE OF makt.

SELECT * FROM makt INTO TABLE lt_mara UP TO 10 ROWS WHERE maktx LIKE '%A%'.

SORT lt_mara BY maktx.

It works fine,

Regards,

Sandeep

GauthamV
Active Contributor
0 Kudos

hi,

check this.


DATA:BEGIN OF it_kna1 OCCURS 0,
     kunnr LIKE kna1-kunnr,
     name1 LIKE kna1-name1,
     END OF it_kna1.

it_kna1-kunnr = '123'.
it_kna1-name1 = 'ABD'.
append it_kna1.

it_kna1-kunnr = '125'.
it_kna1-name1 = 'ABC'.
append it_kna1.

sort it_kna1 by name1.

loop at it_kna1.

write : / it_kna1-kunnr,it_kna1-name1.

endloop.

0 Kudos

Hello chakraverthi,

Thanks for the reply.

But in your case both the values for name1 are in UPPER case, bt the issue comes when u have a upper and lower case as in my example.

Thanks,

Kasi

GauthamV
Active Contributor
0 Kudos

hi,

In general sort statement wil pick the values based on order,

i.e first preference goes to upper case and then later,anyhow we will not be having data in that way in which you have mentioned.

Former Member
0 Kudos

Hi Kasi,

See the below code.

TYPES : BEGIN OF TY_TAB,
         NAME(10) TYPE C,
        END OF TY_TAB.

DATA : IT_TAB TYPE TABLE OF TY_TAB WITH HEADER LINE.

IT_TAB-NAME = 'ABC'.
APPEND IT_TAB.

IT_TAB-NAME = 'ABc'.
APPEND IT_TAB.

IT_TAB-NAME = 'ABD'.
APPEND IT_TAB.

SORT IT_TAB BY NAME AS TEXT.

you can use the extenstion in SORT with AS TEXT

former_member585060
Active Contributor
0 Kudos

Hi,

Try this syntax

SORT ITAB AS TEXT.

Regards

Bala Krishna

madan_ullasa
Contributor
0 Kudos

Hi ,

Try this..

sort filed1 field2 descending...

regards,

Madan..

madan_ullasa
Contributor
0 Kudos

Hi,

I did this.. and its working fine...

data: begin of itab occurs 0,

f1(10) type c,

end of itab.

itab-f1 = 'ABC'.

append itab.

itab-f1 = 'ABc'.

append itab.

sort itab descending.

loop at itab.

write:/ itab-f1.

endloop.

Regards,

Madan,,,

Former Member
0 Kudos

.

Edited by: ganesh prasad on Oct 8, 2008 11:35 AM