*&---------------------------------------------------------------------*
*&
Report ZRP_EVENTS_PARAMETERS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRP_EVENTS_PARAMETERS.
PARAMETERS :
P_VAL1 TYPE I,
P_VAL2 TYPE I.
DATA : RESULT
TYPE I.
*----------------------------------------------------------------------*
* CLASS c1 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C1
DEFINITION .
PUBLIC SECTION.
EVENTS : EVENT1 EXPORTING VALUE(NUM1) TYPE
I
VALUE(NUM2) TYPE
I.
METHODS : METH1 FOR EVENT EVENT1 OF C1
IMPORTING NUM1
NUM2.
METHODS : METH2 IMPORTING VAL1 TYPE I
VAL2 TYPE I.
ENDCLASS. "c1 DEFINITION
*----------------------------------------------------------------------*
* CLASS c1 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS C1
IMPLEMENTATION.
METHOD METH1.
WRITE : / 'the value of num1', NUM1,
/ 'the value of num2', NUM2.
RESULT = NUM1 + NUM2.
WRITE : / 'the result', RESULT.
ENDMETHOD.
"meth1
METHOD METH2.
RAISE EVENT EVENT1 EXPORTING NUM1 = VAL1
NUM2 = VAL2 .
ENDMETHOD.
"meth2
ENDCLASS. "c1 IMPLEMENTATION
START-OF-SELECTION.
DATA : OBJ TYPE REF TO C1.
CREATE OBJECT OBJ.
SET HANDLER OBJ->METH1 FOR ALL INSTANCES.
CALL METHOD OBJ->METH2
EXPORTING
VAL1 = P_VAL1
VAL2 = P_VAL2.
PROGRAM2:
*&---------------------------------------------------------------------*
*&
Report ZRP_EVENTS_PARAMETERS1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRP_EVENTS_PARAMETERS1.
PARAMETERs :
p_var1 TYPE i.
data : result type i.
class c1
DEFINITION .
PUBLIC SECTION.
methods : add1 IMPORTING var1 TYPE i.
events : event1 EXPORTING VALUE(val1) TYPE
i.
ENDClass.
class c1
IMPLEMENTATION.
METHOD add1.
RAISE EVENT event1 EXPORTING val1 = result.
WRITE : / result.
ENDMETHOD.
ENDCLASS.
class c2
DEFINITION .
PUBLIC SECTION.
methods : meth1 FOR EVENT event1 of c1
IMPORTING val1.
ENDCLASS.
class c2
IMPLEMENTATION.
METHOD meth1.
result = 10 + val1.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
data : obj1 TYPE REF TO c1,
obj2 TYPE REF TO c2.
CREATE OBJECT : obj1,obj2.
set HANDLER obj2->meth1 FOR ALL INSTANCEs.
DO 10
TIMES.
CALL METHOD obj1->add1 EXPORTING var1 =
p_var1.
ENDDO.
No comments:
Post a Comment