Klasse CL GUI ALV GRID Eventhandler
Aus SAP-Wiki
Zur Navigation springenZur Suche springen
Etwas gewöhnungsbedürftig ist der Umgang mit den Events, die von der Klasse CL_GUI_ALV_GRID ausgelöst werden.
lcl_event_receiver DEFINITION
*---------------------------------------------------------------------* * CLASS *---------------------------------------------------------------------* CLASS lcl_event_receiver DEFINITION. PUBLIC SECTION. CLASS-METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row "Zeile e_column, "Spalte "#EC NEEDED
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id "Zeile e_column_id, "Spalte
handle_data_changed for event data_changed of cl_gui_alv_grid importing er_data_changed,
handle_toolbar "#EC NEEDED FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive, "#EC NEEDED
handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm, "sy-ucomm
handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid IMPORTING e_object e_ucomm. "#EC NEEDED ENDCLASS. "lcl_event_receiver DEFINITION
lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------* * CLASS lcl_event_receiver IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------* CLASS lcl_event_receiver IMPLEMENTATION. METHOD handle_double_click. PERFORM handle_double_click using e_row "Zeile e_column. "Spalte ENDMETHOD. "handle_double_click
METHOD handle_hotspot_click. PERFORM handle_hotspot_click USING e_row_id "Zeile e_column_id. "Spalte ENDMETHOD. "handle_hotspot_click
METHOD handle_data_changed. PERFORM handle_data_changed USING er_data_changed. "Zeile/Spalte/Geänderter Wert ENDMETHOD. "handle_data_changed
METHOD handle_toolbar. PERFORM handle_toolbar CHANGING e_object e_interactive. ENDMETHOD. "handle_toolbar
METHOD handle_menu_button. PERFORM handle_menu_button USING e_object e_ucomm. ENDMETHOD. "handle_menu_button
METHOD handle_user_command. PERFORM handle_user_command using e_ucomm. "sy-ucomm ENDMETHOD. "handle_user_command ENDCLASS. "lcl_event_receiver IMPLEMENTATION
lcl_event_receiver FORMS
*&---------------------------------------------------------------------* *& Form HANDLE_DOUBLE_CLICK *&---------------------------------------------------------------------* * Doppelklick *----------------------------------------------------------------------* FORM HANDLE_DOUBLE_CLICK USING pis_row type LVC_S_ROW "Zeile = PIS_ROW-INDEX pis_column type LVC_S_COL. "Feldname break-point. ENDFORM. " HANDLE_DOUBLE_CLICK
*&---------------------------------------------------------------------* *& Form HANDLE_HOTSPOT_CLICK *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM handle_hotspot_click USING pis_row TYPE lvc_s_row "Zeile = PIS_ROW-INDEX pis_col TYPE lvc_s_col. "Feldname break-point. ENDFORM. " HANDLE_HOTSPOT_CLICK
*&---------------------------------------------------------------------* *& Form HANDLE_DATA_CHANGED *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM handle_data_changed USING pio_data_changed TYPE REF TO cl_alv_changed_data_protocol. DATA: ls_good TYPE lvc_s_modi. FIELD-SYMBOLS: <fs_itab> TYPE ty_itab. * Tabelle der modifizierten Zellen abarbeiten LOOP AT pio_data_changed->mt_mod_cells INTO ls_good. READ TABLE gt_itab ASSIGNING <fs_itab> INDEX ls_good-row_id. CASE ls_good-fieldname. WHEN 'PDF1'. "<fs_alv>-pdf1 = ls_good-value. ENDCASE. ENDLOOP. ENDFORM. " HANDLE_DATA_CHANGED
*&---------------------------------------------------------------------* *& Form HANDLE_TOOLBAR *&---------------------------------------------------------------------* * Toolbar *----------------------------------------------------------------------* FORM HANDLE_TOOLBAR USING pio_object type ref to CL_ALV_EVENT_TOOLBAR_SET piv_interactive type CHAR01. break-point. ENDFORM. " HANDLE_TOOLBAR
*&---------------------------------------------------------------------* *& Form HANDLE_MENU_BUTTON *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM HANDLE_MENU_BUTTON USING pio_object TYPE REF TO CL_CTMENU piv_ucomm TYPE sy-ucomm. break-point. ENDFORM. " HANDLE_MENU_BUTTON
*&---------------------------------------------------------------------* *& Form HANDLE_USER_COMMAND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM handle_user_command USING piv_ucomm type SY-UCOMM. break-point. ENDFORM.
Objekt instanziieren und Set Handle
if go_cont is not bound. **************************************** * Methode: set_table_for_first_display * **************************************** * Container erzeugen CREATE OBJECT go_cont EXPORTING container_name = 'ALV_CONT'. * ALV erzeugen CREATE OBJECT go_alv_cont EXPORTING i_parent = go_cont. * Rufe die ALV-Liste auf CALL METHOD go_alv_cont->set_table_for_first_display EXPORTING i_bypassing_buffer = 'X' "lv_bypassing_buffer i_save = 'X' "lv_save * i_default = 'X' is_layout = ls_layout * it_toolbar_excluding = lt_toolbar_excluding * is_variant = ls_variant CHANGING it_outtab = pct_list it_fieldcatalog = lt_fcat. if sy-subrc = 0. go_alv_cont->set_gridtitle( i_gridtitle = 'Liste Verträge'(001) ). "Titelbeschriftung in der ALV-Liste endif. * Register events call method go_alv_cont->register_edit_event exporting i_event_id = cl_gui_alv_grid=>mc_evt_enter. call method go_alv_cont->register_edit_event exporting i_event_id = cl_gui_alv_grid=>mc_evt_modified. * Die Eventhandler werden scharf geschaltet SET HANDLER lcl_event_receiver=>handle_double_click FOR go_alv_cont. SET HANDLER lcl_event_receiver=>handle_hotspot_click FOR go_alv_cont. set handler lcl_event_receiver=>handle_data_changed for go_alv_cont. SET HANDLER lcl_event_receiver=>handle_toolbar FOR go_alv_cont. SET HANDLER lcl_event_receiver=>handle_menu_button FOR go_alv_cont. SET HANDLER lcl_event_receiver=>handle_user_command FOR go_alv_cont. * Die Toolbar soll ergänzt werden um eigene Buttons CALL METHOD go_alv_cont->set_toolbar_interactive. else. PERFORM refresh_alv. endif.