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: 

event creation in oops abap

Former Member
0 Kudos

cud u plz guide me how to create the events in oops abap .

why we r using methods instead of perform statements in oops abap?

2 REPLIES 2

Former Member
0 Kudos

Hi,

Triggering and Handling Events

In ABAP Objects, triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.

This section contains explains how to work with events in ABAP Objects. For precise details of the relevant ABAP statements, refer to the corresponding keyword documentation in the ABAP Editor.

Triggering Events

To trigger an event, a class must

· Declare the event in its declaration part

· Trigger the event in one of its methods

Declaring Events

You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:

EVENTS ) TYPE type ..

To declare static events, use the following statement:

CLASS-EVENTS ... ...

It links a list of handler methods with corresponding trigger methods. There are four different types of event.

It can be

· An instance event declared in a class

· An instance event declared in an interface

· A static event declared in a class

· A static event declared in an interface

The syntax and effect of the SET HANDLER depends on which of the four cases listed above applies.

For an instance event, you must use the FOR addition to specify the instance for which you want to register the handler. You can either specify a single instance as the trigger, using a reference variable ...

The registration applies automatically to the whole class, or to all of the classes that implement the interface containing the static event. In the case of interfaces, the registration also applies to classes that are not loaded until after the handler has been registered.

Timing of Event Handling

After the RAISE EVENT statement, all registered handler methods are executed before the next statement is processed (synchronous event handling). If a handler method itself triggers events, its handler methods are executed before the original handler method continues. To avoid the possibility of endless recursion, events may currently only be nested 64 deep.

Handler methods are executed in the order in which they were registered. Since event handlers are registered dynamically, you should not assume that they will be processed in a particular order. Instead, you should program as though all event handlers will be executed simultaneously.

"Example :

REPORT demo_class_counter_event.
 
CLASS counter DEFINITION.
  PUBLIC SECTION.
    METHODS increment_counter.
    EVENTS  critical_value EXPORTING value(excess) TYPE i.
  PRIVATE SECTION.
    DATA: count     TYPE i,
          threshold TYPE i VALUE 10.
ENDCLASS.
 
CLASS counter IMPLEMENTATION.
  METHOD increment_counter.
    DATA diff TYPE i.
    ADD 1 TO count.
    IF count > threshold.
      diff = count - threshold.
      RAISE EVENT critical_value EXPORTING excess = diff.
    ENDIF.
  ENDMETHOD.
ENDCLASS.
 
CLASS handler DEFINITION.
  PUBLIC SECTION.
    METHODS handle_excess 
            FOR EVENT critical_value OF counter
            IMPORTING excess.
ENDCLASS.
 
CLASS handler IMPLEMENTATION.
  METHOD handle_excess.
    WRITE: / 'Excess is', excess.
  ENDMETHOD.
ENDCLASS.
 
DATA: r1 TYPE REF TO counter,
      h1 TYPE REF TO handler.
 
START-OF-SELECTION.
 
  CREATE OBJECT: r1, h1.
 
  SET HANDLER h1->handle_excess FOR ALL INSTANCES.
 
  DO 20 TIMES.
    CALL METHOD r1->increment_counter.
  ENDDO.

The class COUNTER implements a counter. It triggers the event CRITICAL_VALUE when a threshold value is exceeded, and displays the difference. HANDLER can handle the exception in COUNTER. At runtime, the handler is registered for all reference variables that point to the object.

Regards,

Omkar.

Former Member
0 Kudos

HI

Triggering and Handling Events

In ABAP Objects, triggering and handling an event means that certain methods act as triggers and trigger events, to which other methods - the handlers - react. This means that the handler methods are executed when the event occurs.

This section contains explains how to work with events in ABAP Objects. For precise details of the relevant ABAP statements, refer to the corresponding keyword documentation in the ABAP Editor.

Triggering Events

To trigger an event, a class must

· Declare the event in its declaration part

· Trigger the event in one of its methods

Declaring Events

You declare events in the declaration part of a class or in an interface. To declare instance events, use the following statement:

EVENTS ) TYPE type ..

To declare static events, use the following statement:

CLASS-EVENTS ... ...

It links a list of handler methods with corresponding trigger methods. There are four different types of event.

It can be

· An instance event declared in a class

· An instance event declared in an interface

· A static event declared in a class

· A static event declared in an interface

The syntax and effect of the SET HANDLER depends on which of the four cases listed above applies.

For an instance event, you must use the FOR addition to specify the instance for which you want to register the handler. You can either specify a single instance as the trigger, using a reference variable