cancel
Showing results for 
Search instead for 
Did you mean: 

Regarding Performance tuning issue in following ABAP Code

Former Member
0 Kudos

Hi All,

I have issue regarding <b>Performance Tuning</b> of a program. can any body solve how can i increase the performance of the program.

I am giving the main part of code which we need to tune to decrease the execution time.

Here is main code that we need to tune.

FORM f_find_lead_time.

DATA i_temp_marc LIKE i_marc OCCURS 0 WITH HEADER LINE.

CONSTANTS: c_eq(2) TYPE c VALUE 'EQ',

c_i TYPE c VALUE 'I'.

DATA: l_werks LIKE i_marc-werks,

l_wzeit LIKE i_marc-wzeit,

l_material LIKE csap_mbom-matnr,

l_plant LIKE csap_mbom-werks,

l_bom_usage LIKE csap_mbom-stlan,

l_alternative LIKE csap_mbom-stlal,

l_tabix_marc LIKE sy-tabix,

l_tabix_marc1 LIKE sy-tabix,

l_tabix_upd LIKE sy-tabix,

l_tabix_wzeit LIKE sy-tabix,

l_matnr LIKE mara-matnr.

LOOP AT i_bom.

l_material = i_bom-matnr.

l_plant = i_bom-werks.

l_bom_usage = i_bom-stlan.

l_alternative = i_bom-stlal.

CLEAR: i_stpo, r_range_matnr.

REFRESH: i_stpo, r_range_matnr.

CALL FUNCTION 'CSAP_MAT_BOM_READ'

EXPORTING

material = l_material

plant = l_plant

bom_usage = l_bom_usage

alternative = l_alternative

TABLES

t_stpo = i_stpo

EXCEPTIONS

error = 1

OTHERS = 2.

IF sy-subrc <> 0.

CONTINUE.

ENDIF.

LOOP AT i_stpo.

CLEAR l_matnr.

l_matnr = i_stpo-component.

READ TABLE i_marc WITH KEY matnr = l_matnr

werks = i_bom-werks BINARY SEARCH.

IF sy-subrc EQ 0.

l_tabix_upd = sy-tabix.

i_marc-upd = c_x.

MODIFY i_marc INDEX l_tabix_upd. CLEAR i_marc.

ENDIF.

r_range_matnr-option = c_eq.

r_range_matnr-sign = c_i.

r_range_matnr-low = i_stpo-component.

APPEND r_range_matnr. CLEAR r_range_matnr.

ENDLOOP.

i_temp_marc[] = i_marc[].

DELETE i_temp_marc WHERE NOT ( matnr IN r_range_matnr AND

werks = i_bom-werks ).

SORT i_temp_marc BY wzeit DESCENDING.

READ TABLE i_temp_marc INDEX 1.

READ TABLE i_marc WITH KEY matnr = i_bom-matnr

werks = i_bom-werks BINARY SEARCH.

IF sy-subrc EQ 0.

l_tabix_marc = sy-tabix.

i_marc-ztlt = i_temp_marc-wzeit .

i_marc-wzeit = i_marc-zlt + i_marc-ztlt.

i_marc-upd = c_x.

MODIFY i_marc INDEX l_tabix_marc. CLEAR i_marc.

ENDIF.

l_werks = i_bom-werks.

DO.

READ TABLE i_marc WITH KEY matnr = i_bom-matnr

werks = l_werks BINARY SEARCH.

IF sy-subrc = 0.

l_tabix_marc = sy-tabix.

IF i_marc-ind IS INITIAL.

l_wzeit = i_marc-wzeit.

i_marc-ind = c_x.

i_marc-upd = c_x.

MODIFY i_marc INDEX l_tabix_marc TRANSPORTING ind upd.

CLEAR i_marc.

ELSE.

EXIT.

ENDIF.

LOOP AT i_marc WHERE matnr = i_bom-matnr AND pwwrk = l_werks.

  • READ TABLE i_marc WITH KEY matnr = i_bom-matnr

  • pwwrk = l_werks.

  • IF sy-subrc = 0.

l_tabix_marc1 = sy-tabix.

  • LOOP AT i_marc FROM l_tabix_marc1.

  • IF i_marc-matnr = i_bom-matnr AND i_marc-werks = l_werks.

i_marc-ztlt = l_wzeit.

i_marc-wzeit = i_marc-zlt + i_marc-ztlt.

l_werks = i_marc-werks.

i_marc-upd = c_x.

MODIFY i_marc INDEX l_tabix_marc1 TRANSPORTING ztlt wzeit upd.

CLEAR i_marc.

  • ELSE.

  • EXIT.

  • ENDIF.

  • ENDLOOP.

  • ENDIF.

ENDLOOP.

IF sy-subrc NE 0.

EXIT.

ENDIF.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDLOOP.

ENDFORM. "f_find_lead_time

While Running above code program is taking lot of time so can any body give me the solution how to solve this performance issue to make the program run fast.

In the above program as per our test data

<b>I_BOM Internal table is containing 6 Rows of Data</b>.

<b>I_STPO Internal table is containing 2 Rows of Data</b>.

<b>I_MARC Internal table is containing more than 4000 Rows of Data</b>.

So can anybody solve my issue where by i can reduce the execution time of above code[PERFORM] without changing any program logic.

Can anybody solve my problem.

Also please clarify how can we do the parallel processing to the above.

Thanks in advance.

waiting for a reply.

Thanks & Regards,

Rayeez.

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

The other suggestions will help, but if your internal tables are at all large, you main problem is nested loops:


  LOOP AT i_bom.
    LOOP AT i_stpo.
    ENDLOOP.
    DO.
      READ TABLE i_marc WITH KEY matnr = i_bom-matnr
      werks = l_werks BINARY SEARCH.
      IF sy-subrc = 0.
        LOOP AT i_marc WHERE matnr = i_bom-matnr AND pwwrk = l_werks.
        ENDLOOP.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
  ENDLOOP.

Try to use binary reads followed by indexed reads as I pointed out in:

Rob

Former Member
0 Kudos

Hi

How you are checking the performance increase or decrease?

Make sure you clear the buffer(st10) and execute the program again.

Best thing is if you have any selects in the program after running Runtime analysis(se30) go for individual select execution time and you will get the clear picture .

Some tips:

-Always use primary index rather than using Non-Index keys

-If you have any Selects inside the Loop,remove those and put selects outside the loop and read the tables

-sorting,binary search and transporing and move should be taken care.

-ST05(SQL Trace) should be checked .

Thanks

krishna

Former Member
0 Kudos

Hi,

Refer http://www.thespot4sap.com/Articles/SAPABAPPerformanceTuning_PerformanceAnalysisTools.asp

link for performance tunning.

Also i have added some performance related points below so that you can use that in your other programs as well.

1. A task can be completed either by calling a class or a function module. Calling methods of a global class is faster than calling a function module.

2. Calling local methods is nearly identical to calling global methods in terms of performance.

3. Fields of type-I should be used for typical integral variables.

4. If you are dealing with type-I or integral type-P fields, then use numeric literals or named constants with a number type instead of character strings.

5. It is preferable to use constants instead of literals.

6. For arithmetic operations, number types should be used instead of the type-N fields. Type-N fields should be used only for pure digit strings that are not intended for calculations e.g. the pin code for a city.

7. Use WHILE instead of a DO-EXIT-ENDDO construction. WHILE statements are easier to understand and faster in execution.

8. It is preferable to use CASE statements over IF statements. CASE statements bring clarity to the conditional constructs and are a little faster than IF statements.

9. For the calling of routines, PERFORM i Of ... statement can be a much faster alternative to using CASE or IF constructs.

10. If you specify the type for formal parameters in your source code, the ABAP/4 compiler can optimize your code more thoroughly. In addition, the risk of using the wrong sequence of parameters in a PERFORM statement is much less.

11. If you specify the type of field-symbols and formal parameters in your source code, the ABAP/4 compiler can optimize your code better.

12. Unnecessary MOVEs should be avoided by using the explicit work area operations.

I hope from this u have get addtional knowledge on performance.

Regards,

Amey

Former Member
0 Kudos

Instead of LIKE try to use TYPE. Use sort statement before the LOOP at int'table. before reading the i_marc table it needs to be sorted so that the read statement uses internally binary search and reduces timing to fetch data. If possible try to avoid loop within a loop as this will consume most of the time. Try to use Read statement whereever possible.

Also, use workarea for the int'table which will reduce the time to fetch or read the data.

Former Member
0 Kudos

1. If u are using any select Stateent give conditions in the Where clause to reduce the time.

2. In the Loop statements give condition

Former Member
0 Kudos

Shaik

Avoid the follwoings:

1. Avoid OCCURS 0.

Eg: data: iTempMara type standard Table of marc.

2. Avoid WITH HEADER LINE. Instead use an Explicit Work

Area .

Eq: data: waTempMara type marc.

3. Avoid LOOP AT i_bom.

Instead go with , <b>LOOP AT i_bom into waBom.</b>

4. SORT the Internal Table.

Eg : SORT I_MARC.

Thanks

Kam

Former Member
0 Kudos

Hi,

1 & 4 th points are already i place of the sujjestions you have given. If any other way after looking at above code if possible please sujjest so that i can try them.

How can we achieve parallel processing for the above code.

Thanks in advance.

Thanks & Regards,

Rayeez.

Former Member
0 Kudos

Hi,

In the above code i_marc is declared as follows.

TYPES: BEGIN OF t_marc,

matnr LIKE marc-matnr, "Material Number

werks LIKE marc-werks, "Plant

beskz LIKE marc-beskz, "Procurement Type

sobsl LIKE marc-sobsl, "Special procurement type

fhori LIKE marc-fhori, "Scheduling Margin Key for Floats

dzeit LIKE marc-dzeit, "In-house production time

plifz LIKE marc-plifz, "Planned delivery time in days

webaz LIKE marc-webaz, "Goods rcpt processing time

pwwrk LIKE t460a-wrk02, "Production plant in planned order

erhor LIKE t436a-erhor, "Opening periodr

zlt TYPE p DECIMALS 3, "Total replenishment lead time

ztlt TYPE p DECIMALS 3, "Total replenishment lead time

wzeit TYPE p DECIMALS 3, "Total replenishment lead time

upd(1) TYPE c, "UPDATE INDICATER

ind TYPE c,

END OF t_marc.

i_marc TYPE SORTED TABLE OF t_marc INITIAL SIZE 0

WITH HEADER LINE

WITH NON-UNIQUE KEY matnr werks.

So please sujjest how can i improve performence of above program or Code.