You are on page 1of 22

ABAP Performance Check & Code Review Check List

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.

By Debesh

Page 1

ABAP Performance Check & Code Review Check List


There should be ZERO errors/warnings/messages. Click on the red marked errors/warnings and go to the code and make the proper corrections.

After achieving zero errors/messages/warnings go to Code Inspector check from the same path. 2. Code Inspector Check It 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 is used after database statements or not.

By Debesh

Page 2

ABAP Performance Check & Code Review Check List

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 some Performance 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 Database System Go To Transaction SE30 and provide the program name and execute.

By Debesh

Page 3

ABAP Performance Check & Code Review Check List

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.

By Debesh

Page 4

ABAP Performance Check & Code Review Check List

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.

By Debesh

Page 5

ABAP Performance Check & Code Review Check List

Now check in which statements more time is being spent and go back to code and check 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 change the run time significantly. Choose any option and comapare and measure the runtime.

By Debesh

Page 6

ABAP Performance Check & Code Review Check List

4. SQL Trace (ST05). It accesses the DDIC compenents to check SQL statement performances, Locking activities, Remote calls etc. Go to transaction ST05. Make trace on.

By Debesh

Page 7

ABAP Performance Check & Code Review Check List

Run the program and then do trace off.

By Debesh

Page 8

ABAP Performance Check & Code Review Check List

Now click on display trace.

It shows the sequence of database operations that are taking place while a query is processed. It includes prepare, fetch, open, reopen, execute.

By Debesh

Page 9

ABAP Performance Check & Code Review Check List


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).

By Debesh

Page 10

ABAP Performance Check & Code Review Check List


Code Review Check List Result (Y, N or N/A)

Description Run Extended syntax checks with character literals checkbox switched on & Code Inspector to rectify all relevant 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 program performance/runtime if program has multiple inefficient databases selects or complicated internal table operations Use transaction ST05 (SQL Trace) to see what indices your 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 indices if necessary, but do not forget to check the impact by consulting onsite coordinator. TYPE (data element) command is used while declaring the fields whenever feasible instead of LIKE. Remember not always the data element name matches with the table field name Internal Table is defined with TYPE STANDARD TABLE OF & Work-Areas is used instead of header lines Global variables are minimized by declaring local variables or by passing variables through parameters & arguments while creating internal subroutine(s) In SELECT statement, only the required fields are selected in the same order as they reside on the database table/structure/view For selecting single row from a database table, SELECT UP 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 INTO CORRESPONDING FIELDS OF TABLE Always specify as many primary keys as possible in WHERE 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 when the 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 over Loop at ITAB / Select / ENDLOOP (FOR ALL ENTRIES retrieves a unique result set so ensure you retrieve the full key from the database)

Comments

By Debesh

Page 11

ABAP Performance Check & Code Review Check List


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 select statement 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 is NOT 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 are used 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 be processed, use SORT and then the READ TABLE command is used to set index to first relevant row before looping from that index. Use CHECK or IFEXITENDIF as appropriate to exit from the loop Sort fields and Sort Order on the SORT statement should be 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 consumption Sorted 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. Whenever possible formulate SQL statements positively When coding IF or CASE, testing conditions are nested so that the most frequently true conditions are processed first. Also CASE is used instead of IF when testing multiple fields equal to something LOOP AT ITAB INTO WORKAREA WHERE K = XXX should be 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

By Debesh

Page 12

ABAP Performance Check & Code Review Check List


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 ... for single 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 of Modify 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 a logical 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 logical database Avoid the aggregate (Count, Max, Min) functions in the database selection Use Parallel Cursor methods for nested loop into the internal tables if second internal table contains considerable number of records In Smartform/ Sapscript do not make redundant data retrieval where data is available in interface Check List(2) Description Title The title is a concise description Type The type of program is specified correctly Status: Result Comment

By Debesh

Page 13

ABAP Performance Check & Code Review Check List


'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 Name Space The appropriate namespace has been used Documentation: Documentation Block: Must contain: been used

Description: Detailed description Created By: Developers name Created On: Date Program Documentation for FM The Online Program Documentation provides functional leads and end users with necessary information to determine report functionality. It also contains information on file inputs and outputs Code Comments

By Debesh

Page 14

ABAP Performance Check & Code Review Check List


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 appropriately Quality:


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

By Debesh

Page 15

ABAP Performance Check & Code Review Check List


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

By Debesh

Page 16

ABAP Performance Check & Code Review Check List


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 arrangement of the keys in the table records the

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

By Debesh

Page 17

ABAP Performance Check & Code Review Check List


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: does not exist are repeatedly used to make selections Only a small part of a large table is selected (<5%) The WHERE condition of the SELECT is simple Fields that make up the index significantly reduce the selection set of the records by matching the unique qualifiers in the WHERE clause Note: prior to creating secondary indexes, consultation with the database administrator is required Nested SELECTS or Loops Nested selects and loops are avoided through the of dictionary VIEW or by using FOR ALL ENTRIES appendage to the SELECT statement For all Entries Make sure table that you are selecting on for all entries is populated. If not, you will select every record from the table which is not efficient. Column Selection SELECT statements only query the necessary columns from a table. SELECT * is only used when more than one-third of the columns are being used UP TO N ROWS: When a full key is unknown and only one record is needed, the UP TO 1 ROWS appendage is added to the use

Non-key fields or fields for which index support

By Debesh

Page 18

ABAP Performance Check & Code Review Check List


SELECT statement

Preferred: SELECT FIELD1 FROM TABLE UP 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, take advantage of parallel cursor technique Unnecessary MOVEs are avoided by using explicit Work Areas Reading:

By Debesh

Page 19

ABAP Performance Check & Code Review Check List


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 memory allocated 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 tables


OCCURS A number other than zero is only specified for the OCCURS parameter is the required storage is less than 8 kilobytes SORT: All SORT statements are qualified with the BY option and limited to the fields that must be used to satisfy processing requirement

By Debesh

Page 20

ABAP Performance Check & Code Review Check List


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 field is used to initialize rather than explicit moves Table headers and work areas are CLEAR at the end of loop process

By Debesh

Page 21

ABAP Performance Check & Code Review Check List

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.

By Debesh

Page 22