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 Internal Table

Former Member
0 Likes
1,128

Hi ,

I have an internal table as given below. I need to display the O/P by Sorting according to POSNR.

Before sorting :_

POSNR MATNR FLAG LFIMG VRKME MAKTX

120 |000000000000716740| B |10 |ST |Pallet (Euro)

40 |000000000000716740| B |10 |ST |Pallet (Euro)

50 |000000000000716790| B |10 |ST |Pallet (BPD)

130 |000000000000716809| B |10 |ST |Pallet (BPD)

60 |000000000000716809| B |10 |ST |Pallet (BPD)

70 |000000000000716810| B |10 |ST |Container

80 |000000000000716812| B |10 |ST |RIC

Am using statement - SORT t_empties BY POSNR.

After Sorting:-

POSNR MATNR FLAG LFIMG VRKME MAKTX

120 |000000000000716740 |B |10 |ST |Pallet ro)

130 |000000000000716809 |B |10 |ST |Pallet (BPD)

40 |000000000000716740 |B |10 |ST |Pallet (Euro)

50 |000000000000716790 |B |10 |ST |Pallet (BPD)

60 |000000000000716809 |B |10 |ST |Pallet (BPD)

70 |000000000000716810 |B |10 |ST |Container

80 |000000000000716812 |B |10 |ST |RIC

Can any one ples let me know why its not getting sorted correctly

regards

Avi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,028

try this

loop at itab into wa_itab.

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_itab-posnr.
        IMPORTING
          output = wa_itab-posnr.

modify itab from wa_itab.

endloop.

<b>SORT ITAB BY POSNR.</b>

9 REPLIES 9
Read only

alex_m
Active Contributor
0 Likes
1,028

By default it should sort on ascending, may be tru to use ASCENDING key word in SORT statement and see.

Read only

Former Member
0 Likes
1,028

Hi

Keep the POSNR as first field in the internal Table and then it will come correctly

reward if useful

regards,

Anji

Read only

Former Member
0 Likes
1,028

How is the field POSNR defined? It needs to be numeric for the sort to work the way that you want it to. It looks to me like the sort is treating POSNR as a character field, with the values being left-justified (the 1 in 120 comes before the 4 in 40).

- April King

Read only

Former Member
0 Likes
1,029

try this

loop at itab into wa_itab.

   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = wa_itab-posnr.
        IMPORTING
          output = wa_itab-posnr.

modify itab from wa_itab.

endloop.

<b>SORT ITAB BY POSNR.</b>

Read only

Former Member
0 Likes
1,028

Hi ..

it is considering the POSNR according to the starting number..

do one thing..take <b>POSNR field data type as N</b>.

thhis will solve ur problem..

Ram

Read only

0 Likes
1,028

hi Alexander,

I tried with keeping ASCENDING . Its not working.

hi Anji,

Its the FIRST Field of internal table

hi April King,

The internal table is defined according to a Structure created

inside the strcuture its defined as:-

POSNR Component Type = POSNR, Data Type = NUMC

Regards

Avi....

Read only

0 Likes
1,028

so have you tried my cide??

Read only

0 Likes
1,028

There are two things I would suggest trying.

1) You could define POSNR as TYPE N instead of NUMC.

or

2) When you are moving values to POSNR, fill the leading characters with zeroes. This will effectively right justify your field and should result in the correct sort order.

- April

Read only

0 Likes
1,028

Hi Chandra,

Thx a lot solved the issue

Regards

Avi...