[ABAP] SALV-Table – Aggregationsfunktionen

SELECT * FROM sflight INTO TABLE @DATA(it_sflight).

TRY.
* SALV-Table
    DATA: o_salv TYPE REF TO cl_salv_table.

    cl_salv_table=>factory( IMPORTING
                              r_salv_table   = o_salv
                            CHANGING
                              t_table        = it_sflight ).

* Grundeinstellungen
    o_salv->get_functions( )->set_all( abap_true ).
    o_salv->get_columns( )->set_optimize( abap_true ).
    o_salv->get_display_settings( )->set_list_header( 'Aggregationen' ).
    o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
    o_salv->get_selections( )->set_selection_mode( if_salv_c_selection_mode=>row_column ).

* Spaltenüberschriften: technischer Name und Beschreibungstexte, Short Text und Medium Text leer lassen für Autosize
    LOOP AT o_salv->get_columns( )->get( ) ASSIGNING FIELD-SYMBOL(<c>).
      DATA(o_col) = <c>-r_column.
      o_col->set_short_text( || ).
      o_col->set_medium_text( || ).
      o_col->set_long_text( |{ o_col->get_columnname( ) } [{ o_col->get_long_text( ) }]| ).
    ENDLOOP.

* vorher sortieren und subtotal setzen
    o_salv->get_sorts( )->add_sort( columnname = 'CARRID' subtotal = abap_true sequence = if_salv_c_sort=>sort_up ).
    o_salv->get_sorts( )->add_sort( columnname = 'CONNID' subtotal = abap_true sequence = if_salv_c_sort=>sort_up ).
* Aggregation
    o_salv->get_aggregations( )->add_aggregation( columnname = 'SEATSMAX' aggregation = if_salv_c_aggregation=>total ).
* Summenzeilen über den Einträgen anzeigen
    o_salv->get_aggregations( )->set_aggregation_before_items( ).

* Anzeige
    o_salv->display( ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.