2006 Jul 12 4:26 PM
Hi All,
PLease suggest me how to do the sorting in ALV List Display.
I am getting repeated records in ALV output .
Please urgent.
2006 Jul 12 4:29 PM
You must to do this with internal table before show in ALV:
Sort itab.
delete adjacent duplicates from itab comparing all fields.
Regards.
2006 Jul 12 4:30 PM
HI,
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,
write the Above code, then the sort will work i.e no repeted values will come in the output
Thanks
Sudheer
2006 Jul 12 4:32 PM
do this way...
IT_SORT-FIELDNAME = 'MATNR'.
IT_SORT-UP = 'X'.
APPEND IT_SORT.
Regards,
Santosh
2006 Jul 12 4:31 PM
There are two ways.
Before you call the REUSE_ALV_LIST_DISPLAY function module, sort the internal table and pass the same.
Else, pass the internal table and use the 'Sort' key on the ALV output list. You can choose the column by which you want to sort the list.
If you are getting repeated outputs in ALV, check in debug mode weather your internal table has repeated rows.
One way to tackle this is to add a further condistion in your select clauses and filter out duplicate data.
Other way is to use 'DELETE ADJACENT DUPLIACTES FROM ITAB' statement before calling REUSE_ALV_LIST_DISPLAY.
REUSE_ALV_LIST_DISPLAY does nothing but display your data in the ALV format.
2006 Jul 12 4:31 PM
once you have the data ready with you,
sort the internal table according to the fields you want.
sort itab by field1 field2 .
then delete adjacent duplicates from itab.
using
delete adjacent duplicates from itab comparing field1 field2....
then pass the itab to the grid display function module.
Regards,
ravi
2024 Jun 18 10:24 AM
this is very useful and simple but what can i do if my
it_fcat is of type lvc_s_fcat
and when im trying to pass it_sort in call function which is of slis_sortinfo_alv it is giving me runtime dump
although i sort my table through
sort it_final by vbeln
but what is the lvc type for sort ??
2024 Jun 18 10:36 AM
2006 Jul 12 4:32 PM
hi praveen,
*INTERNAL TABLE FOR SORTING
it_sort type slis_t_sortinfo_alv,
wa_sort type slis_sortinfo_alv,
clear wa_sort.
wa_sort-fieldname = 'LIFNR'.
wa_sort-spos = '1'.
wa_sort-up = 'X'.
append wa_sort to it_sort.
clear wa_sort.
wa_sort-fieldname = 'BUKRS'.
wa_sort-spos = '2'.
wa_sort-up = 'X'.
append wa_sort to it_sort.
clear wa_sort.
wa_sort-fieldname = 'EKORG'.
wa_sort-spos = '3'.
wa_sort-up = 'X'.
append wa_sort to it_sort.
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = v_repid
is_layout = wa_layout
it_fieldcat = it_fieldcat[]
it_sort = it_sort[]
tables
t_outtab = itab
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
2009 Apr 17 7:01 AM
Hi All,
In order to sort the fields in ALV, we may have two ways.
1. Sorting the Internal table---The advantage of this methid is, u can sort and can delete the irrelevant line items......
ex: SORT ITAB BY <FIELD NAME> [ASCENDING|DESCENDING]
The above statment will give us the sorted internal with the fields mentioned in Field Name.....
And with the help of the following statment u can reduce the repeated/unwanted line items..
DELETE ADJACENT DUPLICATES FROM ITAB
This method will allow u to filter the datas before displaying it.....
2. 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 this will be helpful..
cheers....
S.Meganadhan.