02-08-2010 10:37 AM
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
02-08-2010 2:09 PM
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
02-08-2010 12:05 PM
Do I need to write SET HANDLER statement anywhere or should it work automatically to trigger event?
02-08-2010 2:09 PM
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
02-09-2010 12:42 PM
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.
02-09-2010 3:06 PM
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