‎2009 Oct 16 8:06 AM
Hi Experts,
I have one query in sorting. I have one column as Character type.
In that column it contains values like 6-9, 10-15, 16, 17, 18 kind of.
Now while sorting I wanted that it should display like
6-9
10-15
16
17
18.
If I do using sort statement it is not coming in desired format. Can anybody will suggest me how I can do that?
Regards,
Neha
‎2009 Oct 16 8:16 AM
Hi Neha,
Is it possible to change the value of 6-9 to 06-09?
If you change it then the sorting will be proper.
Regards,
Vinod
‎2009 Oct 16 8:22 AM
Hi,
i think you can acheive this only by manipulating data when you are creating the internal table
check the last entered value for that column , check if the next value is greater - something like that
Regards
Sajimon Chandran
‎2009 Oct 16 8:32 AM
Hi,
Try this way....
data: begin of it,
chk type i,
fld type char6,
end of it.
data: itab like table of it with header line.
MOVE '1' TO itab-chk.
MOVE '6-9' TO itab-fld.
APPEND itab.
MOVE '2' TO itab-chk.
MOVE '10-15' TO itab-fld.
APPEND itab.
MOVE '3' TO itab-chk.
MOVE '16-20' TO itab-fld.
APPEND itab.
MOVE '4' TO itab-chk.
MOVE '21' TO itab-fld.
APPEND itab.
MOVE '5' TO itab-chk.
MOVE '22' TO itab-fld.
APPEND itab.
MOVE '23' TO itab-fld.
APPEND itab.
SORT ITAB ASCENDING BY chk.
LOOP AT ITAB.
WRITE:/ ITAB-FLD.
ENDLOOP.Regards,
Shankar.
‎2009 Oct 16 8:40 AM
Hi Neha,
You can use a temporary supplementary field in your internal table, say num, that you can fill automatically with the first number and sort by this column :
TYPES : BEGIN OF ts_test,
col TYPE string, " column with your original field
num TYPE i, " column with the first number (integer for the sort)
END OF ts_test.
DATA : lt_test TYPE tt_test,
ld_test TYPE i.
LOOP AT lt_test ASSIGNING <ls_test>.
" Split your field at symbol "-"
FIND '-' IN <ls_test>-col MATCH OFFSET ld_test.
IF sy-subrc = 0.
" If found keep only first number
MOVE <ls_test>-col(ld_test) TO <ls_test>-num.
ELSE.
" else keep your field
MOVE <ls_test>-col TO <ls_test>-num.
ENDIF.
ENDLOOP.
SORT lt_test BY num.
Hope it help!
Samuel
‎2009 Oct 16 9:02 AM
Hi,
Make 1 internal table with 2 fields.
split your target characters on the basis of '-'. And Append into the internal table field respectively.Then sort the table on the basis of first field then second field. Then concatenate the fields of internal table with '-' , if the second field is not vacant.
‎2010 Jan 15 6:22 AM