10-15-2006 10:35 AM
Hi Eswar,
could anyone check my code below and suggest the changes for it interms of performance wise and also the pattern of writting the code. i want to cross check my code before i go for testing
thanks in adance.
form checkdata.
data: wrecord type i.
data:
begin of tmpkey,
mandt like sy-mandt,
wmblnr like mseg-mblnr, "Material Document Number
wmjahr like mseg-mjahr, "Material Document Year
wzeile like mseg-zeile, "Item in Material Document
end of tmpkey.
select * from z4b2 into table t_z4b2.
describe table msegtbl lines wrecord.
if wrecord > 0.
loop at msegtbl.
clear tmpkey.
move sy-mandt to tmpkey-mandt.
move msegtbl-wmblnr to tmpkey-wmblnr.
move msegtbl-wmjahr to tmpkey-wmjahr.
move msegtbl-wzeile to tmpkey-wzeile.
read table t_z4b2 with key tmpkey.
if sy-subrc = 0.
delete msegtbl.
endif.
endloop.
endif.
endform. "CheckDat
********************
form getibminfo.
data: wrecord type i.
describe table msegtbl lines wrecord.
if wrecord > 0.
loop at msegtbl.
refresh: t_val_tab.
call function 'QC01_BATCH_VALUES_READ'
EXPORTING
i_val_matnr = msegtbl-wmatnr
i_val_werks = msegtbl-wwerks
i_val_charge = msegtbl-wcharg
TABLES
t_val_tab = t_val_tab
EXCEPTIONS
no_class
internal_error
no_values
no_chars.
if sy-subrc = 0.
read table t_val_tab with key atnam = 'SUBLOTTYPE'.
if sy-subrc = 0.
if t_val_tab-atwrt eq sublottype.
move msegtbl to 4b2tbl.
append 4b2tbl.
clear 4b2tbl.
endif.
endif.
endif.
endloop.
endif.
refresh mkpftbl.
refresh msegtbl.
endform. "GetIBMInfo
*&----
*& Form GetSeqNo
*&----
form getseqno.
data: wcount(6) type n.
data: wrecord(6) type n.
describe table t_z4b2 lines wrecord.
read table t_z4b2 index wrecord.
write t_z4b2-wseqno+5(6) to wrecord.
wrecord = wrecord + 1.
describe table 4b2tbl lines wcount.
if wcount > 0.
loop at 4b2tbl.
at new wmblnr. wrecord = wrecord + 1. endat.
concatenate preatsg wrecord into 4b2tbl-wseqno.
modify 4b2tbl.
move 4b2tbl to z4b2.
insert z4b2.
clear 4b2tbl.
clear z4b2.
endloop.
endif.
endform. "GetSeqNo
&----
*& Form PutInfo
&----
form putinfo.
data: wrecord type i.
data: dtmp1(10) type c.
data: dtmp2(8) type c.
data: ttmp1(8) type c.
data: ttmp2(6) type c.
describe table 4b2tbl lines wrecord.
if wrecord > 0.
loop at 4b2tbl.
write 4b2tbl-wbldat to dtmp1.
concatenate dtmp16(4) dtmp1(2) dtmp13(2) into dtmp2.
write 4b2tbl-wbldat to ttmp1.
concatenate ttmp10(2) ttmp13(2) ttmp1+6(2) into ttmp2.
concatenate dtmp2 'T' ttmp2 '.000Z' into datetime.
at new wmblnr.
refresh wlines.
perform writeline1.
perform writeline2_1.
endat.
perform writeline2_2.
w_seqno = 4b2tbl-wseqno.
at end of wmblnr.
perform writeline2_3.
perform writeline3.
perform writefile.
endat.
endloop.
endif.
endform. "PutInfo
10-15-2006 7:24 PM
To do the delete correctly, you will need to use an index. Your read will go more quickly if you use a binary search:
<b>data tab_index like sy-tabix.</b>
select * from z4b2 into table t_z4b2.
<b>SORT t_z4b2 BY tmpkey.</b>
describe table msegtbl lines wrecord.
if wrecord > 0.
loop at msegtbl.
<b> tab_index = sy-tabix.</b>
clear tmpkey.
move sy-mandt to tmpkey-mandt.
move msegtbl-wmblnr to tmpkey-wmblnr.
move msegtbl-wmjahr to tmpkey-wmjahr.
move msegtbl-wzeile to tmpkey-wzeile.
read table t_z4b2
with key tmpkey
<b> BINARY SEARCH.</b>
if sy-subrc = 0.
delete msegtbl
<b> index tab_index.</b>
endif.
endloop.
endif.
Test thoroughly - I haven't done a syntax check on this.
Also - this should probably have been posted on the performance tuning forum.
OK - I see that you <b>did</b> post this in the performance tuning forum as well as this one. In the future, please pick one forum. I'd rather not spend time thinking about a problem only to find that it's already been solved.
Rob
Message was edited by: Rob Burbank
10-15-2006 10:43 AM
data : t_z4b2 type sorted table z4b2 with non-unique key wmblnr wmjahr wzeile.
select wmblnr wmjahr wzeile into corresponding fields of table t_z4b2.
if not msegtbl is initial.
loop at msegtbl assigning <l_msegtbl>.
read table t_z4b2 assigning <l_z4b2>
with table key wmblnr = <l_z4b2>-wmblnr
wmjahr = <l_z4b2>-wmjahr
wzeile = <l_z4b2>-wzeile.
if sy-subrc = 0.
delete msegtbl.
endif.
endloop.
endif.
endform. "CheckDat
********************
form getibminfo.
data: wrecord type i.
dat : tl_val_tab_temp sort by wmatnr wwerks wcharg.
tl_val_tab sort by atnam.
if not msegtbl is initial.
loop at msegtbl assigning <l_msegtbl>.
read table tl_val_tab_temp assigning <l_val_tab> with table key
wmatnr = <l_msegtbl>-wmatnr
wwerks = <l_msegtbl>-wwerks
wcharg = <l_msegtbl>-wcharg.
if sy-subrc <> 0.
refresh: t_val_tab.
call function 'QC01_BATCH_VALUES_READ'
EXPORTING
i_val_matnr = <l_msegtbl>-wmatnr
i_val_werks = <l_msegtbl>-wwerks
i_val_charge = <l_msegtbl>-wcharg
TABLES
t_val_tab = t_val_tab
EXCEPTIONS
no_class
internal_error
no_values
no_chars.
endif.
if sy-subrc = 0.
insert lines of t_val_tab into table tl_val_tab.
insert lines of t_val_tab into table tl_val_tab_temp.
read table tl_val_tab assigning <l_val_tab> with table key atnam = 'SUBLOTTYPE'.
if sy-subrc = 0.
if <l_val_tab>-atwrt eq sublottype.
move msegtbl to wa_4b2tbl.
append wa_4b2tbl to 4b2tbl.
clear wa_4b2tbl.
endif.
endif.
endif.
endloop.
endif.
refresh mkpftbl.
refresh msegtbl.
free : tl_val_tab,tl_val_tab_temp.
endform. "GetIBMInfo
*&----
*& Form GetSeqNo
*&----
form getseqno.
data: wcount(6) type n.
data: wrecord(6) type n.
describe table t_z4b2 lines wrecord.
read table t_z4b2 index wrecord.
write t_z4b2-wseqno+5(6) to wrecord.
wrecord = wrecord + 1.
if not 4b2tbl is initial.
loop at 4b2tbl assigning <l_4b2tbl>.
at new wmblnr. wrecord = wrecord + 1. endat.
concatenate preatsg wrecord into <l_4b2tbl>-wseqno.
move 4b2tbl to z4b2.
insert z4b2.
clear 4b2tbl.
clear z4b2.
endloop.
endif.
endform. "GetSeqNo
&----
*& Form PutInfo
&----
form putinfo.
data: wrecord type i.
data: dtmp1(10) type c.
data: dtmp2(8) type c.
data: ttmp1(8) type c.
data: ttmp2(6) type c.
if not 4b2tbl is initial.
loop at 4b2tbl.
write 4b2tbl-wbldat to dtmp1.
concatenate dtmp16(4) dtmp1(2) dtmp13(2) into dtmp2.
write 4b2tbl-wbldat to ttmp1.
concatenate ttmp10(2) ttmp13(2) ttmp1+6(2) into ttmp2.
concatenate dtmp2 'T' ttmp2 '.000Z' into datetime.
at new wmblnr.
refresh wlines.
perform writeline1.
perform writeline2_1.
endat.
perform writeline2_2.
w_seqno = 4b2tbl-wseqno.
at end of wmblnr.
perform writeline2_3.
perform writeline3.
perform writefile.
endat.
endloop.
endif.
endform. "PutInfo
10-15-2006 11:13 AM
Hi Nihi
Please see if you can avoid looping the same internal multiple times. This can cause problem when data is huge.
An example of converting your first two subroutines in one.
form check_get_ibminfo.
select * from z4b2 into table t_z4b2.
sort t_z4b2 by wmblnr wmjahr wzeile.
if not msegtbl[] is initial.
loop at msegtbl.
read table t_z4b2 with key wmblnr = msegtbl-wmblnr
wmjahr = msegtbl-wmjahr
wzeile = msegtbl-wzeile
binary search.
if sy-subrc eq 0.
delete msegtbl.
continue.
endif.
refresh; t_val_tab.
call function 'QC01_BATCH_VALUES_READ'
EXPORTING
i_val_matnr = msegtbl-wmatnr
i_val_werks = msegtbl-wwerks
i_val_charge = msegtbl-wcharg
TABLES
t_val_tab = t_val_tab
EXCEPTIONS
no_class
internal_error
no_values
no_chars.
if sy-subrc = 0.
read table t_val_tab with key atnam = 'SUBLOTTYPE'.
if sy-subrc = 0 and t_val_tab-atwrt eq sublottype.
move msegtbl to 4b2tbl.
append 4b2tbl.
clear 4b2tbl.
endif.
endif.
endloop.
endif.
endform.
I guess this will still serve the purpose. Please check for the same.
Am not on SAP, so please bear incase of any syntax errors.
Kind Regards
Eswar
10-15-2006 7:24 PM
To do the delete correctly, you will need to use an index. Your read will go more quickly if you use a binary search:
<b>data tab_index like sy-tabix.</b>
select * from z4b2 into table t_z4b2.
<b>SORT t_z4b2 BY tmpkey.</b>
describe table msegtbl lines wrecord.
if wrecord > 0.
loop at msegtbl.
<b> tab_index = sy-tabix.</b>
clear tmpkey.
move sy-mandt to tmpkey-mandt.
move msegtbl-wmblnr to tmpkey-wmblnr.
move msegtbl-wmjahr to tmpkey-wmjahr.
move msegtbl-wzeile to tmpkey-wzeile.
read table t_z4b2
with key tmpkey
<b> BINARY SEARCH.</b>
if sy-subrc = 0.
delete msegtbl
<b> index tab_index.</b>
endif.
endloop.
endif.
Test thoroughly - I haven't done a syntax check on this.
Also - this should probably have been posted on the performance tuning forum.
OK - I see that you <b>did</b> post this in the performance tuning forum as well as this one. In the future, please pick one forum. I'd rather not spend time thinking about a problem only to find that it's already been solved.
Rob
Message was edited by: Rob Burbank