Skip to Content
author's profile photo Former Member
Former Member

Performance tuning

Hi guys!

I'll be always in favour to you if u could really help me this out.The program displays all the Sales order(RMA's) who's series starts with number 6 in our company ie for Return Manufacturing Authoriazation.What ever the orders which are returned back has a return reason text of more than 600 char long(for this i'm using FM read_text).The problem here is the we have around 6 fields in the selection screen and the end user only enters three fields ie Plant Org,Document Type(only two values ZORE and ZSRE) and the sales order creation date range.Now when i give a date range of four months it is taking 9 minutes to display the data.And the end user wants the date range of one year.When i give the range for 1 year it is running out of time and displays a runtime erro.Please find the solution for this to improve the performance.For your refrence i'm attaching my coding.Its really urgent.........................Please help..............................

REPORT z_rma_gr_report NO STANDARD PAGE HEADING LINE-SIZE 700.

TYPE-POOLS: slis.

TABLES: ekko,

ekkn,

ekpo,

ekbe,

vbak,

vbap.

SELECTION-SCREEN BEGIN OF BLOCK rmd WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_org FOR vbak-vkorg OBLIGATORY, "PURCHASE ORG IMR928388

s_pnt FOR ekbe-werks, "PLANT

s_doc FOR vbak-auart, "DOCUMENT TYPE

s_so FOR vbak-vbeln, "RMA

s_pno FOR ekko-ebeln, "PURCHASE ORDER NUMBER

s_pdate FOR ekbe-budat, "PURCHASE ORDER DATE

s_cdate FOR vbak-erdat OBLIGATORY. "SO CREATION DATE

SELECTION-SCREEN END OF BLOCK rmd.

TYPES : BEGIN OF ty_itab,

rma LIKE vbak-vbeln,

enpointe_po LIKE ekkn-ebeln,

po_line_item LIKE ekkn-ebelp,

vendor_no LIKE vbap-zzp_lifnr,

vendor_name LIKE lfa1-name1,

material_doc LIKE ekbe-belnr,

gr_rev_date LIKE ekbe-budat,

rma_return(600) TYPE c,

END OF ty_itab.

TYPES: BEGIN OF ty_vbak,

vbeln TYPE vbak-vbeln,

erdat TYPE vbak-erdat,

auart TYPE vbak-auart,

END OF ty_vbak.

TYPES: BEGIN OF ty_vbap,

vbeln TYPE vbap-vbeln,

posnr TYPE vbap-posnr,

vgbel TYPE vbap-vgbel,

vgpos TYPE vbap-vgpos,

zzp_lifnr TYPE vbap-zzp_lifnr,

END OF ty_vbap.

TYPES: BEGIN OF ty_ekkn,

ebeln TYPE ekkn-ebeln,

ebelp TYPE ekkn-ebelp,

vbeln TYPE ekkn-vbeln,

vbelp TYPE ekkn-vbelp,

loekz TYPE ekkn-loekz,

END OF ty_ekkn.

TYPES: BEGIN OF ty_ekbe,

ebeln TYPE ekbe-ebeln,

ebelp TYPE ekbe-ebelp,

belnr TYPE ekbe-belnr,

bewtp TYPE ekbe-bewtp,

bwart TYPE ekbe-bwart,

budat TYPE ekbe-budat,

END OF ty_ekbe.

TYPES: BEGIN OF ty_ekko,

ebeln TYPE ekko-ebeln,

lifnr TYPE ekko-lifnr,

END OF ty_ekko.

TYPES: BEGIN OF ty_lfa1,

lifnr LIKE lfa1-lifnr,

name1 LIKE lfa1-name1,

END OF ty_lfa1.

DATA: t_itab TYPE STANDARD TABLE OF ty_itab WITH NON-UNIQUE DEFAULT KEY

INITIAL SIZE 10 WITH HEADER LINE .

DATA: w_fieldcat TYPE slis_fieldcat_alv.

DATA: t_fieldcat TYPE slis_t_fieldcat_alv.

