Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How I can Improvement this code?

ronaldo_aparecido
Contributor
0 Likes
1,580

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

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
1,534

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

14 REPLIES 14
Read only

Former Member
0 Likes
1,534

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..

Read only

matt
Active Contributor
0 Likes
1,534

Binary search. Why do we always hear that?

Hey guys - HASHED and SORTED tables! They've only been around for 15 years!

Read only

0 Likes
1,534

I just used Ron's statements of read table for some missing important code related to read table. 

Read only

Former Member
0 Likes
1,534

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

Read only

Tomas_Buryanek
Product and Topic Expert
Product and Topic Expert
0 Likes
1,534

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 🙂

-- Tomas --
Read only

hemanth_kumar21
Contributor
0 Likes
1,534

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.

Read only

0 Likes
1,534

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.

Read only

0 Likes
1,534

Correct Chandra.

Read only

0 Likes
1,534

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.

Read only

ThomasZloch
Active Contributor
0 Likes
1,535

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

Read only

0 Likes
1,534

Hi  Mr Thomas

I have a runtime issue.

Read only

0 Likes
1,534

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

Read only

0 Likes
1,534

Thanks Guys and Thanks Mr thomas your links are very ,very goog . iam learn much about SAT .

Read only

Former Member
0 Likes
1,534

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