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

Class Event Error

Former Member
0 Likes
4,136
*----------------------------------------------------------------------*
***INCLUDE MZTEST_CLASS .
*----------------------------------------------------------------------*

DATA gr_event_handler TYPE REF TO lcl_event_handler .
.. ..
*--Creating an instance for the event handler
CREATE OBJECT gr_event_handler .
*--Registering handler methods to handle ALV Grid events
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .

*&---------------------------------------------------------------------*
*&       Class LCL_EVENT_HANDLER
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
  PUBLIC SECTION .
    METHODS:
*--Double-click control
      handle_double_click
      FOR EVENT double_click OF cl_gui_alv_grid
      IMPORTING e_row e_column.
ENDCLASS.               "LCL_EVENT_HANDLER
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_event_handler
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
--Handle Double Click
  METHOD handle_double_click .
    PERFORM handle_double_click USING e_row es_row_no .
  ENDMETHOD .                    "handle_double_click
ENDCLASS.               "lcl_event_handler

I got the below error for the above code

<b>

The type "LCL_EVENT_HANDLER" is unknown.</b>

can u guys help me out

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,695

Have these statements at last instead of first:

DATA gr_event_handler TYPE REF TO lcl_event_handler .

.. ..

*--Creating an instance for the event handler

CREATE OBJECT gr_event_handler .

*--Registering handler methods to handle ALV Grid events

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .

Regards,

Ravi

OR

<b>use this statement at first:

  • Predefine a local class for event handling to allow the

  • declaration of a reference variable before the class is defined.

CLASS lcl_event_receiver DEFINITION DEFERRED.</b>

Message was edited by:

Ravi Kanth Talagana

10 REPLIES 10
Read only

Former Member
0 Likes
2,695

HI,

Check whether the handler LCL_EVENT_HANDLER was declared as PUBLIC or not?May be it declared as Private or protected..that's why it says here that it is not known.

change it to PUBLIC and see.

reward if useful

regards,

ANJI

Read only

0 Likes
2,695

dear anji

can you tell me in detail where it has to be declared Public is there any error in the given code

Read only

0 Likes
2,695

this is my local class

Read only

0 Likes
2,695

Hi,

The error is occuring at the declaration

DATA gr_event_handler TYPE REF TO lcl_event_handler

this is the include program, So in this include you are creating a object

gr_event_handler with reference to <b>lcl_event_handler</b> which wasmight have declared in the main program. check for the definition of that.

in which class/interface it was defined?

Since you are using in this include, for this include it is unknown, so the error is occuring. check the main program..

regards,

ANJI

Read only

Former Member
0 Likes
2,695

????

Read only

Former Member
0 Likes
2,696

Have these statements at last instead of first:

DATA gr_event_handler TYPE REF TO lcl_event_handler .

.. ..

*--Creating an instance for the event handler

CREATE OBJECT gr_event_handler .

*--Registering handler methods to handle ALV Grid events

SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .

Regards,

Ravi

OR

<b>use this statement at first:

  • Predefine a local class for event handling to allow the

  • declaration of a reference variable before the class is defined.

CLASS lcl_event_receiver DEFINITION DEFERRED.</b>

Message was edited by:

Ravi Kanth Talagana

Read only

0 Likes
2,695

i have put those lines in the last now i got this error

Statement is not accessible.

at line CREATE OBJECT gr_event_handler .


*----------------------------------------------------------------------*
***INCLUDE MZVENDOR_CLASS .
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&       Class LCL_EVENT_HANDLER
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    METHODS:
*--Double-click control
      handle_double_click
      FOR EVENT double_click OF cl_gui_alv_grid
      IMPORTING e_row e_column.
  PRIVATE SECTION.
ENDCLASS.               "LCL_EVENT_HANDLER
*&---------------------------------------------------------------------*
*&       Class (Implementation)  lcl_event_handler
*&---------------------------------------------------------------------*
*        Text
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
*--handle double click
  METHOD handle_double_click .
    PERFORM handle_double_click USING e_row e_column .
  ENDMETHOD .                    "handle_double_click
ENDCLASS.               "lcl_event_handler

DATA gr_event_handler TYPE REF TO lcl_event_handler .
CREATE OBJECT gr_event_handler .
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .


Read only

0 Likes
2,695

Did you try my second suggestion?

Follow the code in BCALV_GRID_05 program.

Regards,

Ravi

Read only

0 Likes
2,695

thanx ravi

Read only

Former Member
0 Likes
2,695

----


***INCLUDE MZTEST_CLASS .

----


CLASS lcl_event_handler DEFINITION DEFERRED. <<---- Add this line

DATA gr_event_handler TYPE REF TO lcl_event_handler .

Now, go on and declare the class. You can instantiate the class only once you have declared it. So, "Create Object " should come after the class definition and implementation.