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

Internal table sort problem

Former Member
0 Likes
1,604

Dear all,

I'm having a problem sorting an internal table. The table declaration is something like this

DATA: BEGIN OF ITAB OCCURS 0,

DOKNR LIKE DRAW-DOKNR,

DOKAR LIKE DRAW-DOKAR,

DOKVR LIKE DRAW-DOKVR,

DOKTL LIKE DRAW-DOKTL,

DKTXT LIKE DRAT-DKTXT,

DTCRI LIKE DRAP-DATUM,

DATA LIKE ZDMS_T_DOC-DATA,

HORA LIKE ZDMS_T_DOC-HORA,

...

END OF ITAB.

I'm trying to sort the table by doknr

SORT ITAB BY DOKNR DESCENDING.

The result after the sort command is

703000000009

2000022608

2000022607

2000022196

2000005193

100054788

100054787

10002039975

10002039968.

Thanks in advance,

sb.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,304

If u want sort to work.....take a field of type N and move this value to that field and sort by that field in descending order.

U'll get required output.

Regards

Vasu

11 REPLIES 11
Read only

Former Member
0 Likes
1,304

Hi Sara,

everything is correct, what's the problem - want do you want to get ?

if you want have ist the other way round you have to code.

sort itab by doknr.

regards henner

Read only

0 Likes
1,304

HI,

DRAW-DOKNR is a char field, so the sort is correct, no problem.

bye

Read only

0 Likes
1,304

Hi Henner,

if you see the sort from CV04N, the output is different and just like I need. In fact, for a char type the result that I get is correct.

Thanks,

sb.

Read only

0 Likes
1,304

hi Sara,

what is the order you want to have? Can you copy it here? Probably not everyone has data in transaction CV04N

thanks

ec

Read only

0 Likes
1,304

Hi Eric,

I want something like

703000000009

10002039975

10002039968

2000022608

2000022607

2000022196

2000005193

100054788

100054787

Thanks,

sb.

Read only

0 Likes
1,304

thanks,

than check the values in debug and if they are not right aligned (in the field), than do what I suggested:

SHIFT doknr RIGHT DELETING TRAILING SPACE (of course in a LOOP on each single line)

than the SORT itab BY ... DESCENDING.

Read only

Former Member
0 Likes
1,305

If u want sort to work.....take a field of type N and move this value to that field and sort by that field in descending order.

U'll get required output.

Regards

Vasu

Read only

0 Likes
1,304

Hi Vasu,

with the N type I get the following result

10002039975

10002039968

703000000009

2000022608

2000022607

2000022196

2000005193

100054788

100054787

Any idea?

Thanks,

sb.

Read only

0 Likes
1,304

Other thing I would try is :

SHIFT doknr RIGHT DELETING TRAILING SPACE (of course in a LOOP on each single line)

than the SORT

Read only

Former Member
0 Likes
1,304

hi

good

rather than using one field in the sorting statement try to use two field name in the sorting statement but you have to check in the debug mode that with two field ll give you the exact output as per your requirement.

thanks

mrutyun^

Read only

Former Member
0 Likes
1,304

Thank you all, problem resolved with type N.