1. Declaration of necessary objects
Declare Objects for Receiver Class and ALV Grid (CL_GUI_ALV_GRID) in the top include of the ALV report. Implementation for receiver has to be deferred because receiver class definition is not available before top include (considering top include as first include for program).
CLASS gcl_event_receiver DEFINITION DEFERRED. DATA: g_grid TYPE REF TO cl_gui_alv_grid, g_receiver TYPE REF TO gcl_event_receiver.
2. Activate Hotspot in field catalog
Hotspot property is to be set in the field catalog for the ALV Grid (CL_GUI_ALV_GRID). After this once ALV grid is displayed then the field with hotspot would have an underline beneath just similar to a hyperlink.
DATA: ls_fieldcat TYPE lvc_s_fcat. CLEAR ls_fieldcat. ls_fieldcat-row_pos = 1. ls_fieldcat-col_pos = 2. ls_fieldcat-fieldname = 'BANFN'. ls_fieldcat-tooltip = c_true. ls_fieldcat-col_opt = c_true. ls_fieldcat-hotspot = c_true. ls_fieldcat-scrtext_m = 'Requisition'(006). APPEND ls_fieldcat TO i_fieldcat.
3. Define Event Handler Class
Define handler class for event hotspot_click of class CL_GUI_ALV_GRID. Instance of the handler class would be registered with the instance of ALV grid class later.
Row ID, Column ID and Row number are passed as event parameters when the hotspot click event is triggered to identify on which row hotspot event is fired. Once the row number is obtained the necessary action can be taken.
*--------------------------------------------------------------------* * CLASS LCL_EVENT_RECEIVER DEFINITION *-------------------------------------------------------------------* * Class for Event Handler * *-------------------------------------------------------------------* CLASS gcl_event_receiver DEFINITION. PUBLIC SECTION. METHODS handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid IMPORTING e_row_id e_column_id es_row_no. ENDCLASS. "gcl_event_receiver DEFINITION
4. Implement Event Handler Method
Handler class defined the handler method which would be executed once the event is fired by user command. The action to be performed inside handler method is to be decided. Usually this is call to some SAP transaction.
*-------------------------------------------------------------------* * CLASS gcl_event_receiver IMPLEMENTATION *-------------------------------------------------------------------* * Class for Event Receiver * *-------------------------------------------------------------------* CLASS gcl_event_receiver IMPLEMENTATION. METHOD handle_hotspot_click. PERFORM f_event_hotspot_click USING e_row_id e_column_id es_row_no. ENDMETHOD. "hotspot_click ENDCLASS. "gcl_event_receiver IMPLEMENTATION *&-----------------------------------------------------------------* *& Form F_EVENT_HOTSPOT_CLICK *&-----------------------------------------------------------------* * Handle Hot-spot Click *------------------------------------------------------------------* * -->FP_ROW Row ID * -->FP_COLUMN Column ID *------------------------------------------------------------------* FORM f_event_hotspot_click USING fp_row_id TYPE lvc_s_row fp_column_id TYPE lvc_s_col fp_row_no TYPE lvc_s_roid. DATA: wl_output TYPE ty_output. CLEAR wl_output. READ TABLE i_output INTO wl_output INDEX fp_row_no-row_id. IF sy-subrc IS INITIAL. CASE fp_column_id. WHEN 'BANFN'. SET PARAMETER ID 'BAN' FIELD wl_output-banfn. CALL TRANSACTION 'ME53N' AND SKIP FIRST SCREEN. WHEN OTHERS. ENDCASE. ENDIF. ENDFORM. " EVENT_HOTSPOT_CLICK
5. Register Hotspot Event handler with the instance of ALV Grid
Register hotspot_click event with the instance of ALV grid. This is to be done in the PBO of the screen having ALV Grid. All the registered events are usually monitored. Once this is done the calls are routed to the handler method incase of an event.
SET HANDLER g_receiver->handle_hotspot_click FOR g_grid.
The above ALV Snippets makes use of Object oriented ALV. Only relevant details have been added to increase clarity about the HotSpot_Click event of CL_GUI_ALV_GRID class. Once ALV is displayed hotspot would be available on field and after click navigation would be possible to requisition display transaction ME53N.
