[ABAP] SALV-Grid: Eventhandler für Klick auf eine Zelle (link_click, hotspot)

CLASS lcl_salv DEFINITION FINAL.

  PUBLIC SECTION.

    CLASS-DATA: o_salv TYPE REF TO cl_salv_table.

    CLASS-METHODS on_link_click FOR EVENT link_click OF cl_salv_events_table
      IMPORTING
        row
        column
        sender.
ENDCLASS.

CLASS lcl_salv IMPLEMENTATION.

  METHOD on_link_click.
    IF o_salv IS BOUND.
* Wert in der geklickten Zelle holen
      DATA(lv_matnr18) = CONV matnr18( o_salv->get_selections( )->get_current_cell( )-value ).

* Parameter zum Aufruf MM03:
* https://www.samplecodeabap.com/call-transaction-mm03-with-specific-tab/

* MATNR setzen
      SET PARAMETER ID 'MAT' FIELD lv_matnr18.
* K - Grunddaten anzeigen
      SET PARAMETER ID 'MXX' FIELD 'K'.
* Transaktion MM03 aufrufen (Material anzeigen)
      CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

  SELECT FROM mara AS m
    INNER JOIN makt AS t ON m~matnr = t~matnr
    FIELDS m~matnr,
           m~laeda,
           m~mtart,
           m~meins,
           t~maktx
    WHERE t~spras EQ @sy-langu
    INTO TABLE @DATA(it_mara)
	UP TO 50 ROWS.

  IF sy-subrc = 0.
    TRY.
        cl_salv_table=>factory( IMPORTING r_salv_table = lcl_salv=>o_salv
                                CHANGING  t_table      = it_mara ).

* Grundeinstellungen
        lcl_salv=>o_salv->get_functions( )->set_all( abap_true ).
        lcl_salv=>o_salv->get_columns( )->set_optimize( abap_true ).
        lcl_salv=>o_salv->get_display_settings( )->set_list_header( 'Material' ).
        lcl_salv=>o_salv->get_display_settings( )->set_striped_pattern( abap_true ).
        lcl_salv=>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 lcl_salv=>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_long_text( ) }| ).
        ENDLOOP.

* Link-Klick für Spalte MATNR
        CAST cl_salv_column_table( lcl_salv=>o_salv->get_columns( )->get_column( 'MATNR' ) )->set_cell_type( if_salv_c_cell_type=>hotspot ).
* Event-Hanlder für Link-Klick
        SET HANDLER lcl_salv=>on_link_click FOR lcl_salv=>o_salv->get_event( ).

        lcl_salv=>o_salv->display( ).

      CATCH cx_root INTO DATA(e_txt).
        WRITE: / e_txt->get_text( ).
    ENDTRY.
  ENDIF.