0% found this document useful (0 votes)
175 views13 pages

ABAP OO Explained With Example

This document discusses ABAP programming performance tips and tricks available in SAP transaction SAT/SE30. It covers two main topics: 1. How to access and understand the various groups of performance examples in SAT/SE30, focusing on SQL interface and internal table examples. 2. Examples of preferred coding techniques for database access and internal table access from a performance perspective, such as using WHERE clauses instead of SELECT + CHECK and array operations instead of individual operations. The document provides guidance on using the built-in SAT/SE30 performance examples to choose efficient coding patterns and identify performance issues when developing or tuning ABAP programs.

Uploaded by

Ram Praneeth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views13 pages

ABAP OO Explained With Example

This document discusses ABAP programming performance tips and tricks available in SAP transaction SAT/SE30. It covers two main topics: 1. How to access and understand the various groups of performance examples in SAT/SE30, focusing on SQL interface and internal table examples. 2. Examples of preferred coding techniques for database access and internal table access from a performance perspective, such as using WHERE clauses instead of SELECT + CHECK and array operations instead of individual operations. The document provides guidance on using the built-in SAT/SE30 performance examples to choose efficient coding patterns and identify performance issues when developing or tuning ABAP programs.

Uploaded by

Ram Praneeth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

SAP application performance

SAP DEVELOPMENT

ABAP PROGRAMMING – PERFORMANCE TIPS


AND TRICKS
GALLERY | MAY 11, 2014 | ERIC | LEAVE A COMMENT

When you are coding an ABAP program, you often nd that the ABAP program can be coded in
different ways to do the same job, you are wondering which way would give a better performance.
When you are tuning the ABAP program performance, you encounter an expensive ABAP statement
in SAP ST12/SE30 trace, you are wondering why it is so expensive and what are other BAP coding
alternatives to replace the expensive one to improve the ABAP program performance. Tips and
tricks utility built in standard SAP transaction SAT/SE30 might help you with those questions. SAP
SAT/SE30 is comparing performance of common ABAP techniques/statements used by ABAP
developers via ABAP performance examples. So understanding those trips and tricks can help ABAP
developers to avoid common performance pitfalls during ABAP program development phase. It can
also help you when you need to tune ABAP program performance. This post would cover

1. Introduction of ABAP performance tips and tricks,


2. How to access ABAP performance tips and tricks examples,
1. Preferred coding techniques for SAP SQL interface – database table access,
2. Preferred coding techniques for ABAP internal table access,
3. How to use performance tips and tricks examples in ABAP program development and
performance tuning.

1 Introduction of SAP ABAP performance tips and tricks


SAP SE30/SAT organizes ABAP coding performance tips and tricks into following groups or
categories to make it easier for you to identify speci c ABAP code techniques. See Table 1 for groups
and their explanation.

Table 1 – ABAP performance Tips and Tricks Group

Performance Explanation
Tips/Tricks Group

SQL interface Explain which database access technique would give better performance by comparing
pairs of Database table access techniques: Select+ check vs Select + Where, Select and

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 1/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Exit vs Select … Up to 1 Rows, Find , Select Array select vs single select, read without index
vs read with index, individual operation and mass operation etc.

Context Obsoleted. If applicable in your version, using context is better than select since common
accessed data is stored in the memory and shared across SAP transactions.

Internal Tables Explain which internal table access technique would give better performance by
comparing pairs of kills like binary read vs key read, individual table operation vs mass
internal table operation etc.

Typing Explain that parameters/ eld-symbols whose types are speci ed is more ef cient than
parameters whose types are not speci ed.

If, Case… Explain that case statement is more ef cient than IF statement

Field Conversion Explain that we should avoid un-necessary eld conversion by using the same data type.

Character / String Explain that using string is better than character from performance point view
Manipulation

ABAP Objects Explain that call method and call subroutine has no material performance difference but
calling FM is slower than Method.

If you need to read a record from big internal table, you can read it via key or binary search, then you
can go to “internal table” group to which one is better to your situation.

Two groups – inef cient SQL statements and inef cient ABAP internal table operation are
highlighted based on my experience. They are often culprit of bad ABAP program performance
related to coding. So familiar with performance coding techniques under these two groups should
have priority over other groups.

2 How to access ABAP performance Tips and Tricks


To access SAP ABAP performance tips and tricks, you need to execute SAP transaction SAT/SE30,
then click on button “Tips & Tricks”.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 2/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Figure 1 SE30/SAT initial screen

If you click button “Tips and Tricks” button highlighted in Figure 1, performance tips and tricks for
ABAP objects screen like below Figure 2 would be displayed.

Figure 2 Se30/SAT Performance Tips and Trick Initial screen

I would cover more details related to highlighted groups “SQL interface” and “Internal table” below.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 3/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

2.1 Preferred Performance coding techniques for SAP SQL


interface / database table access
This group would explain preferred coding technique out of two different ways of table access.
Please refer to Table 2 for details

Table 2 SQL interface – preferred SQL coding strategy

ITEM Performance Explanation


preferred

