How to design ALV List with total and subtotals.

The columns of the ALV list can be aggregated using the fields subtot of internal table lvc_t_sort.

There are mainly two changes needed to achieve this Aggregation.

  1. The Internal table lvc_t_sort with the field subtot must be set to ‘X’.
  2. The field ‘do_sum’ of field catalog must be set to ‘X’ to the column which needs to be aggregated.

Let us look at the following code example.

DATA lt_sort TYPE lvc_t_sort.

DATA ls_sort TYPE lvc_s_sort.

ls_sort-fieldname = ‘CONTACT_ID’.

ls_sort-subtot = ‘X’.

APPEND ls_sort TO lt_sort.

LOOP AT lt_field_cat ASSIGNING <ls_field_cat> WHERE fieldname = ‘PURCHASE_COST’.

<ls_field_cat>-do_sum = ‘X’.

ENDLOOP.