2013 Jan 04 6:02 AM
Hello,
I have came with an issue of report in which i have to sort the entries in the table according to some particular entries in a column which as fixed just 5 values in string.Using a simple Sort command I m not able to perform the sort as I required, Please Kindly Help me for the same.
2013 Jan 04 7:08 AM
No ABAP statement will sort those data as you liked it as
Character-like components are sorted by default by their binary representation (code page). Textual sorting of character-like components can be performed using the addition AS TEXT.
(AFAIK no code page has this order BRYGW, those good old characters from birth of ASCII were always sorted in Latin alphabet order)
So either create another column in the internal table and fill it with 1 for B, 2 for R, etc, and sort with this field (not-displayed) or replace temporary the color codes by values in your required order, sort the table, and replace back with the original color codes.
Now you should understand the use of special values in lights_fieldname in ALV grid
'1' = red traffic light
'2' = yellow traffic light
'3' = green traffic light
You have to code yourself your own values as you have 2 other values to manage.
Regards,
Raymond
2013 Jan 04 6:13 AM
Are you giving the correct order in sorting.
SORT itab BY field1 field2 .. ( use AS TEXT) addition if you want character sorting.
more details.
http://help.sap.com/saphelp_erp60_sp/helpdata/en/fc/eb3800358411d1829f0000e829fbfe/content.htm
2013 Jan 04 6:25 AM
Hi,
Thanks for replying,But in my internal table I have a column which contains list of particular colors just five of them used to define zones as Yellow,White,Green,Red &Black. when I use the ascending order it gives me BRGWY and in descending YWGRB colors format. But I want it as in format Black Red Yellow Green White.So the above syntax does not works.Please suggest me any other solution.
2013 Jan 04 6:33 AM
Hi
then try
SORT itab BY Black Red Yellow Green White.
Black Red Yellow Green White. will have the columns to be sorted
Thanks.
2013 Jan 04 6:43 AM
Hi sorry i couldnt get your question are those colors contents of a particular column?
2013 Jan 04 6:51 AM
TYPES:BEGIN OF s_test,
col TYPE char2,
sorder TYPE n,
END OF s_test.
DATA:it_test TYPE STANDARD TABLE OF s_test,
wa_test TYPE s_test.
wa_test-col = 'W'.
wa_test-sorder = 5.
APPEND wa_test TO it_test.
wa_test-col = 'Y'.
wa_test-sorder = 3.
APPEND wa_test TO it_test.
wa_test-col = 'G'.
wa_test-sorder = 4.
APPEND wa_test TO it_test.
wa_test-col = 'B'.
wa_test-sorder = 1.
APPEND wa_test TO it_test.
wa_test-col = 'R'.
wa_test-sorder = 2.
APPEND wa_test TO it_test.
SORT it_test BY col.
LOOP AT it_test INTO wa_test.
WRITE:/5 wa_test-col.
ENDLOOP.
ULINE.
SORT it_test BY sorder.
LOOP AT it_test INTO wa_test.
WRITE:/5 wa_test-col.
ENDLOOP.
ULINE.
With regards,
2013 Jan 04 6:51 AM
Hi
Ajinkya
Some text disn posted on my last reply....
add one more column with integer then modify ur internal table as
Black with 1
Red with 2
Yellow with 3
Green with 4
White.with 5 on the new interger column
now sort with the new interger colum
SORT itab BY interger.
Thanks
Ben
2013 Jan 04 6:51 AM
Hello Ajinkya,
What would you do with the internal table once it is sorted in the order you want? Thanks!
Regards,
Kumud
2013 Jan 04 7:08 AM
No ABAP statement will sort those data as you liked it as
Character-like components are sorted by default by their binary representation (code page). Textual sorting of character-like components can be performed using the addition AS TEXT.
(AFAIK no code page has this order BRYGW, those good old characters from birth of ASCII were always sorted in Latin alphabet order)
So either create another column in the internal table and fill it with 1 for B, 2 for R, etc, and sort with this field (not-displayed) or replace temporary the color codes by values in your required order, sort the table, and replace back with the original color codes.
Now you should understand the use of special values in lights_fieldname in ALV grid
'1' = red traffic light
'2' = yellow traffic light
'3' = green traffic light
You have to code yourself your own values as you have 2 other values to manage.
Regards,
Raymond
2013 Jan 04 8:03 AM