7/30/2019 ABAP Performance Check
1/22
ABAP Performance Check & Code Review Check List
By Debesh Page 1
Normally in every project after the developer completes a development he fills the review
check list and does some performance tests before sending it for lead review. The basic
check list template is attached at the end.
1. Extended Program Check / SLIN Test.After development the developer does a syntax check and after that the very first
test he/she executes is the SLIN Test. Display the program and from Program follow
the path as follows.
Check the items and execute.
7/30/2019 ABAP Performance Check
2/22
ABAP Performance Check & Code Review Check List
By Debesh Page 2
There should be ZERO errors/warnings/messages. Click on the red markederrors/warnings and go to the code and make the proper corrections.
After achieving zero errors/messages/warnings go to Code Inspector check from thesame path.
2. Code Inspector CheckIt does a static analysis before we run the program and reports potential
performance issues.
Although it does not provide any relevant information about the code during runtime
but still it checks for certain coding standards like :
- In where clause all key fields are used or not, and whether sy-subrc check isused after database statements or not.
7/30/2019 ABAP Performance Check
3/22
ABAP Performance Check & Code Review Check List
By Debesh Page 3
Try to remove all errors and warnings .Expand the section , double click the item , it
will take you to the code and take proper action.
To improve the performance and quality of code, SAP has provided somePerformance Analysis tools. They are mentioned below.
3. Run time analysis (transaction SE30)It is used by the developer to calculate or evaluate the quality of the code to
achieve the business requirement. It ensures the performance of program on
Production server.Execution time for the code
Evaluation of the 3 main areas:ABAP
DatabaseSystem
Go To Transaction SE30 and provide the program name and execute.
7/30/2019 ABAP Performance Check
4/22
ABAP Performance Check & Code Review Check List
By Debesh Page 4
It will take you to the program selection screen.
Provide a parameter or choose a variant and execute.
Go back from the result screen to the se30 screen.
It will display a message for run time analysis completion. Click on evaluate.
7/30/2019 ABAP Performance Check
5/22
ABAP Performance Check & Code Review Check List
By Debesh Page 5
It will display the time spend on application server level and data base level.
System and Data base section should be small.
Go to Hit List.
The Hit list summarizes the measurements of execution and processing times into
one entry per operation. Filter Hit List.
Choose from the available options for which the analysis is important.
7/30/2019 ABAP Performance Check
6/22
ABAP Performance Check & Code Review Check List
By Debesh Page 6
Now check in which statements more time is being spent and go back to code andcheck whether these code can be made more efficient or not.
From the main run time analysis menu you can go to tips & tricks.
There you can check how same staments written in two different ways can changethe run time significantly. Choose any option and comapare and measure the
runtime.
7/30/2019 ABAP Performance Check
7/22
ABAP Performance Check & Code Review Check List
By Debesh Page 7
4. SQL Trace (ST05).It accesses the DDIC compenents to check SQL statement performances, Lockingactivities, Remote calls etc.
Go to transaction ST05. Make trace on.
7/30/2019 ABAP Performance Check
8/22
ABAP Performance Check & Code Review Check List
By Debesh Page 8
Run the program and then do trace off.
7/30/2019 ABAP Performance Check
9/22
ABAP Performance Check & Code Review Check List
By Debesh Page 9
Now click on display trace.
It shows the sequence of database operations that are taking place while a query isprocessed.It includes prepare, fetch, open, reopen, execute.
7/30/2019 ABAP Performance Check
10/22
ABAP Performance Check & Code Review Check List
By Debesh Page 10
Now you can have a detailsed list or can make a summery out of it.
There are certain other tools like New Version of Runtime Analysis tool (Transaction
SAT), ST12 (SQL trace, ABAP Trace, Enqueue, RFC all at one place ), STAD etc.
Certain Recommended Coding Standards:
1. Properly document each development with Developer name and change history.2. Follow certain naming conventions (like local variaable lv_name, global variable
gv_name, woel area ls_name , constants c_name and so on).
3. Remove dead codes.4. When possible use MOVE instead of MOVE-CORRESPONDING .5. Code executed more than once should be placed in a form routine.6. Use SORT and READ TABLE t_tab WITH KEY ... BINARY SEARCH when possible .7. Use all key fields for Select Single else use Select up to one row.8. Do a table is empty or not check before For all entries addition.9. Views (inner join) are a fast way to access information from multiple tables.
Use subqueries when possible.
10.Where clause should be in order of index See example.Where clause should contain key fields in an appropriate db index or buffered tables.
11.Avoid nested SELECTs (SELECT...ENDSELECT within another SELECT...ENDSELECT).12.Use CASE statement instead of IF...ELSEIF when possible (It is only possible in
equality tests).
http://web.mit.edu/fss/dev/sample_code.htm#Sort%20and%20READ%20TABLEhttp://web.mit.edu/fss/dev/covp.htmhttp://fuller.mit.edu/hr/complex_subquery.htmlhttp://web.mit.edu/fss/dev/select_examples.htm#optimizer%20quirkhttp://web.mit.edu/fss/dev/select_examples.htm#optimizer%20quirkhttp://web.mit.edu/fss/dev/sample_code.htm#rules%20basedhttp://web.mit.edu/fss/dev/select_examples.htm#Select%20Statement%20Where%20Clause%20ahttp://web.mit.edu/fss/dev/sap_table_types.htm#Buffered%20Tableshttp://web.mit.edu/fss/dev/sample_code.htm#Case%20Statementhttp://web.mit.edu/fss/dev/sample_code.htm#Case%20Statementhttp://web.mit.edu/fss/dev/sample_code.htm#Case%20Statementhttp://web.mit.edu/fss/dev/sap_table_types.htm#Buffered%20Tableshttp://web.mit.edu/fss/dev/select_examples.htm#Select%20Statement%20Where%20Clause%20ahttp://web.mit.edu/fss/dev/sample_code.htm#rules%20basedhttp://web.mit.edu/fss/dev/select_examples.htm#optimizer%20quirkhttp://fuller.mit.edu/hr/complex_subquery.htmlhttp://web.mit.edu/fss/dev/covp.htmhttp://web.mit.edu/fss/dev/sample_code.htm#Sort%20and%20READ%20TABLE7/30/2019 ABAP Performance Check
11/22
ABAP Performance Check & Code Review Check List
By Debesh Page 11
Code Review Check List
DescriptionResult
(Y, N orN/A)
Comments
Run Extended syntax checks with character literals
checkbox switched on & Code Inspector to rectify allrelevant errors and warning (e.g. Use the results of the
above checks to remove all variables/constants etc that
are declared but are not used)
Transaction SE30 (ABAP Runtime Analysis) must be
checked to measure/compare programperformance/runtime if program has multiple inefficientdatabases selects or complicated internal table operations
Use transaction ST05 (SQL Trace) to see what indicesyour 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. Create new indicesif necessary, but do not forget to check the impact byconsulting onsite coordinator.
TYPE (data element) command is used while declaring the
fields whenever feasible instead of LIKE. Remember notalways the data element name matches with the table
field name
Internal Table is defined with TYPE STANDARD TABLEOF & Work-Areas is used instead of header lines
Global variables are minimized by declaring local variablesor by passing variables through parameters & arguments
while creating internal subroutine(s)
In SELECT statement, only the required fields are selectedin the same order as they reside on the database
table/structure/view
For selecting single row from a database table, SELECTUP to 1 Rows is used. Select Single is used only when
full primary key combination is known
No SELECT * is used
Use SELECT INTO TABLE rather than SELECT INTOCORRESPONDING FIELDS OF TABLE
Always specify as many primary keys as possible inWHERE clause to make the Select efficient
Always select into an internal table, except when the table
will be very large (i.e., when the internal table will be
greater than 500,000 records). Use Up to N Rows whenthe number of records needed is known
Select statement within a GET event is not used
Wild cards like A% is avoided as much as possible
Nested Select is not used instead Inner Join and/or For
all Entries is used. For all Entries is to be used overLoop at ITAB / Select / ENDLOOP (FOR ALL ENTRIES
retrieves a unique result set so ensure you retrieve thefull key from the database)
7/30/2019 ABAP Performance Check
12/22
ABAP Performance Check & Code Review Check List
By Debesh Page 12
When creating joins over database tables there should be
an index at least on the inner table for the fields in the
join condition else use FOR ALL ENTRIES selectstatement
Usage of JOIN is limited to a maximum of 2 i.e. not more
than 3 database tables are joined at one time
CHECK that the internal table used in FOR ALL ENTRIES isNOT empty as this will retrieve all entries from the table
Delete adjacent duplicate entries from internal table
before selection from database table using FOR ALL
ENTRIES statement
For copying internal tables use = operator instead of
Looping & Appending
SORT inside a LOOP is not used
Sort internal table by fields in the correct order, which areused in a READ TABLE statement using BINARY SEARCH.If the order of sorting is invalid the BINARY SEARCH will
never work
For large internal tables where only some rows are to beprocessed, use SORT and then the READ TABLE command
is used to set index to first relevant row before loopingfrom that index. Use CHECK or IFEXITENDIF asappropriate to exit from the loop
Sort fields and Sort Order on the SORT statement shouldbe mentioned explicitly (e.g. SORT ITAB BY FLD1 FLD2
ASCENDING)
Hashed table is used for processing large amount of data(provided that you access single records only, and all with
a fully specified key)
DELETE or SORT is not used on a hashed table since it
increases memory consumptionSorted table is used for range accesses involving table
key or index accesses
Fields specified in the WHERE condition with the critical
operators NOT and (negative SQL statements) cannot
be used for a search using database indexes. Wheneverpossible formulate SQL statements positively
When coding IF or CASE, testing conditions are nested so
that the most frequently true conditions are processedfirst. Also CASE is used instead of IF when testing
multiple fieldsequal to something
LOOP AT ITAB INTO WORKAREA WHERE K = XXX shouldbe used instead of LOOP AT ITAB INTO WORKAREA /
CHECK ITAB-K = XXX.
Also READ TABLE INTO WORKAREA should be used
instead of only READ TABLE.
After the APPEND statement inside a loop, the work area
that has been appended is cleared
Internal tables, Work areas & Global Variables are freed
when no longer needed (e.g. using the FREE / REFRESH
7/30/2019 ABAP Performance Check
13/22
ABAP Performance Check & Code Review Check List
By Debesh Page 13
command), especially when the tables are large or the
program is a batch program
Do not delete the records of internal table inside the Loop End loop.
Do not use:LOOP AT ITAB WHERE EQUNR = 00001011.
DELETE ITAB.
ENDLOOP.
Use:DELETE ITAB WHERE EQUNR = 00001011.
Use the MODIFY ITAB ... TRANSPORTING f1 f2 ... forsingle line, and MODIFY ITAB ... TRANSPORTING f1 f2 ...
WHERE condition for a set of line, to accelerate the
updating of internal table
If possible, Update/Insert statement is used instead ofModify
Is the following steps ensured during database updates?
Lock data to be edited Read current data from the database Process data and write it to the database Release the locks set at the beginning
Try to avoid logical databases. If your program uses alogical database, but does not require all fields belonging
to a certain GET event, always use the FIELDS addition to
reduce the amount of data selected by the logicaldatabase
Avoid the aggregate (Count, Max, Min) functions in thedatabase selection
Use Parallel Cursor methods for nested loop into the
internal tables if second internal table containsconsiderable number of records
In Smartform/ Sapscript do not make redundant data
retrieval where data is available in interface
Check List(2)
Description Result Comment
Title
The title is a concise description
Type
Thetypeof program is specified correctly
Status:
7/30/2019 ABAP Performance Check
14/22
ABAP Performance Check & Code Review Check List
By Debesh Page 14
'P' SAP standard production program
'K' Custom-developed program for production
'T' Test Program
'S' System Program
Application
The application area should relate back to Character
Module Identification he program name.
Authorization Group
The appropriate authorization group has been used
Development Class
The appropriate development class has been used
Name Space
The appropriate namespace has been used
Documentation:
Documentation Block:
Must contain:
Description: Detailed description
Created By: Developers name
Created On: Date
Program Documentation for FM
The OnlineProgram Documentationprovides functional
leads and end users with necessary information to
determine report functionality. It also contains
information on file inputs and outputs
Code Comments
7/30/2019 ABAP Performance Check
15/22
ABAP Performance Check & Code Review Check List
By Debesh Page 15
Internal commenting has been done sufficiently enough
to ease program maintenance and reliability of the ABAP
Change History
A chronological history of modification notes; with the
latest change being the last entry in the modification log.
Include Transport Number.
Naming Standards:
The ABAP/4 Naming Standards and Programming
Standards have been followed in naming objects and
components in the program.
Variables
TYPE preferred to LIKE
Constants
Internal Tables
Select Options
Parameters
Program Name
Hardcoding?
TYPES:
Types used appropriatelyQuality:
Event Structure
The standard structure for ABAP/4 report coding has
been followed as outlined in the Programming Standards
documentation
SY-SUBRC
SY-SUBRC is checked after database activities to ensure
proper inputs when dealing with tables (for example:
READ, SELECT, INSERT)
WHEN OTHERS with CASE
7/30/2019 ABAP Performance Check
16/22
ABAP Performance Check & Code Review Check List
By Debesh Page 16
All CASE statements must have WHEN OTHERS to
capture unexpected errors
Code Inspector
Follow menu path: Program, Check, Code Inspector.
Check to see if any performance improvement
opportunities.
Extended Syntax Check
An extended syntax check has been run on the ABAP
Perform Syntax Check on the Transport.
Run-time Trace Analysis (transaction SE30)
The run-time analysis tool has been used to evaluate the
hit lists of the top CPU consumers, table accesses, and to
get a general idea of the coding run during the program
execution.
SQL Trace (ST05)
SQL calls have been checked through the SQL Trace and
Execution Plan to check efficiency
Programming Standards / Program Optimization:
Text Elements
Each ABAP should have associated text elements and
selection texts from the source code placed within the
Text Elements section
Range Tables
For defining internal tables with the same structure as
selection tables, the RANGES statement should be used.
Selection Screen:
Validate the field(s) as much as possible from the
corresponding main table. If invalid, give error such as
Invalid XXXX.
Error Messages:
Validate that there are no hard errors in the code. Hard
errors (Message E000 with XXX) are ok for the selection
7/30/2019 ABAP Performance Check
17/22
ABAP Performance Check & Code Review Check List
By Debesh Page 17
screen, but in the code after START OF SELECTION, the
error should be written to the screen & the code should
be stopped if no further processing should be done. This
will prevent the batch job from canceling & will write the
error to the spool.
SQL Interfaces:
SELECT INTO preferred to SELECT APPEND
ENDSELECT
When an internal table needs to be created directly
from one database table, the SELECT INTO is used to
fill the internal table. It is faster to use the INTO
TABLE version of a SELECT statement than to use
APPEND statements
WHERE clause:
For Transparent or POOL tables, the SELECT
statement is as fully qualified as possible with the
WHERE option, including data fields that are not part of
the key
For Cluster tables, only the fields that are part of the
key are qualified in the WHERE option. The CHECK
command is used to eliminate other records.
The ordering of the WHERE statements match thearrangement of the keys in the table records
Fields compared in the WHERE clause of SELECT
statements have similar types
The use of negative logic in SELECTs is avoided
whenever possible
When using the AND or OR operator the most likely
elimination criteria is specified first. (Expressions are
evaluated left to right and the evaluation ends when
the final result has been established)
Primary Key Used
Whenever possible, the full table key is specified and
SELECT SINGLE is specified
7/30/2019 ABAP Performance Check
18/22
ABAP Performance Check & Code Review Check List
By Debesh Page 18
Secondary Index Usage
When possible, in the WHERE clause the fields of the
INDEX are in the specified order and linked by the
logical AND with comparisons for equality.
A secondary index has been considered if:
Non-key fields or fields for which index supportdoes not exist are repeatedly used to make
selections Only a small part of a large table is selected
(
7/30/2019 ABAP Performance Check
19/22
ABAP Performance Check & Code Review Check List
By Debesh Page 19
SELECT statement
Preferred:
SELECT FIELD1 FROM TABLEUP TO 1 ROWS.
ENDSELECT.
Avoid:
SELECT FIELD1 FROM TABLE.
EXIT.
ENDSELECT.
Sorting
SORT ITAB ORDER BY preferred over SORT ITAB
Delete Adjacent Duplicates
SORT the internal table according to ALL
the fields that you want to compare
when looking for duplicates before using
delete adjacent duplicates.
Aggregates
When finding aggregates such as maximum, minimum
sum, average, and count, a SELECT list with the
aggregate function is used instead of programming the
code.
Internal Tables
Nested Loops
Nested loops are avoided. If unavoidable, takeadvantage of parallel cursor technique
Unnecessary MOVEs are avoided by using explicit
Work Areas
Reading:
7/30/2019 ABAP Performance Check
20/22
ABAP Performance Check & Code Review Check List
By Debesh Page 20
LOOPWHERE is used instead of LOOP/CHECK
For READ operations, the key fields are specified for
READ access explicitly
When performing BINARY search, the internal table
must be first sorted by the key.
BINARY SEARCH
When the read command is used, the table is
sequentially searched. This slows down the processing.
Instead of this, use the binary search addition. The
binary search algorithm helps faster search of a value
in an internal table. Binary search repeatedly divides
the search interval in half. If the value to be searched
is less than the item in the middle of the interval, the
search is narrowed to the lower half; otherwise the
search is narrowed to the upper half.
REFRESH
REFRESH table is used to initialize table records
FREE
The FREE command is used to release the memoryallocated to internal tables when the program is
finished processing the data in the table and when the
following conditions exist:
The internal table is large The internal table is sorted and reprocessed several
times
Program is processing several internal tablesOCCURS
A number other than zero is only specified for the
OCCURS parameter is the required storage is less than8 kilobytes
SORT:
All SORT statements are qualified with the BY option
and limited to the fields that must be used to satisfy
processing requirement
7/30/2019 ABAP Performance Check
21/22
ABAP Performance Check & Code Review Check List
By Debesh Page 21
Modularization:
Break code in to logical segments for modularization
into subroutines whenever possible.
Listed in order of best performance. Be sure the
modularization is worth the extra run-time required.
PERFORM
Cost/Run-time: Factor 1 (Note: this is the base factor
for the techniques to follow)
CALL FUNCTION
Cost/Run-time: Factor 12
Optimization:
General:
All LOOPs, IFs, CASEs, and similar statements are
broken down to their simplest form and nesting is not
complicated unless absolutely necessary
All unused variables and program parts are removed
from the program
MOVE
When possible, the destination operands are kept as
the same data type as the source operands
CASE preferred to IF
IF
When using the AND or OR operator the most likely
elimination criterion is specified first.
WHILE preferred to DO
CLEAR field for Initialization:
CLEAR fieldis used to initialize rather than explicit
moves
Table headers and work areas are CLEAR at the end
of loop process
7/30/2019 ABAP Performance Check
22/22
ABAP Performance Check & Code Review Check List
By Debesh Page 22
MOVE CORRESPONDING:
MOVE CORRESPONDING is only used for small tables or
tables where most, but not all, fields need to be
moved.
Try to avoid using INTO CORRESPONDING FIELDS OF
TABLE. Instead use INTO TABLE.
When all fields need to be moved and the attributes
for every field and position are identical, the table is
MOVEed as a group.