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

Performance Issue

Former Member
0 Likes
1,449

Hi..

Could anyone suggest me to increase performance for the below report.

REPORT  zm02 NO STANDARD PAGE HEADING LINE-COUNT 65 LINE-SIZE 167.
TYPE-POOLS: slis.
TABLES:eban,ekko.
INCLUDE zm01_d01.
SELECT-OPTIONS: s_ebeln FOR ekko-ebeln,
                s_rfq FOR eban-banfn,
                s_col FOR ekko-submi.
PERFORM sub_002"Searching Distinct Material Names.
IF sy-subrc NE 0.
  MESSAGE 'No Purchase Requistion' TYPE 'E' DISPLAY LIKE 'S'.
*    LEAVE LIST-PROCESSING.
ENDIF.
START-OF-SELECTION.
*  WRITE : 40 'Comments :', g_cmts INPUT.
  CONCATENATE  it_item-ebeln tid INTO result.
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
      client    = sy-mandt
      id        = 'A03'
      language  = 'E'
      name      = result
      object    = 'EKPO'
    TABLES
      lines     = it_rm
    EXCEPTIONS
      not_found = 4.
  WRITE : 'Comments :'.
  LOOP AT it_rm INTO wa_rm.
    WRITE : 15  wa_rm-tdline,/.
  ENDLOOP.
  WRITE :/ ,'Apprx P.O. Value :INR',apprx1.
  WRITE : /,/,/,/,'Negotiated By',83  'Verified By', 140 'Approved By CMD/Director'.
TOP-OF-PAGE.
* FORMAT COLOR 1 INTENSIFIED.
  SKIP TO LINE 1.
  WRITE : 1(167) 'HETERO GROUP OF COMPANIES' CENTERED.
  SKIP TO LINE 3.
  WRITE : 1(167) 'QUOTATION ANALYSIS' CENTERED , 140 'Date :', sy-datum .
*  FORMAT COLOR OFF.
* AT USER-COMMAND.
  AT LINE-SELECTION.
  GET CURSOR FIELD c_field.
  IF c_field EQ 'IT_ITEM-EBELN' OR c_field EQ 'G_LND'.
    PERFORM val.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  sub_remarks
*&---------------------------------------------------------------------*
*       Fetching Text For Remarks Field
*----------------------------------------------------------------------*
*      -->P_IT_HEAD_EBELN  text
*----------------------------------------------------------------------*
FORM sub_remarks USING p_ebeln.
  CONCATENATE  p_ebeln tid INTO result.
  CALL FUNCTION 'READ_TEXT'
    EXPORTING
     client    = sy-mandt
      id        = 'A01'
      language  = 'E'
      name      = result
      object    = 'EKPO'
    TABLES
     lines     = it_rm
    EXCEPTIONS
      not_found = 4.
READ TABLE it_rm INTO wa_rm.

  g_text = wa_rm-tdline.

ENDFORM.                    " sub_remarks

*&---------------------------------------------------------------------*

