You are on page 1of 8

ABAP Performance tuning for SAP BW

Document submitted by Vandana Goyal

Table Of Contents
1.

NEED OF ABAP PERFORMANCE TUNING IN SAP BW.............................................................3

2.

START ROUTINE VS. FIELD ROUTINE........................................................................................3

3.

INTERNAL TABLE DECLARATION...............................................................................................3

4.

INTERNAL TABLE OPERATIONS..................................................................................................4


DELETING RECORDS.....................................................................................................................................4
SORTING INTERNAL TABLE...........................................................................................................................5
READING DATA FROM INTERNAL TABLE.......................................................................................................5
MODIFYING INTERNAL TABLE......................................................................................................................6
COPYING INTERNAL TABLES.........................................................................................................................6

5.

FOR ALL ENTRIES STATEMENT...................................................................................................6

6.

SQL STATEMENTS FOR DATABASE ACCESS.............................................................................7

7.

RUNTIME ANALYSIS AND SQL TRACE.......................................................................................8


RUNTIME ANALYSIS (TRANSACTION SE30).................................................................................................8
DATABASE ACCESS (TRANSACTION ST05)...................................................................................................8

2/ 8

1. Need of ABAP Performance tuning in SAP BW


The performance of SAP BW project is always a primary aspect, as it is mainly related to
the users expectations in terms of effectiveness as well as efficiency of project. The more
efficient and effective the performance, higher the chances of success. ABAP code plays
a vital role in performance and it come into picture while loading millions of records.
ABAP code is always written for data retrieval from database tables at R/3 system side
either in extractors or in Transfer / Update Rules of BW system. Many times, ABAP code
fine-tuning dramatically enhances the performance by reducing data retrieval, processing
and loading time. Few measures are mentioned in this document to make ABAP more
efficient.

2. Start routine vs. Field routine


Start routines are always preferred over field routine if filtrations or changes are required
in data package. While field routines are used when simple calculations are required to
assign value to target field based on value of another field or global variable or the value
from global internal table that is populated in start routine.
If we have to do look-ups into other ODS or have to extract data from database tables, it
is best practice to retrieve all the data in start routine only instead of fields routines.
Advantage of going this is that we can fetch all the data from other ODS or database
tables in one database hit only instead of multiple hits (multiple times of number of
records in data package ) to these database sources from field routine. Start routine gives
us opportunity to process all the data package records together.

3. Internal table declaration


Type declaration is very first step if we think to declare our own designed table. It is
always advisable to declare fields under type definition in the same order as they are
declared in database table from which we are interested to fetch selective data. The
reason is that we can avoid use of INTO CORRESPONDING FIELDS OF TABLE
statement and can use more performance efficient statement INTO TABLE in select
statement.
The second thing to consider is that we must avoid use of LIKE keyword to a possible
extends and should prefer TYPE field.

3/ 8

E.g.

In case i, ABAP processer first goes to table /bic/asddwo200 and then it searches for
doc_number field and finally get its data element type. This entire procedure take bit
more time than as we do in case ii. In case ii, ABAP processor directly jumps to domain
and creates a variable of same type or of technical properties.
For internal table declaration, we must declare internal table as hashed table with unique
key if we have to select huge number of records. If number of records to be stored into
internal table is small, then we must go for standard table definition. The reason is that
read statement searches record based on key values. If internal table is not defined as
hashed table, then read statement searches internal table based on value of hashed key for
particular record, which is quite fast as performance point of view.
However, we must always take data size which is to be stored into consideration while
declaring internal table. If number of records is very small and still we are using hashed
table, it can worse the performance. Because ABAP processor spends some time in
calculation of hash keys for every record of internal table. Therefore, we must be very
careful before doing internal table declaration.
We also have to decide scope of internal table. If internal table is only used in start
routine or locally into some other routine, then we must define it locally and free it before
exiting routine. This is good practice as it frees space on ABAP stack. If the internal table
is used by many field routine, then its scope must be enhanced to global and same
internal table be re-used with in routines.

4. Internal table operations


Deleting records
Sometimes we need to filter / delete multiple records from internal table (or may be from
data package), then we should use DELETE...WHERE statement instead of
LOOP...DELETE statement.

4/ 8

E.g.

In case i, deletion of records takes place one by one while in case ii, all the records that
are satisfying criteria are deleted together. So, ABAP processing is achieved quicker in
second case.
Note: One most important thing keep into consideration is to avoid use of NE
operator in DELETE or SELETE statement. This is a slow statement as it follows
only linear searching algorithm.

