You are on page 1of 9

Usage of Parallel cursor method :

Old code
Highlighted code is Nested Loop which need to be replaced by Parallel cursor
method.
LOOP AT i_marc.
*Plant
i_opn-werks = i_marc-werks.
READ TABLE i_plnam WITH KEY werks = i_marc-werks
BINARY SEARCH.
IF sy-subrc = 0.
*Plant Name
i_opn-spl_name = i_plnam-name.
CLEAR i_plnam.
ENDIF.
*Material Code
i_opn-matnr = i_marc-matnr.
*Material Description
READ TABLE i_makt WITH KEY

matnr = i_marc-matnr
BINARY SEARCH.

IF sy-subrc = 0.
i_opn-maktx = i_makt-maktx.

CLEAR i_makt.
ENDIF.
*Material Valuation Class
READ TABLE i_mbew WITH KEY matnr = i_marc-matnr
BINARY SEARCH.
IF sy-subrc = 0.
i_opn-bklas = i_mbew-bklas.
CLEAR i_mbew.
ENDIF.
*Material Division
READ TABLE i_a_mara WITH KEY matnr = i_marc-matnr
BINARY SEARCH.
IF sy-subrc = 0.
i_opn-spart = i_a_mara-spart.
i_opn-meins = i_a_mara-meins.
*Material Division Text
READ TABLE i_tspat WITH KEY spart = i_a_mara-spart
BINARY SEARCH.
IF sy-subrc = 0.
i_opn-vtaxt = i_tspat-vtaxt.
CLEAR i_tspat.
ENDIF.
CLEAR i_a_mara.
ENDIF.
*********************************************************************
LOOP AT i_s031_opn ASSIGNING <fs_s031_opn> WHERE
matnr = i_opn-matnr and werks = i_opn-werks.
" plant add by chandan
l_mzubb_pc = l_mzubb_pc + <fs_s031_opn>-mzubb_pc.
l_mzubb_sqm = l_mzubb_sqm + <fs_s031_opn>-mzubb_sqm.
l_mzubb_na = l_mzubb_na + <fs_s031_opn>-mzubb_na.
l_mzubb_cbm = l_mzubb_cbm + <fs_s031_opn>-mzubb_cbm.
l_magbb_pc = l_magbb_pc + <fs_s031_opn>-magbb_pc.
l_magbb_sqm = l_magbb_sqm + <fs_s031_opn>-magbb_sqm.
l_magbb_na = l_magbb_na + <fs_s031_opn>-magbb_na.
l_magbb_cbm = l_magbb_cbm + <fs_s031_opn>-magbb_cbm.
l_v_mzubb = l_v_mzubb + <fs_s031_opn>-mzubb.
l_v_magbb = l_v_magbb + <fs_s031_opn>-magbb.
l_v_wzubb = l_v_wzubb + <fs_s031_opn>-wzubb.
l_v_wagbb = l_v_wagbb + <fs_s031_opn>-wagbb.
ENDLOOP.
i_opn-rec_pc = ABS( l_mzubb_pc - l_magbb_pc ).
i_opn-rec_sqm = ABS( l_mzubb_sqm - l_magbb_sqm ).
i_opn-rec_na = ABS( l_mzubb_na - l_magbb_na ).

i_opn-rec_cbm = ABS( l_mzubb_cbm - l_magbb_cbm ).