*&      Form  sub_hd_retrive

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM sub_hd_retrive USING p_matnr.

  CLEAR:wa_head.

  SELECT SINGLE a~banfn a~eindt f~maktx c~werks c~name1 b~ktmng b~meins b~matnr e~erdat g~lbkum a~ebeln a~ebelp INTO CORRESPONDING FIELDS OF  wa_head FROM eket AS a

  INNER JOIN ekpo AS b ON a~ebeln = b~ebeln AND a~ebelp = b~ebelp AND b~loekz NE 'L'

  INNER JOIN t001w AS c ON b~werks = c~werks

  INNER JOIN ekko AS d ON a~ebeln = d~ebeln

  INNER JOIN zmt_mat_desc_api AS f ON b~matnr = f~matnr AND b~werks = f~werks

  LEFT JOIN eban AS e ON a~banfn = e~banfn

  LEFT JOIN mbew AS g ON b~matnr = g~matnr AND b~werks = g~bwkey

  WHERE d~submi IN s_col AND a~banfn IN s_rfq AND a~ebeln IN s_ebeln AND b~matnr = p_matnr .

  SELECT SINGLE werks INTO twerks FROM ekpo WHERE ebeln IN s_ebeln.

  CLEAR:pstk1.

  SELECT matnr labst insme einme speme INTO CORRESPONDING FIELDS OF TABLE pstk1 FROM mard WHERE matnr = wa_matnr-matnr AND werks = twerks.

  LOOP AT pstk1.

    AT END OF matnr.

      SUM.

      APPEND pstk1 TO pstk.

      CLEAR: pstk1.

    ENDAT.

  ENDLOOP.

  READ TABLE pstk INTO wa_pstk WITH KEY matnr = wa_matnr-matnr.

  blst = wa_pstk-speme.

  qlst = wa_pstk-einme.

  rlst = wa_pstk-insme.

  ulst = wa_pstk-labst.

  IF wa_head IS INITIAL.

    EXIT.

  ENDIF.

  PERFORM lastpono USING p_matnr.

  PERFORM sub_001.

ENDFORM.                    " sub_hd_retrive

*&---------------------------------------------------------------------*

*&      Form  sub_id_retrive

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM sub_id_retrive USING p_matnr.

  REFRESH it_item.

  SELECT a~name1 a~lifnr d~netpr d~ebeln e~text1 d~ebelp  INTO TABLE it_item FROM lfa1 AS a

  INNER JOIN ekko AS b ON a~lifnr = b~lifnr

  INNER JOIN eket AS c ON b~ebeln = c~ebeln

  INNER JOIN ekpo AS d ON c~ebeln = d~ebeln AND c~ebelp = d~ebelp AND d~loekz NE 'L'

  LEFT JOIN t052u AS e ON b~zterm = e~zterm AND b~spras = e~spras

  WHERE  b~submi IN s_col AND c~banfn IN s_rfq AND b~ebeln IN s_ebeln AND d~matnr = p_matnr.

  SORT it_item BY netpr.

  SELECT SINGLE SUM( lbkum ) INTO lbkum FROM mbew WHERE matnr = p_matnr.

  PERFORM id_display.

ENDFORM.                    " sub_id_retrive

*&---------------------------------------------------------------------*

*&      Form  hd_display

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM hd_display.

  DATA : mname(55) TYPE c.

  MOVE wa_head-maktx TO mname.

  ULINE.

  WRITE : / sy-vline,'Indent No :', wa_head-banfn, 25 'Date :',wa_head-erdat, 50 'Material No:',wa_head-matnr, 83  'Material :',mname , 125 'Last Purchase Order Price :', g_oprice, 167 sy-vline.

*  SKIP TO LINE 8.

  WRITE: / sy-vline, 167 sy-vline.

  WRITE :/ sy-vline, 'Plant :', wa_head-werks,wa_head-name150 'Quantity :',wa_head-ktmng, wa_head-meins, 83 'Purchase Order No :', g_pno, 125 'Name :', vname1, 167 sy-vline.

  WRITE :/ sy-vline,'Delivery Date :', wa_head-eindt,85 'P.O. Date', wpo-aedat,'P.O.Qty',wpo-menge, 167 sy-vline.

  ULINE.

*  FORMAT COLOR 1 INTENSIFIED.

  WRITE : sy-vline, 'Supplier Name' , 22 sy-vline,'Quated', 37 sy-vline,'Basic', 54 sy-vline, 'P & F', 62 sy-vline,

  'ED', 70 sy-vline'CST/', 76 sy-vline, 'Frei', 86 sy-vline,

  'Other', 93 sy-vline, 'Disc', 102 sy-vline, 'Total', 116 sy-vline, 'Landed Price', 130 sy-vline, 'Payment', 148 sy-vline,'Remarks', 167 sy-vline.

  WRITE : sy-vline22 sy-vline,'Price', 37 sy-vline,'Price', 54 sy-vline, 62 sy-vline70 sy-vline,'VAT',

   76 sy-vline, 'ght',   86 sy-vline, 'Charg', 93 sy-vline, '   %  ',

   102 sy-vline 116 sy-vline130 sy-vline, 'Terms', 148 sy-vline,167 sy-vline.

  ULINE.

