[ABAP] SALV-Table – Gruppen für Spaltenvorrat im SALV-Layout

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.

* Gruppen definieren --> verfügbar im Grid unter Toolbar-Button "Layout ändern ..." --> Spaltenvorrat
    o_salv->get_functional_settings( )->get_specific_groups( )->add_specific_group( id = 'GRP1' text = 'Spaltengruppe 1' ).
    o_salv->get_functional_settings( )->get_specific_groups( )->add_specific_group( id = 'GRP2' text = 'Spaltengruppe 2' ).

* Spalten GRP1 zuordnen
    DATA(o_col_max) = CAST cl_salv_column_list( o_salv->get_columns( )->get_column( 'SEATSMAX' ) ).
    o_col_max->set_specific_group( id = 'GRP1' ).
    DATA(o_col_occ) = CAST cl_salv_column_list( o_salv->get_columns( )->get_column( 'SEATSOCC' ) ).
    o_col_occ->set_specific_group( id = 'GRP1' ).

* Spalten GRP2 zuordnen
    DATA(o_col_max_b) = CAST cl_salv_column_list( o_salv->get_columns( )->get_column( 'SEATSMAX_B' ) ).
    o_col_max_b->set_specific_group( id = 'GRP2' ).
    DATA(o_col_occ_b) = CAST cl_salv_column_list( o_salv->get_columns( )->get_column( 'SEATSOCC_B' ) ).
    o_col_occ_b->set_specific_group( id = 'GRP2' ).
    DATA(o_col_max_f) = CAST cl_salv_column_list( o_salv->get_columns( )->get_column( 'SEATSMAX_F' ) ).
    o_col_max_f->set_specific_group( id = 'GRP2' ).
    DATA(o_col_occ_f) = CAST cl_salv_column_list( o_salv->get_columns( )->get_column( 'SEATSOCC_F' ) ).
    o_col_occ_f->set_specific_group( id = 'GRP2' ).

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