i_opn-mzubb = ABS( l_v_mzubb - l_v_magbb ).
i_opn-wzubb = l_v_wzubb - l_v_wagbb.
CLEAR: l_mzubb_pc,
l_mzubb_sqm,
l_mzubb_na,
l_mzubb_cbm,
l_magbb_pc,
l_magbb_sqm,
l_magbb_na,
l_magbb_cbm,
l_v_wzubb,
l_v_wagbb,
l_v_mzubb,
l_v_magbb.
LOOP AT i_s031_opnt ASSIGNING <fs_s031_opn> WHERE
matnr = i_opn-matnr and werks = i_opn-werks.
" Plant add by chandan
l_mzubb_pc = l_mzubb_pc + <fs_s031_opn>-mzubb_pc.
l_mzubb_sqm = l_mzubb_sqm + <fs_s031_opn>-mzubb_sqm.
l_mzubb_na = l_mzubb_na + <fs_s031_opn>-mzubb_na.
l_mzubb_cbm = l_mzubb_cbm + <fs_s031_opn>-mzubb_cbm.
l_magbb_pc = l_magbb_pc + <fs_s031_opn>-magbb_pc.
l_magbb_sqm = l_magbb_sqm + <fs_s031_opn>-magbb_sqm.
l_magbb_na = l_magbb_na + <fs_s031_opn>-magbb_na.
l_magbb_cbm = l_magbb_cbm + <fs_s031_opn>-magbb_cbm.
l_v_mzubb = l_v_mzubb + <fs_s031_opn>-mzubb.
l_v_magbb = l_v_magbb + <fs_s031_opn>-magbb.
ENDLOOP.
i_opn-tr_pc = ABS( l_mzubb_pc - l_magbb_pc ).
i_opn-tr_sqm = ABS( l_mzubb_sqm - l_magbb_sqm ).
i_opn-tr_na = ABS( l_mzubb_na - l_magbb_na ).
i_opn-tr_cbm = ABS( l_mzubb_cbm - l_magbb_cbm ).
i_opn-trqty = ABS( l_v_mzubb - l_v_magbb ).
CLEAR: l_mzubb_pc,
l_mzubb_sqm,
l_mzubb_na,
l_mzubb_cbm,
l_magbb_pc,
l_magbb_sqm,
l_magbb_na,
l_magbb_cbm,
l_v_wzubb,

l_v_wagbb,
l_v_mzubb,
l_v_magbb.
i_opn-mzubb = i_opn-mzubb - i_opn-trqty.
********************************************************
i_opn-rec_pc = i_opn-rec_pc - i_opn-tr_pc.
i_opn-rec_sqm = i_opn-rec_sqm - i_opn-tr_sqm.
i_opn-rec_na = i_opn-rec_na - i_opn-tr_na.
i_opn-rec_cbm = i_opn-rec_cbm - i_opn-tr_cbm.
********************************************************
*Total Quantity
i_opn-totqty = i_opn-mzubb + i_opn-trqty.
********************************************************
i_opn-tot_pc = i_opn-rec_pc + i_opn-tr_pc.
i_opn-tot_sqm = i_opn-rec_sqm + i_opn-tr_sqm.
i_opn-tot_na = i_opn-rec_na + i_opn-tr_na.
i_opn-tot_cbm = i_opn-rec_cbm + i_opn-tr_cbm.
********************************************************
*Total Value
i_opn-totval = i_opn-wzubb + i_opn-trval.
IF i_opn-totqty IS NOT INITIAL.
l_mov_pr = ( i_opn-totval / i_opn-totqty ).
ENDIF.
CLEAR: i_opn-wzubb,
i_opn-trval.
i_opn-wzubb = i_opn-mzubb * l_mov_pr.
i_opn-trval = i_opn-trqty * l_mov_pr.
APPEND i_opn.
CLEAR : i_marc,
i_opn.
CLEAR l_mov_pr.
ENDLOOP.

New Code
Highlighted in Yellow section contain Parallel cursor method.
LOOP AT i_marc.
*Plant

i_opn-werks = i_marc-werks.
READ TABLE i_plnam WITH KEY werks = i_marc-werks
BINARY SEARCH.
IF sy-subrc = 0.
*Plant Name
i_opn-spl_name = i_plnam-name.
CLEAR i_plnam.
ENDIF.
*Material Code
i_opn-matnr = i_marc-matnr.
*Material Description
READ TABLE i_makt WITH KEY

matnr = i_marc-matnr
BINARY SEARCH.

