Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

performance issue!

how do i improve my codes performance?

LOOP AT bestand.

v_matnr1 = bestand-matnr.

PERFORM f2100_mat_text USING bestand-matnr.

FORM F2100_MAT_TEXT

USING L_F_MATNR TYPE STYPE_MAT_KEY-MATNR.

IF L_F_MATNR NE G_S_MAKT-MATNR. "n451923

  • read in table imakt "n451923

READ TABLE G_T_MAKT INTO G_S_MAKT "n451923

WITH KEY MATNR = L_F_MATNR "n451923

BINARY SEARCH. "n451923

"n451923

IF SY-SUBRC <> 0. "n451923

  • record not found "n451923

CLEAR G_S_MAKT-MAKTX. "n451923

ENDIF. "n451923

ENDIF. "n451923

ENDFORM. "f2100_mat_text

-


PERFORM bin USING bestand-matnr CHANGING v_lgpbe.

FORM bin USING p_bestand_matnr

CHANGING p_v_lgpbe.

SELECT SINGLE lgpbe FROM mard INTO p_v_lgpbe

WHERE matnr = p_bestand_matnr AND

werks = p_werks AND

lgort IN lgort.

ENDFORM. "bin

-


PERFORM price USING bestand-matnr CHANGING v_price.

FORM price USING p_bestand_matnr

CHANGING p_v_price.

DATA: wa_mbew TYPE mbew.

SELECT SINGLE * FROM mbew INTO wa_mbew

WHERE matnr = p_bestand_matnr AND

bwkey = p_werks AND

bwtar = ''.

IF wa_mbew-vprsv = 'V'.

p_v_price = wa_mbew-verpr.

ELSEIF wa_mbew-vprsv = 'S'.

p_v_price = wa_mbew-stprs.

ENDIF.

ENDFORM. "price

-


READ TABLE imarc WITH KEY matnr = bestand-matnr .

if imarc-matnr = bestand-matnr.

IF bestand-anfmenge <> '0.000' OR bestand-soll <> '0.000' OR

bestand-haben <> '0.000' OR bestand-endmenge <> '0.000' .

v_anfmenge = bestand-anfmenge.

v_soll = bestand-soll.

v_endmenge = bestand-endmenge .

*Quality Calculation Starts

PERFORM QUA_CALCULATION USING BESTAND-MATNR

CHANGING V_MSEG_SUM Q_QUANTITY.

IF NOT r_budat IS INITIAL.

SELECT mseg~matnr mseg~shkzg mkpf~mblnr

mkpf~mjahr mkpf~budat mseg~insmk

mseg~menge mseg~zeile mseg~bwart

mseg~kostl mseg~anln1 mseg~aufnr

FROM mkpf AS mkpf JOIN mseg AS mseg

ON mkpf~mblnr = mseg~mblnr AND mkpf~mjahr = mseg~mjahr

INTO TABLE i_mkpf_mseg "FOR ALL ENTRIES IN bestand

WHERE mseg~werks IN g_ra_werks AND

mseg~lgort in lgort AND

mseg~matnr = p_matnr AND

mkpf~budat IN r_budat.

if sy-subrc eq 0.

i_new_mkpf_mseg-matnr = p_matnr.

LOOP AT i_mkpf_mseg.

IF i_mkpf_mseg-bwart NE '321' AND i_mkpf_mseg-insmk EQ 'X'

AND i_mkpf_mseg-shkzg = 'S'.

v_mseg_sum1 = v_mseg_sum1 + i_mkpf_mseg-menge.

ELSEIF i_mkpf_mseg-bwart NE '321' AND i_mkpf_mseg-insmk EQ 'X'

AND i_mkpf_mseg-shkzg = 'H'.

v_mseg_sum2 = v_mseg_sum2 + i_mkpf_mseg-menge.

ELSEIF

i_mkpf_mseg-bwart EQ '321' AND i_mkpf_mseg-shkzg = 'H'.

v_mseg_sum3 = v_mseg_sum3 + i_mkpf_mseg-menge.

ENDIF.

AT END OF matnr.

v_mseg_sum = v_mseg_sum1 - v_mseg_sum2 - v_mseg_sum3.

p_v_mseg_sum = v_mseg_sum.

CLEAR: i_mkpf_mseg,i_new_mkpf_mseg,v_mseg_sum1,

v_mseg_sum2,v_mseg_sum3.

ENDAT.

ENDLOOP.

endif.

ENDIF.

  • Selecting Entries from Mardh

  • Even if we don't get data from mseg mkpf we have to pick the entries

  • from mardh and mard.

SELECT * FROM mardh INTO CORRESPONDING

FIELDS OF TABLE i_new_mardh WHERE

matnr = P_MATNR AND werks = p_werks

AND lfgja EQ v_year AND lfmon GE v_month and lgort in lgort.

IF sy-subrc EQ 0.

  • picking the quality for all storage locations ( Without Repeated

  • entrie ) .

LOOP AT i_new_mardh.

v_insme = i_new_mardh-insme.

AT NEW lgort.

i_lgort-lgort = i_new_mardh-lgort.

APPEND i_lgort.

q_quantity = q_quantity + v_insme.

CLEAR v_insme.

CLEAR i_lgort.

ENDAT.

endloop.

CLEAR: i_new_mardh, i_new_mardH[].

endif.

  • 1.Even if we don't get any value from mardh we have to select the

  • entries in mard

  • 2.Selecting Entries from Mard

SELECT * FROM mard INTO CORRESPONDING

FIELDS OF TABLE i_new_mard WHERE

matnr = p_matnr AND werks = p_werks AND

lfgja EQ v_year and lgort in lgort.

if sy-subrc eq 0.

  • picking the quality for all available diff. storage locations

  • except the ones which are there in mardh.

LOOP AT i_lgort.

LOOP AT i_new_mard.

IF i_new_mard-lgort = i_lgort-lgort.

DELETE i_new_mard.

ENDIF.

ENDLOOP.

CLEAR I_NEW_MARD.

ENDLOOP.

LOOP AT i_new_mard .

IF i_new_mard-lfmon LT v_cmonth.

v_insme = i_new_mard-insme.

AT NEW lgort.

q_quantity = q_quantity + v_insme.

CLEAR v_insme.

ENDAT.

ENDIF.

ENDLOOP.

ENDIF.

CLEAR i_lgort.

CLEAR i_lgort[].

p_q_quantity = Q_QUANTITY.

CLEAR: i_new_mard,i_new_mard[].

ENDFORM. " QUA_CALCULATION

-


*Quality Calculation Ends

v_quality = Q_QUANTITY + V_MSEG_SUM.

v_endwert = V_ENDMENGE * V_PRICE.

v_total_quality = v_total_quality + v_quality.

v_unres = v_endmenge - v_quality.

v_total_unres = v_total_unres + v_unres.

v_op_stock_sum = v_op_stock_sum + v_anfmenge.

v_rcvd_sum = v_rcvd_sum + v_soll .

v_issued_sum = v_issued_sum + bestand-haben .

v_bestand-endmenge = v_bestand-endmenge + v_endmenge .

v_cl_stock_sum = v_cl_stock_sum + v_endwert.

-


regards

Essam

essamsaud@yahoo.co.in

Former Member
Not what you were looking for? View more on this topic or Ask a question