‎2008 Jul 10 12:07 PM
Experts kindly give suggestions on performance tuning of the
follows code.greatful for all the replys
DATA: BEGIN OF itab_mara OCCURS 0 ,
matnr LIKE mara-matnr,
mvgr3 LIKE mvke-mvgr3,
mabst LIKE marc-mabst,
minbe LIKE marc-minbe,
trame LIKE marc-trame,
werks LIKE marc-werks,
END OF itab_mara.
DATA: BEGIN OF itab_pbim OCCURS 0,
matnr LIKE pbim-matnr,
mvgr3 LIKE mvke-mvgr3,
werks LIKE pbim-werks,
bdzei LIKE pbim-bdzei.
DATA END OF itab_pbim.
DATA:BEGIN OF itab_pbed OCCURS 0,
pdatu LIKE pbed-pdatu,
bdzei LIKE pbed-bdzei,
matnr LIKE pbim-matnr,
mvgr3 LIKE mvke-mvgr3,
werks LIKE pbim-werks,
plnmg LIKE pbed-plnmg,
END OF itab_pbed.
DATA : itab_pbed_tmp LIKE itab_pbed OCCURS 1 WITH HEADER LINE.
SELECT amatnr bmvgr3 cwerks cminbe cmabst ctrame
INTO CORRESPONDING FIELDS OF TABLE itab_mara
FROM mara AS a
INNER JOIN mvke AS b ON mmatnr = bmatnr
INNER JOIN marc AS c ON mmatnr = cmatnr
WHERE a~matnr IN matnr
AND b~mvgr3 IN mvgr3
AND b~vkorg EQ 'IN01'
AND b~vtweg EQ 'AT'
AND c~werks IN plant
AND a~mtart EQ 'ZFRT'.
SORT itab_mara BY matnr werks.
DELETE ADJACENT DUPLICATES FROM itab_mara .
LOOP AT itab_mara .
PERFORM getdata.
FORM getdata.
SELECT matnr werks bdzei
FROM pbim
INTO (pbim-matnr , pbim-werks , pbim-bdzei)
WHERE matnr = itab_mara-matnr
AND werks = itab_mara-werks.
READ TABLE itab_pbim WITH KEY matnr = pbim-matnr werks = pbim-werks.
IF sy-subrc = 0.
IF pbim-bdzei GT itab_pbim-bdzei.
DELETE itab_pbim INDEX sy-tabix.
itab_pbim-matnr = pbim-matnr.
itab_pbim-mvgr3 = itab_mara-mvgr3.
itab_pbim-werks = pbim-werks.
itab_pbim-bdzei = pbim-bdzei.
APPEND itab_pbim.
ENDIF.
ELSE.
itab_pbim-matnr = pbim-matnr.
itab_pbim-mvgr3 = itab_mara-mvgr3.
itab_pbim-werks = pbim-werks.
itab_pbim-bdzei = pbim-bdzei.
APPEND it_pbim.
ENDIF.
ENDSELECT.
CLEAR lv_lines .
DESCRIBE TABLE itab_pbim LINES lv_lines.
IF lv_lines GT 0.
SELECT plnmg pdatu bdzei
INTO CORRESPONDING FIELDS OF TABLE itab_pbed_tmp
FROM pbed
FOR ALL ENTRIES IN itab_pbim
WHERE bdzei = itab_pbim-bdzei.
LOOP AT itab_pbed_tmp.
IF sy-datum+6(2) = 01.
c_date = sy-datum+0(6) - 1.
ELSE.
c_date = sy-datum+0(6).
ENDIF.
IF itab_pbed_tmp-pdatu+0(6) = c_date.
READ TABLE itab_pbim WITH KEY bdzei = itab_pbed_tmp-bdzei .
IF sy-subrc = 0 .
MOVE-CORRESPONDING it_pbed_tmp TO it_pbed.
itab_pbed-matnr = itab_pbim-matnr.
itab_pbed-mvgr3 = itab_pbim-mvgr3.
itab_pbed-werks = itab_pbim-werks.
COLLECT itab_pbed. CLEAR itab_pbed.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
endform.
‎2008 Jul 10 12:10 PM
HI madan,
1) Remove into corresponiding .
2) use read table with binary search ,
before the read table sort table with key in ascending order.
3) instead of move corresponding use idvidual field move.
4) instead of join you can use for all entries.
regards,
sandeep
Edited by: Sandeep patel on Jul 10, 2008 4:42 PM
Edited by: Sandeep patel on Jul 10, 2008 4:44 PM
Edited by: Sandeep patel on Jul 10, 2008 4:51 PM
‎2008 Jul 10 12:08 PM
‎2008 Jul 10 12:10 PM
HI madan,
1) Remove into corresponiding .
2) use read table with binary search ,
before the read table sort table with key in ascending order.
3) instead of move corresponding use idvidual field move.
4) instead of join you can use for all entries.
regards,
sandeep
Edited by: Sandeep patel on Jul 10, 2008 4:42 PM
Edited by: Sandeep patel on Jul 10, 2008 4:44 PM
Edited by: Sandeep patel on Jul 10, 2008 4:51 PM
‎2008 Jul 10 12:12 PM
SORT itab_mara BY matnr werks.
DELETE ADJACENT DUPLICATES FROM itab_mara comparing matnr werks.
LOOP AT itab_mara .
PERFORM getdata.
endloop.
FORM getdata.
Remove (select.. endselect) select from this perform .. as UR
calling this form in loop.. endloop ..
endform.
‎2008 Jul 10 12:15 PM
Hi Madan
Try to do following things :
1. Use seprate field move instead of Move-Corresponding.
2. Do not use into correposding.
3. sort your table.
Hope this will help you.
With Regards
Nikunj Shah
‎2008 Jul 10 12:16 PM
The structuring of program in the page is not clear. But based on my understanding,
1) Are you using SELECT pbim inside LOOP ? Dont do that . Just create internal table gt_pbim and populate the data into that internal table. then use READ gt_pbim inside perform getdata.
2) Also avoid SELECT..ENDSELECT for PBIM fetch. Use a FOR ALL ENTRIES as follows
SELECT matnr werks bdzei
FROM pbim
into table gt_pbim
for all entries in itab_mara
where matnr = itab_mara-matnr
AND werks = itab_mara-werks.
this is a good form of usage.
Hope this helps
Cheers
Kothand
‎2008 Jul 10 12:17 PM
Hi,
1.First avoid join in select statment.
2.Avoid to use Perform get_data within loop.
3. Avoid to use select, endselect.
4.Instead of move-corresponding try to use move fields1 to fields2.
Regards
Prabhhu
‎2008 Jul 10 12:19 PM
Hi madan,
Instead of using so multiple joins, i would suggest you to use views and read the table with binary search.This would enhance the data retrieval..
Best of luck,
Bhumika
‎2008 Jul 10 12:19 PM
LOOP AT itab_mara .
PERFORM getdata.
FORM getdata.
SELECT matnr werks bdzei
FROM pbim
INTO (pbim-matnr , pbim-werks , pbim-bdzei)
WHERE matnr = itab_mara-matnr
AND werks = itab_mara-werks.
This one will make a huge difference. You should never use select statements inside loop if there is one single other way.
1) Here you can do a for all entries selection on pbim based on itab. Get all the results in an internal table with the three fields (pbim-matnr , pbim-werks , pbim-bdzei).then loop at this internal table to perform the statements that you have written inside the select endselect. select inside loop is definitely having a hude impact
2) sort the internal tables and use binary search for all the read statements that u make using the sort keys.
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Jul 10, 2008 4:12 PM
‎2008 Jul 10 12:22 PM
Hi,
You can use FOR ALL ENTRIES instead of JOIN.
Don't use INTO CORRESPONDING FIELDS OF TABLE,
use INTO TABLE.
Instead of SELECT within a LOOP you can use FOR ALL ENTRIES .
Don't use SELECT within a LOOP and ENDLOOP .
Regards,
Rajitha.
‎2008 Jul 10 12:23 PM
Hi Madan,
a) first check whether the table on which you are using for all
entries is initial or not. If it is not initial, then go for 'For all entries'.
b) Don't use 'Corresponding fields', instead try to fill individual
fields.
c) Go for 'for all entries' instead of Joins.
Check this wonderful link on Performance Tuninig, in which you have all the options of how you can tune your program:
http://www.sapbrainsonline.com/ARTICLES/TECHNICAL/optimization/optimization.html
Hope this helps yoou.
Regards,
Chandra Sekhar
Edited by: Chandrasekhar Gandla on Jul 10, 2008 1:23 PM
‎2008 Jul 10 6:02 PM