Documente Academic
Documente Profesional
Documente Cultură
0
v1.0 3
1. PURPOSE .................................................................................................................................. 4
2. ABSTRACT ................................................................................................................................. 5
3. DESCRIPTION ............................................................................................................................ 6
3.1. PARALLEL PROCESSING DRIVER PROGRAM ........................................................................... 6
3.2. REMOTE ENABLE FUNCTION MODULE .................................................................................... 8
3.3. AN SPECIFIC SCENARIO: UPDATING SERVICE CONTRACTS ...................................................... 9
4. RESULTS ................................................................................................................................. 18
5. CONCLUSIONS ......................................................................................................................... 19
6. SOURCE .................................................................................................................................. 20
1. Purpose
This document brings a detailed knowledge on how to use parallel processing approach to update
CRM Business Transactions.
v1.0 5
2. Abstract
Customer need to do a mass update for any Business Transaction. Performance has to be considered as
is one of the key requirements.
Working with large amount of data using a unique local process can lead to very large time for
processing (typically client says when is too expensive). Parallel processing using asynchronous remote
function calls (aRFC) can be the solution.
When updating CRM Business Transaction through interface reports using aRFC there are common steps
which always apply.
- Parallel Processing Driver Program: obtains data based on selection screen entries, splits the whole
data into packages, manages parallel processing coordination calling aRFC, show log after entire
processing ends.
- Remote enable Function module: receives GUIDs or IDs and do all necessary logic to get business
transaction updated: typically includes calling function modules CRM_ORDER_READ,
CRM_ORDER_MAINTAIN, CRM_ORDER_SAVE. Besides returns log table for changed transactions.
3. Description
3.1. Parallel processing driver program
Selection Screen
Apart from necessary fields to data selection from DB (depending purely on the requirement)
user should be able to switch parallel execution on or off, and (if switched on) to configure
details of parallel processing. Making parallelism optional is useful when the workload is small
and parallel processing doesn’t make sense.
“Batch size” is the quantity of Business Transactions which together make a package. Supposing this
field set to 100, and the whole data consisting of 1000 business transaction ID, then data will be split
into 10 packages.
“Max # of jobs” indicates the maximum quantity of parallel processes running simultaneously.
“Server group” is required when calling remote function module for asynchronous processing.
Last two parameters help handling when remote function module results unsuccessful:
“Max. # of Attempt” is the maximum consecutive times that a FM recall can fail before cancelling
program (forcing program cancelation helps avoiding dead-lock).
“Max. wait time per attempt” is how many seconds to wait before recalling a FM after failing.
Data selection
This section is really very simple as there is no difference comparing to a simple report.
Data to be processed first has to be selected from database filtering accordingly to selection screen
parameters.
The important thing here is to select data into an internal table which will be used then to split data into
packages using a LOOP ENDLOOP logic calling remote function call from there.
v1.0 7
The heart of the report is a WHILE loop in which the function module that is to be processed in parallel is
called (CALL FUNCTION STARTING NEW TASK DESTINATION IN GROUP CALLING
‘FORM_WHEN_TASK_END’ ON END OF TASK).
- In sy-subrc are 3 this is directly related to lack of free parallel process. In this case the only thing
to do is waiting until current processes end so new task can begin processing. For this purpose
the same logic that previous case is done.
For exceptions 1 and 2, as these are related directly to server availability additionally could exclude
specific server from group calling function 'SPBT_DO_NOT_USE_SERVER'.
As part of task management, job must wait until all of the parallel processing tasks have been
completed. To do this, the program uses the WAIT keyword to wait until the number of completed
parallel processing tasks is equal to the number of tasks that were created. Independently of this WAIT;
the callback form ‘FORM_WHEN_TASK_ENDS’ (used in remote function call) is triggered. The callback
form keeps track of the number of completed parallel processing tasks, so that the WAIT condition can
be correctly evaluated.
Additionally, this routine can receive result from remote function execution like a log table.
A possible approach would be to receive transaction’ GUIDs necessary to call CRM_ORDER_READ (most
of times this call is a must in order to obtain further data about transaction):
After processing further according to logic (logging all important information in log structure), at the end
of execution log table has to be returned:
Logic
Again, this section is very simple as there are no additional considerations but only related to functional
requirement.
A typical update scenario in CRM involves calling function ‘CRM_ORDER_READ’ obtaining tables
according to requested logic, modify calling ‘CRM_ORDER_MAINTAIN’, saving changes with a call to
‘CRM_ORDER_SAVE’ and finally persisting data with 'BAPI_TRANSACTION_COMMIT'.
Considering that this FM runs on and independent LUW (logical unit of work) then in case that any
exception occurs in function calls it has to be caught and logged so the caller program (here Parallel
processing driver program) can be aware of this and take corrective action (action will depend on
requirement, perhaps doing nothing but reporting to user is enough).
v1.0 9
Existing more than 100 thousand contracts in the system and being execution time a key factor of
success, using parallel processing is an excellent idea and can lead to the success of our development.
Selection screen
This selection screen let user decides for which process type, including specific product id at item level,
even specifying contracts id (if blank so include all which apply restricting only by other parameters).
Different options for running basically include a control report (no update to contract is done), and 3
update options each of them involving specific validations.
Last tab includes parallel processing related parameters as explained in section 3.1.
Data selection
This part of the program is required to obtain all the contracts which applied according to filtering
parameters.
Is important to select into a table (it_hdr_guid). This will be use later for parallel processing logic using a
while structure.
*&---------------------------------------------------------------------*
*& Form F_PARALEL_PROCESS
*&---------------------------------------------------------------------
FORM f_paralel_process CHANGING pv_error TYPE char1
pv_error_from TYPE i.
ELSE.
v1.0 11
*HANDLE Error
ENDIF.
lv_index_low = 1.
lv_run_ok = c_x.
* aRFC Call
CALL FUNCTION 'ZCRM_ESM_RESET_CONT_ARFC'
STARTING NEW TASK lv_taskname DESTINATION IN GROUP lv_server_group
PERFORMING f_return_info ON END OF TASK
EXPORTING
i_product_guid = v_prod_guid " Product GUID
i_year = p_curr_y " Processing year
CASE sy-subrc .
WHEN 0 .
lv_run_ok = c_x.
* increment no. of jobs currently being Executed by the System
gv_current_jobs = gv_current_jobs + 1.
WHEN 1 OR 2.
"Remove server from further consideration for
"parallel processing tasks in this program.
CALL FUNCTION 'SPBT_GET_PP_DESTINATION' "#EC *
IMPORTING
rfcdest = lv_rfcdest
EXCEPTIONS
OTHERS = 1.
lv_no_use_serv = lv_rfcdest.
IF lv_res_fail LT p_maxres.
WAIT UP TO p_w_res SECONDS.
lv_res_fail = lv_res_fail + 1.
CLEAR lv_run_ok.
ELSE.
v1.0 13
pv_error = c_x.
pv_error_from = lv_index_low.
* In case there are other tasks still running
WAIT UNTIL gv_current_jobs EQ 0.
RETURN.
ENDIF.
WHEN 3.
IF lv_res_fail LT p_maxres.
WAIT UP TO p_w_res SECONDS.
lv_res_fail = lv_res_fail + 1.
CLEAR lv_run_ok.
ELSE.
pv_error = c_x.
pv_error_from = lv_index_low.
* In case there are other tasks still running
WAIT UNTIL gv_current_jobs EQ 0.
RETURN.
ENDIF.
WHEN OTHERS.
IF lv_res_fail LT p_maxres.
WAIT UP TO p_w_res SECONDS.
lv_res_fail = lv_res_fail + 1.
CLEAR lv_run_ok.
ELSE.
pv_error = c_x.
pv_error_from = lv_index_low.
* In case there are other tasks still running
WAIT UNTIL gv_current_jobs EQ 0.
RETURN.
ENDIF.
ENDCASE.
ENDWHILE.
EXCEPTIONS
system_failure = 1
communication_failure = 2
OTHERS = 4.
IF sy-subrc IS INITIAL.
APPEND LINES OF lt_log TO it_log.
ELSE.
READ TABLE it_tasks WITH KEY taskname = p_taskname
INTO lw_task.
Finally, the log table is shown for each contract previously processed.
v1.0 15
Interface
Necessary input to do corresponding validations is imported:
Always need to have contracts GUID to process. These are the contracts contained in task currently
executing:
Logic
Function logic is the continuation of the main program. At this time contract GUID is available and
further processing is intended to be done here. In this way heaviest time-consuming logic is performed
for a limited number of contracts (in this example 100 per task) and running at the same time (in this
example 3 maximum).
FUNCTION zcrm_esm_reset_cont_arfc .
*"---------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_PRODUCT_GUID) TYPE CRMT_OBJECT_GUID
*" VALUE(I_YEAR) TYPE SA_GJAHR
*" VALUE(I_MODE) TYPE CHAR1
*" VALUE(I_CONTRACT_SEL) TYPE CHAR1 OPTIONAL
*" EXPORTING
*" VALUE(ET_LOG) TYPE ZTT_CNTR_RESET_LOG
*" TABLES
*" T_CONTRACT_GUID STRUCTURE ZCRMT_OBJECT_GUID_FLAT
*"--------------------------------------------------------------------
DATA: lw_guid TYPE zcrmt_object_guid_flat.
REFRESH: it_log,
it_hdr_guid,
it_orderadm_h,
it_orderadm_i,
it_customer_h,
it_appointment,
it_partner,
it_status,
it_schedlin_i,
it_cumulated_i,
it_doc_flow.
v_prd_gu = i_product_guid.
v_curr_y = i_year.
v_id_sel = i_contract_sel.
v_curr_year = v_curr_y.
v_prev_year = v_curr_year - 1.
PERFORM f_ret_contract_info.
PERFORM f_proccess.
PERFORM f_save_objects.
ENDFUNCTION.
Along these calls any relevant message is logged and finally the log table is returned.
4. Results
After implementing parallel processing processing time decreased considerably.
In a real production environment with 30k contracts it took about 8 hours to process in a normal report
(without parallelism) for full cycle modifications (CRM_ORDER_READ, CRM_ORDER_MAINTAIN,
CRM_ORDER_SAVE).
Once parallel processing logic was add to report, the same operations took about 2,5 hours. This means
less than the third part of original time.
It is recommended when measuring response times to ensure that environment variables remain the
same so that conclusions are right (i.e. users currently processing, server processes available, etc.).
v1.0 19
5. Conclusions
Parallel processing using asynchronic remote function calls is recommended to be used when a large
amount of data has to be processed and time is a valuable resource. Being simple to implement, is an
alternative that can lead to development success.
For a deeper look at the code refer to files in section 6 (based on example from section 5).
6. Source