Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

where to write the class

Former Member
0 Likes
727

Event handler class to handle double click of the user on alv grid.

such a class:

The class will be written in the main program or not?

Thanks.

CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION .

METHODS:

*--Hotspot click control

handle_hotspot_click

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING e_row_id e_column_id es_row_no ,

*--Double-click control

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column es_row_no.

PRIVATE SECTION.

ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION .

*--Handle Hotspot Click

METHOD handle_hotspot_click .

PERFORM handle_hotspot_click USING e_row_id e_column_id es_row_no .

ENDMETHOD .

*--Handle Double Click

METHOD handle_double_click .

PERFORM handle_double_click USING e_row e_column es_row_no .

ENDMETHOD .

ENDCLASS .

FORM CREATEOBJECT.

DATA gr_event_handler TYPE REF TO lcl_event_handler .

*--Creating an instance for the event handler

CREATE OBJECT gr_event_handler .

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .

SET HANDLER gr_event_handler->handle_hotspot_click FOR gr_alvgrid .

ENDFORM.

FORM handle_hotspot_click USING i_row_id TYPE lvc_s_row

i_column_id TYPE lvc_s_col

is_row_no TYPE lvc_s_roid.

READ TABLE zbficheentry_list2 INDEX is_row_no-row_id .

IF sy-subrc = 0." AND i_column_id-fieldname = 'SEATSOCC'.

CALL SCREEN 200 . "Details about passenger-seat matching

ENDIF .

ENDFORM .

FORM handle_double_click USING i_row TYPE lvc_s_row

i_column TYPE lvc_s_col

is_row_no TYPE lvc_s_roid.

READ TABLE zbficheentry_list2 INDEX is_row_no-row_id .

IF sy-subrc = 0." AND i_column-fieldname = 'SEATSOCC' .

CALL SCREEN 120 . "Details about passenger-seat matching

ENDIF .

ENDFORM .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
692

Yes, you should write the class in your main program (definition and implementation). Here's an example:

&----


*& Class LCL_EVENT_HANDLER

&----


  • Text

----


CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.

METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING es_row_no e_column.

ENDCLASS. "LCL_EVENT_HANDLER

&----


*& Class (Implementation) lcl_event_handler

&----


  • Text

----


CLASS lcl_event_handler IMPLEMENTATION.

METHOD on_double_click.

DATA: text TYPE string, es_row_text TYPE string.

es_row_text = es_row_no-row_id.

CONCATENATE 'You have selected row:' es_row_text 'and column:' e_column

INTO text SEPARATED BY ' '.

MESSAGE text TYPE 'I'.

ENDMETHOD. "on_double_click

ENDCLASS. "lcl_event_handler

In the main program you also need to define an instance of your class, like this:

DATA: r_handler TYPE REF TO lcl_event_handler.

Then after START-OF-SELECTION put this:

CREATE OBJECT r_handler.

Be sure to use something like this in your main program after you instantiate the ALV container:

SET HANDLER r_handler->on_double_click FOR r_alv_grid.

I hope this helps.

- April King

Event handler class to handle double click of the user on alv grid.

such a class:

The class will be written in the main program or not?

Thanks.

CLASS lcl_event_handler DEFINITION .

PUBLIC SECTION .

METHODS:

*--Hotspot click control

handle_hotspot_click

FOR EVENT hotspot_click OF cl_gui_alv_grid

IMPORTING e_row_id e_column_id es_row_no ,

*--Double-click control

handle_double_click

FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING e_row e_column es_row_no.

PRIVATE SECTION.

ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION .

*--Handle Hotspot Click

METHOD handle_hotspot_click .

PERFORM handle_hotspot_click USING e_row_id e_column_id es_row_no .

ENDMETHOD .

*--Handle Double Click

METHOD handle_double_click .

PERFORM handle_double_click USING e_row e_column es_row_no .

ENDMETHOD .

ENDCLASS .

FORM CREATEOBJECT.

DATA gr_event_handler TYPE REF TO lcl_event_handler .

*--Creating an instance for the event handler

CREATE OBJECT gr_event_handler .

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .

SET HANDLER gr_event_handler->handle_hotspot_click FOR gr_alvgrid .

ENDFORM.

FORM handle_hotspot_click USING i_row_id TYPE lvc_s_row

i_column_id TYPE lvc_s_col

is_row_no TYPE lvc_s_roid.

READ TABLE zbficheentry_list2 INDEX is_row_no-row_id .

IF sy-subrc = 0." AND i_column_id-fieldname = 'SEATSOCC'.

CALL SCREEN 200 . "Details about passenger-seat matching

ENDIF .

ENDFORM .

FORM handle_double_click USING i_row TYPE lvc_s_row

i_column TYPE lvc_s_col

is_row_no TYPE lvc_s_roid.

READ TABLE zbficheentry_list2 INDEX is_row_no-row_id .

IF sy-subrc = 0." AND i_column-fieldname = 'SEATSOCC' .

CALL SCREEN 120 . "Details about passenger-seat matching

ENDIF .

ENDFORM .

4 REPLIES 4
Read only

Former Member
0 Likes
692

u need to call this class in ur main program

Read only

Former Member
0 Likes
692

Hello,

Yes the idea is to do it during in the start of selection event.

Hope this helps,

Gabriel

Read only

Former Member
0 Likes
693

Yes, you should write the class in your main program (definition and implementation). Here's an example:

&----


*& Class LCL_EVENT_HANDLER

&----


  • Text

----


CLASS lcl_event_handler DEFINITION.

PUBLIC SECTION.

METHODS: on_double_click FOR EVENT double_click OF cl_gui_alv_grid

IMPORTING es_row_no e_column.

ENDCLASS. "LCL_EVENT_HANDLER

&----


*& Class (Implementation) lcl_event_handler

&----


  • Text

----


CLASS lcl_event_handler IMPLEMENTATION.

METHOD on_double_click.

DATA: text TYPE string, es_row_text TYPE string.

es_row_text = es_row_no-row_id.

CONCATENATE 'You have selected row:' es_row_text 'and column:' e_column

INTO text SEPARATED BY ' '.

MESSAGE text TYPE 'I'.

ENDMETHOD. "on_double_click

ENDCLASS. "lcl_event_handler

In the main program you also need to define an instance of your class, like this:

DATA: r_handler TYPE REF TO lcl_event_handler.

Then after START-OF-SELECTION put this:

CREATE OBJECT r_handler.

Be sure to use something like this in your main program after you instantiate the ALV container:

SET HANDLER r_handler->on_double_click FOR r_alv_grid.

I hope this helps.

- April King

Read only

0 Likes
692

Dear April King

Thank you, thank you, thank you. I was in a trouble, you helped me very much.