Skip to Content
0
Jun 01, 2020 at 06:27 PM

How to fire event in alv

108 Views

Hello i'm using cl_salv_table to create my alv with hotspot so how can i fire an event when i clic on one hotspot?

This is my code and is working fine:

include zvim_monitor2_top.
"INCLUDE ZVIM_MONITOR2_scr.

selection-screen begin of block a with frame title text-001 .
parameters: p_bukrs    type /opt/vim_1head-bukrs obligatory, " Sociedad
            p_lifnr    type /opt/vim_1head-lifnr,            " Acreedor
            p_name     type /opt/vim_1head-vend_name,        " Nombre
            p_ref      type /opt/vim_1head-xblnr,            " Referencia
            p_ddoc     type /opt/vim_1head-bldat,            " Fecha documento
            p_dexp     type /opt/vim_1head-zfbdt.            " Fecha vencimiento
selection-screen end of block a.

include zvim_monitor2_f01.
include zvim_monitor2_alv.

start-of-selection.

  perform authority_check using sy-tcode.
  perform get_data.
  perform display_alv.

end-of-selection.
form get_data .

  ls_datos-num_fac   = '4789'.
  ls_datos-acree     = '678842'.
  ls_datos-name      = 'Softtek S.A'.
  ls_datos-monto     = '12.099.902,90'.
  ls_datos-id_excp   = '1'.
  ls_datos-des_exc   = 'HES ocupada en otro documento de cobro'.
  ls_datos-date_doc  = '04.07.2020'.
  ls_datos-id_hes    = '456'.
  ls_datos-moneda    = 'CLP'.
  ls_datos-visual    = 'Visualizar'.
  ls_datos-aprob     = 'Aprobar'.
  ls_datos-rechaz    = 'Rechazar'.
  append ls_datos to t_datos.

  clear: ls_datos.
  ls_datos-num_fac   = '6661'.
  ls_datos-acree     = '678880'.
  ls_datos-name      = 'Parque Arauco'.
  ls_datos-monto     = '100.145.902,00'.
  ls_datos-id_excp   = '3'.
  ls_datos-des_exc   = 'HES no está Liberada'.
  ls_datos-date_doc  = '01.01.2022'.
  ls_datos-id_hes    = '672'.
  ls_datos-moneda    = 'YN'.
  ls_datos-visual    = 'Visualizar'.
  ls_datos-aprob     = 'Aprobar'.
  ls_datos-rechaz    = 'Rechazar'.
  append ls_datos to t_datos.

  clear: ls_datos.
  ls_datos-num_fac   = '9087'.
  ls_datos-acree     = '418842'.
  ls_datos-name      = 'LG'.
  ls_datos-monto     = '972.344,01'.
  ls_datos-id_excp   = '7'.
  ls_datos-des_exc   = 'Sociedad emisora de HES distinta a sociedad receptora de factura'.
  ls_datos-date_doc  = '08.11.2020'.
  ls_datos-id_hes    = '982'.
  ls_datos-moneda    = 'USD'.
  ls_datos-visual    = 'Visualizar'.
  ls_datos-aprob     = 'Aprobar'.
  ls_datos-rechaz    = 'Rechazar'.
  append ls_datos to t_datos.

  loop at t_datos assigning <fs>.
    clear: ls_celltype.
    ls_celltype-columnname = 'VISUAL'.
    ls_celltype-value      = if_salv_c_cell_type=>hotspot.
    append ls_celltype to lt_celltype.

    clear: ls_celltype.
    ls_celltype-columnname = 'APROB'.
    ls_celltype-value      = if_salv_c_cell_type=>hotspot.
    append ls_celltype to lt_celltype.

    clear: ls_celltype.
    ls_celltype-columnname = 'RECHAZ'.
    ls_celltype-value      = if_salv_c_cell_type=>hotspot."BUTTON.
    append ls_celltype to lt_celltype.

    <fs>-i_celltype = lt_celltype.

    clear: ls_color.
    ls_color-fname = 'VISUAL'.
    ls_color-color-col = 4.
    ls_color-color-int = 0.
    ls_color-color-inv = 0.
    append ls_color to lt_color.
    clear: ls_color.
    ls_color-fname = 'APROB'.
    ls_color-color-col = 5.
    ls_color-color-int = 0.
    ls_color-color-inv = 0.
    append ls_color to lt_color.
    clear: ls_color.
    ls_color-fname = 'RECHAZ'.
    ls_color-color-col = 6.
    ls_color-color-int = 0.
    ls_color-color-inv = 0.
    append ls_color to lt_color.
    <fs>-color = lt_color.
  endloop.
endform.          
FORM display_alv .
  TRY.
    cl_salv_table=>factory(
      IMPORTING r_salv_table = gr_table
      CHANGING  t_table      = t_datos ).
  CATCH cx_salv_msg.                              "#EC NO_HANDLER
  ENDTRY.

  " El status gui 'STANDARD_FULLSCREEN' o cualquier que este asociado debe existir para activar
  gr_table->set_screen_status( report         = sy-repid
                               pfstatus       = 'STANDARD_FULLSCREEN'
                               set_functions  = 2 ).           "2 = all

  DATA: lr_columns TYPE REF TO cl_salv_columns.

  lr_columns = gr_table->get_columns( ).
  lr_columns->set_optimize( abap_true ).

  PERFORM set_columns_technical USING lr_columns.

  gr_table->display( ).


ENDFORM.

*&---------------------------------------------------------------------
*&      Form  set_columns_technical
*&---------------------------------------------------------------------
*       modificar las propiedas de las columas
*----------------------------------------------------------------------
FORM set_columns_technical USING ir_columns TYPE REF TO cl_salv_columns.


  DATA: lo_cols TYPE REF TO cl_salv_columns_table.
    lo_cols = gr_table->get_columns( ).

*   set the Column optimization
    lo_cols->set_optimize( 'X' ).

*   Set the Cell Type
    TRY.
        lo_cols->set_cell_type_column( 'I_CELLTYPE' ).
      CATCH cx_salv_data_error.                         "#EC NO_HANDLER
    ENDTRY.

  TRY.
      CALL METHOD lo_cols->set_color_column
        EXPORTING
          value = 'COLOR'.
    CATCH cx_salv_data_error.
  ENDTRY.
ENDFORM.                    " set_columns_technical

But my problem is that i don't know when i clic a hotspot fire an event to capture the source info to do other things

i tried to create a pai but is not called

module get_hotspot_info input.
  data: w_grid type ref to cl_gui_alv_grid.
  data: l_cont type p.
  data: t_rowindex type lvc_t_row.
  data: t_row_no   type lvc_t_roid,
        ls_row_no  type lvc_s_roid.
  data: w_valid    type char01.

  refresh: t_row_no, t_rowindex. clear: w_valid.
  call method w_grid->check_changed_data
    importing
      e_valid = w_valid.
  call method w_grid->get_selected_rows
    importing
      et_index_rows = t_rowindex
      et_row_no     = t_row_no.
  clear: l_cont.
  describe table t_row_no lines l_cont.
  if l_cont eq 0.
    message 'Favor seleccionar un registro' type 'W'.
    exit.
  endif.
  loop at t_row_no into ls_row_no.
    clear: ls_datos.
    read table t_datos into ls_datos index ls_row_no-row_id.
  endloop.
endmodule.    

Attachments

myalv.png (12.6 kB)