‎2005 Jun 16 4:14 PM
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!
‎2005 Jun 16 5: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
‎2005 Jun 16 5: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
‎2005 Jun 16 5:54 PM
Here is the sample program that I'm working with. I took your code and changed some things in order to get it working on my system(46c). Maybe this will help you.
report zrich_0003 .
data: session(1) type c.
data: event_fired(1) type c.
*---------------------------------------------------------------------*
* CLASS receiver_class DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class receiver_class definition.
public section.
methods: trigger_event,
start importing value(i_taskname) type char8,
receiver1 importing value(p_task) type c .
events: finished.
endclass.
*---------------------------------------------------------------------*
* CLASS receiver_class IMPLEMENTATION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class receiver_class implementation.
method start.
data: messtab type table of bdcmsgcoll,
bdcdata type table of bdcdata .
call function 'ABAP4_CALL_TRANSACTION' starting new task i_taskname
* calling me->receiver1 on end of task
performing reciever on end of task
exporting mytask = i_taskname
tcode = 'SM50'
mode_val = 'N'
update_val = 'S'
tables
using_tab = bdcdata
mess_tab = messtab.
wait until session = 'X'.
* if sy-subrc = 0.
* write: / i_taskname, ' TASK started...'.
* endif.
endmethod. "start
method receiver1.
* data: myinfo type table of zcra1.
* receive results from function 'ABAP4_CALL_TRANSACTION'
* tables
* mess_tab = messtab.
* raise event finished.
endmethod.
method trigger_event.
raise event finished.
endmethod.
endclass.
*---------------------------------------------------------------------*
* CLASS caller DEFINITION
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
class caller definition.
public section.
* data: y_ref type ref to receiver_class,
* z_ref type ref to receiver_class.
methods:
constructor,
result for event finished of receiver_class.
endclass.
*---------------------------------------------------------------------*
* CLASS caller 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.
method result.
event_fired = 'X'.
endmethod.
endclass.
data: y_ref type ref to receiver_class,
z_ref type ref to receiver_class.
data: mycaller type ref to caller.
start-of-selection.
create object mycaller.
create object: y_ref, z_ref.
call method y_ref->start( 'ZRICH2' ).
write:/ 'Event Fired:', event_fired.
*---------------------------------------------------------------------*
* FORM reciever *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> TASKNAME *
*---------------------------------------------------------------------*
form reciever using taskname.
data: messtab type table of bdcmsgcoll.
receive results from function 'ABAP4_CALL_TRANSACTION'
tables
mess_tab = messtab.
session = 'X'.
call method y_ref->trigger_event.
endform.
Regards,
Rich Heilman
‎2005 Jun 17 9:45 AM
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