Will discuss Totaling and Sub Totaling.
First Totaling:
Last week I showed you the catalog well with one addition you can cause the grid to total.
itab_field_catalog-fieldname = 'BALANCE'.
itab_field_catalog-tabname = 'itab_ftab'.
itab_field_catalog-seltext_l = 'Balance'.
itab_field_catalog-do_sum = 'X'.
append itab_field_catalog.
clear itab_field_catalog.
That's it you will now have a total line in your grid for the column BALANCE you can put this on as many of the numeric fields as you want.
Now lets add Sub Totals. The following picture gives you an idea of what I am talking about I blanked out the names of my customers.
As you can see there are three levels of totaling. Company, Payer, and Grand Total.
First you have to create an internal table for the sort catalog. Along with a structure.
Data:
it_sortcat type slis_sortinfo_alv occurs 1,
wa_sort like line of it_sortcat.
The following is an example of how to populate the sort catalog.
wa_sort-fieldname = KUNN2.
wa_sort-tabname = 'itab_ftab'.
wa_sort-subtot = 'X'.
wa_sort-spos = 1.
append wa_sort to it_sortcat.
wa_sort-fieldname = 'KUNNR'.
wa_sort-tabname = 'itab_ftab'.
wa_sort-spos = 2.
wa_sort-subtot = 'X'.
append wa_sort to it_sortcat.
wa_sort-fieldname = 'BUKRS'.
wa_sort-tabname = 'itab_ftab'.
wa_sort-spos = 3.
wa_sort-subtot = 'X'.
append wa_sort to it_sortcat.
Thats pretty much it the only thing left is to add the call for the function module.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_grid_title = 'Sold To - Payer Report'
is_layout = wa_layout
it_fieldcat = itab_field_catalog[]
i_save = 'A'
it_sort = it_sortcat
tables
t_outtab = itab_ftab
exceptions
program_error = 1
others = 2.
As you can see this is only a small snap shots of the code if you would like the whole program e-mail me and I would be happy to send it to you.