Skip to Content
author's profile photo Former Member
Former Member

event creation in oops abap

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?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 21, 2007 at 07:47 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 21, 2007 at 07:49 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.