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

SORT in ABAP

0 Likes
7,947

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
Read only

former_member585060
Active Contributor
0 Likes
1,885

Hi,

Try this syntax

SORT ITAB AS TEXT.

Regards

Bala Krishna

Hi,

Try this syntax

SORT ITAB AS TEXT.

Regards

Bala Krishna

11 REPLIES 11
Read only

Sandeep_Panghal
Product and Topic Expert
Product and Topic Expert
0 Likes
1,885

Hi,

yes this is possible.

Regards,

Sandeep

Read only

0 Likes
1,885

Hi Sandeep,

Thanks for the information.

Bt how do i do that ?

Thanks,

Kasi

Read only

0 Likes
1,885

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

Read only

GauthamV
Active Contributor
0 Likes
1,885

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.

Read only

0 Likes
1,885

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

Read only

GauthamV
Active Contributor
0 Likes
1,885

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.

Read only

Former Member
0 Likes
1,885

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

Read only

former_member585060
Active Contributor
0 Likes
1,886

Hi,

Try this syntax

SORT ITAB AS TEXT.

Regards

Bala Krishna

Read only

madan_ullasa
Contributor
0 Likes
1,885

Hi ,

Try this..

sort filed1 field2 descending...

regards,

Madan..

Read only

madan_ullasa
Contributor
0 Likes
1,885

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,,,

Read only

Former Member
0 Likes
1,885

.

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