2014 May 08 8:03 PM
Hi,
Below is my requirement. Any ideas how to make the program wait?
I have Z program has 4 different process chains that needs to be triggered. When the user executes the program, I trigger an event using FM. A process chain in BW will get executed once this event is triggered.
Now I want my main program to wait until the first process chain is completed to trigger the next event which will start another process chain. how do I achieve this?
I do not want to have a wait until N seconds (in a loop) and then query some table to check if the first process chain is completed. Is there any other way to achieve this?
Thanks,
Vikram.M
Hi,
Below is my requirement. Any ideas how to make the program wait?
I have Z program has 4 different process chains that needs to be triggered. When the user executes the program, I trigger an event using FM. A process chain in BW will get executed once this event is triggered.
Now I want my main program to wait until the first process chain is completed to trigger the next event which will start another process chain. how do I achieve this?
I do not want to have a wait until N seconds (in a loop) and then query some table to check if the first process chain is completed. Is there any other way to achieve this?
Thanks,
Vikram.M
2014 May 08 8:13 PM
What I actually want is for my program to wait for another event to be triggered by the process chain. Once the process chain triggers a "completed" event, I want to resume my program trigger another event to start another process chain and then go back to wait state until the 2nd process chain
triggers a "completed" event.
2014 May 08 10:09 PM
Hi Vikram,
you can use event handlers and WAIT UNTIL (WAIT UNTIL - Application Development on AS ABAP - SAP Library) to achieve this. What you need to do is the following:
Finally you need to raise the necessary events once the BW process is finished, e.g. via some remote function call.
Christian
2014 May 08 10:24 PM
2014 May 09 3:04 PM
Christian,
I haven't got a chance to try this out yet. But I was thinking about this and a question popped up in my head. Hope you can help.
Since we will be creating a global class and a public attribute that will be set to X by an event handler and my program is waiting for this variable to be X.
What if there are 2 users run the same program the same time with different data to be processed.
User 1 runs the program and kicks off process chain1. the program now waits for process to be completed.
User 2 runs the same program and kicks of process chain 1 with different data. the program waits for completion of PC1.
Lets says user 2 has less data to process, the PC1 completes before PC1 kicked off by user 1.
Now the variable will be set to X which will cause both program for both user1 and user2 to come out of wait but actually only user2 program should come out of wait.
So my question here is, in case of global class/public attribute, does the user specific LUW still come into play?
thanks,
Vikram.M
2014 May 10 7:09 AM
Hi Vikram,
your assumption that a parallel execution if the report could be a problem is right. Therefor I would create a global class with instance attributes not static attributes. You then instanziate this class with each execution if the report.
As the LUWs won't help you in the cross system scenario you further need a way to differentiate between the events raised by BW upon finishing of the process. Therefor you need to add some parameter to the event which you can check in the method that updates the attribute. You could, for example, create a guid upon instantiation of your class an pass it along with the events as a parameter. On processing of the event you check if the guid of the current process was given or not and only update the attribute if the correct guid is provided.
One additional thing came to my mind when thinking of your requirement. Instead of wating in a report for different Events and continue with the execution after they occurred, you could simply put all the logic in the event handler methods. Then your report only needs to create the event handler class, invoke the first method and wait until completion.
Christian
2014 May 10 7:12 PM
Christian,
One additional thing came to my mind when thinking of your requirement. Instead of wating in a report for different Events and continue with the execution after they occurred, you could simply put all the logic in the event handler methods. Then your report only needs to create the event handler class, invoke the first method and wait until completion.
I think the above was the most simplest solution and I can only blame me for not thinking this through
And may be I was not sure if I had helped you understand the problem statement clearly, there is no cross system scenario here. The report will be run in BW and the report will start process chains within BW. So even making the attribute as static should do it. again I should have thought of that.
Been a procedural programmer all the while and I think your suggestions are some good steps for me towards OO.
Also, I wrote a POC and the WAIT UNTIL actually does not work (for some reason). Did not have time to check why but I am going to do that now. I wll keep you posted.
Thanks,
Vikram.M
2014 May 12 10:15 PM
Christian,
So I wrote a small POC to test this out. Creating the variable as a instance attribute works perfect. But the WAIT UNTIL statement does not work.
So I changed to DO..ENDDO with the check inside and that works as I want.
So even though I got my solution, I still wonder why the WAIT UNTIL does not work. Any ideas?
Thanks,
Vikram.M
2014 May 13 9:00 PM
Hi Vikram,
i read the documentation of WAIT UTIL again. It explicitly states that WAIT UTIL can only be used in the context of asynchronous RFCs. In thei context the exprsession is evallayed after the call back function of the aRFC was invoked.
So your approach using busy waiting is indeed the only possible. Sorry for pointing you in the wrong direction.
Christian
2014 May 13 9:03 PM
Thanks for your time Christian. At least now I know when to use WAIT UNTIL. Again thanks for the help.
2014 May 15 7:43 AM
Hi Muralidharan,
Please consider the code snippet below for your a-synchronous function moduling process.
Please be aware that the function module must be made 'Remote enabled'.
Good luck, and if you have any queries, please let us know.
Best,
Sander
CLASS lcl_parallel_process_construct DEFINITION.
PUBLIC SECTION.
DATA mv_id TYPE char8.
DATA mv_jobs TYPE int4.
DATA mv_dest_group TYPE rzlli_apcl VALUE 'parallel_generators'.
DATA mv_jobs TYPE int4.
METHODS rfc_parallel_process
IMPORTING
!iv_jobs TYPE i .
METHODS rfc_parallel_processed
IMPORTING
!p_task TYPE clike.
ENDCLASS.
CLASS lcl_parallel_process_construct IMPLEMENTATION.
METHOD rfc_parallel_process.
* These should be globals
WAIT UNTIL mv_jobs LT iv_jobs.
mv_jobs = mv_jobs + 1.
mv_id = mv_id + 1.
CALL FUNCTION 'ZYOUR_FUMO'
STARTING NEW TASK mv_id
DESTINATION IN GROUP mv_dest_group
CALLING me->rfc_parallel_processed ON END OF TASK
EXPORTING
iv_id = 'TOOLBOX'.
ENDMETHOD.
METHOD rfc_parallel_processed.
DATA lv_failed TYPE i.
DATA lv_success TYPE i.
RECEIVE RESULTS FROM FUNCTION 'ZYOUR_FUMO'
IMPORTING
ev_failed = lv_failed
ev_success = lv_success
EXCEPTIONS
OTHERS = 1.
mv_jobs = mv_jobs - 1.
ENDMETHOD.
ENDCLASS.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |