Application Development 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: 

handle events in global class

Former Member
0 Kudos

Hi all,

I am working on handling events in global classes.

but my event is not triggererd,i m not able to find where it's going wrong.

Below is my code.

Global Class:ZCL_TEST_EVENT

events :EXCEEDEDRANGE

methods:CHECKRANGE,DISPLAYVENDOR.

Checkrange is event handler for exceededrange.

below is the code for methods.

method checkrange.

write:/ 'Vendor not within the range'(001).

exit.

endmethod.

method displayvendor.

DATA : exlfa1 TYPE lfa1.

IF imlifnr NOT BETWEEN 1000 AND 2000.

RAISE EVENT exceededrange.

ENDIF.

SELECT SINGLE * FROM lfa1

INTO exlfa1

WHERE lifnr = imlifnr

.

IF sy-subrc = 0.

WRITE : / exlfa1-lifnr,exlfa1-name1.

ELSE.

WRITE : / 'No vendor found'(002).

ENDIF.

endmethod.

-


below is the report I developed.

REPORT ztest_113.

parameters :plifnr type lfa1-lifnr obligatory.

data : obj type ref to ZCL_TEST_EVENT.

START-OF-SELECTION.

CREATE OBJECT obj.

CALL METHOD obj->displayvendor

EXPORTING

imlifnr = plifnr

.

Please help

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

Yes, you do need to write the SET HANDLER statement. As per your current design, you can set the event handler in your method CONSTRUCTOR. Like:


method constructor.
  SET HANDLER me->CHECKRANGE FOR me.
endmethod.

Regards,

Naimesh Patel

4 REPLIES 4

Former Member
0 Kudos

Do I need to write SET HANDLER statement anywhere or should it work automatically to trigger event?

naimesh_patel
Active Contributor
0 Kudos

Yes, you do need to write the SET HANDLER statement. As per your current design, you can set the event handler in your method CONSTRUCTOR. Like:


method constructor.
  SET HANDLER me->CHECKRANGE FOR me.
endmethod.

Regards,

Naimesh Patel

0 Kudos

Thank you Naimesh,

it's working well now.But letme know one thing why my obj's instance is vanished when I call any method of it's class and it exists after I come out of that method.While in method, 'me' wil have instance and 'obj' will not have vice versa.

0 Kudos

The visibility of the variable OBJ is only in your program, not in your class. When you in inside the class, you would always get the current instance as the ME.

Regards,

Naimesh Patel