Application Development and Automation 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: 
Read only

Using parallel processing

Former Member
0 Likes
2,393

Hi all

I want to let my function run on worker thread like coroutine and try as follow:

report zam_parallel_processing.

data lf_msg type c length 80.
data lf_finish type string.
data lf_wait type xfeld.

start-of-selection.

   call function 'ZAM_FUNCS_PARA_COUNTER'
     starting new task 'COROUTINE'
     performing end_processing on end of task
     exceptions
       system_failure        = 1 message lf_msg
       communication_failure = 2 message lf_msg
       resource_failure      = 3.

   write:/ 'After parallel'.

   wait up to 3 seconds.
   write:/ lf_finish.
   receive results from function 'ZAM_FUNCS_PARA_COUNTER'
     changing
       cf_finish = lf_finish
     exceptions
       communication_failure = 1
       system_failure = 2.

   if sy-subrc <> 0.
     write:/ 'Parallel aborted'.
   else.
     write:/ lf_finish.
   endif.

end-of-selection.


form end_processing using result.

   write:/ result.

endform.


When programm is executed, I've as output Parallel aborted, that means can not got the result from the function call. The function module that I called looks like:

function zam_funcs_para_counter.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*"  CHANGING
*"     REFERENCE(CF_FINISH) TYPE  STRING
*"----------------------------------------------------------------------

   data lf_counter type i value 0.

   while lf_counter < 100000000.
     add 1 to lf_counter.
   endwhile.

   cf_finish = 'Finish'.

endfunction.


I expected as result Finish. What am I doing wrong?



1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,823

Anujit,

There are a few things that you need you need to understand while implementing parallel processing. Let me try to explain the same with a simple example.

Lets say you have a main program which call the Z function. You do not want your main program to wait for the Z function to complete. Instead you want your Z function to run along with the main program but the Z function needs to communicate the results back to the main program.

Your approach is right expect for a few little things.


CALL FUNCTION 'abc'

DESTINATION 'NONE'

STARTING NEW TASK 'TASK1'

PERFORMING 'END_PROCESSING' ON END OF TASK

In the above 'END_PROCESSING' is a subroutine. So you need to have a subroutine named 'END_PROCESSING'. This sub routine needs to use the command 'RECEIVE RESULTS' in order to get the results back from the Z function.


FORM end_processing USING lv_task LIKE CLIKE.

RECEIVE RESULTS FROM FUNCTION 'z function name' TABLES A=B

                                                                                                                        C=D.

ENDFORM.

The above subroutine gets called when the Z function is complete and is ready to transmit results back to the main program.

The next problem that you need to solve is to make your main program wait based on some action in order to receive the results from the Z function. This can be achieved using.


WAIT UNTIL logic expression.

A simple logic expression can be used in order to achieve this. For ex:

Use 2 different variables, lets say A and B. Before the Z function is called , increase the value of the variable A by 1. Then inside the subroutine end_processing increase the value of the variable B by 1.

Your wait statement should be WAIT UNTIL A = B. This way the program will keep waiting. When the Z function is complete it will get into the routine where B will be increased. Once you come out of the routine back to the wait statement, the condition will be satisfied and the program will continue.

Let me know if you need more help.

Thanks,

Vikram.M

Message was edited by: vikram Muralidharan

5 REPLIES 5
Read only

Former Member
0 Likes
1,823

Hi Anujit,

For parallel process, The Function module you are calling must be externally callable, Please check the radio button Remote Enable module in the above screen shot and check if its working fine or not.

Regards,

Salil B

Read only

Former Member
0 Likes
1,823

I checked the radio button to Remote Enable module as you mentioned above but still not working.  I've got exception system_failure again:

receive results from function 'ZAM_FUNCS_PARA_COUNTER'
     changing
       cf_finish = lf_finish
     exceptions
       communication_failure = 1
       system_failure = 2.

Read only

0 Likes
1,823

Hi,

Can you check in the code in FM where this exception is getting raised..and the reason for it.
There must be some condition getting failed and its a custom FM so you can modify it.

Thanks,

Salil B

Read only

Former Member
0 Likes
1,824

Anujit,

There are a few things that you need you need to understand while implementing parallel processing. Let me try to explain the same with a simple example.

Lets say you have a main program which call the Z function. You do not want your main program to wait for the Z function to complete. Instead you want your Z function to run along with the main program but the Z function needs to communicate the results back to the main program.

Your approach is right expect for a few little things.


CALL FUNCTION 'abc'

DESTINATION 'NONE'

STARTING NEW TASK 'TASK1'

PERFORMING 'END_PROCESSING' ON END OF TASK

In the above 'END_PROCESSING' is a subroutine. So you need to have a subroutine named 'END_PROCESSING'. This sub routine needs to use the command 'RECEIVE RESULTS' in order to get the results back from the Z function.


FORM end_processing USING lv_task LIKE CLIKE.

RECEIVE RESULTS FROM FUNCTION 'z function name' TABLES A=B

                                                                                                                        C=D.

ENDFORM.

The above subroutine gets called when the Z function is complete and is ready to transmit results back to the main program.

The next problem that you need to solve is to make your main program wait based on some action in order to receive the results from the Z function. This can be achieved using.


WAIT UNTIL logic expression.

A simple logic expression can be used in order to achieve this. For ex:

Use 2 different variables, lets say A and B. Before the Z function is called , increase the value of the variable A by 1. Then inside the subroutine end_processing increase the value of the variable B by 1.

Your wait statement should be WAIT UNTIL A = B. This way the program will keep waiting. When the Z function is complete it will get into the routine where B will be increased. Once you come out of the routine back to the wait statement, the condition will be satisfied and the program will continue.

Let me know if you need more help.

Thanks,

Vikram.M

Message was edited by: vikram Muralidharan

Read only

0 Likes
1,823

Thanks so much.