DATA: t_vbak TYPE ty_vbak OCCURS 0 WITH HEADER LINE.

DATA: t_vbap TYPE ty_vbap OCCURS 0 WITH HEADER LINE.

DATA: t_ekko TYPE ty_ekko OCCURS 0 WITH HEADER LINE .

DATA: t_ekkn TYPE ty_ekkn OCCURS 0 WITH HEADER LINE.

DATA: t_ekbe TYPE ty_ekbe OCCURS 0 WITH HEADER LINE.

DATA: t_lfa1 TYPE ty_lfa1 OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF t_line OCCURS 0.

INCLUDE STRUCTURE tline.

DATA: END OF t_line.

START-OF-SELECTION.

PERFORM rma_sales.

END-OF-SELECTION.

PERFORM display_data.

&----


*& Form t_fieldcat

&----


  • Subroutine for fielcat and alv_list_display

----


FORM display_data.

PERFORM fieldcat.

PERFORM alv_list_display.

ENDFORM. "display_data

&----


*& Form fieldcat

&----


  • For the output field Columns

----


FORM fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '1'.

w_fieldcat-fieldname = 'RMA'.

w_fieldcat-seltext_l = 'RMA'.

w_fieldcat-ref_fieldname = 'VBELN'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '2'.

w_fieldcat-fieldname = 'ENPOINTE_PO'.

w_fieldcat-ref_fieldname = 'EBELN'.

w_fieldcat-seltext_l = 'ENPOINTE PO#'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '3'.

w_fieldcat-fieldname = 'PO_LINE_ITEM'.

w_fieldcat-ref_fieldname = 'EBELP'.

w_fieldcat-seltext_l = 'PO Line Item'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '4'.

w_fieldcat-fieldname = 'VENDOR_NO'.

w_fieldcat-ref_fieldname = 'ZZP_LIFNR'.

w_fieldcat-seltext_l = 'Vendor No'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '5'.

w_fieldcat-fieldname = 'VENDOR_NAME'.

w_fieldcat-ref_fieldname = 'NAME1'.

w_fieldcat-seltext_l = 'Vendor Name'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '6'.

w_fieldcat-fieldname = 'MATERIAL_DOC'.

w_fieldcat-ref_fieldname = 'BELNR'.

w_fieldcat-seltext_l = 'Material Do#(Reversal)'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '7'.

w_fieldcat-fieldname = 'GR_REV_DATE'.

w_fieldcat-ref_fieldname = 'BUDAT'.

w_fieldcat-seltext_l = 'GR Reversal Date'.

APPEND w_fieldcat TO t_fieldcat.

CLEAR w_fieldcat.

w_fieldcat-col_pos = '8'.

w_fieldcat-fieldname = 'RMA_RETURN'.

w_fieldcat-outputlen = 600.

w_fieldcat-datatype = 'CHAR'.

w_fieldcat-seltext_l = 'RMA(Return Reason Details)'.

APPEND w_fieldcat TO t_fieldcat.

ENDFORM. "fieldcat

&----


*& Form alv_list_display

&----


  • Displaying the output

----


FORM alv_list_display.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_callback_program = sy-repid

it_fieldcat = t_fieldcat

TABLES

t_outtab = t_itab.

ENDFORM. "alv_list_display

&----


*& Form rma_sales

&----


*Queries for Getting the Sales order Number and its corresponding PO,

*Line Item,Material Doc and Reversal date values.

----


FORM rma_sales.

SELECT vbeln

erdat

auart

FROM vbak

INTO TABLE t_vbak

WHERE vbeln IN s_so "Sales order

AND erdat IN s_cdate "Sales order creation date

AND auart IN s_doc "Document type

AND vkorg IN s_org. "IMR928535

SORT t_vbak BY vbeln.

IF sy-subrc = 0.

SELECT vbeln

posnr

vgbel

vgpos

zzp_lifnr

FROM vbap

INTO TABLE t_vbap

FOR ALL ENTRIES IN t_vbak

WHERE vbeln = t_vbak-vbeln

AND werks IN s_pnt. "IMR928388

IF sy-subrc = 0.

SELECT ebeln

ebelp

vbeln

vbelp

loekz

FROM ekkn INTO TABLE t_ekkn

FOR ALL ENTRIES IN t_vbap

WHERE ebeln IN s_pno

AND vbeln = t_vbap-vgbel

AND vbelp = t_vbap-vgpos.

  • AND loekz = ' '. "IMR928535

IF sy-subrc = 0.

SORT t_ekkn BY ebeln ebelp.

DELETE ADJACENT DUPLICATES FROM t_ekkn COMPARING ebeln ebelp."IMR928405

SELECT ebeln

ebelp

belnr

bewtp

bwart

budat

FROM ekbe INTO TABLE t_ekbe

FOR ALL ENTRIES IN t_ekkn

WHERE ebeln = t_ekkn-ebeln

AND ebelp = t_ekkn-ebelp

AND bewtp = 'E'

AND bwart = '122'

AND budat IN s_pdate.

ENDIF.

ENDIF.

ENDIF.

LOOP AT t_vbak.

LOOP AT t_vbap WHERE vbeln = t_vbak-vbeln.

LOOP AT t_ekkn WHERE vbeln = t_vbap-vgbel

AND vbelp = t_vbap-vgpos.

LOOP AT t_ekbe WHERE ebeln = t_ekkn-ebeln "IMR928405

AND ebelp = t_ekkn-ebelp.

t_itab-rma = t_vbak-vbeln.

t_itab-enpointe_po = t_ekkn-ebeln .

t_itab-po_line_item = t_ekkn-ebelp .

t_itab-material_doc = t_ekbe-belnr.

t_itab-gr_rev_date = t_ekbe-budat .

t_itab-vendor_no = t_vbap-zzp_lifnr.

ENDLOOP.

ENDLOOP.

  • PERFORM vendor_detail.

  • PERFORM rejection_reason.

ENDLOOP.

PERFORM vendor_detail. "IMR928442

PERFORM rejection_reason.

IF NOT t_itab-rma IS INITIAL.

APPEND t_itab.

ENDIF.

CLEAR t_itab.

ENDLOOP.

ENDFORM. "rma_sales

&----


*& Form vendor_details

&----


*Subroutine for vendor name

----


FORM vendor_detail.

  • CLEAR t_lfa1.

  • REFRESH t_lfa1.

SELECT lifnr

name1 FROM lfa1

INTO TABLE t_lfa1

FOR ALL ENTRIES IN t_vbap

WHERE lifnr = t_vbap-zzp_lifnr.

IF sy-subrc = 0.

SORT t_lfa1 BY lifnr.

DELETE ADJACENT DUPLICATES FROM t_lfa1.

  • MOVE t_vbap-zzp_lifnr TO t_lfa1-lifnr.

  • LOOP AT t_lfa1 WHERE lifnr = t_vbap-zzp_lifnr.

READ TABLE t_lfa1 WITH

KEY lifnr = t_vbap-zzp_lifnr

BINARY SEARCH. "IMR928442

  • MOVE t_lfa1-name1 TO t_itab-vendor_name.

t_itab-vendor_name = t_lfa1-name1.

  • ENDLOOP.

ENDIF.

ENDFORM. "vendor_detail

&----


*& form rejection_reason

&----


  • Subroutine for Rma return reasons

----


FORM rejection_reason. "IMR928405

DATA: i_tdname TYPE thead-tdname.

  • DATA: l_vbak(10) TYPE c VALUE '0000000000'.

  • DATA: l_vbap(6) TYPE c VALUE '000000'.

DATA: text1(132) TYPE c,

text2(132) TYPE c,

text3(132) TYPE c,

text4(132) TYPE c,

text5(132) TYPE c.

*REFRESH: t_line. "IMR928521

*CLEAR: t_line.

  • OVERLAY t_vbak-vbeln WITH l_vbak."IMR928521

  • OVERLAY t_vbap-posnr WITH l_vbap.

*

CONCATENATE t_vbak-vbeln t_vbap-posnr INTO i_tdname.

