Antes de eliminar algún elemento verificar que no se utilice en otros programas aunque sea
únicamente una referencia.
End of ty_name
Tipo de tabla:
Tabla Interna
Estructura:
La declaración de tabla interna HASHED/SORTED debe ser utilizada para tablas internas que
recibirán un gran volumen de información, sino usar type Standard TABLE .
La performance en cualquier programa ABAP, depende principalmente del acceso a las bases
de datos. Mientras más se optimice la selección de datos, será mejor la performance.
1. Usar todos los campos claves en la sentencia SELECT o la gran mayoría de los mismos
2. Evitar la sentencia SELECT * utilice solamente los campos que serán necesarios en la
selección de datos .
3. Si coloca todos los campos claves, codificar con un SELECT SINGLE y no un SELECT …
END SELECT. En caso de no contar con todos los campos clave, deberá usar SELECT UP
TO 1 ROWS, si nos interesa únicamente el primer registro.
4. Evitar la sentencia SELECT – ENDSELECT, antes que hacer esto es mejor seleccionar la
información en una tabla interna, y dentro de un loop se puede descartar los registros
que no necesitamos.
5. Se hace lo posible por usas índices para acceder a una tabla, en caso de no existir las
claves por las cuales se accede.
6. Evite usar INTO CORRESPONDING FIELDS de la Tabla. En cambio, mencione
explícitamente los campos, si los campos de la tabla no están en la misma secuencia
que la selección
Select Distinct
Siempre que sea posible, evite SELECCIONAR DISTINCIÓN, en su lugar, seleccione datos en la
tabla interna, clasifique y use ELIMINAR DUPLICADOS ADYACENTES.
e.g.
En lugar de
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 omitirá el buffer. Por lo tanto, el rendimiento disminuirá. Si desea ordenar datos, es
eficiente ORDENALOS en una tabla interna en lugar de usar ORDER BY. Solo use un ORDER BY
en su SELECT si el orden coincide con el índice, que debe usarse.
Append Lines of
Whenever it is possible use APPEND LINES OF to append the internal Tables instead of using
loop and then APPEND Statement.
Subroutine Usage
For good modularization, the decision of whether or not to execute a subroutine should be
made before the subroutine is called.
Example:
IF f1 NE 0.
PERFORM sub1.
Hashed table
If the number of entries in the Internal Table is high then use Hashed Table with Keys to access
the table.
Transporting
With READ or MODIFY Statements use TRANSPORTING and specify the fields being
transported.
( Modifying internal table its best to use field symbol )
Using LDB
In order to improve performance in case of an LDB, individual tables can be excluded from
selection. Under the section ‘Table Selection’ in the Documentation of LDB the fields with
proper description has been given those fields can be set in the application report at the time
of INITIALIZATION or at the START OF SELECTION. This can enhance the performance.
Use WHILE
Use WHILE instead of a DO+EXIT-construction, as WHILE is easier to understand and faster to
execute
Identical Structures
If two structures are identical, use MOVE x to y, rather than MOVE-CORRESPONDING x to y
When records a and b have the exact same structure, it is more efficient to MOVE a TO b than
to MOVE-CORRESPONDING a TO b.
MOVE BSEG TO *BSEG.
is better than
MOVE-CORRESPONDING BSEG TO *BSEG.
Nested loop
Ensure that instead of nested loop, parallel cursor method is used wherever possible. Parallel
cursor method involves finding out the index using READ statement & searching only the
relevant entries. This will give huge performance benefits. And if possible, RFC parallelization
method can also be considered.
Nested loop
Loop at T1 into W1.
Loop at T2 into W2 where F1 = W1-F1.
Endloop
Endloop
Parallel cursor method
Loop at T1 into W1.
Read table T2 into W2 with key F1 = W1-F1 Binary Search.
l_index = SY-tabix.
Loop at T2 into W3 from l_index.
If W3-F1 <> W1-F1.
Exit. “ Exit inner loop when condition fails
Endif.
Endloop
Endloop
Use Parallel Cursor methods for nested loop into the internal tables if second internal table
contains considerable number of records.
Index tables
Try to make use of INDEX tables as much as possible to improve the performance.
e.g.: If data needs to be fetched from VBAP table based on Material number which is not a key
field, prior looking for a secondary index with material, try to find whether any INDEX TABLE
exists. In this case VAPMA is an index table which will return the SD Document number and
item where a material exists.
Note: In all the cases Index table may not exists and even if Index table exists make sure its
active. i.e. the index table contains approximately the same no entries compared to the main
table
OPEN / RE-OPEN.
FETCH.
OPEN / RE-OPEN: This is the process to start or to flag-off the process of getting data from the
database. This is like a green signal of the traffic lights that denotes that it is the time to get
the data from the source location.
FETCH: This locates the database data that satisfies the conditions and then transfers it into
the Application Server. The data is transferred in one or more Fetches; it is called an Array
Fetch. An Array Fetch offers better performance than transferring data in the form of single
records in Client/Server architecture.
Maximum number of records that can be Fetched in an operation is determined by the SAP DB
interface.
The default value that is set by the SAP for this purpose is 33,792 bytes.
from application system to presentation system also fixed. But we can change that value.
Performance diagnosis
SQL Trace
Use transaction ST05 (SQL Trace) to see what indices your database accesses are using. Check
these indices against your “where” clause to assure they are significant. Check other indices
for this table and where you have to change your “where” clause to use it.
1. DATABASE
a. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved. Very
important !!
b. Design your Query to Use as much index fields as possible in your WHERE statement
c. Use INNER (or OUTER under some circumstances) JOIN in your SELECT statement to retrieve
the matching records at one shot
d. Avoid using nested SELECT statement and SELECT within LOOPs, better use JOINs or FOR ALL
ENTRIES. Use FOR ALL ENTRIES when the internal table is already there or the end of some
processing. Try JOINs if the SELECT are right behind each other
e. Avoid using INTO CORRESPONDING FIELDS OF TABLE during buffered access. Otherwise use
the most appropriate for the program.
f. Avoid using SELECT * and Select only the required fields from the table.
g. Avoid using ORDER BY in SELECT statements if it differs from used index (instead, sort the
resulting internal table), because this may add additional work to the database system which is
unique, while there may be many ABAP servers
h. INDEX: Creation of Index for improving performance should not be taken without thought.
Index speeds up the performance but at the same time adds two overheads namely; memory
and insert/append performance. When INDEX is created, memory is used up for storing the
index and index sizes can be quite big on large transaction tables! When inserting new entry in
the table, all the index's are updated. More index more time. More the amount of data, bigger
the indices, larger the time for updating all the indices
i. Avoid Executing an identical Select (same SELECT, same parameter) multiple times in the
program. Buffer in your abap code.
j. Avoid using join statements if adequate standard views exist no performance impact
2. TABLE BUFFER:
a. Defining a table as buffered (SE11) can help in improving the performance but this has to be
used with caution. Buffering of tables leads to data being read from the buffer rather than
from table. Buffer sync with table happens periodically, only if something changes which is
happen rarely. If this table is a transaction table chances are that the data is changing for a
particular selection criteria, therefore application tables are usually not suited for table
bufferung. Using table buffering in such cases is not recommended. Use Table Buffering for
configuration data and sometimes for Master Data..
What is the difference between SELECT SINGLE and SELECT ... UP TO 1 ROWS?
SELECT SINGLE and SELECT UP TO n ROWS return the first matching row/rows for the given
condition. It may not be unique, if there are more matching rows for the given condition.
With ORACLE database system, SELECT SINGLE is converted into SELECT ... UP TO 1 ROWS, thus
they are exactly the same in that case. The only difference is the ABAP syntax prevents from
using ORDER BY with SELECT SINGLE, but it is allowed with SELECT ... UP TO 1 ROWS. Thus, if
several records may be returned and we want to get the highest record for example, SELECT
SINGLE cannot be used, but SELECT ... UP TO 1 ROWS WHERE ... ORDER BY ... may be used.
Instead of using logic to do summation use collect statement. COLLECT is especially efficient
with HASHED tables.
LOOP AT ITAB1.
....
ENDLOOP.