2008 Aug 11 9:04 AM
Hi Experts!
I have a problem in sorting.
I have a field called Remaining time having data type char20.
Format is HH:MM:SS.
The problem is, i want it to be sorted in a way that a number is sorted.
Example (descending):
I want it to be sorted this way:
121:89
111:00
12:34
10:78
00:00
-01:44
-10:22
-11:45
-109:11
but in my program, it is sorted as text:
121:89
12:34
111:00
10:78
-109:11
-11:45
-10:22
-01:44
00:00
Edited by: navi on Aug 11, 2008 4:04 PM
2008 Aug 11 9:06 AM
Hi,
Step 1. Sort your internal table by time field before passing it to
ALV.
Step 2. Pass the sorted table.
OR
use function module reuse_alv_grid_display.
IMPORTING
REFERENCE(I_INTERFACE_CHECK) DEFAULT SPACE
VALUE(I_BYPASSING_BUFFER) TYPE CHAR01 DEFAULT SPACE
VALUE(I_BUFFER_ACTIVE) DEFAULT SPACE
REFERENCE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE
REFERENCE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME DEFAULT
SPACE
REFERENCE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME DEFAULT
SPACE
REFERENCE(I_CALLBACK_TOP_OF_PAGE) TYPE SLIS_FORMNAME DEFAULT
SPACE
REFERENCE(I_CALLBACK_HTML_TOP_OF_PAGE) TYPE SLIS_FORMNAME
DEFAULT SPACE
REFERENCE(I_CALLBACK_HTML_END_OF_LIST) TYPE SLIS_FORMNAME
DEFAULT SPACE
REFERENCE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL
REFERENCE(I_BACKGROUND_ID) TYPE SDYDO_KEY DEFAULT SPACE
REFERENCE(I_GRID_TITLE) TYPE LVC_TITLE OPTIONAL
REFERENCE(I_GRID_SETTINGS) TYPE LVC_S_GLAY OPTIONAL
REFERENCE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL
REFERENCE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL
REFERENCE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL
REFERENCE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL
REFERENCE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL ---> uncomment this (see details bellow)
REFERENCE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL
REFERENCE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL
REFERENCE(I_DEFAULT) DEFAULT 'X'
REFERENCE(I_SAVE) DEFAULT SPACE
REFERENCE(IS_VARIANT) LIKE DISVARIANT STRUCTURE DISVARIANT
OPTIONAL
REFERENCE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL
REFERENCE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL
REFERENCE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL
REFERENCE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL
REFERENCE(I_SCREEN_START_COLUMN) DEFAULT 0
REFERENCE(I_SCREEN_START_LINE) DEFAULT 0
REFERENCE(I_SCREEN_END_COLUMN) DEFAULT 0
REFERENCE(I_SCREEN_END_LINE) DEFAULT 0
REFERENCE(I_HTML_HEIGHT_TOP) TYPE I DEFAULT 0
REFERENCE(I_HTML_HEIGHT_END) TYPE I DEFAULT 0
REFERENCE(IT_ALV_GRAPHICS) TYPE DTC_T_TC OPTIONAL
REFERENCE(IT_HYPERLINK) TYPE LVC_T_HYPE OPTIONAL
REFERENCE(IT_ADD_FIELDCAT) TYPE SLIS_T_ADD_FIELDCAT OPTIONAL
REFERENCE(IT_EXCEPT_QINFO) TYPE SLIS_T_QINFO_ALV OPTIONAL
REFERENCE(IR_SALV_FULLSCREEN_ADAPTER) TYPE REF TO
CL_SALV_FULLSCREEN_ADAPTER OPTIONAL
EXPORTING
REFERENCE(E_EXIT_CAUSED_BY_CALLER)
REFERENCE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER
TABLES
T_OUTTAB
EXCEPTIONS
PROGRAM_ERROR
( Using internal table IT_SORT, the caller determines the sort order and/or the subtotalling of the basic list.)
Regards,
anirban
Hi Experts!
I have a problem in sorting.
I have a field called Remaining time having data type char20.
Format is HH:MM:SS.
The problem is, i want it to be sorted in a way that a number is sorted.
Example (descending):
I want it to be sorted this way:
121:89
111:00
12:34
10:78
00:00
-01:44
-10:22
-11:45
-109:11
but in my program, it is sorted as text:
121:89
12:34
111:00
10:78
-109:11
-11:45
-10:22
-01:44
00:00
Edited by: navi on Aug 11, 2008 4:04 PM
2008 Aug 11 9:06 AM
Hi,
Step 1. Sort your internal table by time field before passing it to
ALV.
Step 2. Pass the sorted table.
OR
use function module reuse_alv_grid_display.
IMPORTING
REFERENCE(I_INTERFACE_CHECK) DEFAULT SPACE
VALUE(I_BYPASSING_BUFFER) TYPE CHAR01 DEFAULT SPACE
VALUE(I_BUFFER_ACTIVE) DEFAULT SPACE
REFERENCE(I_CALLBACK_PROGRAM) LIKE SY-REPID DEFAULT SPACE
REFERENCE(I_CALLBACK_PF_STATUS_SET) TYPE SLIS_FORMNAME DEFAULT
SPACE
REFERENCE(I_CALLBACK_USER_COMMAND) TYPE SLIS_FORMNAME DEFAULT
SPACE
REFERENCE(I_CALLBACK_TOP_OF_PAGE) TYPE SLIS_FORMNAME DEFAULT
SPACE
REFERENCE(I_CALLBACK_HTML_TOP_OF_PAGE) TYPE SLIS_FORMNAME
DEFAULT SPACE
REFERENCE(I_CALLBACK_HTML_END_OF_LIST) TYPE SLIS_FORMNAME
DEFAULT SPACE
REFERENCE(I_STRUCTURE_NAME) LIKE DD02L-TABNAME OPTIONAL
REFERENCE(I_BACKGROUND_ID) TYPE SDYDO_KEY DEFAULT SPACE
REFERENCE(I_GRID_TITLE) TYPE LVC_TITLE OPTIONAL
REFERENCE(I_GRID_SETTINGS) TYPE LVC_S_GLAY OPTIONAL
REFERENCE(IS_LAYOUT) TYPE SLIS_LAYOUT_ALV OPTIONAL
REFERENCE(IT_FIELDCAT) TYPE SLIS_T_FIELDCAT_ALV OPTIONAL
REFERENCE(IT_EXCLUDING) TYPE SLIS_T_EXTAB OPTIONAL
REFERENCE(IT_SPECIAL_GROUPS) TYPE SLIS_T_SP_GROUP_ALV OPTIONAL
REFERENCE(IT_SORT) TYPE SLIS_T_SORTINFO_ALV OPTIONAL ---> uncomment this (see details bellow)
REFERENCE(IT_FILTER) TYPE SLIS_T_FILTER_ALV OPTIONAL
REFERENCE(IS_SEL_HIDE) TYPE SLIS_SEL_HIDE_ALV OPTIONAL
REFERENCE(I_DEFAULT) DEFAULT 'X'
REFERENCE(I_SAVE) DEFAULT SPACE
REFERENCE(IS_VARIANT) LIKE DISVARIANT STRUCTURE DISVARIANT
OPTIONAL
REFERENCE(IT_EVENTS) TYPE SLIS_T_EVENT OPTIONAL
REFERENCE(IT_EVENT_EXIT) TYPE SLIS_T_EVENT_EXIT OPTIONAL
REFERENCE(IS_PRINT) TYPE SLIS_PRINT_ALV OPTIONAL
REFERENCE(IS_REPREP_ID) TYPE SLIS_REPREP_ID OPTIONAL
REFERENCE(I_SCREEN_START_COLUMN) DEFAULT 0
REFERENCE(I_SCREEN_START_LINE) DEFAULT 0
REFERENCE(I_SCREEN_END_COLUMN) DEFAULT 0
REFERENCE(I_SCREEN_END_LINE) DEFAULT 0
REFERENCE(I_HTML_HEIGHT_TOP) TYPE I DEFAULT 0
REFERENCE(I_HTML_HEIGHT_END) TYPE I DEFAULT 0
REFERENCE(IT_ALV_GRAPHICS) TYPE DTC_T_TC OPTIONAL
REFERENCE(IT_HYPERLINK) TYPE LVC_T_HYPE OPTIONAL
REFERENCE(IT_ADD_FIELDCAT) TYPE SLIS_T_ADD_FIELDCAT OPTIONAL
REFERENCE(IT_EXCEPT_QINFO) TYPE SLIS_T_QINFO_ALV OPTIONAL
REFERENCE(IR_SALV_FULLSCREEN_ADAPTER) TYPE REF TO
CL_SALV_FULLSCREEN_ADAPTER OPTIONAL
EXPORTING
REFERENCE(E_EXIT_CAUSED_BY_CALLER)
REFERENCE(ES_EXIT_CAUSED_BY_USER) TYPE SLIS_EXIT_BY_USER
TABLES
T_OUTTAB
EXCEPTIONS
PROGRAM_ERROR
( Using internal table IT_SORT, the caller determines the sort order and/or the subtotalling of the basic list.)
Regards,
anirban
2008 Aug 11 9:25 AM
Hi Anirban,
How would your answer could possibly solve my problems?
I didn't get the gest of your solution.
Thanks2x.
2008 Aug 11 9:29 AM
I have a field called Remaining time having data type char20.
Format is HH:MM:SS.
If that field is of type sy-uzeit or type t then it your sort will work. But in your case it is a character field.
And what ever the same data you are showing is not at all like HH:MM:SS format. then how you can say that it is Time format.
if you want to sort the List by default then you have to use SORT(IT_SORT prameter if ALV function).
SORT-FIELDNAME = 'TIME'.
SORT-UP = 'X'.
APPEND SORT TO IT_SORT.
pass this to IT_SORT of the ALV Function.
2008 Aug 11 9:41 AM
Hi Vijay, sorry for the confusion.
I am addressing these 2 defects one having format HH:MM:SS and the other one HH:MM, but nevertheless the problem is the same.
The user want it to be sorted like a numbers but the display would still be separated by colons and negative sign if ever my calculation for the time will be negative.
And the sorting will be done in the ALV display and not in program itself.
Thanks.
2008 Aug 11 9:54 AM
>I am addressing these 2 defects one having format >HH:MM:SS and the other one HH:MM, but nevertheless the >problem is the same.
Then my suggestion would be some thing like this...
Have one more extra filed with referring to Time (Type SY-UZEIT not character field). Populate the time value to this field.
along with character field. Now populate SORT on this field. so that sort will be done on this field. and you will get the Required sorting and displays the required output.
you hide this field in display using NO_OUT = 'X'. in the fieldcatalog.
2008 Aug 11 10:02 AM
Hi Vijay,
Will this still works if the sorting will be done on the display?
Thanks for the reply.
I'll try implementing this.
Thanks.
2008 Aug 11 10:06 AM
> Will this still works if the sorting will be done on the display?
> Thanks for the reply.
> I'll try implementing this.
if you sort that , you may loose this functionality. Then you have to think for alternative..
2008 Aug 13 8:21 AM
2008 Aug 11 9:12 AM
hi
what is the field for your time , just use this statement to sort it (sort internal table name by field name)
(like sort itab by time.)
thnaks
2008 Aug 11 9:19 AM
Hi all!
Yes, I already tried sorting it in the program itself and in the ALV display.
But the display is wrong since it sorted the time as a text.
I want it it to be displayed/sorted in a way a number is sorted.
How can i do that?
Is there an event that can solve it? or a data type perhaps that sorts a character type fields as number?
Pls help.
Thanks!
2008 Aug 11 9:23 AM
Hi
Solution 1: Change the data type of the field from char to type T (time).
Solution 2: Add 2 new fields in the internal table (Say X(4) and Y(4) of data type N) and write the following code.
LOOP AT ITB.
SPLIT ITAB-REMTIME BY ':' INTO ITAB-X ITAB-Y. " Remaining time Field into X and Y
ENDLOOP.
SORT ITAB BY X Y.
Hope it helps.
Murthy
2008 Aug 11 9:31 AM
Hi Kalyanam,
But the sorting will be done by the sorting functionality of ALV.
Not in the program.
How will I do that in such a way that ALV sort functionality, will sort my data as numbers?
Thanks.
2008 Aug 11 9:37 AM
Hi Navi,
As you have stated the problem is caused by the data type for the field being sorted.
The problem as I see it is you want to display the time as HHH:MM:SS which is different from the internal represtation of time in ABAP as HHMMSS for a 24 hour clock.
My Advice to you is to split the duration into 3 separate fields HHH MM SS and to sort by these either in the ALV or before.
Also trap when the sort function is called so that you can test if it is your displayed field being sorted and act accordingly. The fields used for sorting do not have to be displayed, but they do need to be part of the fieldcat definition.
Kind Regards
David Cooper
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |