[ABAP] SALV IDA: Funktionsbutton einfügen

DATA: o_alv TYPE REF TO if_salv_gui_table_ida.

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
* Konstante für Button-Event
    CONSTANTS: co_btn_showdetail type UI_FUNC VALUE 'SHOW_DETAIL'.

    CLASS-METHODS: on_toolbar_function_selected FOR EVENT function_selected OF if_salv_gui_toolbar_ida
      IMPORTING
          ev_fcode
          sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.

  METHOD on_toolbar_function_selected.
    DATA: lv_row TYPE sflight.

    CASE ev_fcode.
* wenn Button-Funktion
      WHEN co_btn_showdetail.

        IF abap_true = o_alv->selection( )->is_row_selected( ).
* ganzen Datensatz holen
          o_alv->selection( )->get_selected_row( EXPORTING
                                                   iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
                                                 IMPORTING
                                                   es_row = lv_row ).
* Datensatz anzeigen
          cl_salv_ida_show_data_row=>display( iv_text = 'Flug-Details'
                                              is_data = lv_row ).
        ENDIF.
    ENDCASE.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

  o_alv = cl_salv_gui_table_ida=>create( iv_table_name = 'SFLIGHT' ).

* Single-Selection
  o_alv->selection( )->set_selection_mode( if_salv_gui_selection_ida=>cs_selection_mode-single ).

* Toolbar button einfügen
  o_alv->toolbar( )->add_button( EXPORTING
                                   iv_fcode                     = lcl_events=>co_btn_showdetail
                                   iv_icon                      = icon_flight
                                   iv_text                      = 'Details'
                                   iv_quickinfo                 = 'Flug-Details'
                                   iv_before_standard_functions = abap_true ).
* Separator
  o_alv->toolbar( )->add_separator( EXPORTING
                                      iv_before_standard_functions = abap_true ).

* Event-handler
  SET HANDLER lcl_events=>on_toolbar_function_selected FOR o_alv->toolbar( ).

* Tabelle anzeigen
  o_alv->fullscreen( )->display( ).

[ABAP] SALV IDA: Klick-Events (Link, Button, Doppelklick) abfangen

CLASS lcl_events DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS: on_cell_click FOR EVENT cell_action OF if_salv_gui_field_display_opt
      IMPORTING
          ev_field_name
          eo_row_data
          sender.

    CLASS-METHODS: on_double_click FOR EVENT double_click OF if_salv_gui_table_display_opt
      IMPORTING
          ev_field_name
          eo_row_data
          sender.
ENDCLASS.

CLASS lcl_events IMPLEMENTATION.

  METHOD on_cell_click.
    DATA: lv_row TYPE sflight.

    eo_row_data->get_row_data( EXPORTING
                                 iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
                               IMPORTING
                                 es_row = lv_row ).

    cl_salv_ida_show_data_row=>display( iv_text = |Datenfeld: { ev_field_name }|
                                        is_data = lv_row ).
  ENDMETHOD.

  METHOD on_double_click.
    DATA: lv_row TYPE sflight.

* Daten der geklickten Zeile holen
    eo_row_data->get_row_data( EXPORTING
                                 iv_request_type = if_salv_gui_selection_ida=>cs_request_type-all_fields
                               IMPORTING
                                 es_row =  lv_row ).

* Daten anzeigen
    cl_salv_ida_show_data_row=>display( iv_text = |Datenfeld: { ev_field_name }|
                                        is_data = lv_row ).
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

  DATA(o_alv) = cl_salv_gui_table_ida=>create( iv_table_name = 'SFLIGHT' ).

* Single-Selection
  o_alv->selection( )->set_selection_mode( if_salv_gui_selection_ida=>cs_selection_mode-single ).

* Zellen der Spalte 'CONNID' sind als Link klickbar
  o_alv->field_catalog( )->display_options( )->display_as_link_to_action( iv_field_name = 'CONNID' ).
  SET HANDLER lcl_events=>on_cell_click FOR o_alv->field_catalog( )->display_options( ).

* Zellen der Spalte 'CARRID' sind als Button klickbar
  o_alv->field_catalog( )->display_options( )->display_as_button( iv_field_name = 'CARRID' ).
  SET HANDLER lcl_events=>on_cell_click FOR o_alv->field_catalog( )->display_options( ).

* Double-Click für alle Zellen
  o_alv->display_options( )->enable_double_click( ).
  SET HANDLER lcl_events=>on_double_click FOR o_alv->display_options( ).

* Tabelle anzeigen
  o_alv->fullscreen( )->display( ).