2008 Jun 25 12:40 PM
hello can anyone tell how we can handle the event hotspot_click in oops alv with some sample code.
thanks,
srinu
2008 Jun 25 12:43 PM
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_hotspot_click
FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING e_row_id.
ENDCLASS. "lcl_events DEFINITION
----
CLASS lcl_events_d1001 IMPLEMENTATION "Local Class Implementation
----
CLASS lcl_events IMPLEMENTATION.
METHOD on_hotspot_click.
PERFORM navigate_to_detail_view
USING e_row_id.
ENDMETHOD. "on_hotspot_click
ENDCLASS. "lcl_events IMPLEMENTATION
*****Data declaration
DATA : wa_fieldcat TYPE lvc_s_fcat. "Field Catalog for List Viewer Control - Header Data
DATA : it_fieldcat TYPE lvc_t_fcat. "Field Catalog table for List Viewer Control - Header Data
DATA : w_container TYPE scrfname VALUE 'ALV_CNTR'. "Grid container for Header Data
DATA : w_grid TYPE REF TO cl_gui_alv_grid. "Grid Instance for Header Data
DATA : w_custom_container TYPE REF TO cl_gui_custom_container. "Container Instance for Header Data
DATA : w_layout TYPE lvc_s_layo. "ALV control: Layout structure for Header Data
DATA : w_events TYPE REF TO lcl_events. "Instance for the local class
DATA : w_okcode_100 TYPE sy-ucomm.
Call screen 100.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'GUI100'.
SET TITLEBAR 'T01'.
ENDMODULE. " status_0100 OUTPUT
&----
*& Module user_command_0100 INPUT
&----
text
----
MODULE user_command_0100 INPUT.
w_okcode_100 = sy-ucomm.
CLEAR sy-ucomm.
CASE w_okcode_100.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " user_command_0100 INPUT
&----
*& Module display_report OUTPUT
&----
text
----
MODULE display_report OUTPUT.
IF w_custom_container IS INITIAL.
CREATE OBJECT w_custom_container
EXPORTING
container_name = w_container.
CREATE OBJECT w_grid
EXPORTING
i_parent = w_custom_container.
ENDIF.
CREATE OBJECT w_events.
SET HANDLER w_events->on_hotspot_click FOR w_grid.
PERFORM fieldcat_header.
w_layout-grid_title = text-002.
CALL METHOD w_grid->set_table_for_first_display
EXPORTING
is_layout = w_layout
CHANGING
it_outtab = it_result1
it_fieldcatalog = it_fieldcat
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDMODULE. " display_report OUTPUT
2008 Jun 25 12:48 PM
we have to write this code as the event hotspot_click is available i n the class cl_gui_alv_grid.
thanks
vaasu
2008 Jun 25 12:49 PM
hi vaasu,
please see the items in bold.
CLASS lcl_screen_object DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar_1
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object.
ENDCLASS.
CLASS lcl_screen_object IMPLEMENTATION.
METHOD handle_hotspot_1.
ENDMETHOD.
ENDCLASS.
start-of-selection.
data:
go_alvg1 TYPE REF TO cl_gui_alv_grid,
go_scrnx TYPE REF TO lcl_screen_object.*
CREATE OBJECT go_alvg1
EXPORTING
i_parent = go_left1.
CREATE OBJECT go_scrnx.
CALL METHOD go_alvg1->set_table_for_first_display
EXPORTING
is_layout = gwa_layt1
it_toolbar_excluding = git_xcld1
CHANGING
it_outtab = git_grpcl
it_fieldcatalog = git_fldc1
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
SET HANDLER:
go_scrnx->handle_toolbar_1 FOR go_alvg1.
regards,
Peter
2008 Jun 25 12:52 PM
Define the Event Class
CLASS CL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
HANDLE_HOTSPOT
FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID.
ENDCLASS.
Implement the class
CLASS CL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_HOTSPOT.
CLEAR FS_OUTPUT.
READ TABLE T_OUTPUT INTO FS_OUTPUT INDEX E_ROW_ID-INDEX.
IF SY-SUBRC EQ 0.
IF E_COLUMN_ID EQ 'EBELN'.
SET PARAMETER ID 'BES' FIELD FS_OUTPUT-EBELN.
CALL TRANSACTION 'ME23N'.
ENDIF.
ENDIF.
ENDCLASS.
Create the instance of the Event class only after instantiation of the grid. Here obj_grid is the instance.
CREATE OBJECT OBJ_EVENT_RECEIVER.
SET HANDLER OBJ_EVENT_RECEIVER->HANDLE_HOTSPOT FOR OBJ_GRID.
ENDMETHOD.
Note: Here obj_event_receiver of type cl_event_receiver.
The above code is calling the ME23N transaction. T_OUTPUT table contains the data displayed on the alv grid and E_ROW_ID-INDEX contains the row number on the output where user has clicked.
********Reward points if useful
Regards,
Kiran Bobbala