By optimizing existing ABAP programs, you can achieve significant performance gains. As an ABAP developer, you can identify programs that are suitable candidates for optimization and then modify them so that they benefit from the SAP HANA architecture.

8Sample Scenario: Optimizing an Existing Application

In the previous chapters, we described the basic principles of the in-memory technology and ABAP development on SAP HANA. You now know how to move portions of the application logic (especially complex calculations with large amounts of data) to the database layer. In addition, you learned which tools SAP NetWeaver AS ABAP provides to identify optimization potential in programs.

This chapter now deals with combining and using the individual techniques and tools in sample scenario in which an application is optimized for SAP HANA.

This chapter is divided into three parts. We’ll start with a description of the necessary steps to optimize systems and applications. The second part introduces the sample scenario and optimization requirements. To conclude the chapter, you’ll learn how to optimize the sample program. In this part, we won’t explain every step in detail, but we’ll focus on the most important excerpts that are relevant for optimization. You can download the application and its source code in the download area for this book at www.sap-press.com/3973 (see Appendix E).

8.1Optimization Procedure

This section presents the general procedure in optimization projects. We’ll discuss the following scenarios:

Every scenario has a different focus and different roles of responsibility. This chapter lists and describes the most important tools for every scenario. Some tools are used in several scenarios, with a different focus in each case.

8.1.1Migrating to SAP HANA

When performing a migration to SAP HANA, you want to make sure that all programs continue to run as before. You also might want to identify optimization potential with regard to database access before or during the migration, and implement the necessary adjustments. These tasks are mainly the responsibility of ABAP developers and quality managers for ABAP programs. In addition, process owners may also need to work with these employees to prioritize possible performance optimizations based on the importance of the respective business process.

When migrating to SAP HANA, the following steps are necessary to analyze and possibly modify or optimize ABAP code:

You should examine the coding statically and combine the analysis results with runtime data to facilitate prioritization, so the first step is to schedule a data collection. To do this, activate the SQL Monitor in the production system for a period of time where all important business processes are run (refer to Chapter 7, Section 7.5.2). For the month-end closing processes to be considered, this time period should contain at least one period-end. We recommend a time period of at least six weeks.

While collecting the data, you can simultaneously use the SAP Code Inspector and the ABAP Test Cockpit to analyze ABAP code. When doing so, a distinction is made between functional checks and performance checks (refer to Chapter 7, Section 7.3.1). Run the tests on a development system that has developments and coding that are comparable to the production system.

We recommend that you prioritize the results of the performance checks based on their importance in the business process, the impact on the system, and the required effort for the optimizations. For prioritization, combine the results of the ABAP code analysis with the runtime data in the SQL performance optimization tool:

While adjusting programs, suitable measures can be derived from the results of the functional checks and the performance checks:

8.1.2System Optimization

System optimization considers the system as a whole. Its focus is highly technical, and SAP system and database administrators usually perform the required steps. When dealing with applications that system and database administrators can’t optimize directly, ABAP developers will also be involved in the optimization measures. System optimization has priority if a large number of system processes are too slow, and the runtime problems can’t be narrowed down to one or a few applications.

There are two possible approaches for system optimization: analysis of system settings and hardware resources on the one hand, and application and SQL analysis on the other. In this context, note that the two subject areas are interdependent, which means that nonoptimal system settings or resource bottlenecks can lead to slow applications. Slow applications (e.g., with high resource consumption), in turn, can lead to resource bottlenecks.

When analyzing the system settings and hardware resources, the system settings are checked using different configuration parameters (for memory size, number of processes, CPU, etc.). A tool also verifies whether the available hardware resources are sufficient for the workload or whether the system is overloaded and needs more hardware. Tools used for these analyses are typically the SAP memory settings in Transaction ST02, the database performance monitor (Transaction ST04 or Transaction DBACOCKPIT), and the Operating System Monitor (Transaction ST06). In addition to this, the system load can be analyzed in SAP HANA Studio.

Another approach is to analyze which applications or SQL statements are resource intensive enough to have a negative impact on the entire system. For this task, you can use the Workload Monitor (Transaction ST03), the SQL Monitor, the SQL cache of the database, and the expensive statement trace.

If necessary, resource-intensive applications can be further analyzed using the tools described in Section 8.1.3. For resource-intensive SQL statements, the following cases in particular are possible:

In the first and second case, often the applications must be optimized to solve the problem. In the third case, the access path to the database must be analyzed. In some cases, SAP system or database administrators can optimize the runtime of those statements (e.g., with an index).

With system optimization, you can identify configuration problems, resource bottlenecks, and expensive ABAP programs or SQL statements. This type of optimization is described in detail in SAP Performance Optimization Guide: Analyzing and Tuning SAP Systems by Thomas Schneider (7th ed., SAP PRESS, 2013) and included in the learning content of the SAP ADM315 course on workload analysis.

8.1.3Application Optimization

The goal of application optimization is to optimize the performance of an existing application or of individual programs of that application. Concrete complaints by end users often motivate an organization to optimize an application.

ABAP developers usually optimize applications. In some cases, SAP system or database experts give consulting guidance on technical aspects. It may also be necessary to work with business-process specialists to discuss design changes or questions regarding a given business process.

Application optimization is an iterative process that mainly consists of three phases:

Analysis

During the analysis, you try to identify reasons for performance problems and determine possible performance optimizations.

We recommend starting the analysis of a program by first evaluating the runtime statistics, that is, by using Transaction STAD (refer to Chapter 7, Section 7.4.1). This will provide early hints on the areas that constitute large portions of the runtime and on the tools that are best suited for a more comprehensive analysis. Three distinct types of cases emerge:

If the largest portion of the runtime is CPU time, we recommend continuing the analysis with an ABAP trace (Transaction SAT or ABAP Profiler).

If the database time is the problem, Transaction STAD already provides further information on the database accesses (e.g., with regard to the affected database tables). If this information isn’t sufficient, you can run an SQL trace in the next step. This delivers detailed information on the number of executions of an SQL statement on the database and the number of records processed. In addition to that, you can use the SQL Monitor and the SQL Performance Tuning Worklist to create an SQL profile of the application and combine this profile with the data from a static code analysis. If necessary, you can then run further analyses using the execution plan and/or the SAP HANA Plan Visualizer (PlanViz). However, both tools require very good knowledge of the SAP HANA database.

If the largest portion of the runtime is neither CPU time nor database time, there are usually long wait times, which can be caused by synchronous Remote Function Calls (RFC), the ABAP WAIT statement, or synchronous updates. In this case, you should analyze the causes of the wait times. When dealing with RFC or update modules, you should first evaluate the runtime statistics of the function that was called and then examine the CPU and database time based on those results.

Adjustment

The analysis results are used to adjust the program. You have very distinct options for program adjustments. You might, for example, be able to increase the performance by changing the table type of an internal table or by making a few simple changes to a data selection. In other cases, fundamental modifications might be necessary to accelerate the program.

For every modification, you should consider possible side effects. After adjusting a program, make sure to run functional tests. By executing unit tests, you can make sure that a given adjustment won’t lead to regression.

Comparison

After or during adjustments, you compare the runtime of the optimized program with the runtime from when you performed the analysis. If the performance didn’t increase at all or not to the extent expected, you can run another analysis with further adjustments before comparing the programs again. Figure 8.1 shows the sequence of application optimization.

Application Analysis

Figure 8.1Application Analysis