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

Event in not triggered in parallel processing

Hello ABAP community,

i am playing around with ABAP OO and doing my first lessons in parallel processing. I am trying to comibine parallel processing (CALL FUNCTION STARTING NEW TASK) with the ABAP OO concept of events.

The idea is to create many instances of a class (RECEIVER_CLASS) and call them in parallel. I want to catch the result of each CALL with the RECEIVE statement and trigger an event to inform the caller class about the finished function/class. In this case a method RESULT is called. I want to access the data of the event via the implicit parameter SENDER (according to online documentation).

Here you can find a simple report. The event seems to be triggerd but the method RESULT will never be called.

REPORT  zcra_parallel2.

*---------------------------------------------------------------------*
*       CLASS receiver_class DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS receiver_class DEFINITION.
  PUBLIC SECTION.
    METHODS:
      start IMPORTING value(i_taskname) TYPE char8,
      receiver1 IMPORTING value(p_task) TYPE clike.
    <b>EVENTS:
      finished.</b>
ENDCLASS.                    "receiver_class DEFINITION
*---------------------------------------------------------------------*
*       CLASS receiver_class IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS receiver_class IMPLEMENTATION.
  METHOD start.
    CALL FUNCTION 'ZZ_CRA1' STARTING NEW TASK i_taskname
      CALLING me->receiver1 ON END OF TASK
      EXPORTING
        mytask = i_taskname.

    IF sy-subrc = 0.
      WRITE: /, i_taskname, ' TASK started...'.
    ENDIF.
  ENDMETHOD.   "start

  METHOD receiver1.
    DATA:
      myinfo TYPE TABLE OF zcra1.
    RECEIVE RESULTS FROM FUNCTION 'ZZ_CRA1'
      TABLES my_itab = myinfo.
    <b>RAISE EVENT finished.</b>
  ENDMETHOD.                                                "receiver1
ENDCLASS.                    "receiver_class IMPLEMENTATION

*---------------------------------------------------------------------*
*       CLASS x DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS caller DEFINITION.
  PUBLIC SECTION.
    DATA:
      y_ref TYPE REF TO receiver_class,
      z_ref TYPE REF TO receiver_class.
    METHODS:
      constructor,
      <b>result FOR EVENT finished OF receiver_class.</b>
ENDCLASS.                    "callerx DEFINITION


*---------------------------------------------------------------------*
*       CLASS callerx IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS caller IMPLEMENTATION.
  METHOD constructor.
    SET HANDLER: me->result FOR ALL INSTANCES.
    CREATE OBJECT: y_ref, z_ref.
    CALL METHOD y_ref->start( 'WAIT1' ).
    CALL METHOD z_ref->start( 'WAIT2' ).
  ENDMETHOD.                    "constructor
  <b>METHOD result.
    WRITE: /, 'EVENT TRIGGERD!'.
  ENDMETHOD.</b>                    "result
ENDCLASS.                    "callerx IMPLEMENTATION


DATA:
  mycaller TYPE REF TO caller.

START-OF-SELECTION.

  CREATE OBJECT mycaller.

Thanks for any help!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jun 16, 2005 at 04:36 PM

    What makes you think that RESULT is never being called. Is it the fact, that its not writing "Event Triggered". I have taken your code and made some modifications to it and tested it in my system. The event is being fired, and the method is being executed, but the write statement is not being processed correctly. I think it has something to do with the number of lists that are being generated, the first write statement is probably a different list id. Anyway put CHECK SY-SUBRC = 0 into the result method. But a breakpoint on it. It should stop there.

    Regards,

    Rich Heilman

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Rich Heilman

      Yeahh! You were right. Just the write statement is not working.

      BTW you can implicit import the instance of the class that has triggered the event.

      result FOR EVENT finished OF receiver_class
            IMPORTING sender.

      Now all attributes of the trigger class are available in method RESULT via the reference SENDER.

      Thanks for help,

      Christian

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.