Select + check VS. Select Select with where Use as much elds as possible in where clause: index
with where conditions conditions might be possible with the elds and lter earlier to
avoid unnecessary data traf c between DB server and
application server

Select + exit Vs. Select with Select with up to 1 Select with up to 1 rows would incur less trips/traf c
Up to 1 rows rows between DB and Application server.

Select + check VS. Select Select using Aggregate Avoid round trip between DB server and application
using Aggregate function function server, reduce traf c

Select * Vs. Select with a list Select with a list of Reduce round trip and traf c between application
of elds elds server and database server

Update one row VS update Update with speci ed Reduce network traf c
speci ed eld elds

Select without index VS Select with index Using an Index would reduce number of logical DB
Select with index reads, so it would be faster than a full table scan when
limited # of records are fetched.

Select without buffer Select with buffer Reading buffer could be up to 100 time faster than
support VS select with read from db disc.
buffer support

Select with Append Select into table Reduce round trips between DB and application server
statement VS select into
table

Many individual inserts VS Array insert Reduce round trips between DB and application server
Array insert

Select + Endselect VS Select Select into table + loop Reduce round trips between db server and application
into table + loop table table servers as well as network traf c

Nested Select Statement VS Select with view Reduce round trips between db server and application
Select with view servers as well as network traf c

Nested Select statement VS Select with join Reduce round trips between db server and application
Select with Join servers as well as network traf c

Using two Selects VS Select Select with subquery Reduce round trips between db server and application
using a subquery servers as well as network traf c

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 4/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

In following section, I would go through some SQL performance examples.

2.1.1 Select + Check VS Select with where conditions


I clicked SQL interface group and all child groups under SQL interface, then I clicked “Select…
Where” Vs. “Select + Check”, I got screen like Figure 3.

Figure 3 ABAP performance example – SELECT + Check Vs Select + Where clause

The display is divided into 3 portions in Figure 3, left panel – navigation to different group and ABAP
code performance techniques, Right upper window is showing two sample ABAP codes using two
code solutions which achieve same result. Right bottom window explains what is the performance-
preferred ABAP coding technique.

Based on explanation in Figure 3, it is clear that “select with where conditions” has better
performance than “select + check”. In another word, the sample code at right in gure 3 should have
better performance than ABAP sample code in the right. Is that true? You can actually test this to get
a feeling by clicking “Measure Runtime” button in Figure 3. Upon clicking it, I got Figure 4 screen.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 5/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Figure 4 ABAP performance example- Select + check vs select with where conditions

In this particular care, time spent by “Select + check” example code is 10 times longer than time
spent by “select with where clause” example code.

In the same fashion, you can navigate to other SQL coding techniques to get a feeling of performance
difference created by different ABAP coding techniques via sample codes.

2.1.2 Select without buffer support VS Select with buffer support


Figure 5 shows that Reading data from application buffer is 10 times faster than reading data from
database system.

Figure 5 ABAP performance example – Select without buffer support vs Select with buffer support

2.1.3 Select into table + loop at table VS. Select Endselect


Select into table is much more ef cient than Select … Endselect. Select into table needs more
“memory” to hold the result set. In normal situation, this is not a concern. When memory is a concern,
you can divide the result set into smaller sets.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 6/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Figure 6 ABAP performance example – Select Into table + loop at table VS Select.. ENDSelect.

2.1.4 Array/Mass Insert VS single-row Insert


Array/Mass Insert is always better from performance point view since it can reduce unnecessary
round trips between database and application server by utilizing full capacity of data communication
bus between database and application server. It can also allow database

Figure 7 ABAP performance example – Single-line insert VS Array Insert

2.1.5 Nested selects VS Select with view


Select with view always performances better than “Nested Select”.

Figure 8 ABAP performance example – Nested Select VS Select with View

2.1.6 Nested select VS Select with Join


Select with join always performances better than Nested selected.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 7/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Figure 9 ABAP performance example – Nested Select Vs Select join

2.2 Preferred Performance coding techniques for ABAP


internal table operation
Please refer to Table-3 for some ABAP code techniques which are important to application
performance. They are selected from what offered by SAP SAT/SE30 tips and tricks based on my
performance experience.

Table 3 SAT/SE30 ABAP internal table handling performance tips and tricks

ITEM Performance Explanation


preferred

Linear search VS Binary Binary search If internal tables are assumed to have many (>20) entries, a linear
search search through all entries is very time-consuming. Try to keep the
table ordered and use binary search or used a table of type SORTED
TABLE. If TAB has n entries, linear search runs in O(n) time,
whereas binary search takes only O( log2( n ) ).

Secondary index Vs No Using secondary When an internal table is accessed with different keys repeatedly,
Secondary index for repeated create your own secondary index. With a secondary index, you can
accesses replace a linear search with a binary search plus an index access.

LOOP internal table and Loop… where LOOP … WHERE is faster than LOOP/CHECK because LOOP …
CHECK VS LOOP … WHERE evaluates the specified condition internally. As with any
WHERE logical expressions, the performance is better if the operands of a
comparison share a common type. The performance can be further
enhanced if LOOP … WHERE is combined with FROM i1 and/or TO i2,
if possible.