Sorting internal table


SORT statement is always proved to be very expensive statement, therefore we must
avoid it to a possible extend unless and until is used for some specific requirement.
If we are sorting internal table that may have large number of duplicate records, then we
can delete duplicate records using DELETE ADJUCANT DUPLICATE statement from
data package or internal table. It has two advantages. First, it release unnecessary space
occupied by duplicate records of internal table. Second, it helps to avoid doing repetitive
or unnecessary duplicate records processing.

Reading data from internal table


If we are using hashed table, then we need not to worry about READ statement
performance. It uses hash algorithm. If we have to read data from standard internal table
then we can improve read statement performance by using binary search instead of using
linear search, but the pre-requisite is that internal table must be sorted.

5/ 8

E.g.

Modifying internal table


Modify statement is slow statement as well as need bit more space. This statement first
allocated a workarea into ABAP stack then copies desired record to that workarea, does
modifications and copies back into internal table. There is another faster method exists.
We can do all this in just 0.1 times of times in compare to first method by using field
symbols. Field symbol directly does to desired record and do modification there only.
Since field symbols behaves as a pointer and hence performances modification operation
on record directly.

Copying internal tables


We can copy data of one internal table to another using LOOP...APPEND statement and
by directly assigning one internal table to another. Second approach is more performance
efficient in compare to first.

5. FOR ALL ENTRIES Statement


We generally use FOR ALL ENTRIES statement to restrict number of records in Select
statement. This statement turns expensive if few systems setting are missing. It increases
CPU load and memory usage. This situation can be avoided by implementing SAP Note:
634263.

6/ 8

C:\Documents and
Settings\Goyal2V\Desktop\sapnote_0000634263[1].pdf

6. SQL statements for database access


Database read / write are most expensive operations. If memory is limited, then it causes
memory-swapping operation and increases processor activities. By careful ABAP coding
and design, we can reduce processor to great extent.
We can improve the performance of data loading (database read operation) by extracting
restricted data and selecting only useful data for our functionality. We should try to do
minimum number of hits to database for better performance. Below are some mentioned
tips to reduce database access.
i.

ii.

iii.

iv.

Lazy practice of most ABAP programmer is to use SELECT * even when very few
fields are required. This practice slow downs extraction processes and put
unnecessary load over entire system. Application server send request to database
server to return entire structure. If return structure is very large, then it consumes lots
of CPU recourses as well as network resources. Therefore, we must avoid Select *
statement, especially when source database table have many fields. We must specify
list of fields that is we need to extract into target workarea or internal table. There are
two advantages of doing this. First, we can reduce database read time and second,
comparative less memory will be required while processing. E.g. SELECT <field1>
<field2> . INTO <workarea> / INTO TABLE <itab>.
While selecting records, we must always extract columns or fields of table in the
same order in which they are defined in table. If we extract fields in different order
than in which they are defined in table, then relining of search index takes place and it
increases read / fetch time.
Always try to restrict number of fetched records from database table by specifying
selection criteria in where clause. In start routine, we can restrict number of look-up
records based on records present in data package. So, we can use for all entries
statement with where clause. We must use as many key fields as possible with where
clause.
We can also avoid unnecessary load over database by selecting data into internal
tables instead of local variables or structures as it reduces database attempts.
E.g.

7/ 8

v.
vi.
vii.

For multiple records, avoid loop...select sigle...endloop.Instead of this approach,


select all desired records into internal table in single database access.
Try to access header information first then detail information, so that we can specify
as many key as possible while accessing detail information.
The order by clause is executed on the database server, while the sort statement is
executed on the application server. Thus instead of giving the order by in the select
clause statement, it is better to collect the records in an internal table and then use the
sort command to sort the resulting data set.

There are many more ways to improve database access time. Careful ABAP
programming can help to reduce database read / write time.

7. Runtime Analysis and SQL Trace


Runtime analysis (Transaction SE30)
This transaction gives analysis of ABAP program in terms of database and non-database
processing. Its shows how much time is spent on hitting database and accessing it and
how much time spend in non-database activities by ABAP code.
This transaction also shows hints and tips for good database access statement options.

Database access (Transaction ST05)


With this transaction, we can analyze all the database hits. We can check which tables we
have accessed and how many times. With this trace log, it become easy to check
repetitive or unnecessary database access and can be avoided.

8/ 8