Skip to Content
avatar image
Former Member

Trigger event on alv volum header click - click_col_header

I want to trigger an even on ALV column header click.I used the event click_col_header of

cl_gui_alv_grid an But its not triggering.

capture.png

CLASS lcl_event_receiver DEFINITION INHERITING FROM cl_gui_alv_grid.
 PUBLIC SECTION.
 INTERFACES:
 if_alv_rm_grid_friend.
 METHODS:

 handle_double_click_capex
          FOR EVENT double_click OF cl_gui_alv_grid
          IMPORTING e_row
                   e_column,

 handle_hotspot_capex FOR EVENT hotspot_click OF cl_gui_alv_grid
                   IMPORTING e_row_id
                           e_column_id
                              es_row_no,
 handle_data_changed_capex FOR EVENT data_changed OF cl_gui_alv_grid
                         IMPORTING er_data_changed,
 handle_toolbar_capex FOR EVENT toolbar OF cl_gui_alv_grid
                      IMPORTING e_object,
 handle_user_command_capex FOR EVENT user_command OF cl_gui_alv_grid
                     IMPORTING e_ucomm.

 PROTECTED SECTION.
 METHODS:
 handle_click_col_header_capex FOR EVENT click_col_header OF cl_gui_alv_grid
                    IMPORTING col_id.


 PRIVATE SECTION.
 DATA:ls_stbl TYPE lvc_s_stbl,
 ls_mod_cells TYPE lvc_s_modi.
 CLASS-DATA:
 lv_row_id TYPE lvc_s_row,
 lv_col_id TYPE lvc_s_col.
ENDCLASS. "lcl_event_receiver DEFINITION
 SET HANDLER capex_event_receiver->handle_click_col_header_capex FOR lr_capex_grid.
 METHOD handle_click_col_header_capex.
  BREAK-POINT.
 ENDMETHOD.
capture.png (3.7 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Nov 07, 2016 at 03:38 PM

    Any reason to add the method in protected section, hoping to be allowed to use a protected event of the standard class thru inheritance (you didn't redefine method dispatch)

    Isn't the click on header used to sort data from value of the column (layout fieldsgl_clk_hd) so triggers function code '&SORT' (cl_gui_alv_grid=>mc_fc_sort), you could try to intercept this function code in a public event like before_user_command (so no need to inherit from standard class)

    Regards,
    Raymond

    Add comment
    10|10000 characters needed characters exceeded

    • Following Raymond suggestion, here is a demonstration:

      CLASS lcl_alv DEFINITION.
        PUBLIC SECTION.
          METHODS constructor.
          METHODS free.
          METHODS on_before_user_command FOR EVENT before_user_command OF cl_gui_alv_grid IMPORTING e_ucomm.
          METHODS on_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm.
          DATA go_alv TYPE REF TO cl_gui_alv_grid.
          DATA gt_sflight TYPE TABLE OF sflight.
      ENDCLASS.
      
      CLASS lcl_alv IMPLEMENTATION.
      
        METHOD constructor.
          CREATE OBJECT go_alv
            EXPORTING
              i_parent = cl_gui_container=>screen0.
      
          SET HANDLER on_user_command FOR go_alv.
          SET HANDLER on_before_user_command FOR go_alv.
      
          SELECT * FROM sflight INTO TABLE gt_sflight.
          go_alv->set_table_for_first_display(
              EXPORTING
                i_structure_name = 'SFLIGHT'
                is_layout = VALUE #( sgl_clk_hd = abap_true )
              CHANGING
                it_outtab = gt_sflight ).
        ENDMETHOD.
      
        METHOD free.
          go_alv->free( ).
        ENDMETHOD.
      
        METHOD on_before_user_command.
          CASE e_ucomm.
            WHEN go_alv->mc_fc_sort.
              go_alv->set_user_command( i_ucomm = 'ZZSORT' ).
          ENDCASE.
        ENDMETHOD.
      
        METHOD on_user_command.
          CASE e_ucomm.
            WHEN 'ZZSORT'.
              go_alv->get_selected_columns( IMPORTING et_index_columns = data(columns) ).
              MESSAGE |Columns: { COND #( WHEN lines( columns ) > 0 THEN columns[ 1 ]-fieldname ) }| TYPE 'I'.
          ENDCASE.
        ENDMETHOD.
      
      ENDCLASS.
      
      DATA go_alv TYPE REF TO lcl_alv.
      
      PARAMETERS dummy.
      
      AT SELECTION-SCREEN OUTPUT.
        IF go_alv IS NOT BOUND.
          go_alv = NEW lcl_alv( ).
        ENDIF.
      
      AT SELECTION-SCREEN ON EXIT-COMMAND.
        go_alv->free( ).
        FREE go_alv.
  • Nov 07, 2016 at 06:34 PM
    hi Check if after setting SGL_CLK_HD field in layout would work. Thanks, Mona
    Add comment
    10|10000 characters needed characters exceeded