Application Development 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: 

SAP ABAP Parallel Processing Controls

Former Member

Hi All,

I have gone through parallel processing concept of SAP where we are using below statement to achieve it:

'CALL FUNCTION ‘ZPARALLEL_PROCESS_FM’ STARTING NEW TASK lv_taskname

DESTINATION IN GROUP p_rfcgr'

But I wanted to know below:

We have a scenario where we are running a daily batch job and that job has parallel processing logic. But the parallel processing is not getting completed by the time the same job starts again on the very next day. Due to which the output files are generating incorrectly.

How we can control/handle a scenario to make sure the next job should not start until previous job completes or is it possible to make sure the asynchronous job should get complete with in some limited time.

There is a work around, we can write a condition in the report using lock object, we can do lock a table when job starts and unlock when it finishes in between if any the same job triggers again we will put it on wait.

But may i know is there any standard way of handling.

Regards,

Prince Joshi

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor

Keep the main program active til end of execution (it would use one process) you can check execution of RFC call using option CALLING method ON END OF TASK. (add a counter when starting a task and decrement it in the end of task method, wait til 0 running tasks)

" Call
DO  n TIMES.
  ADD 1 TO taskname.
  CALL FUNCTION ‘zparallel_process_fm’
    STARTING NEW TASK taskname
    CALLING method ON END OF TASK.
  "
ENDDO.
" Wait
WAIT UNTIL taskname LT '0001'.
" Method
SUBTRACT 1 FROM taskname.

In the main program check that no other job (same name or same report is currently running, don't forget you are running so exit when 2 'R'unning job are found.

" Look for jobs running same program
CALL FUNCTION 'BP_FIND_JOBS_WITH_PROGRAM'
  EXPORTING
    abap_program_name = lv_repid
    status            = 'R'
  TABLES
    joblist           = lt_joblist
  EXCEPTIONS
    OTHERS            = 0.
" Exit if 2 jobs 
DESCRIBE TABLE lt_joblist LINES lv_nbjobs. " lines( ) 
6 REPLIES 6

raymond_giuseppi
Active Contributor

Keep the main program active til end of execution (it would use one process) you can check execution of RFC call using option CALLING method ON END OF TASK. (add a counter when starting a task and decrement it in the end of task method, wait til 0 running tasks)

" Call
DO  n TIMES.
  ADD 1 TO taskname.
  CALL FUNCTION ‘zparallel_process_fm’
    STARTING NEW TASK taskname
    CALLING method ON END OF TASK.
  "
ENDDO.
" Wait
WAIT UNTIL taskname LT '0001'.
" Method
SUBTRACT 1 FROM taskname.

In the main program check that no other job (same name or same report is currently running, don't forget you are running so exit when 2 'R'unning job are found.

" Look for jobs running same program
CALL FUNCTION 'BP_FIND_JOBS_WITH_PROGRAM'
  EXPORTING
    abap_program_name = lv_repid
    status            = 'R'
  TABLES
    joblist           = lt_joblist
  EXCEPTIONS
    OTHERS            = 0.
" Exit if 2 jobs 
DESCRIBE TABLE lt_joblist LINES lv_nbjobs. " lines( ) 

0 Kudos

Hi Raymond,

Thanks a lot for your inputs.

So, Ideally you mean we should use FM 'BP_FIND_JOBS_WITH_PROGRAM' in the starting of our main program. So, It will check if already the report is executing in parallel or not.

yes it seems to be correct for below statement where we are using END OF TASK method as our main program will still be running:

CALL FUNCTION ‘zparallel_process_fm’ STARTING NEW TASK taskname
CALLING method ON END OF TASK.

But what if we not using statement CALLING ZMETHOD END OF TASK (as i asked this in my question).

In that case, this FM 'BP_FIND_JOBS_WITH_PROGRAM' will not be useful because main program would have been finished the execution and in parallel the FM would be executing/waiting. So, how we can make sure that all the asynchronous FMs must execute before the next job starts(as it is a daily job).

Regards,

Prince Joshi

Then you could

  • switch from STARTING NEW TASK to IN BACKGROUND TASK/UNIT commit to trigger executions, at start of report select from ARFCSTATE for running task
  • Store number of submitted task somewhere (table, cluster, shared cluster...) decrement it at end of FM execution, read at start of report
  • Use some lock (create a z-lock object, lock value of task at start of FM, enqueue read at start of program for any lock)
  • ...

0 Kudos

Yes Correct, I think we have to go for Lock objects only to make sure process is consistent.

Thanks Raymond 🙂

roberto_forti
Contributor

Hi Joshi,

SAP documentation about asynchronous tasks also will help you.

Regards

0 Kudos

Yes Correct!!

Parallel Processing means Asynchronous Type of function module.

Generally, when we call a function module, it will stop the current program , execute another ( called ) program and then returns control to original program and again origi...Read More