Upload
mpdineshkumar
View
162
Download
5
Embed Size (px)
DESCRIPTION
SAP ABAP Tuning Mechanisms
Citation preview
ABAP Training
ABAP Performance Tuning
ABAP Training ABAP Performance Tuning 2
3 Major Areas
Select statements Internal table usage Database index
ABAP Training ABAP Performance Tuning 3
Select Statements
Ensure that data is selected with primary key /secondary index support with the fields in the select statements WHERE clause in the same order as fields in the index
Avoid negative WHERE clause (NE) because negative where clauses disable the index
Avoid long selects within AT SELECTION-SCREEN event
ABAP Training ABAP Performance Tuning 4
Select Statements Where Clause Fields
Select up to 1 rows when 'where' clause fields 'primary key fieldsE.G. Select MATNR UPTO 1 rows from VBAP
Where VBELN = 0001500080 Select single when 'where' clause fields = 'primary key fields'
E.G. Select single AUDAT VBTYP from VBAKWhere VBELN = 0001500080
ABAP Training ABAP Performance Tuning 5
Joined Select Statements
Select with join instead of nested select statements, if the number of records to be fetched is more than 5. Ensure that the join fields are the keyed fields
Limit tables in a join to three tables
ABAP Training ABAP Performance Tuning 6
Select Statements Contd..
Select fields only instead of select *, when no. Of fields < 1/3rd of total fields in table or no. Of fields getting selected less than or equal to 16.
Use SAP standards views for multiple table data selection Data should not be selected within loop .. Endloop statements. Instead
use the select statement in join or for for all entries
ABAP Training ABAP Performance Tuning 7
Select Statements Contd..
Select with where condition instead of checking them yourself with check-statements in transparent tables, else use the check statement in the pooled/cluster tables.
For a buffered table, if a program does require the latest data from a table it is better to qualify the SELECT statement with BYPASSING BUFFER specification
Accesses to cluster type tables via non-key selection criteria should be avoided if possible
ABAP Training ABAP Performance Tuning 8
Select Statements Contd..
Select using an aggregate function (SUM, MIN, MAX, COUNT) instead of computing the aggregates yourself
Use select into table than select + append statement
ABAP Training ABAP Performance Tuning 9
Internal Table Usage
Check whether the internal table has records in it before executing the validation checks and related processing steps for that internal table. Example before for all entries in itab1, loop at itab1
It is more efficient to use the AT statements ( AT NEW, AT END OF, AT LAST ...) for summing and control breaks purpose. Avoid using ON CHANGE OF
If using loop at WHERE statement never use internal tables events such as AT new inside the loopEndloop
ABAP Training ABAP Performance Tuning 10
Internal Table Usage Contd..
All internal table reads with binary search only, after sorting it on the 'with key' fields
To add data to an internal table and keep it sorted, use a READ with BINARY SEARCH followed by an INSERT rather than using the APPEND statement followed by the SORT statement E.G. Read table INT_table with key INT_table binary search.
If SY-SUBRC 0.Insert INT_table index SY-TABIX.
ENDIF
ABAP Training ABAP Performance Tuning 11
Internal Table Usage Contd..
When deleting records from an internal table, if possible, WHERE should be used together with FROM...And/or to ... to enhance performance even more E.G. Delete ITAB [from ...] [to ...] where
When nested loops, include a 'read table itab2 with key binary serach transporting no fields + 'loop at ' itab2 from sy-tabix + key fields not equal to exit check)
ABAP Training ABAP Performance Tuning 12
Internal Table Usage Contd..
Specify the sort fields explicitly in a sort statement Use 'if itab[] is initial' instead of 'describe table itab lines n + if n ge 0
..') Key access to multiple lines use LOOP WHERE which is faster than
LOOP/CHECK. Performance can be further enhanced if the LOOP WHERE is combined with FROM i1 and/or TO i2
For copying internal tables of same structure use TAB_DEST[] = TAB_SRC[]
ABAP Training ABAP Performance Tuning 13
Internal Table Usage Contd..
Avoid unnecessary moves by using the explicit workarea for internal table operations
Internal tables of same structure can be compared in logical expressions just like other data objects. If tab1[] = tab2[]. ... ENDIF
Use DELETE itab WHERE, instead of LOOP AT itab WHERE DELETE itab. Endloop
ABAP Training ABAP Performance Tuning 14
Database Index
The purpose of an index is to quicken the scanning process when searching for specific records in a table.
An index is a copy of a table reduced to particular sorted fields to enable faster access to needed data.
ABAP Training ABAP Performance Tuning 15
Creating Indexes
Indexes may be developed when the required access to a database table is based on fields other than the primary key of the table
Only include fields in an index if they reduce the selected data significantly
As indexes are adjusted each time table contents are changed, create secondary indexes discerningly to minimize the impact on the system
ABAP Training ABAP Performance Tuning 16
Creating Indexes Contd..
Place the most common columns at the beginning of an index. The most common columns are those where reports are selecting columns with no ranges - the WHERE clause for these columns is an equal to expression. Rearrange columns of an index to match the selection criteria. For example, if a SELECT statement is written to include columns 1 and 2 with equal to expressions in the where clause and column 3 and 4 are selected with value ranges, then the index should be created with columns in the sequence of 1, 2, 3, 4.
Place columns toward the end of the index if they are either infrequently used in SELECTS or are part of reporting SELECTS that involve ranges of values
ABAP Training ABAP Performance Tuning 17
Creating Indexes Contd..
Indexes should be small (few fields). Some optimizers are able to combine two or more indexes to execute a query. This is not possible with wide indexes
Multiple indexes of one table should be disjoint (have few common fields), in order not to confuse the optimizer which index to use
ABAP Training ABAP Performance Tuning 18
Using Indexes
When selecting data from a table, look at the structure of all of the available indexes and tailor the WHERE clause to take advantage of the most selective index. Use all fields in the WHERE clause in the same order for an index, as skipping one field disables the index
Be sure to order the columns in the WHERE clause of a SELECT in the same order as an index table
ABAP Training ABAP Performance Tuning 19
Time Costs for Key Access
ABAP Training ABAP Performance Tuning 20
When To Use Which Table
ABAP Training ABAP Performance Tuning 21
Explicit Binary Search
ABAP Training ABAP Performance Tuning 22
Memory Costs
ABAP Training ABAP Performance Tuning 23
Points to Be Considered
Each index slows down the inserts into the table. Updates are only slowed down if indexed fields are updated. On the other hand, the indexes increase the efficiency of reads. These tradeoffs must be weighed against one another. In general, frequently updated tables should have only few indexes while frequently selected tables might have more
Remove unused indexes or ones that change due to report design changes
ABAP Training ABAP Performance Tuning 24
Points of Caution
The creation of an index can affect performance adversely The most suitable index for the select criteria might not be the index
chosen for use by the database optimizer. Validate the use of table indexes by performing a SQL trace
Creating indexes should be done carefully and jointly with the SAP database administrator
ABAP Training ABAP Performance Tuning 25
Performance Tuning Tools
Extended syntax check
Runtime analysis
SQL trace
ABAP Training ABAP Performance Tuning 26
Extended Syntax Check
Transaction code - SLIN or go through Choose program check extended program check
The system checks the entire program and allows you to run additional checks with a greater scope than the normal syntax check
ABAP Training ABAP Performance Tuning 27
Runtime Analysis
Transaction code SE30
Allows you to examine the performance of any transaction, ABAP program, or function module that you create in the ABAP workbench
Is intended for fine-tuning individual transactions, programs, and function modules
ABAP Training ABAP Performance Tuning 28
SQL Trace
Transaction code ST05 (performance trace tool)
Allows you to monitor the database access from reports and transactions
Allows you to see how the OPEN SQL statements that you use in ABAP programs are converted to standard SQL statements
ABAP Training ABAP Performance Tuning 29
SQL Trace Contd..
The SQL trace tells you: The SQL statements executed by your program. The values that the system uses for particular database access and
changes. How the system converts ABAP open SQL statements (such as SELECT)
into standard SQL statements. Where your application executes commits. Where your application repeats the same database access. The database accesses and changes that occur in the update part of
your application
ABAP Performance Tuning3 Major AreasSelect StatementsSelect Statements Where Clause FieldsJoined Select StatementsSelect Statements Contd..Select Statements Contd..Select Statements Contd..Internal Table UsageInternal Table Usage Contd..Internal Table Usage Contd..Internal Table Usage Contd..Internal Table Usage Contd..Database IndexCreating IndexesCreating Indexes Contd..Creating Indexes Contd..Using IndexesTime Costs for Key AccessWhen To Use Which Table Explicit Binary SearchMemory CostsPoints to Be ConsideredPoints of CautionPerformance Tuning ToolsExtended Syntax CheckRuntime AnalysisSQL TraceSQL Trace Contd..