DATA: o_dock TYPE REF TO cl_gui_docking_container.
DATA: o_alv TYPE REF TO cl_gui_alv_grid.
DATA: it_t001 TYPE STANDARD TABLE OF t001.
DATA: lv_temp TYPE string.
SELECTION-SCREEN BEGIN OF BLOCK var WITH FRAME TITLE title1.
PARAMETERS: p_param1 TYPE string.
SELECTION-SCREEN END OF BLOCK var.
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
METHODS: on_single_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id " obsolet, stattdessen es_row_no benutzen
es_row_no
e_column_id.
METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING
e_row e_column.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
* Doppel-Klick für Hotspot-Felder
METHOD on_double_click.
IF e_row > 0.
lv_temp = it_t001[ e_row ]-butxt.
ENDIF.
ENDMETHOD.
* Single-Klick für Hotspot-Felder
METHOD on_single_click.
IF es_row_no-row_id > 0.
lv_temp = it_t001[ es_row_no-row_id ]-butxt.
ENDIF.
ENDMETHOD.
ENDCLASS.
INITIALIZATION.
title1 = 'Selektion'.
* Daten holen
SELECT * FROM t001 INTO TABLE it_t001.
* Docking-Container erzeugen
o_dock = NEW #( side = cl_gui_docking_container=>dock_at_left
ratio = 20 ).
* ALV-Grid erzeugen
o_alv = NEW #( i_parent = o_dock
i_appl_events = abap_true ).
* Eventhandler setzen
DATA(o_events) = NEW lcl_events( ).
SET HANDLER o_events->on_double_click FOR o_alv.
SET HANDLER o_events->on_single_click FOR o_alv.
* Layout anpassen
DATA(lv_layout) = VALUE lvc_s_layo( grid_title = 'Auswahl mit Doppelklick:'
no_toolbar = abap_false
smalltitle = abap_true
zebra = abap_true ).
* ALV-Grid initialisieren
o_alv->set_table_for_first_display( EXPORTING
i_structure_name = 'T001'
i_save = space
is_layout = lv_layout
CHANGING
it_outtab = it_t001 ).
* Feldkatalog holen
DATA: it_fcat TYPE lvc_t_fcat.
o_alv->get_frontend_fieldcatalog( IMPORTING
et_fieldcatalog = it_fcat ).
* Hotspot für die Spalte 'BUTXT' aktivieren, damit Event handle_single_click abgefangen werden kann
LOOP AT it_fcat ASSIGNING FIELD-SYMBOL(<fcat>).
CASE <fcat>-fieldname.
WHEN 'BUTXT'.
<fcat>-hotspot = abap_true.
ENDCASE.
ENDLOOP.
* Feldkatalog speichern
o_alv->set_frontend_fieldcatalog( it_fieldcatalog = it_fcat ).
* ALV-Grid anzeigen
o_alv->refresh_table_display( ).
AT SELECTION-SCREEN OUTPUT.
* Selektion an Parameter geben
p_param1 = lv_temp.
START-OF-SELECTION.
WRITE: / 'Gewählter Parameter: ', p_param1.