Paralel Processing
data: h_parallel(1) type c value space,
gv_counter type i,
gv_row type i,
gv_paralel type i,
gv_taskname(30).
data: gt_mara like table of mara with header line,
gt_marc like table of marc with header line,
gt_marc2 like table of marc with header line.
parameters: p_rfcgr like bdfields-rfcgr default ' '.
* Parallel >>>>>>>>>>>>>>>>
if p_rfcgr <> space.
h_parallel = 'X'.
else.
h_parallel = space.
endif.
if h_parallel = 'X'.
translate p_rfcgr to lower case.
call function 'SPBT_INITIALIZE'
exporting
group_name = p_rfcgr
exceptions
invalid_group_name = 1
internal_error = 2
pbt_env_already_initialized = 3
currently_no_resources_avail = 4
no_pbt_resources_found = 5
others = 6.
if sy-subrc = 1 or sy-subrc = 2 or sy-subrc = 5 or sy-subrc = 6.
h_parallel = space.
endif.
endif.
select * from mara into table gt_mara up to 100000 rows.
describe table gt_mara lines gv_counter.
if h_parallel = 'X'.
clear gv_paralel.
loop at gt_mara.
clear: gt_marc, gt_marc[].
concatenate 'MM_' gt_mara-matnr into gv_taskname.
call function 'YTEST'
starting new task gv_taskname
destination in group p_rfcgr
performing f_return_here on end of task
exporting
i_matnr = gt_mara-matnr
tables
t_marc = gt_marc
exceptions
communication_failure = 1
system_failure = 2
resource_failure = 3.
if sy-subrc <> 0.
call function 'YTEST'
exporting
i_matnr = gt_mara-matnr
tables
t_marc = gt_marc.
clear gv_row.
describe table gt_marc lines gv_row.
append lines of gt_marc to gt_marc2.
gv_counter = gv_counter - 1.
endif.
endloop.
else.
loop at gt_mara.
call function 'YTEST'
exporting
i_matnr = gt_mara-matnr
tables
t_marc = gt_marc.
append lines of gt_marc to gt_marc2.
endloop.
endif.
if h_parallel = 'X'.
wait until gv_counter = 0.
endif.
write gv_paralel.
*&---------------------------------------------------------------------*
*& Form f_return_here
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TASKNAME text
*----------------------------------------------------------------------*
form f_return_here using p_taskname.
gv_counter = gv_counter - 1.
receive results from function 'YTEST'
tables
t_marc = gt_marc.
* DESCRIBE TABLE gt_marc LINES gv_row.
append lines of gt_marc to gt_marc2.
add 1 to gv_paralel.
endform. "f_return_here
function ytest.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_MATNR) TYPE MATNR OPTIONAL
*" TABLES
*" T_MARC STRUCTURE MARC
*"----------------------------------------------------------------------
select * from marc into table t_marc
where matnr = i_matnr.
endfunction.
***Paralel Processing Example,Program Ex. With Background Job (Monitoring SM37 )
report ytest.
data: gv_jobname like tbtcjob-jobname value 'TEST',
gv_jobgroup like tbtcjob-jobgroup,
gv_jobcount like tbtcjob-jobcount.
perform f_create_job.
form f_create_job .
call function 'JOB_OPEN'
exporting
jobname = gv_jobname
importing
jobcount = gv_jobcount
exceptions
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
others = 4.
if sy-subrc ne 0.
write: /1 'JOB_OPEN FAILED reason code :', sy-subrc.
check 1 = 2.
endif.
submit yolcay_v2
with p_rfcgr = 'parallel_generators'
user sy-uname
via job gv_jobname number gv_jobcount
and return.
call function 'JOB_CLOSE'
exporting
jobcount = gv_jobcount
jobname = gv_jobname
strtimmed = 'X'
exceptions
cant_start_immediate = 1
invalid_startdate = 2
jobname_missing = 3
job_close_failed = 4
job_nosteps = 5
job_notex = 6
lock_failed = 7
invalid_target = 8
others = 9.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
message i000(yuauth) with gv_jobname.
endif.
endform. " f_create_job