IF sy-subrc = 0.
i_opn-maktx = i_makt-maktx.
CLEAR i_makt.
ENDIF.
*Material Valuation Class
READ TABLE i_mbew WITH KEY matnr = i_marc-matnr
BINARY SEARCH.
IF sy-subrc = 0.
i_opn-bklas = i_mbew-bklas.
CLEAR i_mbew.
ENDIF.
*Material Division
READ TABLE i_a_mara WITH KEY matnr = i_marc-matnr
BINARY SEARCH.
IF sy-subrc = 0.
i_opn-spart = i_a_mara-spart.
i_opn-meins = i_a_mara-meins.
*Material Division Text
READ TABLE i_tspat WITH KEY spart = i_a_mara-spart
BINARY SEARCH.
IF sy-subrc = 0.
i_opn-vtaxt = i_tspat-vtaxt.
CLEAR i_tspat.
ENDIF.
CLEAR i_a_mara.
ENDIF.
********
Start of changes Shreedhar 1/4/2016
Replacing loop using para
llel cursor *****
*********************************************************************
*
LOOP AT i_s031_opn ASSIGNING <fs_s031_opn> WHERE
*
matnr = i_opn-matnr and werks = i_opn-

werks. " plant add by chandan


READ TABLE i_s031_opn TRANSPORTING NO FIELDS
WITH KEY matnr = i_opn-matnr
werks = i_opn-werks
BINARY SEARCH.
IF sy-subrc = 0 .
* Get the TABIX number
lv_tabix = sy-tabix.
ENDIF.

* Start the LOOP from the first accessed record in


* previous READ i.e. LV_TABIX
IF lv_tabix is not INITIAL.

LOOP AT i_s031_opn FROM lv_tabix ASSIGNING <fs_s031_opn>.


*

End the LOOP, when there is no more record with similar key
IF <fs_s031_opn>-matnr <> i_opn-matnr
OR <fs_s031_opn>-werks <> i_opn-werks.
EXIT.
ENDIF.
********
End of changes Shreedhar 1/4/2016
Replacing loop using parall
el cursor *****
l_mzubb_pc = l_mzubb_pc + <fs_s031_opn>-mzubb_pc.
l_mzubb_sqm = l_mzubb_sqm + <fs_s031_opn>-mzubb_sqm.
l_mzubb_na = l_mzubb_na + <fs_s031_opn>-mzubb_na.
l_mzubb_cbm = l_mzubb_cbm + <fs_s031_opn>-mzubb_cbm.
l_magbb_pc = l_magbb_pc +
l_magbb_sqm = l_magbb_sqm
l_magbb_na = l_magbb_na +
l_magbb_cbm = l_magbb_cbm

<fs_s031_opn>-magbb_pc.
+ <fs_s031_opn>-magbb_sqm.
<fs_s031_opn>-magbb_na.
+ <fs_s031_opn>-magbb_cbm.

l_v_mzubb = l_v_mzubb + <fs_s031_opn>-mzubb.


l_v_magbb = l_v_magbb + <fs_s031_opn>-magbb.
l_v_wzubb = l_v_wzubb + <fs_s031_opn>-wzubb.
l_v_wagbb = l_v_wagbb + <fs_s031_opn>-wagbb.
ENDLOOP.
ENDIF.
i_opn-rec_pc = abs( l_mzubb_pc - l_magbb_pc ).
i_opn-rec_sqm = abs( l_mzubb_sqm - l_magbb_sqm ).
i_opn-rec_na = abs( l_mzubb_na - l_magbb_na ).
i_opn-rec_cbm = abs( l_mzubb_cbm - l_magbb_cbm ).

i_opn-mzubb = abs( l_v_mzubb - l_v_magbb ).


i_opn-wzubb = l_v_wzubb - l_v_wagbb.
CLEAR: l_mzubb_pc,
l_mzubb_sqm,
l_mzubb_na,
l_mzubb_cbm,
l_magbb_pc,
l_magbb_sqm,
l_magbb_na,
l_magbb_cbm,
l_v_wzubb,
l_v_wagbb,
l_v_mzubb,
l_v_magbb.

********
Start of changes Shreedhar 1/4/2016
llel cursor *****
CLEAR lv_tabix.

Replacing loop using para

