In this chapter, we will see recipes related to program optimization. We will look at:
An entire description of the topic constitutes a book by itself. However, we will see some useful and important techniques, as well as some new tools and concepts that are important for developers for program optimization. There are two main techniques—optimizing database statements, particularly
SELECT
statements and the optimizing ABAP code particularly internal table's access. We will see useful recipes related to both the optimization of database statements as well as internal tables.
We will start with some general rules necessary for optimization. We will start with a recipe showing the usage of transaction SAT for measuring performance of report programs. Then, we will see in detail the steps required in creating secondary indexes for database tables in order to boost performance of queries used in the concerned program. We will then see how hints may be used in programs within SELECT
statements, so that a particular index may be used by the system. Finally, we will see how the FOR ALL ENTRIES
construct may be replaced with ranges
table. The usage of hashed
internal tables as well as the new concept of secondary indexes for internal tables will be discussed in separate recipes.
For this chapter, I assume that the reader has basic knowledge of SELECT
statements and database concepts and internal tables, as well as basic optimization techniques. For the better understanding of the information in this chapter, the reader should know which database would be used in his or her project and know some tricks specific to the database.
Before starting with the recipes, let us see some rules for program optimization:
SELECT
statements. It means not to select unnecessary columns from database.SELECT
statements. Rather use subqueries or inner joins.WHERE
clause conditions should be written.FOR ALL ENTRIES
within SELECT
statements when multiple tables are involved. Also check that the FOR ALL ENTRIES
tables are not empty. Otherwise, all records in the underlying table will be accessed that will drastically affect the performance.Aggregate
functions within SELECT
clause such as AVG
, MIN
, MAX
, COUNT
(DISTINCT col
), and COUNT
(*
) rather than calculating them yourselves in programs.SELECT
or SELECT SINGLE
within a loop.hashed
tables where a single record within the table is to be searched.For more examples of the previously discussed items, see the Tips and Tricks screen of transaction SAT
. For doing so, you need to call transaction
SAT. Then press the button on the toolbar.
3.144.123.155