Following are the some of the best practices which ABAP developer should take care to achieve optimal performance.
1. Avoid writing select query on a same table more
than once
Since the retrieval of
the data from the database take most of the processing time, it is better to
fetch the required data from the table and store it in a internal table for
further processing
2. Refreshing the internal tables. Clearing
variables & structures
In the custom program,
before using the declared internal tables, work area& variables initialize
them to default values. Use CLEAR statement for variables &work area. Use
REFRESH statement for internal tables
3. Clearwork area at the end of every LOOP pass
In order to avoid the
problems such as carryover of the values of some field of work area
corresponding to the last loop pass to the next loop pass, we need to clear the
work area at the end of every LOOP pass.
4. Avoid using the MOVE-CORRESPONDING
Compiler has to search
& map the corresponding fields in case of MOVE-CORRESPONDING statement,
hence it impact the performance. So, it is better to go for individual field
assignment in case of copying the work area content to other inside the LOOP.
5. Release the memory occupied by internal tables
&work area
At the end of the
program uses FREE statement to release the memory occupied by the internal
tables, work area& internal tables.
6. Avoid hard coding
Declare the CONSTANTS
& use them in the program instead of hard coding the values.
7. Check SY-SUBRC value after SELECT , READ
statements
Putting the appropriate
set of code based on the value of the sy-subrc after SELECT or READ statement
enhances the performance & helps in avoiding execution of the unwanted code
8. Check for internal table (it_tab) IS NOT INITIAL
before using FOR ALL ENTRIES
Before using FOR ALL
ENTRIES in the select statements, it is best practice to check does the table
in the in the FOR ALL ENTRIES is having some values, else it result in fetching
0 records.
9. Remove the unused constants, variables, work
area& internal tables from the program
Unused constants,
variables, work area & internal tables are the dead codes in the program.
So, by removing the dead codes we can improve the performance of the code &
make the code more readable.
10. Avoid LOOP on the same internal table more than
once
Try to include the
required logic inside the same LOOP in order to enhance the performance.
11. Avoid declaring the internal tables with header
line
Declare separate work
area to process the records of the internal table. By doing this one can avoid
the chances of not clearing the header line in case of internal table with
header line.
12. SORT the internal table before using BINARY
SEARCH in the READ statement.
READ statement fails to
read the entry from the table if you are using BINARY SEARCH on unsorted
internal table. So, SORT the internal table by the key fields which you are
using in the READ statement.
13. Place the most probable condition in the IF
statement
This enhances the
performance of the code when processing large amount of data.
No comments:
Post a Comment