Using RFCs Not Just For Integration
Using RFCs Not Just For Integration
DATA:
ls_spagpa TYPE rfc_spagpa,
lt_spagpa TYPE STANDARD TABLE OF rfc_spagpa,
l_act_sessions TYPE sm04dic-counter,
l_max_sessions TYPE sm04dic-counter.
IF l_act_sessions GE l_max_sessions.
MESSAGE i027(14).
RETURN.
ENDIF.
ENDFORM.
/in/borodin-igor Using RFCs not only for integration
To handle it, staying inside the source LUW (using BADI or UE), you can use IN BACKGROUND TASK instruction to
schedule required function (in this case, BAPI for related document creation) start directly after the high-priority
update function modules execution.
Another example is when you need to scheduling the material stock revaluation process each time when prices
changes. Here we schedule it from Badi called while source document is saving, but revaluation process will start
after source document is already saved.
METHOD if_ex_invoice_update~change_at_save. " -->> BADI-impl. method
" 1) At this point the document (which sets new prices) is beginning to create,
" and we are INSIDE its LUW now
"
" 2) We need to schedule the start of Stock revaluation process
" immediately AFTER current UPDATE TASK will be finished
" (this requirement is because external stock revaluation process must consider current document)
ENDMETHOD.
FUNCTION 'Z_MY_REVALUATION_PROCESS'.
ENDFUNCTION.
/in/borodin-igor Using RFCs not only for integration
...................
...................
ENDMETHOD.
FUNCTION 'Z_MY_SEPARATE_LUW_WITH_COMMIT'.
ENDFUNCTION.
Skip the global variables data buffered while previous function call
LOOP AT ....
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' DESTINATION 'NONE'
EXPORTING
wait = abap_true.
ENDIF.
ENDLOOP.
/in/borodin-igor Using RFCs not only for integration
CLASS-METHODS:
run
IMPORTING it_key TYPE ty_t_some_key
RETURNING VALUE(rt_result) TYPE ty_t_some_result,
end_processing_of_portion
IMPORTING p_task TYPE clike.
PRIVATE SECTION.
CLASS-METHODS:
start_processing_of_portion
IMPORTING iv_taskname TYPE i
it_key TYPE ty_t_some_key
CHANGING cv_successfully_started TYPE i,
get_available_workprocesses
RETURNING VALUE(rv_count) TYPE i.
ENDCLASS.
"====================================================================
" determine the number of available work processes
"====================================================================
DATA(lv_available_workprocesses) = get_available_workprocesses( ).
"====================================================================
" if there are not enough available work processes,
" we push to perform without parallelization
"====================================================================
IF lv_available_workprocesses <= 1.
CALL FUNCTION 'Z_VERY_SLOW_PROCESSING'
TABLES
it_key = it_key
et_result = rt_result.
RETURN.
ENDIF.
/in/borodin-igor Using RFCs not only for integration
"====================================================================
" if available work processes exists,
" we split keys table into portions, and push portions to parallel processing
"====================================================================
DATA(lv_lines) = lines( it_key ).
DATA(lv_portion_size) = lv_lines / lv_available_workprocesses.
DATA lv_successfully_started TYPE i.
DO lv_available_workprocesses TIMES.
" --- calculate first and last line for current portion
DATA(lv_index_from) = lv_portion_size * ( lv_current_workprocess - 1 ) + 1.
IF lv_current_workprocess = lv_available_workprocesses.
DATA(lv_index_to) = lv_lines.
ELSE.
lv_index_to = lv_portion_size * lv_current_workprocess.
ENDIF.
ENDMETHOD.
METHOD start_processing_of_portion.
ENDMETHOD.
/in/borodin-igor Using RFCs not only for integration
METHOD end_processing_of_portion.
mv_processed += 1.
ENDMETHOD.
METHOD get_available_workprocesses.
CLEAR rv_count.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
ENDLOOP.
ENDFUNCTION.
FORM random_delay.
ENDFORM.