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

Why my OOPs Event is not working in this simple code example ?

Former Member
0 Likes
466

In this code below , my event 'Positive ' is not working (not triggered when result is positive), but the 'Negative'  one is working.

method SUB.

      RESULT = NUM1 - NUM2.

      IF RESULT <= 0 .

        RAISE EVENT NEGATIVE.

      ELSE.

        RAISE EVENT POSITIVE.

      ENDIF.

endmethod.


----------------------------------------------------------

My code in se38:

PARAMETERS : INT1 TYPE I,

                           INT2 TYPE I.

DATA               : RES  TYPE I.

DATA       : OBJ TYPE REF TO myclass.

CREATE OBJECT OBJ.

SET HANDLER OBJ->NEGATIVE_HANDLER FOR OBJ.

CALL METHOD OBJ->SUB

   EXPORTING

     NUM1   = INT1

     NUM2   = INT2

   IMPORTING

     RESULT = RES

     .

   WRITE😕 RES.

_________________________________

Is there a reason why ?

Thank you.

In this code below , my event 'Positive ' is not working (not triggered when result is positive), but the 'Negative'  one is working.

method SUB.

      RESULT = NUM1 - NUM2.

      IF RESULT <= 0 .

        RAISE EVENT NEGATIVE.

      ELSE.

        RAISE EVENT POSITIVE.

      ENDIF.

endmethod.


----------------------------------------------------------

My code in se38:

PARAMETERS : INT1 TYPE I,

                           INT2 TYPE I.

DATA               : RES  TYPE I.

DATA       : OBJ TYPE REF TO myclass.

CREATE OBJECT OBJ.

SET HANDLER OBJ->NEGATIVE_HANDLER FOR OBJ.

CALL METHOD OBJ->SUB

   EXPORTING

     NUM1   = INT1

     NUM2   = INT2

   IMPORTING

     RESULT = RES

     .

   WRITE😕 RES.

_________________________________

Is there a reason why ?

Thank you.

2 REPLIES 2
Read only

0 Likes
433

Hi Sami,

Did you define event handler class for your class. Also I did not see the SET HANDLER command for raising event . Also events has to be there in that class.

Please check again.

Thanks,

Santosh

Read only

0 Likes
433

Hi Santosh,

Thank you for your reply. Actually you are right , I forgot to add:

SET HANDLER OBJ->POSITIVE_HANDLER FOR OBJ. as I did for the Negative event.My

bad. That is the reason it was not triggered.

Cheers.