*  FORMAT COLOR OFF.

* , 200 sy-vline , 'Remarks', 200 sy-vline ,

ENDFORM.                    " hd_display

*&---------------------------------------------------------------------*

*&      Form  id_display

*&---------------------------------------------------------------------*

*         Display Line Items

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM id_display.

  DATA:c_val TYPE n,

       c_val1 TYPE n.

  sno = 0.

  LOOP AT it_item.

    PERFORM sub_remarks USING it_item-ebeln.

    PERFORM sub_old USING it_item-ebeln it_item-ebelp.

    sno = sno + 1.

*word wrap for payment terms

    CALL FUNCTION 'RKD_WORD_WRAP'

      EXPORTING

        textline  = it_item-text1

        outputlen = 16

      IMPORTING

        out_line1 = gt_text

        out_line2 = gt_tex1

        out_line3 = gt_tex2.

*word wrap for remarks

    CALL FUNCTION 'RKD_WORD_WRAP'

      EXPORTING

        textline  = g_text

        outputlen = 18

      IMPORTING

        out_line1 = rm_text

        out_line2 = rm_text1

        out_line3 = rm_text2.

* word wrap for vendor

    CALL FUNCTION 'RKD_WORD_WRAP'

      EXPORTING

        textline  = it_item-name1

        outputlen = 20

      IMPORTING

        out_line1 = name

        out_line2 = name1

        out_line3 = name2.

    CONCATENATE it_item-ebeln it_item-ebelp INTO vakey.

    PERFORM price_cond USING vakey.

    HIDE it_item-ebelp.

    IF sno EQ 1.

      c_val = 0.

    ELSE.

      c_val = 6.

    ENDIF.

    IF c_val = 0.

      apprx = wa_head-ktmng * g_lnd.

      ADD:apprx TO apprx1.

    ENDIF.

    WRITE : / sy-vline, it_item-ebelp,2 it_item-ebeln HOTSPOT22 sy-vline, oldval, 37 sy-vline, kbetr  , 54 sy-vline, g_pf NO-ZERO62  sy-vline, g_ed1, 70 sy-vline, g_cst1,

    76 sy-vline g_fre NO-ZERO, 86 sy-vline, g_mis NO-ZERO, 93 sy-vline, g_disc NO-ZERO, 102 sy-vline, g_price , 116 sy-vline, g_lnd,130 sy-vline,

     gt_text ,148 sy-vline, rm_text,167 sy-vline.

    WRITE : / sy-vline,name, 22 sy-vline,   37 sy-vline54 sy-vline, 62  sy-vline, 70 sy-vline,

    76 sy-vline 86 sy-vline, 93 sy-vline, 102 sy-vline, 116 sy-vline, 130 sy-vlinegt_tex1 ,148 sy-vline, rm_text1,167 sy-vline.

    WRITE : / sy-vline,it_item-lifnr, 22 sy-vline,   37 sy-vline54 sy-vline, 62  sy-vline, 70 sy-vline,

    76 sy-vline 86 sy-vline, 93 sy-vline, 102 sy-vline, 116 sy-vline, 130 sy-vline ,148 sy-vline,167 sy-vline.

    PERFORM text_clear.

    ULINE.

  ENDLOOP.

  CLEAR sno.

  ULINE 1(166).

  WRITE :/ sy-vline, 'Current Plant stock :', 22 wa_head-lbkum ,sy-vline,45 'Unrestricted :', ulst,sy-vline,75 'Quality: ',rlst, sy-vline ,

  105 'Restricted : ', qlst, sy-vline ,

  145 'Blocked:' , blst, sy-vline ,/ sy-vline, 'Current Group Stock : ', 22 lbkum, sy-vline,70 '',sy-vline,95 ' ', sy-vline ,129' ', sy-vline ,164 ' ' ,sy-vline,/ sy-vline.

  ULINE 1(166).

