SAP Tech Pro

SAP Technical Blog
Topprice Price Comparison

Object Oriented Programming in ABAP - Events with export parameters

Object Oriented Programming in ABAP - Events with export parameters

Events can have export parameters, which it passes to its event handler method. The triggering method must pass values for all the exporting parameters of the event while raising the event using RAISE EVENT statement. The interface of an event handler method consists of a list of IMPORTING parameters, whose names are identical with those in the EXPORTING list and which are automatically created from the interface of the event. Each handler method can however specify which event parameters it wants to handle and which it does not.

Class C1 contains event E1 which exports two parameters , NUM1 and NUM2 to its event handler method , M1 in class C1. Method T1 is the triggering method for the event, which passes values to the EXPORTING parameters of the event at the time of RAISE EVENT statement.



REPORT zstp_oo_abap.

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    EVENTS : e1 EXPORTING VALUE(num1) TYPE i
                          VALUE(num2) TYPE i.

    METHODS : m1 FOR EVENT e1 OF c1
      IMPORTING num1
                  num2
      .
    METHODS : t1.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD : m1.
    WRITE:/5 'First input ' ,  num1 .
    WRITE:/5 'Second input ' , num2 .
  ENDMETHOD.

  METHOD t1.
    RAISE EVENT e1 EXPORTING num1 = 2
                             num2 = 3.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  DATA : oref TYPE REF TO c1.
  CREATE OBJECT oref.
  SET HANDLER oref->m1 FOR oref.
  CALL METHOD oref->t1.

Output -

Events with export parameters

Add comment

Before Buying, Compare Prices at Topprice.in

Topprice.in