CONDENSE i_tdname.

CALL FUNCTION 'READ_TEXT'

EXPORTING

id = 'Z010'

language = 'E'

name = i_tdname

object = 'VBBP'

TABLES

lines = t_line

EXCEPTIONS

id = 1

language = 2

name = 3

not_found = 4

object = 5

reference_check = 6

wrong_access_to_archive = 7

OTHERS = 8.

CLEAR: t_itab-rma_return.

IF sy-subrc <> 0.

ELSE .

READ TABLE t_line INDEX 1. "IMR928442

IF sy-subrc = 0.

text1 = t_line-tdline.

ENDIF.

READ TABLE t_line INDEX 2.

IF sy-subrc = 0.

text2 = t_line-tdline.

ENDIF.

READ TABLE t_line INDEX 3.

IF sy-subrc = 0.

text3 = t_line-tdline.

ENDIF.

READ TABLE t_line INDEX 4.

IF sy-subrc = 0.

text4 = t_line-tdline.

ENDIF.

READ TABLE t_line INDEX 5.

IF sy-subrc = 0.

text5 = t_line-tdline.

ENDIF.

*

  • LOOP AT t_line.

  • IF sy-tabix GT 5.

  • EXIT.

  • ENDIF.

  • CONCATENATE t_itab-rma_return t_line-tdline INTO t_itab-rma_return.

*

  • ENDLOOP.

  • ENDIF.

ENDIF.

CONCATENATE text1 text2 text3 text4 text5 INTO t_itab-rma_return.

