10-15-2006 10:05 AM
Hi,
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 10:28 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 10:28 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-16-2006 11:07 AM
Hi,
Please use preety printer which helps a lot in code review !!
Cheers...