DATA: it_spfli TYPE STANDARD TABLE OF spfli.
DATA: o_dock TYPE REF TO cl_gui_docking_container.
DATA: o_alv TYPE REF TO cl_gui_alv_grid.
PARAMETERS: p_carr TYPE spfli-carrid DEFAULT '%'.
INITIALIZATION.
* Container und ALV-Grid erzeugen
IF NOT o_dock IS BOUND.
* Container für ALV-Grid erzeugen
o_dock = NEW #( side = cl_gui_docking_container=>dock_at_bottom
ratio = 80 ).
* Feldkatalog automatisch erstellen lassen
DATA: o_salv TYPE REF TO cl_salv_table.
cl_salv_table=>factory( IMPORTING
r_salv_table = o_salv
CHANGING
t_table = it_spfli ).
DATA(it_fcat) = cl_salv_controller_metadata=>get_lvc_fieldcatalog( r_columns = o_salv->get_columns( )
r_aggregations = o_salv->get_aggregations( ) ).
* Spalten/Zell-Eigenschaften (Anzeige, F4-Hilfe, Edit ...) des Feldkatalogs setzen
LOOP AT it_fcat ASSIGNING FIELD-SYMBOL(<fs_fcat>).
CASE <fs_fcat>-fieldname.
WHEN 'MANDT'.
<fs_fcat>-no_out = abap_true. " ausblenden
ENDCASE.
ENDLOOP.
* ALV-Grid erzeugen
o_alv = NEW #( i_parent = o_dock
i_appl_events = abap_true ).
* ALV-Grid initialisieren
DATA(lv_layout) = VALUE lvc_s_layo( grid_title = 'Flugverbindungen' " Titel
no_toolbar = abap_false " Toolbar sichtbar
smalltitle = abap_false " große Überschrift
zebra = abap_true " Zebrastreifen
cwidth_opt = abap_true ). " Spaltenbreiten optimieren
o_alv->set_table_for_first_display( EXPORTING
is_layout = lv_layout
i_bypassing_buffer = abap_false
CHANGING
it_fieldcatalog = it_fcat
it_outtab = it_spfli ).
ENDIF.
AT SELECTION-SCREEN OUTPUT.
IF o_alv IS BOUND.
* SELECT mit LIKE, für % als Wildcard
SELECT * FROM spfli
INTO TABLE @it_spfli
WHERE carrid LIKE @p_carr.
* Inhalt neu darstellen
o_alv->refresh_table_display( ).
* Spaltenbreiten erneut optimieren
DATA: lv_ucomm TYPE sy-ucomm VALUE '&OPT'.
o_alv->set_function_code( CHANGING
c_ucomm = lv_ucomm ).
ENDIF.