ENDFORM. "vendor_detail

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Posted on Feb 19, 2007 at 05:00 PM

    Hi Again,

    As pointed out by <b>Rob Burbank</b>, nested loops are a problem in the code. I have calculated the most optimal number of traversing in the above code.

    <i><b>Though my code too has nested loops, but here the outer most loop has the least number of entries. Just replace your loops with mine and see it working fast.</b></i>

    <i><b>Also, you can use field symbols to make it faster. Plus use binary search with read in one of my statements in above solution.</b></i>

    Hope i provided you with appropiate solution.

    Thanks and regards,

    Ravi.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hai Rob!

      Sorry to trouble you again i have a same performance problem yet again.

      can i use the delete statement that you've mentioned for the table t_vbak.For the same select statement this time with other requirement the end user will be using only posting date that is t_ekbe-budat plz find this in the first page.Now i've changed the style of my selection options.What my user wants is now he'll be entering Posting date range instead of sales order creation date it t_vbak-erdat.Leaving sales order numbe , sales order date as blank.With this the first select statements retrievs huge data more than 40,600 entries but if i give the Sales order date range then it retrievs 4069 entries only.So for this entries we again have 50,300 entries in t_vbap and time is runing out at t_ekkn table.

      i'm trying to use this statement

      delete t_vbak where not vbeln in s_po date which is posting date here no sales order date which was the previous case but no use.. can u give some suggestion to reduce the entries and get exact sales order for the concern posting date

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2007 at 02:17 PM

    Your problem is int this portion of code:

      LOOP AT t_vbak.
    
    
        LOOP AT t_vbap WHERE vbeln = t_vbak-vbeln.
    
    
          LOOP AT t_ekkn WHERE vbeln = t_vbap-vgbel
          AND vbelp = t_vbap-vgpos.
    
            LOOP AT t_ekbe WHERE ebeln = t_ekkn-ebeln           "IMR928405
            AND ebelp = t_ekkn-ebelp.
    
              t_itab-rma = t_vbak-vbeln.
              t_itab-enpointe_po = t_ekkn-ebeln .
              t_itab-po_line_item = t_ekkn-ebelp .
              t_itab-material_doc = t_ekbe-belnr.
              t_itab-gr_rev_date = t_ekbe-budat .
    *t_itab-vendor_no = t_vbap-zzp_lifnr.
    
            ENDLOOP.
    
          ENDLOOP.
    
    * PERFORM vendor_detail.
    * PERFORM rejection_reason.
        ENDLOOP.
    
        PERFORM vendor_detail.                                  "IMR928442
        PERFORM rejection_reason.
    
        IF NOT t_itab-rma IS INITIAL.
          APPEND t_itab.
        ENDIF.
        CLEAR t_itab.
      ENDLOOP.
    

    Nested loops are bad for performance. Triply nested loops will be far worse. This should give you an idea of how to fix the problem.:

    <a href="/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops">The Performance of Nested Loops</a>

    Rob

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 19, 2007 at 02:37 PM

    Hi!

    Just a very common idea: check out transaction SE30. It is very useful to determine, which part of your program is the slowest.

    Regards

    Tamá

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 19, 2007 at 04:55 PM

    Hi Younus,

    I went through your code. Its really good. I found out a huge performance problem at one place. Here is the description :-

    In Sub-Routine RMA_SALES, the following code should be changed:-

    LOOP AT t_vbak.

    LOOP AT t_vbap WHERE vbeln = t_vbak-vbeln.

    LOOP AT t_ekkn WHERE vbeln = t_vbap-vgbel

    AND vbelp = t_vbap-vgpos.

    LOOP AT t_ekbe WHERE ebeln = t_ekkn-ebeln "IMR928405

    AND ebelp = t_ekkn-ebelp.

    t_itab-rma = t_vbak-vbeln.

    t_itab-enpointe_po = t_ekkn-ebeln .

    t_itab-po_line_item = t_ekkn-ebelp .

    t_itab-material_doc = t_ekbe-belnr.

    t_itab-gr_rev_date = t_ekbe-budat .

    t_itab-vendor_no = t_vbap-zzp_lifnr.

    ENDLOOP.

    ENDLOOP.

    • PERFORM vendor_detail.

    • PERFORM rejection_reason.

    ENDLOOP.

    *****************************NEW CODE would be as follows:-***********************

    loop at t_ekbe.

    loop at t_ekkn where ebeln = t_ekbe-ebeln and ebelp = t_ekbe-ebelp.

    loop at t_vbap where vgbel = t_ekkn-vbeln and vgpos = t_ekkn-ebelp.

    read table t_vbak with key vbeln = t_vbak-vbeln.

    if sy-subrc eq 0.

    t_itab-rma = t_vbak-vbeln.

    t_itab-enpointe_po = t_ekkn-ebeln .

    t_itab-po_line_item = t_ekkn-ebelp .

    t_itab-material_doc = t_ekbe-belnr.

    t_itab-gr_rev_date = t_ekbe-budat .

    t_itab-vendor_no = t_vbap-zzp_lifnr.

    endif.

    endloop.

    endloop.

    endloop.

    *********************************************************************************

    Try this it would work :).

    NOTE: Please award me appropiate points if the problem is solved :).

    Looking forward for more queries.

    Thanks and regards,

    Ravi 😊.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 22, 2007 at 11:57 AM

    Instead of nested loop use only one loop and read the next internal table using the key field.Check sy-subrc equal to zero,move the data into final internal table itab.

    This will improves the performance of the program.Even use if not t_vbak[] is initial.

    select vbeln posnr vgbel zzp_lifnr from vbap

    into table t_vbap

    for all entries in t_vbak

    where vbeln = tvbak-vbeln

    and werks in s_pnt.

    if sy-subrc eq 0.

    message e000 'no data found'.

    endif.

    endif.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      please go through my coding and the chain of my questions.The problem regarding the nested loops is solved and the problem here is not with the select statement in t_vbap but in the select statement mentioned above this is having huge data and the problem is the date range mentioned above is not accomidating that memory of 62MB(which it displays in the runtime error and points that the problem is in the above select statement.

      The problem here is purely based on resource management(Memory our operating system has called Malloc(Roll Area Memory distribution done by the Administrator) and time management(this we call as performance as u know).Both are inversly proportional in SAP.So this is tough time for me out here,any ways please go through the Page 1 and 2 and help me out again.Thanks soooo much for spending time.........(this is itself is more to me)

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.