Sorted table VS Hashed Sorted table for Hashed tables are optimized for single entry access. The entries have
Table repeated accesses. no specific order. Therefore, a partial sequential access cannot be
Hashed table for optimized. Every entry must be checked to match the condition (full
single access table scan). Sorted tables are ordered ascendingly by their key
components. If a partial key of the form “k1 = v1 AND … AND kn =
vn” where k1 .. kn matches a left part of the table key, the access is
optimized by the kernel. In that case, only the matching entries are
visited.

Copying a table via loop Equal operation Internal tables can be copied by MOVE just like any other data
VS equal better object.
If an internal table itab has a header line, the table itself is accessed
by itab[].

Join table – Loop table 1 Loop table 1 then If ITAB1 has n1 entries and ITAB2 has n2 entries, the time needed
then read table 2 VS read 2nd table with an for joining ITAB1 and ITAB2 with the straightforward algorithm is O(
loop table1 then read index n1 * log2( n2 ) ), whereas the parallel cursor approach takes only O(
table 2 with index n1 + n2 ) time. The above parallel cursor algorithm assumes that
ITAB2 is a secondary table containing only entries also contained in
primary table ITAB1. If this assumption does not hold, the parallel

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 8/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

cursor algorithm gets slightly more complicated, but its performance


characteristics remain the same.

In following sections, performance code examples from SAT/SE30 are covered for selected topics.

2.2.1 Read internal table via key VS Read Internal table via binary
search
Figure 10 show It is more ef cient to read an internal table via binary search if the table entries is
huge. This bene t might be more signi cant if you need to read the table many times.

Figure 10 ABAP performance example – Linear against Binary search in an internal table

2.2.2 Read internal table without secondary index VS secondary index


Reading an internal table using a secondary index could be more ef cient than read via a key.

Figure 11 ABAP performance example – Read internal table using index VS no-index

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 9/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

2.2.3 Read internal table via combination of Loop and Check VS read
internal table via Loop… Where
Reading an internal table with loop… where statements is more ef cient than loop + check
statements.

Figure 12 ABAP performance example – Loop and Check VS Loop where

2.2.4 Read internal table – Hashed table VS sorted table


When you need to read the internal table many times, using sorted table is more ef cient than using
hashed table.

Figure 13 ABAP performance example – Sorted table VS Hashed table

2.2.5 Copy internal table – Loop + append and copy VS “=”


Using “=” to copy table is more ef cient than using Loop + append to copy an internal table.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 10/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Figure 14 ABAP performance example – copy internal table

2.2.6 Join internal tables – Loop table1 and read table2 against loop
table 1 and read table2 via Index
Using method of looping table 1 than reading table 2 via INDEX is more ef cient than method of
looping table 1 then reading table 2 without index.

Figure 15 ABAP performance example – join internal tables

3 Testing performance of your own ABAP codes


I have seen ABAP developer to compare performance of two different sets of ABAP code which
achieve the same purpose via SE30. It looks like that this can be done via SAT/SE30 menu path EDIT-
> Editing -> LEFT-hand /Right-Hand as showed in Figure 16. I do not have authorization to do this in
the system I owned.. Readers like you can explore this more should you be interested in it.

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 11/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

Figure 16 SAT/SE30 – your own sample codes

4 Further Information
A SAP ABAP program performance can have many contributing factors like solution design,
functional con guration and program code from application performance point view. An application
performance issue can be rooted from database performance, system capacity, network, IO design
as well. SAP performance tips and tricks cannot help to improve ABAP program performance issue
which is rooted from solution design, functional con guration, database performance issue and etc.
It can help to verify whether a program performance issue is rooted from programming techniques.
In my experience, over 50% of ABAP program performance issues are related to program code. So it
is important for a SAP developer to become familiar with those performance examples and
performance-preferred ABAP coding techniques.

Again, not all performance examples from SAP SAT/SE30 are covered here. My intention is to cover
most common/critical examples based on my experiences. You can run SAP SAT/SE30 online to
review the remaining ABAP performance examples. Also, SAT/SE30 covers “common” performances
examples. There are many ways to put ABAP statement together for the same purpose. It is not the
expectation that SAT/SE30 provides a examples for each situation.

SE30 allows you to do ABAP runtime analysis but it would not provide much data to support SQL
performance. My preferred tool to do ABAP program runtime analysis is SAP transaction ST12
which I nd ef cient to do performance analysis on ABAP logic operation and database access. I
might come out a post on how to use SE30 to do ABAP runtime analysis in the future.

I have following posts related to SAP program performance: how to improve a SAP ABAP program
performance; how to run SAP ST12 to do a performance trace; how to analyze ABAP trace; how to
analyze SQL trace;

SAP ABAP PROGRAMMING PERFORMANCE TIPS AND TRICKS; SAP ABAP PROGRAM PERFORMANCE EXAMPLES; SAP ABAP
PERFORMANCE CODING TECHNIQUES

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 12/13
8/9/2018 ABAP programming – performance tips and tricks | SAP application performance

https://www.sap-perf.ca/abap-programming-performance-tips-and-tricks/ 13/13

You might also like