*
LOOP AT i_s031_opnt ASSIGNING <fs_s031_opn> WHERE
*
matnr = i_opn-matnr and werks = i_opnwerks. " Plant add by chandan
READ TABLE i_s031_opnt TRANSPORTING NO FIELDS
WITH KEY matnr = i_opn-matnr
werks = i_opn-werks
BINARY SEARCH.
IF sy-subrc = 0 .
* Get the TABIX number
lv_tabix = sy-tabix.
ENDIF.
* Start the LOOP from the first accessed record in
* previous READ i.e. LV_TABIX
IF lv_tabix is not INITIAL.

LOOP AT i_s031_opnt FROM lv_tabix ASSIGNING <fs_s031_opn>.


*

End the LOOP, when there is no more record with similar key
IF <fs_s031_opn>-matnr <> i_opn-matnr
OR <fs_s031_opn>-werks <> i_opn-werks.
EXIT.
ENDIF.
********
End of changes Shreedhar 1/4/2016
Replacing loop using parall
el cursor *****

l_mzubb_pc = l_mzubb_pc +
l_mzubb_sqm = l_mzubb_sqm
l_mzubb_na = l_mzubb_na +
l_mzubb_cbm = l_mzubb_cbm

<fs_s031_opn>-mzubb_pc.
+ <fs_s031_opn>-mzubb_sqm.
<fs_s031_opn>-mzubb_na.
+ <fs_s031_opn>-mzubb_cbm.

l_magbb_pc = l_magbb_pc +
l_magbb_sqm = l_magbb_sqm
l_magbb_na = l_magbb_na +
l_magbb_cbm = l_magbb_cbm

<fs_s031_opn>-magbb_pc.
+ <fs_s031_opn>-magbb_sqm.
<fs_s031_opn>-magbb_na.
+ <fs_s031_opn>-magbb_cbm.

l_v_mzubb = l_v_mzubb + <fs_s031_opn>-mzubb.


l_v_magbb = l_v_magbb + <fs_s031_opn>-magbb.
ENDLOOP.
ENDIF.
CLEAR lv_tabix.
" Shreedhar 1/4/2016
i_opn-tr_pc = abs( l_mzubb_pc - l_magbb_pc ).
i_opn-tr_sqm = abs( l_mzubb_sqm - l_magbb_sqm ).
i_opn-tr_na = abs( l_mzubb_na - l_magbb_na ).
i_opn-tr_cbm = abs( l_mzubb_cbm - l_magbb_cbm ).
i_opn-trqty = abs( l_v_mzubb - l_v_magbb ).
CLEAR: l_mzubb_pc,
l_mzubb_sqm,
l_mzubb_na,
l_mzubb_cbm,
l_magbb_pc,
l_magbb_sqm,
l_magbb_na,
l_magbb_cbm,
l_v_wzubb,
l_v_wagbb,
l_v_mzubb,
l_v_magbb.

i_opn-mzubb = i_opn-mzubb - i_opn-trqty.


********************************************************
i_opn-rec_pc = i_opn-rec_pc - i_opn-tr_pc.
i_opn-rec_sqm = i_opn-rec_sqm - i_opn-tr_sqm.
i_opn-rec_na = i_opn-rec_na - i_opn-tr_na.
i_opn-rec_cbm = i_opn-rec_cbm - i_opn-tr_cbm.
********************************************************

*Total Quantity
i_opn-totqty = i_opn-mzubb + i_opn-trqty.
********************************************************

i_opn-tot_pc = i_opn-rec_pc + i_opn-tr_pc.


i_opn-tot_sqm = i_opn-rec_sqm + i_opn-tr_sqm.
i_opn-tot_na = i_opn-rec_na + i_opn-tr_na.
i_opn-tot_cbm = i_opn-rec_cbm + i_opn-tr_cbm.
********************************************************
*Total Value
i_opn-totval = i_opn-wzubb + i_opn-trval.
IF i_opn-totqty IS NOT INITIAL.
l_mov_pr = ( i_opn-totval / i_opn-totqty ).
ENDIF.
CLEAR: i_opn-wzubb,
i_opn-trval.
i_opn-wzubb = i_opn-mzubb * l_mov_pr.
i_opn-trval = i_opn-trqty * l_mov_pr.

APPEND i_opn.
CLEAR : i_marc,
i_opn.
CLEAR l_mov_pr.
ENDLOOP.

You might also like