Skip to Content
0
Former Member
Jul 23, 2007 at 08:30 AM

experts try to modify the code .

39 Views

experts try to modify the code to increase performance. It is very difficult to alter this code ie removing select inside the loop etc. I hope someone is there to prove that they r expert

tables: zmtp, mkpf, mseg, mast, lfa1. “ztemp has lifnr, matnr,kbetr

data: begin of sk_data occurs 0,

matnr like mseg-matnr, "1

idnrk like stpo-idnrk, "2

kbetr like zmtp-kbetr, "3

menge like mseg-menge, "4

compu like mseg-menge, "5

alqty like mseg-menge, "6

scqty like mseg-menge, "7

chqty like mseg-menge, "8

lifnr like lfa1-lifnr, "9

bomus like mseg-menge, "bom usage

rsq like mseg-menge, "real scrap qty

end of sk_data.

data: t_data like table of sk_data with header line.

parameters: p_werks like t001w-werks obligatory memory id wer,

p_lifnr like lfa1-lifnr obligatory memory id lif.

select-options: s_budat for mkpf-budat.

start-of-selection.

perform get_data.

perform display.

top-of-page.

perform top.

form get_data .

data: lt_stb like stpox occurs 0 with header line.

data: begin of lt_we occurs 0,

mblnr like mkpf-mblnr,

end of lt_we.

data: lt_wo like table of lt_we with header line.

data: lt_wa like table of lt_we with header line.

data: lt_121 like table of lt_we with header line.

data: begin of lt_menge occurs 0,

mblnr like mseg-mblnr,

matnr like mseg-matnr,

bwart like mseg-bwart,

menge like mseg-menge,

end of lt_menge.

select mblnr into table lt_we

from mkpf

where budat in s_budat

and vgart = 'WE'.

select mblnr into table lt_wo

from mkpf

where budat in s_budat

and vgart = 'WO'.

select lifnr matnr kbetr

into corresponding fields of table t_data

from zmtp

where lifnr = p_lifnr.

select single * from lfa1

where lifnr = p_lifnr.

loop at t_data

if not lt_we[] is initial.

select mblnr matnr bwart menge into table lt_menge

from mseg

for all entries in lt_we

where mblnr = lt_we-mblnr

and matnr = t_data-matnr

and werks = p_werks

and bwart in ('101', '102').

loop at lt_menge.

if lt_menge-bwart = '102'.

lt_menge-menge = - lt_menge-menge.

endif.

t_data-menge =t_data-menge + lt_menge-menge.

endloop.

modify t_data.

endif.

if not lt_wo[] is initial.

select mblnr into table lt_121

from mseg

for all entries in lt_wo

where mblnr = lt_wo-mblnr

and matnr = t_data-matnr

and werks = p_werks

and bwart = '121'.

if not lt_121[] is initial.

select mblnr matnr bwart menge into table lt_menge

from mseg

for all entries in lt_121

where mblnr = lt_121-mblnr

and bwart in ('543', '544').

loop at lt_menge.

if lt_menge-bwart = '544'.

lt_menge-menge = - lt_menge-menge.

endif.

t_data-rsq = t_data-rsq + lt_menge-menge.

endloop.

modify t_data.

endif.

endif.

endloop.

loop at t_data.

select single stlnr into mast-stlnr

from mast

where matnr = t_data-matnr

and stlan = '1'

and werks = p_werks.

if sy-subrc = 0.

select single stlal into stko-stlal

from stko

where stlnr = mast-stlnr

and stlty = 'M'

and stlst <> '02'

and datuv <= sy-datum.

call function 'CS_BOM_EXPL_MAT_V2'

exporting

capid = 'PP01'

datuv = sy-datum

mtnrv = t_data-matnr

stlal = stko-stlal

stlan = '1'

werks = p_werks

tables

stb = lt_stb

exceptions

alt_not_found = 1

call_invalid = 2

material_not_found = 3

missing_authorization = 4

no_bom_found = 5

no_plant_data = 6

no_suitable_bom_found = 7

conversion_error = 8

others = 9.

loop at lt_stb.

if lt_stb-menge > 0.

sk_data = t_data.

sk_data-idnrk = lt_stb-idnrk.

sk_data-bomus = lt_stb-menge.

sk_data-compu = sk_data-menge * sk_data-bomus.

sk_data-alqty = sk_data-compu * sk_data-kbetr / 100. "

if not lt_wa[] is initial.

select mblnr matnr bwart menge into table lt_menge

from mseg

for all entries in lt_wa

where mblnr = lt_wa-mblnr

and matnr = sk_data-idnrk

and werks = p_werks

and bwart in ('551', '552').

loop at lt_menge.

if lt_menge-bwart = '552'.

lt_menge-menge = - lt_menge-menge.

endif.

sk_data-rsq = sk_data-rsq + lt_menge-menge.

endloop.

endif.

sk_data-scqty = sk_data-rsq.

sk_data-chqty =sk_data-scqty - sk_data-alqty.

append sk_data.

endif.

endloop.

else.

sk_data = t_data.

append sk_data.

endif.

endloop.

sort sk_data by matnr idnrk.

endform. " get_data