performance in abap development

Upload: sivab2wkumar

Post on 04-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Performance in ABAP Development

    1/24

    Ho do you care

    About Performancein ABAPDevelopment ?By Ashok Kumar Reddy S on Thursday, 17November 2011 at 18:33

    ABAP Performance Standards

    Following are the performancestandards need to be following inwriting ABAP programs:

    1. Unused/Dead code

    https://www.facebook.com/SAshokKumarReddyhttps://www.facebook.com/SAshokKumarReddyhttps://www.facebook.com/SAshokKumarReddy
  • 8/13/2019 Performance in ABAP Development

    2/24

    Avoid leaving unused code in theprogram. Either comment out or deletethe unused situation. Use program -->check --> extended program to checkfor the variables, which are not usedstatically.

    2. Subroutine Usage

    For good modularization, the decisionof whether or not to execute asubroutine should be made before thesubroutine is called. For example:

    This is better:IF f1 NE 0.

  • 8/13/2019 Performance in ABAP Development

    3/24

    PERFORM sub1.

    ENDIF.

    FORM sub1....

    ENDFORM.

    Than this:

    PERFORM sub1.

    FORM sub1.IF f1 NE 0.

    ...ENDIF.

  • 8/13/2019 Performance in ABAP Development

    4/24

    ENDFORM.

    3. Usage of IF statements

    When coding IF tests, nest the testingconditions so that the outer conditionsare those which are most likely to fail.For logical expressions with AND ,place the mostly likely false first and forthe OR, place the mostly likely true first.

    Example - nested IF's:

    IF (least likely to be true).

    IF (less likely to be true).

  • 8/13/2019 Performance in ABAP Development

    5/24

    IF (most likely to be true).ENDIF.

    ENDIF.ENDIF.

    Example - IF...ELSEIF...ENDIF :

    IF (most likely to be true).

    ELSEIF (less likely to be true).

    ELSEIF (least likely to be true).

    ENDIF.

    Example - AND:

  • 8/13/2019 Performance in ABAP Development

    6/24

    IF (least likely to be true) AND(most likely to be true).

    ENDIF.

    Example - OR:

    IF (most likely to be true) OR(least likely to be true).

    4. CASE vs. nested Ifs

    When testing fields "equal to"something, one can use either thenested IF or the CASE statement. TheCASE is better for two reasons. It iseasier to read and after about five

  • 8/13/2019 Performance in ABAP Development

    7/24

    nested IFs the performance of theCASE is more efficient.

    5. MOVE statements

    When records a and b have the exactsame structure, it is more efficient toMOVE a TO b than to MOVE-CORRESPONDING a TO b.

    MOVE BSEG TO *BSEG.

    is better than

    MOVE-CORRESPONDING BSEG TO*BSEG.

  • 8/13/2019 Performance in ABAP Development

    8/24

    6. SELECT and SELECT SINGLE

    When using the SELECT statement,study the key and always provide asmuch of the left-most part of the key aspossible. If the entire key can bequalified, code a SELECT SINGLE not

    just a SELECT. If you are onlyinterested in the first row or there isonly one row to be returned, usingSELECT SINGLE can increaseperformance by up to three times.

    7. Small internal tables vs. completeinternal tables

  • 8/13/2019 Performance in ABAP Development

    9/24

    In general it is better to minimize thenumber of fields declared in an internaltable. While it may be convenient todeclare an internal table using the LIKEcommand, in most cases, programs willnot use all fields in the SAP standardtable.

    For example:

    Instead of this:

    data: t_mara like mara occurs 0 withheader line.

    Use this:

  • 8/13/2019 Performance in ABAP Development

    10/24

    data: begin of t_mara occurs 0,

    matnr like mara-matnr,...end of t_mara.

    8. Row-level processing andSELECT SINGLE

    Similar to the processing of a SELECT-ENDSELECT loop, when callingmultiple SELECT-SINGLE commandson a non-buffered table (check DataDictionary -> Technical Info), youshould do the following to improveperformance:

  • 8/13/2019 Performance in ABAP Development

    11/24

    o Use the SELECT into tobuffer the necessary rows in an internaltable, then

    o sort the rows by the key fields,then

    o use a READ TABLE WITH KEY... BINARY SEARCH in place of theSELECT SINGLE command. Note thatthis only make sense when the tableyou are buffering is not too large (thisdecision must be made on a case bycase basis).

    9. READing single records ofinternal tables

  • 8/13/2019 Performance in ABAP Development

    12/24

    When reading a single record in aninternal table, the READ TABLE WITHKEY is not a direct READ. This meansthat if the data is not sorted accordingto the key, the system mustsequentially read the table. Therefore,you should:

    o SORT the table

    o use READ TABLE WITH KEYBINARY SEARCH for betterperformance.

    10. SORTing internal tables

  • 8/13/2019 Performance in ABAP Development

    13/24

    When SORTing internal tables, specifythe fields to SORTed.

    SORT ITAB BY FLD1 FLD2.

    is more efficient than

    SORT ITAB.

    11. Number of entries in an internaltable

    To find out how many entries are in aninternal table use DESCRIBE.

    DESCRIBE TABLE ITAB LINESCNTLNS.

  • 8/13/2019 Performance in ABAP Development

    14/24

    is more efficient than

    LOOP AT ITAB.

    CNTLNS = CNTLNS + 1.

    ENDLOOP.

    12. Performance diagnosis

    To diagnose performance problems, itis recommended to use the SAPtransaction SE30, ABAP/4 RuntimeAnalysis. The utility allows statisticalanalysis of transactions and programs.

  • 8/13/2019 Performance in ABAP Development

    15/24

    13. Nested SELECTs versus tableviews

    Since releASE 4.0, OPEN SQL allowsboth inner and outer table joins. Anested SELECT loop may be used toaccomplish the same concept.However, the performance of nestedSELECT loops is very poor incomparison to a join. Hence, toimprove performance by a factor of 25xand reduce network load, you shouldeither create a view in the datadictionary then use this view to selectdata, or code the select using a join.

    14. If nested SELECTs must be used

  • 8/13/2019 Performance in ABAP Development

    16/24

    As mentioned previously, performancecan be dramatically improved by usingviews instead of nested SELECTs,however, if this is not possible, then thefollowing example of using an internaltable in a nested SELECT can alsoimprove performance by a factor of 5x:

    Use this:form select_good.

    data: t_vbak like vbak occurs 0 withheader line.

    data: t_vbap like vbap occurs 0 withheader line.

  • 8/13/2019 Performance in ABAP Development

    17/24

    select * from vbak into table t_vbak upto 200 rows.

    select * from vbapfor all entries in t_vbakwhere vbeln = t_vbak-vbeln.

    ...endselect.

    endform.

    Instead of this:form select_bad.

    select * from vbak up to 200 rows.

    select * from vbap where vbeln =vbak-vbeln.

  • 8/13/2019 Performance in ABAP Development

    18/24

    ...endselect.

    endselect.

    endform.

    Although using "SELECT...FOR ALLENTRIES IN..." is generally very fast,you should be aware of the threepitfalls of using it:

    Firstly, SAP automatically removes anyduplicates from the rest of the retrievedrecords. Therefore, if you wish toensure that no qualifying records arediscarded, the field list of the inner

  • 8/13/2019 Performance in ABAP Development

    19/24

    SELECT must be designed to ensurethe retrieved records will contain noduplicates (normally, this would meanincluding in the list of retrieved fields allof those fields that comprise that table'sprimary key).

    Secondly, if you were able to code"SELECT ... FROM FOR ALL ENTRIES IN TABLE "and the internal table is empty,then all rows from willbe retrieved.

    Thirdly, if the internal table supplyingthe selection criteria (i.e. internal table in the example "...FOR ALL

  • 8/13/2019 Performance in ABAP Development

    20/24

    ENTRIES IN TABLE ") containsa large number of entries, performancedegradation may occur.

    15. SELECT * versus SELECTingindividual fields

    In general, use a SELECT statementspecifying a list of fields instead of aSELECT * to reduce network traffic andimprove performance. For tables withonly a few fields the improvements maybe minor, but many SAP tables containmore than 50 fields when the programneeds only a few. In the latter case,the performace gains can besubstantial. For example:

  • 8/13/2019 Performance in ABAP Development

    21/24

    Use:

    select vbeln auart vbtyp from table vbak

    into (vbak-vbeln, vbak-auart, vbak-vbtyp)

    where ...

    Instead of using:

    select * from vbak where ...

    16. Avoid unnecessary statements

  • 8/13/2019 Performance in ABAP Development

    22/24

    There are a few cases where onecommand is better than two. Forexample:

    Use:

    append to .

    Instead of:

    = .

    append (modify ).

    And also, use:

    if not [] is initial.

  • 8/13/2019 Performance in ABAP Development

    23/24

    Instead of:

    describe table lines.

    if > 0.

    17. Copying or appending internaltables

    Use this:

    [] = []. (if isempty)

    Instead of this:

  • 8/13/2019 Performance in ABAP Development

    24/24

    loop at .

    append to .

    endloop.

    However, if is not empty andshould not be overwritten, then use:

    append lines of [from index1] [toindex2] to .------------------------------------------------------------