Professional Documents
Culture Documents
SAP Performance Optimization & Table Buffer
SAP Performance Optimization & Table Buffer
SAP Performance
Optimization
9 SAP Table Buffering
Every SAP instance has various buffers, in which data to be accessed by
users is stored. When the data is in the buffer, the database does not have
to be accessed, because buffers enable direct reads from the main
memory of the application server. There are two advantages to this:
Table Table
Buffer Buffer
Database instance
Database Buffer
Database
This chapter deals with table buffering on the SAP application level. Table
buffering on database level is dealt with in Chapter 11.
To better understand this chapter you should have some familiarity with
ABAP programming and SQL programming.
Technical analysis The main aim of the following chapters is to help you to identify
– logical analysis performance problems in these areas, that is, to find the program or table
causing the problem, in order to be able to then deal with it. However,
before making any concrete changes to solve the problem, you should
perform a technical analysis and also a logical analysis. The procedure for
technical analysis is explained in this book. This type of analysis can be
carried out by a system or database administrator, for example. The
logical analysis can only be executed by the developer responsible. You
should bear the following recommendations in mind:
The buffering status and database indices of SAP tables are already pre-
set when the SAP system is delivered. In some cases it may be
necessary to change these standard settings. Before you perform a
change, you should look in the SAP Service Marketplace for notes on
the program name, table or number name which will confirm whether
or not you can change the object in question. These notes correspond
to the SAP developer's input for the logical analysis. Changes
performed without the proper expertise can lead to unexpected
performance problems and to data inconsistencies. Take note of the
warnings and recommendations provided in the respective sections of
this book.
Buffering types
We differentiate between three different types of table buffering: single
record buffering, generic buffering and full buffering.
Single record buffering is suitable for accesses that are executed using all Single record
table keys – in other words, all fields of the primary index. With single buffering
record buffering, each record (a row in a table) that is read from the
database for the first time is archived in the buffer. Then, whenever the
record needs to be read again, it can be read directly from the buffer.
Let us take an example of a table <tab_sngl>, with the key fields <key1>,
<key2> and <key3>. A record is read from the table with the following
SQL statement:
In order for the buffer to be accessed, the ABAP key word SINGLE must
be contained in the SQL statement. SQL statements in which not all key
fields are specified in the WHERE clause cannot be processed from single
record buffers; instead, the database will be accessed.
On the first attempt to access a table for which single record buffering is
activated, if the required record is not in the database, information is
stored in the buffer to indicate that the record does not exist. In other
words, negative information is also buffered. On a second attempt to
access this record, the buffer search recognizes that the record does not
exist and thus makes no attempt to access the database. As a result, the
number of entries for a specific table in the single record buffer may be
larger than the number of actual records in that table in the database.
Full buffering Full buffering is another way of buffering tables. With fully buffered
tables, on the first reading of a table record, the entire table is loaded into
the buffer. This type of buffering is mainly used for small tables.
Figure 9.2 compares the different types of buffering. The buffered records
of a table are shown in dark gray. A fully buffered table is shown on the
left. Because the table is either completely contained in the buffer or not
at all, either all entries will be dark gray or none at all. The right-hand table
in Figure 9.2 shows a single-record buffered table. Some individual
records are buffered, others are not.
Generic buffering The third form of buffering is generic buffering with <n> key fields. On first
read access of a record in a generically <n> buffered table, all records with
the same <n> key field values as the targeted record are loaded into the
buffer. In Figure 9.2 the table second from the left is a table for which
generic buffering is activated and n = 1. For this table all records with the
first key value = "002" are stored in the buffer. These records make up
what is referred to as a generic region. Similarly, in the third column from
the left, under "generic buffering, two key fields", the buffer contains
generic regions with the first two key fields the same.
For table <tab_gen2> generic 2 buffering has been set. The first two
primary key fields are the client (MANDT) and the company code
(BUKRS). The table also contains the primary key fields <key3> and
<key4>. Let us also assume that the table contains data on the company
codes "Poland", "Czech Republic" and "Slovakia". The table is now
accessed with the following SQL statement:
SELECT * FROM <tab_gen2> WHERE mandt = '100' AND bukrs = 'Poland’ AND
<key3> = a3.
Buffer accessing
Even after a table is stored in the buffer, the database interface does not
automatically access the table buffers. As we have explained above, to
access a single-record buffered table, all fields of the primary key of the
For table <tab_gen3> generic 3 buffering has been set. The fields <key1>,
<key2>, <key3> and <key4> are the key fields of the table.
The following SQL statements cannot be processed with the help of the
SAP buffer and require access to the database:
The buffer for the generic-3 buffered table is not accessed, because the
fields <key1>, <key2> and <key3> are not all specified.
With a fully buffered table the buffer is always accessed, provided that
the table in question has been loaded into the buffer.
Table <tab_ful> has full buffering. The fields <key1>, <key2>, <key3> and
<key4> are the key fields of the table.
Buffer synchronization
If an entry to a buffered table is changed, the corresponding entries in the
table buffers of all SAP instances must be updated. This process is referred
to as buffer synchronization.
Pending period After an invalidation, the contents of a table are not immediately loaded
into the buffer at the next read access. Rather, a certain waiting or pending
period is observed. The next "n" accesses are redirected to the database. The
buffer is only reloaded after the pending period. This protects the buffer
from frequent successive invalidations and reloading operations.
Table Table
Buffer Buffer
UPDATE
T001 ...
Database interface Database interface
SELECT DDLOG
T001 table
INSERT DDLOG
DDLOG
table Database
Thus, table contents are invalidated in the same units that they are filled.
Invalidations should not be confused with displacements, which are Invalidations and
displayed in the SAP Memory Configuration Monitor (ST02) in the Swaps displacements
column. When there is not enough space in the buffer to store new data,
the data that has not been accessed in the longest time is displaced.
Displacement occurs asynchronously, determined by accesses to the
buffer. It occurs when the space available in the buffer falls below a
certain level or when access quality falls below a certain point.
Activating buffering
1. To activate or deactivate buffering for a table, call the ABAP dictionary
function by selecting:
Tools • ABAP Workbench • Dictionary
2. Enter the table name, select the Display button and then Technical
settings.
Since the technical settings of a table are linked to the SAP Change and
Transport System (CTS), to change the buffering for a table you need a
change request. Buffering can be activated or deactivated while the SAP
system is running.
If you try to activate buffering for a table that SAP has delivered with the
setting Buffering not allowed, this is considered a modification of the
SAP system and must be registered in the SAP Service Marketplace. You
should activate the buffering for such tables only if you have been
explicitly advised to do so by SAP.
If you set the buffering type for a client-dependent table to "full", the
table will automatically be buffered as generic 1.
Transaction data includes, for example: sales orders, deliveries, material Never buffer
movements and material reservations which, for example, are stored in transaction data!
the tables VBAK, LIKP, MKPF and RESB. These tables grow over time and
As a rule, do not Typical master data includes, for example, materials, customers and
buffer master suppliers, stored in the tables MARA, KNA1 and LFA1. Tables with master
data!
data grow slowly over time and can reach sizes of several hundred
Mbytes. For this reason, master data is generally not buffered. Another
argument against buffering master data tables is that master data is
normally accessed with many different selections and not necessarily via
the primary key. Rather than buffering, accesses to these tables can be
optimized by the use of secondary indices.
Customizing data Customizing data portrays, among other things, the business processes of
is normally your enterprise in the SAP system. Examples of customizing data include
buffered!
the definition of clients, the company codes, plant and sales
organizations, for example in tables T000, T001, T001W and TVKO.
Customizing tables are generally small and are seldom changed once the
system has gone live. As such, customizing data is very suited to table
buffering.
Table TCURR, for example, contains exchange rates for foreign currencies.
The key fields in this table are MANDT (client), KURST (type of exchange
rate), FCURR (source currency), TCURR (target currency) and GDATU
(start of validity period). In most customer systems this table is small, it is
rarely changed and thus meets all the conditions for buffering. As a result,
it is delivered by SAP with the status "full buffering" set.
In some SAP systems, however, it may occur that this table grows quickly
because many exchange rates are required and the rates are frequently
changed. Because the table is fully buffered, older entries (entries with
validity periods that have long since expired) are also loaded into the buffer,
although they are no longer necessary for normal operation. As a result,
once the table reaches a particular size, table buffering is no longer
effective. If the table is changed during daily operation, invalidations and
displacements reduce performance.
In this case, you should remove the table from buffering. You should also try
to achieve a long-term application-specific solution: are all table entries
really necessary? Could old entries be removed – for example by archiving?
We will look at this example again in greater detail in the section “Detailed
table analysis” on page 304.
Field Explanation
Table Name of the table; if it is a pooled table, the name of the table pool is
given first, for example, KAPOL A004
Buffer State The status of the table in the buffer – if this table can be buffered. See
Table 9.2 for more information
Buf key opt Buffering type: "ful" indicates full buffering, "gen" indicates generic
buffering and "sng" indicates single record buffering.
Buffer size Space occupied by the table in the SAP table buffer
[bytes]
Size Maximum size of the table in the SAP table buffer since system startup
maximum
[bytes]
DB activity – Number of rows that are transferred between the database and the
Rows SAP instance.
affected
Table 9.1 The fields in the Table Calls Statistics Monitor (Contd.)
Reads, Inserts, Updates and Deletes. Direct Reads are SELECT SINGLE
statements that have specified all the primary key fields in the WHERE
clause with an EQUALS condition. All other select statements are known
as sequential reads. Inserts, Updates and Deletes are referred to as
Changes.
In a request, the ABAP program calls up the database interface of the SAP
work process. The database interface checks to see if the data needed for
the query can be provided by the table buffer in the SAP instance. If this
is not the case, the database interface passes the SQL statement on to the
database. An SQL statement performing a read is made up of an OPEN
operation, that transfers the SQL statement to the database, and one or
more FETCHES, that transfer the resulting data from the database to the
SAP work process. An SQL statement that is performing a change is
similarly made up of an OPEN operation and an EXEC Operation. For
more detailed explanations of the Prepare, Open, Reopen, Fetch and
Exec operations, see chapter 4, “Evaluating an SQL trace” on page 155.
For tables that can be buffered, requests encounter one of three possible
situations:
왘 The contents of the table are located in the buffer with the "valid"
status: The required data can be read from the buffer. As a result, this
request requires no database activity.
왘 The contents of the table are located in the "valid" buffer, but the SQL
statement does not specify the correct fields or it contains the clause
BYPASSING BUFFER to prevent reading from the SAP buffer. A
complete list of SQL statements that do not read from the SAP buffer
can be found in the section “Buffer accessing” on page 285. In this
situation, database activity is required to satisfy the request.
왘 The table contents are not yet located in the buffer or are not valid: In
this situation the data needed for the request cannot be read from the
buffer. The database interface loads the buffer (if the table is not in the
pending period).
During the initial buffer load process, the field Database activity: Rows
affected is not increased. If a table has been loaded only once into the
buffer and all subsequent requests are read from the buffer, the value in
the Database activity: Rows affected field remains at zero in the table
access statistics. If the table is invalidated or displaced and then reloaded
into the buffer from the database or if the buffer is bypassed, the
Database activity: Rows affected field is increased by the number of
table rows that are read.
Buffer status The Buffer State field shows the buffer status of a table. The various status
possibilities are listed in Table 9.2.
Status Explanation
valid The table (or parts of it) is valid in the buffer, which means that the next
access can be read from the buffer.
invalid The table has been invalidated. It cannot yet be reloaded into the buffer
because the operation that changed the table has not yet been
completed with a "commit".
pending The table has been invalidated. It cannot be loaded at the next access
because the pending period is still running.
loadable The table has been invalidated. The pending period has expired and the
table will be reloaded at the next access.
absent, The table is not in the buffer (because, for example, it was never loaded
displaced or it has been displaced).
multiple Can occur for tables with generic buffering: Some generic areas are valid,
others have been invalidated because of changes.
error An error occurred while the table was being loaded. This table cannot be
buffered.
Figure 9.5 shows the screen shot of a table access statistic in an SAP
system (SAP Basis 3.1). The list is sorted according to the DB activity –
Rows affected column which indicates the number of records read from
the database. At the top of the list we find buffered tables, such as the
condition tables A004, A005 and A952. The entry KAPOL preceding the
name indicates that these tables are located in the KAPOL table pool. We
shall come back to the evaluation of this example in the next section.
the tables VBAK, S508 and MDVM in Figure 9.5. For many of these tables
the number of requests is around the same as the number of "rows
affected".
For buffered tables the number of "rows affected" should be low, because
for accesses to these tables, data should be read from the buffer and not
from the database. Therefore, such tables should not appear towards the
top of the list. If, as in Figure 9.5, you find buffered tables with a high
number of "rows affected", there are two possible causes:
If buffered tables appear among the top entries in Table Calls Statistics
sorted according to "rows affected", this is a sure sign that buffering these
tables is counter-productive. These tables should be analyzed in greater
detail.
The following counters may be of use in deciding whether a table should 4.0B
be buffered or not: Tables that are smaller than 1 Mbyte and with an
invalidation rate of less than 1% do not generally present any technical
problems and can be buffered. Tables between 1 Mbyte and 5 Mbytes
should have an invalidation rate of less than 0,1%. For tables that are
bigger than 5 Mbytes, the developer must decide individually for each
table whether buffering is worthwhile. Please note that these guideline
values reflect experience up to the time of going to print of this book.
Ideally, you should know the programs and transactions that access the
tables in question and can directly observe how the changes affect
runtime.
In the Table Calls Statistics you can verify the success of your changes by
comparing the number of "requests" to "rows affected". The purpose of a
table buffer is to reduce the number of database accesses. This should be
reflected in the ratio of "requests" to "rows affected". If, by changing the
buffering for a table you have not managed to increase this ratio,
reanalyze the buffer and, if in doubt, undo the changes you made to
buffering.
Example
Figures 9.5 and 9.6 show two screen shots of Table Calls Statistics from
two real SAP systems. Both lists are sorted according to the DB activity –
Rows affected column.
To verify this suspicion, examine the number of invalidations and the size
of the table in the buffer. To do this, double-click the row containing the
table that you want to analyze. This takes you to a screen summarizing all
the available information on this table. In our example you will see that
tables A004, A005 and A952 are frequently invalidated, which means
that they have an invalidation rate or more than 1% of the total requests.
The size of the tables in the buffer (Buffer size [bytes] field in Figure 9.5)
An analysis similar to that just carried out on the Table Calls Statistics
shown in Figure 9.5 can also be carried out for Figure 9.6. In this example
the list is also sorted according to DB activity – Rows affected and we
also have a number of buffered tables at the top of the list. The entry
"displcd" in the Buffer State column shows that table A005 was not
invalidated because of a change, rather, it was displaced because of a lack
of space in the buffer. Therefore, in this example two factors come
together: On the one hand, tables were buffered that were possibly too
large and changed too often for buffering, on the other hand the table
buffer is too small and this causes displacements. You can see if
displacements occur in the table buffer, by checking the Swaps column in
the SAP Memory Configuration Monitor (transaction code ST02).
Since the example in Figure 9.6 reveals two problems, the corresponding
solution strategy is more complex. First of all, the size of the table buffers
should be increased. The size and number of invalidations in tables A005,
A004, A006 and A017 should be examined in more detail and using the
guideline values listed above, you should decide whether buffering should
be deactivated for these tables. For example, if you find that table A005 is
larger than 1 Mbyte and the number of invalidations is greater than 0.1%,
you should deactivate buffering for this table. After this first optimization
step, you should carry out a second analysis on the Table Calls Statistics to
see if the number of database accesses to the buffered tables is noticeably
reduced. If not, analyze the table statistics further to determine whether you
need to enlarge the table buffer size or deactivate buffering for other tables.
For computers with large main memory it is not unusual for the generic
buffer table to be configured with as much as 100 Mbytes and single record
buffers to be configured to 40 Mbytes.
왘 Tables with transaction data or large master data tables, such as the
tables MARA, MARC, VBAK, MKPF from SAP logistics modules and
SAP update tables VBHDR, VBMOD and VBDATA. These tables cannot
be buffered.
왘 Buffered tables with customizing data. Make sure that buffered tables
with a high number of requests show the "valid" status.
The result from the first step is a list of tables that could potentially be
buffered because they receive a high number of requests.
One criterion for deciding if a table should be buffered is the change rate, Changes
which can be calculated from the ratio of Changes to Requests. Note that
the Changes column only displays the changes on the selected SAP
instance but not changes performed on other SAP instances nor those
that are imported as table content.
You should also determine the size of the table (see also the section Table size
“Detailed table analysis” on page 304).
1. To start the detailed table analysis, mark a table in the Table Calls
Statistics Monitor and select the Analyze button, or enter the
transaction code DB05. For older SAP versions, start the report
RSTUNE59.
2. Enter a table name and mark Analysis for primary key. Start the
analysis. (Please note: This may take some time for large tables. The
results of the analysis are then shown.
3. Use this list to check the size of the table. In the upper part of the list
you find, among other things, the number of table entries and the size
that the table would be if fully buffered. This size can be smaller or
larger than the space needed for the table on the database. For
example, database fragmentation can cause the table to consume
unnecessary space on the database. In addition, unlike some
databases, the table buffer does not compress empty fields to minimize
the need for storage space.
4. Check the distribution of the generic areas of the table. You will find
the necessary information in the lower part of the analysis screen.
Rows per Distinct 1–10 11–100 101– 1 001– 10 000– > 100 000
generic key values 1 000 10 000 100 000
1. KURST 41 10 14 11 0 6
Table 9.3 Example of detailed analysis of generic regions for table TCURR
Table 9.3 Example of detailed analysis of generic regions for table TCURR (Contd.)
왘 KURST row
The Distinct values column shows the number of generic regions,
which in this example is the number of different types of currency
exchange (KURST field). Table TCURR contains 41 different types of
currency exchange. Of these, 10 types have between 1 and 10 entries
in the table (1-10 column), 14 types have between 11 and 100 entries
and so on. Finally there are 6 exchange rates with between 10 000 and
100 000 entries. No exchange rate type has more than 100000 entries.
왘 FCURR row
There are 1311 different combinations of exchange rate types (KURST
field) and source currencies (FCURR). There is no combination with
more than 10000 entries (The row 10000–100000 is empty).
왘 Last row; GATU
There are 169795 different entries with the combination MANDT,
KURST, FCURR, TCURR and GDATU. This is also the total number of
entries in client 100, because MANDT, KURST, FCURR, TCURR and
GDATU make up the complete primary key for table TCURR.
How does this distribution analysis actually help you to decide how table
TCURR should be buffered?
왘 First of all you can see that table TCURR has 169795 different entries
in the live client. If TCURR has full or generic-1 buffering, a change
operation always invalidates the client entirely. Therefore, after a
change operation 169 795 records must be reloaded into the buffer. In
From this analysis it is clear that full buffering for table TCURR is out of
the question. Depending on the invalidation rate, this table should be set
to generic-3 buffering, or not buffered at all.
The larger the table, the more you should favor generic buffering.
In the initial screen of the detailed table analysis you have the possibility of
selecting the Analysis for fields function. This enables you to start analyses
for any combination of table fields, to be specified in the fields Field1,
Field2 and so on. With this analysis you can determine the selectivity of a
secondary index. See also chapter 11, "Optimizing SQL Statements with
Secondary Indexes".
Figure 9.7 shows an example of the output of this monitor. Table 9.4
explains the various different fields.
Field Explanation
Hostname Name of the application server that has written the synchronization
entry. If the referral originates from an import, this column shows the
entry "tp" or "R3trans".
왘 The WHERE clause for the generic-n buffered tables, specifies the first
"n" fields with an equals sign. For a table with full buffering or generic-
1 buffering, this is the client (if the table is client-dependent).
왘 The SQL statement contains an Order-by condition, which contains all
the fields of the table key.
The following SQL statement loads the buffer for table TMODU, a
generic-1 buffered table:
Pooled table A002 is fully buffered and is located in the KAPOL table
pool. The SQL statement for loading the buffer is:
ATAB and KAPOL are important table pools. ATAB contains many SAP
Basis buffered tables (such as T<nnn>), KAPOL contains many condition
tables (such as A<nnn>).
Summary
Buffering tables in the main memory of the SAP application server is an
important instrument for optimizing performance. Table buffering is only
effective if the following conditions are met:
The Table Calls Statistics Monitor is the central tool for monitoring SAP
table buffering. Using these statistics it can be decided whether the
buffering of a particular table is effective or not. The main statistics to
look at are the number of ABAP requests (ABAP/IV processor requests),
the size of tables (buffer size [bytes]), the number of invalidations and the
database activity (DB activity: Rows affected). Figure 9.8 shows the
corresponding procedure roadmap for analyzing table buffering.
Figure 9.8 Procedure roadmap for analyzing the efficiency of table buffering
Questions
1. Which of the following factors are reasons for not activating full
buffering on a table?
a) The table is very large.
Summary 309
b) In the SQL statement most frequently used to access the table, the
first two of five key fields are contained in an equals condition.
c) The table is changed frequently.
2. Which statements apply in regard to buffer synchronization?
a) During buffer synchronization, the application server executing the
change instructs the message server to communicate the change
made to the buffered table to the other application servers.
b) After a transaction changes a buffered table, the change transaction
must first be completed with a database commit before the table
can be reloaded into the buffer.
c) In a central system the SAP profile parameter rdisp/bufrefmode
must be set to "sendoff, exeoff".
d) In a central system, the entries in the table buffer are never
invalidated, because the table buffer is changed synchronously after
a database change operation.