ENDFORM.                    " id_display

*&---------------------------------------------------------------------*

*&      Form  sub_old

*&---------------------------------------------------------------------*

*       Finding Basic Value for Quatation

*----------------------------------------------------------------------*

*      -->P_IT_ITEM_EBELN  text

*----------------------------------------------------------------------*

FORM sub_old  USING    p_ebeln

                       p_ebelp.

  CONCATENATE '100' p_ebeln p_ebelp INTO tabkey.

  SELECT SINGLE value_new FROM cdpos INTO wa_old WHERE objectid = p_ebeln AND fname = 'NETPR' AND tabkey = tabkey.

  oldval = wa_old-new.

ENDFORM.                    " sub_old

*&---------------------------------------------------------------------*

*&      Form  text_clear

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM text_clear.

  CLEAR g_text.

  CLEAR oldval.

  CLEAR gt_text.

  CLEAR gt_tex1.

  CLEAR gt_tex2.

  CLEAR rm_text.

  CLEAR rm_text.

  CLEAR rm_text.

  CLEAR g_ed.

  CLEAR g_ed1.

  CLEAR g_cst.

  CLEAR g_cst1.

  CLEAR g_vat.

  CLEAR g_vat1.

  CLEAR g_fre.

  CLEAR g_fre1.

  CLEAR g_tot.

  CLEAR g_disc.

  CLEAR g_mis.

  CLEAR g_pf.

  CLEAR g_sec1.

  CLEAR g_hi1.

ENDFORM.                    " text_clear

*&---------------------------------------------------------------------*

*&      Form  price_cond

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_VAKEY  text

*----------------------------------------------------------------------*

FORM price_cond USING p_vakey.

  g_price = 0.

  g_lnd = 0.

  SELECT SINGLE knumh FROM konh INTO wa_cond WHERE vakey = p_vakey.

  SELECT  kschl kbetr konwa  FROM konp  INTO TABLE  it_konp WHERE knumh = wa_cond-knumh AND loevm_ko NE 'X'." ORDER BY KBETR DESCENDING .

  READ TABLE it_konp INTO wa_konp WITH KEY kschl = 'P000'.

  kbetr = wa_konp-kbetr.

  READ TABLE it_konp INTO wa_konp WITH KEY kschl = 'RA01'.

  IF sy-subrc EQ 0.

    CLEAR descbase.

    descbase = wa_konp-kbetr / 10.

    descbase = ( kbetr * descbase ) / 100.

    descbase = descbase * -1.

    kbetr = kbetr - descbase.

  ENDIF.

  READ TABLE it_konp INTO wa_konp WITH KEY kschl = 'JEX1'.

  IF sy-subrc EQ 0.

    g_ed1 = wa_konp-kbetr / 10.

    g_ed = ( kbetr * g_ed1 ) / 100.

    g_sec = ( g_ed * 2 ) / 100.

    g_hi = ( g_ed * 1 ) / 100.

    g_ed = g_ed + g_sec + g_hi.

    g_ed1 = g_ed1 + ( ( g_ed1 * 2 ) / 100 + ( g_ed1 * 1 ) / 100 ).

    DELETE it_konp WHERE kschl = 'JEX1'.

  ENDIF.

  READ TABLE it_konp INTO wa_konp WITH KEY kschl = 'JEXC'.

  IF sy-subrc EQ 0.

    g_ed1 = wa_konp-kbetr .

    g_sec = ( g_ed1 * 2 ) / 100.

    g_hi = ( g_ed1 * 1 ) / 100.

    g_ed = g_ed1 + g_sec + g_hi.

    g_ed1 = g_ed1 + g_sec + g_hi.

    DELETE it_konp WHERE kschl = 'JEXC'.

  ENDIF.

  LOOP AT it_konp INTO wa_konp.

    CASE wa_konp-kschl.

      WHEN 'ZST1'.

        g_cst1 = wa_konp-kbetr / 10.

        g_cst = ( ( kbetr + g_ed + g_sec1 + g_hi1 ) * g_cst1 ) / 100.

      WHEN 'ZVAT'.

        g_vat1 = wa_konp-kbetr / 10.

        g_vat = ( ( kbetr + g_ed ) * g_vat1 ) / 100.

      WHEN 'FRA1'.

        g_fre = wa_konp-kbetr / 10.

        g_fre = ( kbetr * g_fre ) / 100.

      WHEN 'FRB1'.

        g_fre = wa_konp-kbetr.

      WHEN 'FRC1'.

        g_fre = wa_konp-kbetr.

      WHEN 'RA00'.

        g_disc = wa_konp-kbetr / 10.

      WHEN 'RA01'.

        g_disc = wa_konp-kbetr / 10.

        descbase = ( kbetr * g_disc ) / 100.

      WHEN 'ZMIS'.

        g_mis wa_konp-kbetr.

      WHEN 'ZA01'.

        g_pf = wa_konp-kbetr / 10.

    ENDCASE.

  ENDLOOP.

  IF g_cst1 EQ 0.

    g_cst1 = g_vat1.

  ENDIF.

  g_price kbetr + g_ed +  g_cst + g_vat +  g_fre + g_mis.

  g_lnd = g_price - ( g_ed + g_vat ).

ENDFORM.                    " price_cond

*&---------------------------------------------------------------------*

*&      Form  SUB_001

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM sub_001.

  PERFORM hd_display.

  PERFORM sub_id_retrive USING wa_head-matnr.

ENDFORM.                                                    " SUB_001

*&---------------------------------------------------------------------*

*&      Form  sub_002

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*  -->  p1        text

*  <--  p2        text

*----------------------------------------------------------------------*

FORM sub_002 .

  SELECT DISTINCT a~matnr INTO TABLE  it_matnr FROM ekpo AS a

  INNER JOIN ekko AS b ON a~ebeln = b~ebeln

  INNER JOIN eket AS c ON a~ebeln = c~ebeln

  WHERE b~submi IN s_col AND c~banfn IN s_rfq AND a~ebeln IN s_ebeln.

  LOOP AT it_matnr INTO wa_matnr.

    PERFORM sub_hd_retrive USING wa_matnr-matnr.

  ENDLOOP.

ENDFORM.                                                    " sub_002

*&---------------------------------------------------------------------*

*&      Form  VAL

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

FORM val." USING UCOMM TYPE SY-UCOMM SELFIELD TYPE SLIS_SELFIELD.

  READ LINE sy-lilli FIELD VALUE it_item-ebeln.

  READ LINE sy-lilli FIELD VALUE it_item-ebelp.

  SET PARAMETER ID 'ANF' FIELD it_item-ebeln.

  IF c_field EQ 'G_LND'. "'IT_ITEM-NETPR'.

    SET PARAMETER ID 'BSP' FIELD it_item-ebelp.

  ENDIF.

  CALL TRANSACTION 'ME47' AND SKIP  FIRST SCREEN.

ENDFORM.                    "VAL

*&---------------------------------------------------------------------*

*&      Form  lastpono

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->P_P_MATNR  text

*----------------------------------------------------------------------*

FORM lastpono  USING    p_matnr.

  DATA:lifnr1 TYPE lfa1-lifnr.

