Abap Performance Tips

Páginas: 7 (1613 palabras) Publicado: 28 de diciembre de 2012
ABAP Performance tips

* Page restrictions apply
* Added by Gokul R Nair, last edited by Gokul R Nair on Jul 22, 2011
Comment:

The performance of any ABAP program mainly depends on the database accesses used in it. The more optimized the selections, the better the performance. Consider the points mentioned in the following sections while writing any ABAP code that accesses thedatabase.
·         Using all the keys in SELECT statement
When using the SELECT statement, study the key and always provide as much of the left-most part of the key as possible.
·         Avoid SELECT *
The SELECT * command is to be avoided rigorously, (unless you need every field in the table), because it drags every field in the table through the I/O bottleneck thus slowing the program.·         Fetching Single Record
If the entire key can be qualified, code a SELECT SINGLE not a SELECT … ENDSELECT.  If all the keys are not available, we should use SELECT UPTO 1 ROWS if we are interested only in the first record.
·         Avoid SELECT-ENDSELECT
Selecting data into an internal table using an array fetch versus a SELECT-ENDELECT loop will give at least a 2x performance improvement.After the data has been put into the internal data, then row-level processing can be done.
Example:
select ... from table
             into
           where ...
loop at

endloop.
·         Using Indices
When accessing the database, careful consideration should be given to index access in order to make the program as efficient as possible.  Tune the Query so that optimum indexing willhappen.
·         Avoid “INTO CORRESPONDING”
Avoid using INTO CORESPONDING FIELDS of Table. Instead, explicitly mention the fields, if the table fields are not in the same sequence as the selection
·         SELECT statement inside LOOP
Do not write SELECT statements inside a loop. Instead, use the FOR ALL ENTRIES Command
Before using FOR ALL ENTRIES command, check that the
 1. CorrespondingInternal table is not empty. If the Internal table is empty, the statement will select ALL the entries in the Database
 2. The Internal table is sorted by the File used in the Where Clause: This makes selection faster.  (And delete adjacent duplicates for the key fields.)
·         Nested SELECT statement
Avoid using nested SELECT statements. Instead, make use of different internal tables to fetchthe data, and Use Nested LOOPS to read them.
·         Select Distinct
Whenever it's possible avoid SELECT DISTINCT, instead select data into internal table, sort and use DELETE ADJACENT DUPLICATES.
·         Use of OR in Where Clause
Do not use OR when selecting data from DB table using an index because the optimizer generally stops if the WHERE condition contains an OR expression.
e.g.Instead of
SELECT * FROM spfli WHERE carrid = ‘LH’
AND (cityfrom = ‘FRANKFURT’ OR
city from = ‘NEWYORK’)
Use
SELECT * FROM spfli WHERE (carrid = ‘LH’ AND cityfrom = ‘FRANKFURT’)
OR (carrid = ‘LH’ AND cityfrom = ‘NEWYORK’).
·         Order By
ORDER BY will bypass buffer. So, performance will decrease. If you want to sort data, it is efficient to SORT them in an internal table rather thanusing ORDER BY. Only use an ORDER BY in your SELECT if the order matches the index, which should be used.
·         Using the READ statement
When reading a single record in an internal table, the READ TABLE WITH KEY is not a direct READ. The table needs to be sorted by the Key fields and the command READ TABLE WITH KEY BINARY SEARCH is to be used; otherwise the table is read from top to bottom untila field matching the KEY is found.
·         Append Lines of
Whenever it is possible use APPEND LINES OF to append the internal Tables instead of using loop and then APPEND Statement.
·         DELETE WHERE
Use DELETE WHERE…for deleting records from an internal table.
e.g.
Instead of
LOOP AT WHERE = ‘0001’
DELETE .
ENDLOOP.
Use
DELETE WHERE = ‘0001’.
·         Using WHERE...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Manual Abap Performance
  • Performance en abap
  • Performance abap
  • Mejores Performance Abap
  • Abap
  • Abap
  • Abap
  • Abap

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS