Code: Alles auswählen.
DATA button TYPE stb_button.
CLEAR button.
button-function = 'SUBRC'.
button-icon = icon_execute.
button-quickinfo = 'Funktion'.
button-butn_type = 2.
button-disabled = ' '.
button-text = 'meine Funktion'.
APPEND button TO e_object->mt_toolbar.
Code: Alles auswählen.
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF
cl_gui_alv_grid
IMPORTING e_object
e_interactive,
handle_user_command
FOR EVENT user_command OF
cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
Code: Alles auswählen.
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_toolbar.
DATA button TYPE stb_button.
* Einfügen eines Separators =
* senkrechter Strich zum Absetzen
* von anderen Buttons
CLEAR button.
button-butn_type = 3. "Separator
APPEND button TO e_object->mt_toolbar.
* Einfügen Button
CLEAR button.
button-function = 'RETURN'.
button-icon = icon_execute.
button-quickinfo = 'Info'.
button-butn_type = '2' "normaler Btn.
button-disabled = ' '.
button-text = 'Meine Funktion'.
APPEND button TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'RETURN'.
* hier kommt Quellcode für
* Funktion rein
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
ENDCLASS.
Code: Alles auswählen.
DATA gref_event_receiver type ref to
lcl_event_receiver.
Code: Alles auswählen.
CALL METHOD grid->set_table_for_first_display
EXPORTING
[...]
* a) instanziieren
CREATE OBJECT gref_event_receiver.
* b) registrieren
SET HANDLER gref_event_receiver->handle_user_command
gref_event_receiver->handle_toolbar FOR ALL INSTANCES.
* c) Methodenaufruf, löst Ereignis
* toolbar aus und zeigt Button an
CALL METHOD grid->set_toolbar_interactive.