Chapter 5. Optimizing Programs

In this chapter, we will see recipes related to program optimization. We will look at:

  • Using transaction SAT to find problem areas
  • Creation of secondary indexes in database tables
  • Adding hints in SELECT clause
  • Secondary indexes for internal tables
  • Hashed table for single read access
  • Replacing for all entries construct with Ranges

Introduction

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:

  • Do not use asterisk (*) in SELECT statements. It means not to select unnecessary columns from database.
  • Do not use nested SELECT statements. Rather use subqueries or inner joins.
  • Create views when multiple tables' data is required.
  • Appropriate and complete WHERE clause conditions should be written.
  • Using 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.
  • Using Aggregate functions within SELECT clause such as AVG, MIN, MAX, COUNT(DISTINCT col), and COUNT(*) rather than calculating them yourselves in programs.
  • Avoiding SELECT or SELECT SINGLE within a loop.
  • Usage of hashed tables where a single record within the table is to be searched.
  • Usage of secondary index for internal tables.

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 Introduction button on the toolbar.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.123.155