Copyright 2022 - BV TallVision IT

For this example a layout needs to be stored (hence abap coding alone is not enough).

Storing a layout (much like a variant but not with selection screen settings but with the ALV column configuration) is demonstrated here, with a focus on aggregate fields (totals and subtotals). 

ALV reports have cells and cells can have numeric values. These numerics or quentity fields can be accumulated into totals and subtotals. Aggregating is standard ALV functionality for which the developer needs to do nothing at all. One thing you may consider: add a column to your report with the number 1 and call the column "One". Aggregating on this numeric (!) column would render record counts, which can be very useful.

report ZDEMO_ALV_3_LAYOUTS.
include ZABAPCADABRA_EASY_ALV.
data: gt_data type table of t100,
      gw_data type t100,
      gv_randomnumber type datatype-integer4,
      go_alv type ref to lcl_easy_alv.  "Define

start-of-selection.

  select * from t100
    up to 20 rows into table gt_data.
* Some random data for the MSGNR field: loop at gt_data into gw_data. call function 'RANDOM_I4' IMPORTING rnd_value = gv_randomnumber. move gv_randomnumber to gw_data-MSGNR. modify gt_data from gw_data. endloop. create object go_alv. * The template include the implementation of layouts. go_alv->set_alv_from_template( exporting title = 'Aggregation example - settings stored as global layout' changing content = gt_data ). go_alv->display( ). "Report

The above example can be set up to show this: