02-02-2007 6:20 AM
Just like to ask how to group all the subtotals at the end of ALV GRID just before the total line?
The output should be somehow look like this:
Data1 GroupA 20.00
Data2 GroupA 10.00
Data3 GroupA 40.00
Data4 GroupB 20.00
Data5 GroupB 40.00
Subtotal(GroupA) 70.00
Subtotal(GroupB) 60.00
Total 130.00
Thanks in advance!
02-02-2007 6:25 AM
run this program & see whether it helps u
type-pools: slis.
data: it_spfli type table of spfli,
it_fcat type slis_t_fieldcat_alv,
wa_fcat like line of it_fcat,
it_sort type slis_t_sortinfo_alv,
wa_sort like line of it_sort.
select * into table it_spfli from spfli.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'SPFLI'
CHANGING
CT_FIELDCAT = IT_FCAT.
wa_fcat-do_sum = 'X'.
modify it_fcat from wa_fcat
transporting do_sum
where fieldname = 'DISTANCE'.
wa_sort-fieldname = 'CARRID'.
wa_sort-subtot = 'X'.
append wa_sort to it_sort.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
IS_LAYOUT = WA_LAYOUT
it_fieldcat = it_fcat
it_sort = it_sort
tables
t_outtab = it_spfli.
02-02-2007 9:56 AM
Thanks for your reply but the output is still like the normal subtotals of ALV. What I like to do is to group all the subtotals together at the end of the ALV just before the total line.
02-02-2007 10:01 AM
Hi,
I think this is not possible with standard alv functionality.
When you have the final internal table ready to be output, you have to add those subtotal lines and total lines programatically.(Note that once you click the alv buttons for sorting and filtering..the layout would be a mess..so make sure you disable the standard alv buttons for sorting, totalling etc).
sort itab by field1 group.
loop at itab.
at end of group.
clear itab.
sum.
concatenate 'Subtotal(Group' itab-group into
itab-field1.
append itab.
endat.
endloop.
Regards,
Ravi
02-02-2007 10:12 AM
so you mean there is no way to do this using standard ALV functionality? I also consider your suggestion before, but because we need all the standard alv functionalities then I could not implement this.
is there really no way to do this? what if i use OO ALV, would it be possible?
Thanks!
02-02-2007 10:17 AM
Hi,
I'm not sure of OOPS Alv, but there is a method GET_SUBTOTALS n the class CL_GUI_ALV_GRID which would give only the subtotals lines. You can have a custom button on the alv toolbar, upon clicking which, you can shown the subtotals table in a popup. Try this alternative when there is no other way.
Regards,
Ravi
02-02-2007 10:22 AM
Do you have a sample code for this? Also, if i implement this, would it be possible that I could download it to Excel, do sorting, filtering and other ALV functionalities? Thanks!