‎2013 Nov 15 1:37 PM
Hi gurus how i can improvement this code for better performance?
SORT: t_tab[] BY matnr,
t_mm[] BY ebeln,
t_tab_makt[] BY matnr,
t_tab_mara[] BY matnr.
LOOP AT t_tab INTO e_tab.
READ TABLE t_tab_makt INTO e_tab_makt WITH KEY matnr = e_tab-matnr BINARY SEARCH.
READ TABLE t_tab_mara INTO e_tab_mara WITH KEY matnr = e_tab-matnr BINARY SEARCH.
READ TABLE t_mm_saldo_fixado INTO e_mm WITH KEY ebeln = e_tab-ebeln.
IF sy-subrc = 0.
e_tela-ktwrt = e_mm-ktwrt.
e_tela-zzwmwst = e_mm-saldo.
ENDIF.
e_tela-mwskz = e_tab-mwskz.
e_tela-ebeln = e_tab-ebeln.
e_tela-bsart = p_tcont-low.
e_tela-ebelp = e_tab-ebelp.
e_tela-matnr = e_tab-matnr.
e_tela-txz01 = e_tab_makt-maktx.
e_tela-valor = e_tab-netpr.
IF NOT e_tab_mara-bstme IS INITIAL.
e_tela-bstme = e_tab_mara-bstme.
ELSE.
e_tela-bstme = e_tab_mara-meins.
ENDIF.
e_tela-data = sy-datum + 10.
e_tela-waers = e_tab-waers.
e_tela-ekgrp = e_tab-ekgrp.
e_tela-zterm = e_tab-zterm.
e_tela-netpr = e_tab-netpr.
e_tela-ebelp = e_tab-ebelp.
e_tela-ebeln = e_tab-ebeln.
e_tela-peinh = e_tab-peinh.
* Carrega valores com/sem Juros
PERFORM zcarrega_com_sem_jurosmm06 USING e_tela.
IF e_tela-juros_com_sem = c_c.
MOVE: e_tab-zterm_juros TO e_tela-zterm_juros,
e_tab-taxa_juros TO e_tela-taxa_juros.
ENDIF.
IF e_tela-taxa_juros IS INITIAL AND e_tela-juros_com_sem = 'C'.
CONTINUE.
ENDIF.
APPEND e_tela TO t_tela.
ENDLOOP.
*----------------------------------------------------------------------*
* -->P_E_TAB text
*----------------------------------------------------------------------*
FORM zcarrega_com_sem_jurosmm06 USING p_tela TYPE ty_tela.
DATA: l_net_price TYPE bwert,
l_price TYPE bwert,
l_taxcom TYPE taxcom, "#EC NEEDED
l_gross_price TYPE bwert,
l_retorno(3) TYPE c.
DATA: t_xkomv TYPE TABLE OF komv.
CLEAR: l_net_price,l_gross_price,
l_taxcom,t_xkomv[],t_xkomv.
* Verifica se é material com juros
CALL FUNCTION 'ZMMF_VALIDA_MATERIAL_PJ'
EXPORTING
i_matnr = p_tela-matnr
IMPORTING
e_retorno = l_retorno.
IF l_retorno = c_nok.
* Só Material sem juros
p_tela-juros_com_sem = c_s.
ELSE.
* Só Material com juros
p_tela-juros_com_sem = c_c.
IF e_tab-taxa_juros IS INITIAL.
RETURN.
ENDIF.
ENDIF.
MOVE p_tela-netpr TO l_price.
* Efetua calculo
CALL FUNCTION 'Z_NET_PRICE_GROSS'
EXPORTING
i_matnr = p_tela-matnr
i_werks = p_werks
i_mwskz = p_tela-mwskz
i_lifnr = s_lifnr-low
i_valor_sem_pis_cofins = l_price
IMPORTING
e_net_price = l_net_price
e_taxcom = l_taxcom
e_gross_price = l_gross_price
TABLES
t_xkomv = t_xkomv.
* Preço PO s/ Juros ( Liquido - com PIS/Cofins)
p_tela-netpr_sem = l_net_price.
IF p_tela-juros_com_sem = c_s.
RETURN.
ENDIF.
IF NOT l_gross_price IS INITIAL.
* Juros Nominal
p_tela-netpr_juros = ( ( l_gross_price * e_tab-taxa_juros ) / 100 ).
CLEAR: l_net_price,l_gross_price,
l_taxcom,t_xkomv[],t_xkomv.
CLEAR: l_price.
CALL FUNCTION 'Z_NET_PRICE_GROSS'
EXPORTING
i_matnr = p_tela-matnr
i_werks = p_werks
i_mwskz = p_tela-mwskz
i_lifnr = s_lifnr-low
i_valor_sem_pis_cofins = p_tela-netpr_juros
IMPORTING
e_net_price = l_net_price
e_taxcom = l_taxcom
e_gross_price = l_gross_price
TABLES
t_xkomv = t_xkomv.
* Preco final PO = Preço PO original s/ Juros(com pis/cofins) + Juros Efetutivo(com pis/cofins).
p_tela-netpr_com = p_tela-netpr_sem + l_net_price.
ENDIF.
thanks
ENDFORM. " ZCARREGA_COM_SEM_JUROSMM06
‎2013 Nov 15 2:40 PM
Do you actually have a runtime issue or is this just an academic question?
Did you run an ABAP trace to find out where most of the time is spent?
If not, why not?
If yes, please post the results here so everybody can focus on this part instead of guessing around.
Thomas
‎2013 Nov 15 1:45 PM
First of all use the sy-subrc check after each read table and write the other statement related to that inside those only.
READ TABLE t_tab_makt INTO e_tab_makt WITH KEY matnr = e_tab-matnr BINARY SEARCH.
READ TABLE t_tab_mara INTO e_tab_mara WITH KEY matnr = e_tab-matnr BINARY SEARCH.
like..
READ TABLE t_tab_makt INTO e_tab_makt WITH KEY matnr = e_tab-matnr BINARY SEARCH.
if sy-subrc = 0.
e_tela-txz01 = e_tab_makt-maktx.
endif.
same for 2nd Query..
‎2013 Nov 15 2:43 PM
Binary search. Why do we always hear that?
Hey guys - HASHED and SORTED tables! They've only been around for 15 years!
‎2013 Nov 15 2:57 PM
I just used Ron's statements of read table for some missing important code related to read table.
‎2013 Nov 15 1:46 PM
Dear Ronaldo,
I guess your custom FM's are eating up all the time and not this code. This code looks very much aligned and fine.
Kindly copy paste the custom FM coding also to analyse.
Thanks
Rakesh
‎2013 Nov 15 2:40 PM
I dont see any big performance problems neither. It is probably too big LOOP or problem in Zfunctions.
Best way to identify biggest performance "eaters" is to use old SE30 or new SAT transaction, which will measure all parts of execution of your program. After it you can easily find what consumes most time 🙂
‎2013 Nov 15 1:51 PM
Hi Ronaldo Aparecido,
READ TABLE t_tab_makt INTO e_tab_makt WITH KEY matnr = e_tab-matnr BINARY SEARCH.
if sy-subrc eq 0.
e_tela-txz01 = e_tab_makt-maktx.
endif.
READ TABLE t_tab_mara INTO e_tab_mara WITH KEY matnr = e_tab-matnr BINARY SEARCH.
IF NOT e_tab_mara-bstme IS INITIAL.
e_tela-bstme = e_tab_mara-bstme.
ELSE.
e_tela-bstme = e_tab_mara-meins.
ENDIF.
Read statment
->You are sorting the field which you are using in with key.
->read in binary search
In the loop you are using you are using three FM'ZMMF_VALIDA_MATERIAL_PJ', 'Z_NET_PRICE_GROSS', 'Z_NET_PRICE_GROSS' for Gross amount, conversion. Anyway these function modules will execute in a separte memory/instance. So, there wont be a problem in Performance.
‎2013 Nov 15 2:01 PM
Hello Modadugu,
Did you missed using of sy-subrc in second read table. ?
READ TABLE t_tab_mara INTO e_tab_mara WITH KEY matnr = e_tab-matnr BINARY SEARCH.
IF NOT e_tab_mara-bstme IS INITIAL.
e_tela-bstme = e_tab_mara-bstme.
ELSE.
e_tela-bstme = e_tab_mara-meins.
ENDIF.
In this query also we can use the sy-subrc. right..
READ TABLE t_tab_mara INTO e_tab_mara WITH KEY matnr = e_tab-matnr BINARY SEARCH.
if sy-subrc = 0.
IF NOT e_tab_mara-bstme IS INITIAL.
e_tela-bstme = e_tab_mara-bstme.
ELSE.
e_tela-bstme = e_tab_mara-meins.
ENDIF.
else.
clear e_tela-bstme.
endif.
‎2013 Nov 18 5:34 AM
‎2013 Nov 18 1:19 PM
The code of Functions:
FUNCTION zmmf_valida_material_pj.
*"----------------------------------------------------------------------
*"*"Interface local:
*" IMPORTING
*" VALUE(I_MATNR) LIKE MARA-MATNR
*" EXPORTING
*" VALUE(E_RETORNO) TYPE CHAR03
DATA: vl_strlen(2) TYPE n,
vl_matnr TYPE matnr.
* Converte Material
CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT'
EXPORTING
input = i_matnr
IMPORTING
output = vl_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* Verifica a quantidade de caracteres do material.
vl_strlen = strlen( vl_matnr ).
* Verifica se material é novo modelo PJ
IF vl_strlen = '12' AND vl_matnr+11(1) = '7' and vl_matnr(2) <> 'YG'.
* Verifica se o material é do tipo 'ZREV'.
SELECT SINGLE mtart
INTO mara-mtart
FROM mara
WHERE matnr = vl_matnr
AND mtart = 'ZREV'.
IF sy-subrc IS INITIAL.
e_retorno = 'OK'.
ELSE.
e_retorno = 'NOK'.
ENDIF.
ELSE.
e_retorno = 'NOK'.
ENDIF.
‎2013 Nov 15 2:40 PM
Do you actually have a runtime issue or is this just an academic question?
Did you run an ABAP trace to find out where most of the time is spent?
If not, why not?
If yes, please post the results here so everybody can focus on this part instead of guessing around.
Thomas
‎2013 Nov 18 1:19 PM
‎2013 Nov 18 1:56 PM
OK, then please learn to narrow down the problem yourself first e.g. by running an SAT or ST12 trace, there is good documentation available:
It's difficult for somebody else to do it for you on the "green table", we don't have the same data distribution etc., so it usually leads to generic recommendations, which might or might not be relevant to your specific issue.
Thomas
‎2013 Nov 25 3:15 PM
Thanks Guys and Thanks Mr thomas your links are very ,very goog . iam learn much about SAT .
‎2013 Nov 15 3:25 PM
To add to what Thomas said.
Are you having a performance issue on this piece of code?
So it is not in any of the functions that you are calling within the loop?
Regarding internal table operations,I haven't encountered any performance issue on this for at least five years. As long as you are not using obsolete statements (like occurs) and as long as it is easy to read for other developers I don't care that much on optimizing performance.
Loops within loops within loops which then call a FM which reads twenty SAP tables are a different matter altogether.
Kind regards, Rob Dielemans