SELECT  MAX( a~aedat ) INTO mdate FROM ekko AS a

  INNER JOIN ekpo AS b ON a~ebeln = b~ebeln WHERE b~matnr = p_matnr AND a~bstyp = 'F'

    AND a~lifnr GE '0000100000' AND  a~lifnr < '0000200000' AND b~loekz NE 'L' .

  SELECT  a~ebeln c~eruhr b~netpr a~aedat b~menge INTO TABLE ipo FROM ekko AS a

  INNER JOIN ekpo AS b ON a~ebeln = b~ebeln

  INNER JOIN erev AS c ON a~ebeln = c~edokn

  WHERE c~erdat = mdate AND b~matnr = p_matnr AND a~bstyp = 'F' ORDER BY c~eruhr DESCENDING .

  READ TABLE ipo INTO wpo INDEX 1.

  g_pno = wpo-ebeln.

  g_oprice = wpo-netpr.

  v_menge = wpo-menge.

  SELECT SINGLE a~name1 INTO vname1 FROM lfa1 AS a

    INNER JOIN ekko AS b ON a~lifnr = b~lifnr WHERE b~ebeln = g_pno.

ENDFORM.                    " lastpono

Regards

Kalpana

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
1,387

Nobody in their right mind will study that entire code you posted.

Don't believe the urband legends ("avoid joins"...), run a ST12 trace (blogs are easy to find via the search box on the top right) and focus on the parts of the code that show the longest net runtime.

Once you have narrowed it down like that, we're happy to help with specific issues.

By the way, nowadays I would always use ST12 first, as it combines the essential functions of SAT/SE30 and ST05 in one tool.


Thomas

12 REPLIES 12
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,387

Please first do a performance analysis by using tcode SAT and SE30 and check which are the pain areas. Once they are indentified then you can catch hold of them one by one.

Read only

0 Likes
1,387

Thanku nabheet for your suggestion.

Could you please explain me in detail as I am somewhat new to ABAP.

Read only

0 Likes
1,387

Please search for the tcode which i have mentioned. there is lot material tutorial available

Read only

Former Member
0 Likes
1,387

This message was moderated.

Read only

himanshu_gupta13
Product and Topic Expert
Product and Topic Expert
0 Likes
1,387

Dear Kalpana,

Do performance tuning by using 'Extendend Programing check', then do database injection check by using st05, then do at last st12 or sat..

Many Thanks / Himanshu Gupta

Read only

Former Member
0 Likes
1,387

Hi Kalpana

Maybe these two links will help you getting started. Search more in SCN and do R&D before posting.

<link farm removed>

Reward points if useful.

Do not ask for points. Let the OP decide!

Warm Regards,

Jagraj Singh

Message was edited by: Suhas Saha

Read only

former_member188282
Active Participant
0 Likes
1,387

This message was moderated.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,387
<false information>

Avoid aggregate statements like sum(), avg().

May be suggest - Avoid using SELECTs, it'll increase the DB times. Instead read the data from the Application server file

Read only

0 Likes
1,387

Now will put red paint over the section which favors For All Entries over Inner Join.

Waiting for him to take action...

Read only

0 Likes
1,387

Which posts would they be?

Come on, EVERY one knows that FAE is in most cases far less efficient than an INNER JOIN.

Read only

ThomasZloch
Active Contributor
0 Likes
1,388

Nobody in their right mind will study that entire code you posted.

Don't believe the urband legends ("avoid joins"...), run a ST12 trace (blogs are easy to find via the search box on the top right) and focus on the parts of the code that show the longest net runtime.

Once you have narrowed it down like that, we're happy to help with specific issues.

By the way, nowadays I would always use ST12 first, as it combines the essential functions of SAT/SE30 and ST05 in one tool.


Thomas

Read only

0 Likes
1,387

It took only 21 page-downs to scroll through the post.

11 page-downs would have been sufficient if there were no blank lines.

Removing all blank lines is a matter of 1 search-and-replace operation.