2009 Mar 09 11:05 AM
Hi all,
Please reply me if anybody knows how to 'SORT' Currency field Value in ALV grid display.
Thanks,
2009 Mar 09 11:16 AM
Hi Busam,
While displaying ypur ALV report, You write a select query right?So there itself sort it by currency field.
Or else in your ALV report who have a symbol to sort.Choose your field and sort it.
Much Regards,
Amuktha.
2009 Mar 09 12:08 PM
Hi,
data:
t_sort type slis_t_sortinfo_alv,
wa_sort like line of t_sort.
wa_sort-spos = 1.
wa_sort-fieldname = 'CARRID'.
wa_sort-tabname = 'T_SPFLI'.
wa_sort-up = 'X'.
*WA_SORT-DOWN = 'X'.
append wa_sort to t_sort.
clear wa_sort.
Sort up is for ascending,
Sort down is for descending.
Thanks,
Nithya
2009 Mar 09 12:58 PM
Hi Nitya,
Thanks for your reply, I have tried this but this logic not working for 'Currency (VALUE) fields' , and there is no TABNAME field in LVC_S_SORT structure.
Please let me know if you have any other solution.
Thanks.
2009 Mar 10 5:17 AM
Hi Busam,
I have done a small example for u.I have checked with both CUURENCY and PRICE fields. Its working fine..
data:
R_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
R_GRID TYPE REF TO CL_GUI_ALV_GRID.
data:
t_sort type lvc_t_sort,
fs_sort type lvc_s_sort,
t_sflight type table of sflight.
select * from sflight into table t_sflight.
fs_sort-SPOS = 4.
* fs_sort-SPOS = 5.
*fs_sort-FIELDNAME = 'CURRENCY'.
fs_sort-FIELDNAME = 'PRICE'.
fs_sort-down = 'X'.
append fs_sort to t_sort.
CALL SCREEN 100.
MODULE LIST_OUTPUT OUTPUT.
CREATE OBJECT
R_CONTAINER
EXPORTING
CONTAINER_NAME = 'CONTAINER1'.
CREATE OBJECT R_GRID
EXPORTING
I_PARENT = R_CONTAINER.
CALL METHOD R_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING
IT_OUTTAB = T_SFLIGHT
IT_SORT = T_SORT.
ENDMODULE.
SPOS - position of the field in the display.
Regards,
Nithya
2009 Mar 09 5:49 PM
Hi Busam
Have a look at this wiki.It explains the SORT statement with screen shots and example.
[https://wiki.sdn.sap.com/wiki/display/ABAP/SORTinALV]
Hope this helps you.
Regards
Hareesh Menon
2009 Mar 10 5:16 AM
Hi,
there are 3 possible ways of sorting..
1. Sort the Internal Table w.r.t the curr field and than pass that to alv.
2. Use the Sort Class and appl;y the sort on the sort field.
3. In table choose the sort tool from the standard toolbar of alv.
thanks
ravi
2009 Mar 10 5:43 AM
hi
Inorder to SORT the table data,you have to create an internal table of type LVC_T_SORT.
LVC_T_SORT is a table type whic has a line type LVC_S_SORT.
You need to create a work area of type LVC_S_SORT
Then populate the internal table using this work area and pass it to the method
SET_TABLE_FOR_FIRST_DISPLAY using the parameter IT_SORT.
Regards
2009 Apr 21 7:31 AM
hi,
declare a data type as:
data: it_sort type slis_t_sortinfo_alv,
wa_sort type slis_sortinfo_alv.
then after creating the fieldcatalog give
wa_sort-spos = '1'.
wa_sort-fieldname = 'name of d field u wanna sort'.
wa_sort-tabname = 'name of the table u hv used'.
wa_sort-up = ' X'.
wa_sort-down = 'X'
use any 1 either up or down,up is used for ascending and down for descending
append wa_sort to it_sort
clear wa_sort.
then in fm
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
exporting
IT_SORT = IT_SORT
i think this wl solve ur problem
thanks
shivraj
2009 Apr 21 12:18 PM
hi,
Sort Using sort structure----- This is can be used while displaying the data using "REUSE_ALV_GRID_DISPLAY" or " REUSE_ALV_GRID_DISPLAY_LVC" .
Steps for sorting in this way ,
If you are using REUSE_ALV_GRID_DISPALY
a). We have to decare a structure of sort type slis_sortinfo_alv
Like:
it_sort TYPE TABLE OF slis_sortinfo_alv "Internal Table
wa_sort TYPE slis_sortinfo_alv, "Work area
b) Then before calling the function REUSE_ALV_GRID_DISPALY sort like...
wa_sort-spos = '01' .
wa_sort-fieldname = 'RACCT'.
wa_sort-tabname = 'IT_FAGLFLEXA'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort .
CLEAR wa_sort.
c) When calling the function REUSE_ALV_GRID_DISPALY ,U must have to specify the sorting structure
it_sort = it_sort
Note: This field is optional and will be commented while u are calling the fucntion..So u have to uncomment this particular field and assign the sorting internal table of ur program.
If you are using REUSE_ALV_GRID_DISPALY_LVC
a). We have to decare a structure of sort type lvc_t_sort
Like:
it_sort TYPE TABLE OF lvc_t_sort "Internal Table
wa_sort TYPE lvc_s_sort, "Work area
b) Then before calling the function REUSE_ALV_GRID_DISPALY sort like...
wa_sort-spos = '01' .
wa_sort-fieldname = 'RACCT'.
wa_sort-tabname = 'IT_FAGLFLEXA'.
wa_sort-up = 'X'.
wa_sort-subtot = 'X'.
APPEND wa_sort TO it_sort .
CLEAR wa_sort.
c) When calling the function REUSE_ALV_GRID_DISPALY_LVC , U must have to specify the sorting structure
it_sort_lvc = it_sort
Note: This field is optional and will be commented while u are calling the fucntion..So u have to uncomment this particular field and assign the sorting internal table of ur program.
hope it will help you.
regards,
lokesh
Edited by: Lokesh Tripathi on Apr 21, 2009 4:48 PM
2009 Apr 21 1:57 PM
Hi,
you can try this code for sorting :
Sort Criteria.
IT_SORT-FIELDNAME = 'Give you field name'.
IT_SORT-UP = 'X'.
APPEND IT_SORT.
CLEAR IT_SORT.
***
IT_SORT-FIELDNAME = 'Give you field name'.
IT_SORT-UP = 'X'.
APPEND IT_SORT.
if you use the Function module then there is a Internale table Caled IT_SORT,
if you use the Class then there is also a Internal table IT_SORT,
Thanks,
Sarita Singh Rathour
2009 Apr 22 3:46 AM
Hi,
when u r selecting data from database table you get data n sorted order (if the field is of type n).
1. even after writing sort if u r not geting currency field in sorted order the probably you have taken currency field as type text. if so make it as type P or num with x decimal places. and jst sorting using sort statement will work.
ex: sort itab with <currency>.
2. else it_sort-up = 'X' in your layout should work.
3. you can even give in function module REUSE_ALV_GRID_DISPLAY.
2010 May 26 4:15 PM
If you want you can use it with alv_grid_object_name_here->set_table_for_first_diplay
FORM build_fieldsort CHANGING p_field_sort TYPE lvc_t_sort.
DATA: wa_sort TYPE lvc_s_sort.
REFRESH p_field_sort.
CLEAR wa_sort.
wa_sort-spos = '2'. " number of the col in the fieldcatalog corresponding to the fieldname
wa_sort-fieldname = 'BDEGR'.
wa_sort-down = 'X'.
APPEND wa_sort TO p_field_sort.
CLEAR wa_sort.
ENDFORM.
CALL METHOD g_grid_03->set_table_for_first_display
EXPORTING
is_layout = gs_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_sort = gs_field_sort " required
it_fieldcatalog = gt_fieldcat " required
it_outtab = it_zhrgt_t705l[]. " required
there's a catch if you want cells to merge when they have equal fields
you must not use the
- alv_grid_object_name_here->SET_READY_FOR_INPUT
- or change the fieldcatlog edit property to editable