parallel-processingabap

How do I know how many RFC tasks I can create?


I'm implementing a report that executes the same code twice, in parallel.

To achieve this, I do the following:

  call function 'my_func'
  starting new task 'T1' destination 'NONE'
  calling go_results->receive_results on end of task
    exporting
      it_pernr_tab            = lt_1st_half
      is_selection_parameters = gs_parm.

  call function 'my_func'
  starting new task 'T2' destination 'NONE'
  calling go_results->receive_results on end of task
    exporting
      it_pernr_tab            = lt_2nd_half
      is_selection_parameters = gs_parm.

  wait until go_results->mv_received_results = 2.

This will create two new tasks, which will execute just fine.

But I don't make any validations at all, I simply call the task twice because I've decided to.

I don't know if there is enough "room" for two new tasks, nor if there is room for 10 and I could use them better.

And this is precisely my question:

a) can I calculate somehow the max number of tasks that I can create, so that I use parallism to its full? for example, get the number of available work processes?


Solution

  • Before you start your asnyc function modules you should call the function module SPBT_INITIALIZE.

    Relevant are the parameters group_name, max_pbt_wps and free_pbt_wps

    CALL FUNCTION 'SPBT_INITIALIZE'
      EXPORTING
        group_name                     = 'YOUR_SERVER_GROUP'
      IMPORTING
        MAX_PBT_WPS                    = lv_max
        free_pbt_wps                   = lv_free
      EXCEPTIONS
        invalid_group_name             = 1
        internal_error                 = 2
        pbt_env_already_initialized    = 3
        currently_no_resources_avail   = 4
        no_pbt_resources_found         = 5
        cant_init_different_pbt_groups = 6
        OTHERS                         = 7.
    

    Server Groups are used to avoid that someone will use all available processes at the SAP system. If you do not want to configure Server Groups you will use the DEFAULT server group. In addition you should start your async function modules with the name of your Server Group

    CALL FUNCTION 'YOUR_ASYNC_FUNCTION' STARTING NEW TASK 'YOUR_TASK_IDENTIFIER'
      DESTINATION IN GROUP 'YOUR_SERVER_GROUP'
    

    or if you want to use the Default Group

    CALL FUNCTION 'YOUR_ASYNC_FUNCTION' STARTING NEW TASK 'YOUR_TASK_IDENTIFIER'
      DESTINATION IN GROUP DEFAULT
    

    Here you will find the SAP Documentation for the Server Groups

    https://help.sap.com/doc/saphelp_nw70/7.0.31/en-US/fa/096e92543b11d1898e0000e8322d00/content.htm?no_cache=true

    But anyway, after your call of SPBT_INITIALIZE you will receive the infos you requested.

    lv_max: the maximum available processes for your Server Group

    lv_free: available processes at the moment for your Server Group