0% found this document useful (0 votes)
9 views5 pages

SAP ABAP SQL Performance FAQs

This document discusses SQL statements and performance optimization in ABAP development. It describes: 1) The different types of SQL statements used in ABAP - Open SQL and Native SQL. Open SQL offers a unified syntax while Native SQL allows database-specific features but reduces portability. 2) Best practices for performance include reducing data selection and transport, using indexes, aggregating data, and minimizing database accesses. Tools like Runtime Analysis and SQL Trace can analyze performance. 3) Runtime Analysis reveals expensive operations, unnecessary calls, and inefficient database usage to optimize programs.

Uploaded by

rupakb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

SAP ABAP SQL Performance FAQs

This document discusses SQL statements and performance optimization in ABAP development. It describes: 1) The different types of SQL statements used in ABAP - Open SQL and Native SQL. Open SQL offers a unified syntax while Native SQL allows database-specific features but reduces portability. 2) Best practices for performance include reducing data selection and transport, using indexes, aggregating data, and minimizing database accesses. Tools like Runtime Analysis and SQL Trace can analyze performance. 3) Runtime Analysis reveals expensive operations, unnecessary calls, and inefficient database usage to optimize programs.

Uploaded by

rupakb
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SAP R/3 Document – FAQ SQL / Performance

1. What are the different SQL statements used in abap/4?

a) Open SQL.
They are a set of ABAP/4 commands, which perform operation on database tables. The
results of these operations and the associated error messages are independent of database
systems used. Open SQL thus offers a unified SQL syntax and semantics of different
database systems.

To avoid incompatibilities between different database tables and also to make ABAP
programs independent of the database system in use, SAP has created a set of separate
SQL statements called Open SQL. Open SQL contains a subset of standard SQL
statements as well as some enhancements, which are specific to SAP. Using Open SQL
enables you to access any database tables available to the SAP system, regardless of the
manufacturer.

There are no DDL and DCL statements in Open SQL.

The open SQL command set include the following command –


SELECT, INSERT, UPDATE, DELETE, MODIFY, OPEN CURSOR, FETCH, CLOSE
CURSOR, COMMIT WORK, ROLLBACK WORK.

All SQL Statements used in ABAP other than native SQL.

NOTE : TO Execute an open SQL command:


1) The addressed database system is supported by SAP.
2) The database table is defined in ABAP dictionary.

b) Native SQL.
These are database specific SQL statements or the ANSI SQL which all RDBMS
supports..
Syntax
EXEC SQL [PERFORMING <form>].
<Native SQL statement> [;]
ENDEXEC.

Advantage :
1) Tables which are not declared in ABAP dictionary can be accessed. ( e.g.
TABLES belonging to sys or system user of oracle etc.)
2) To use some of the special features supported by the database specific SQL.
(e.g. Passing hints to Oracle optimizer.)

Disadvantage :.
1) No syntax check is performed what ever is written between EXEC &
ENDEXEC.
2) ABAP program containing database-specific SQL statements will not run
under different database systems.
3) There is no automatic client handling for client dependent tables.
4) Care has to be taken during migration to higher versions.
SAP R/3 Document – FAQ SQL / Performance

NOTE : Use of Native SQL is highly discouraged by SAP.

NOTE :

2. How to take care for performance in ABAP development?

♦ Keep the data selection small.


Ø To avoid transporting unnecessary data across the network
Ø Always use the WHERE clause
Ø Avoid selecting useless data that you filter out later (using CHECK, for example).
Ø Use the indexes of the relevant database tables to make your WHERE clause more
efficient, by checking all index fields for equality (EQ, =) and using the AND
operator
Ø Avoid using complex WHERE clauses, since the system has to break them down into
several individual statements for the database system
Ø If possible, avoid using the NOT operator in the WHERE clause, because it is not
supported by database indexes; invert the logical expression instead.

♦ Transport as little data as possible.


Ø Transport only the fields of the database table that you really need. If you do not need
all of the fields in a table, use a field list in the SELECT clause instead of SELECT *.
Ø Use the aggregate functions in the SELECT clause for calculations, instead of
transporting large amounts of data and then performing the equivalent calculation.
Ø Use the UPDATE statement sparingly: Only update the columns that have actually
changed, and do not overwrite the entire line.
SAP R/3 Document – FAQ SQL / Performance

Ø Note here that the addition INTO CORRESPONDING FIELDS in the INTO clause
of the SELECT statement is only effective for large amounts of data, because the
time required to compare the field names is otherwise too great.
Ø Consider using the DISTINCT option if you are expecting a lot of duplicate table
entries.
Ø Use fewer database accesses
Ø Transfer all of the data at once from the database into internal tables
Ø Where possible, avoid accessing the same data more than once (for example, by
using SELECT before an UPDATE or DELETE statement).
Ø Avoid nested SELECT loops. Instead, use an internal table and a second SELECT
statement with the FOR ALL ENTRIES addition.
Ø In exceptional cases, you can also select data using a separate cursor.

Ø Using Database Buffering


Ø Saving database tables in local buffers can save a considerable amount of time.
Wherever possible, use buffered data, and only use the BYPASSING BUFFER
addition where absolutely necessary.
Ø Note that the following additions automatically bypass the buffer: DISTINCT,
SINGLE FOR UPDATE, and aggregate functions in the SELECT clause.

TIPS:
q You can check the performance of your SQL or ABAP functions by using the ‘SQL
Trace’ and ‘Runtime analysis’ utilities.
q For tips on how to improve the performance of ABAP tasks, choose transaction SE30

3. What is Runtime analysis and its benefits?

Definition: The Runtime Analysis tool lets you analyze the performance of any transaction or
program created within the ABAP Workbench. The Runtime Analysis tool creates lists that reveal
expensive statements, summarize table accesses, and show the hierarchy of a program's overall
flow. This information enables you to detect and analyze problems resulting from:

• Overuse of or unnecessary calling of modularization units (such as subroutines or function


modules) and ABAP statements
• CPU-intensive programming functions
• User-programmed functions that replace existing ABAP statements
• Inefficient and unnecessary database accesses
• find out the database tables accessed by an ABAP program.
• find out resource utilization for the distributed environment of processing for all the 3 tiers of
SAP.

4. What is SQL trace tool?

The SQL Trace tool lets you examine the database calls of reports and transactions. This tool
shows you:
Ø the SQL statements that your application uses.
Ø which values the system uses for specific database accesses and changes
Ø how the system translates ABAP OPEN SQL commands (such as SELECT) into standard
SQL commands
SAP R/3 Document – FAQ SQL / Performance

Ø where your application makes unnecessary database accesses or repeated accesses


Ø where your application positions COMMIT statements
Ø what database accesses or changes occur in the update section of your application
Ø which index and with what cost it is used for data retrieval.

NOTE : Only one user can use the trace tool at a time. So, it is very important to switch off the
tool as soon as the execution is over.

5. What is Explain SQL function?


The Explain SQL function provides you with an analysis of a database's strategy for accessing
any ABAP Dictionary object. You can use this analysis to identify the indexes used for database
access.

6. When to buffer a table?


A table should be buffered when it is
• Rather small in size
• Accessed mostly for read purposes
• Changed very infrequently
Tables which are very good candidate for buffering:
• Control tables / customizing tables
• “SMALL” master data tables

7. Which SQL statement bypasses the table buffer?


Following are the SQL statements which bypasses table buffer:
• SELECT ------- BYPASSING BUFFER.
• SELECT from database views (projection views are OK)
• SELECT ----- DISTINCT --------.
• SELECT ----- COUNT, SUM, AVG, MIN, MAX.
• SELECT ----- ORDER BY (other than the primary key)
• SELECT ----- FOR UPDATE. ( EXEC ------ ENDEXEC)
• Native SQL statements.
NOTE : Avoid this statements when working with buffered tables

8. What is an expensive select statement?


• Long response time
• Many data blocks are scanned to find the selected records.
• Long DB request time caused by too many buffer gets.

9. Explain the open SQL statement modify?


This is used for Adding or changing lines in DB tables.
To insert a line into a database table, regardless of whether the primary key of this line already
exists, you use the MODIFY statement.
There are two possibilities:
• If the database table contains no line with the same primary key as the line to be inserted,
MODIFY works like INSERT, i.e. the line is added.
SAP R/3 Document – FAQ SQL / Performance

• If the database already contains a line with the same primary key as the line to be
inserted, MODIFY works like UPDATE, i.e. the line is changed.

Note : For performance reasons, you should use MODIFY only if you cannot distinguish
between these two options in your ABAP program.

10 . How automatic client handling is switched off in Open SQL?


The CLIENT SPECIFIED option switches off automatic client handling. You can then specify
the client in a WHERE condition, and fill the client field in table work areas.

Common questions

Powered by AI

To optimize ABAP file access, developers should keep data selection small by using WHERE clauses, avoiding complex conditions, and inverting NOT operators for better index usage . They should transport only essential data fields, use aggregate functions for calculations, and apply the DISTINCT option to manage duplicate entries . Fewer database accesses can be achieved by transferring all data at once into internal tables, avoiding repetitive data access, and using internal tables with SELECT FOR ALL ENTRIES . Employing database buffering save time by locally storing data, though only under conditions where buffer bypass is unnecessary . Performance tracking should involve SQL Trace and Runtime Analysis tools to identify inefficient database interactions .

It's recommended to avoid using the NOT operator in WHERE clauses because it isn't supported by database indexes, leading to performance degradation . Instead, logical expressions should be inverted to take advantage of database indexes, which improve efficiency. Complex WHERE clauses should also be simplified to minimize breakdown into multiple statements, and equality operators should be favored to utilize indexed fields effectively . Using minimized field lists instead of SELECT * can also enhance performance by reducing unnecessary data transportation .

The SQL Trace tool allows developers to examine database calls by reports and transactions to identify the SQL statements used, review the values for database accesses, and check how ABAP OPEN SQL commands translate into standard SQL . It highlights unnecessary or repeated database accesses and displays the application of index use, which aids developers in pinpointing inefficient areas for optimization . By showing where COMMIT statements are placed and detailing database access strategies, it enables targeted refinements to improve overall performance .

Using Native SQL allows leveraging specific database capabilities like optimization hints or accessing tables not defined in the ABAP dictionary . However, it bypasses syntax checks and makes programs highly dependent on a specific database system, compromising portability across platforms . This can hinder program migration to different database systems or versions, requiring manual code adjustments and testing, thereby increasing maintenance complexity and costs . Despite its targeted performance benefits, these drawbacks limit its practical deployment in SAP environments.

It is crucial to switch off the SQL Trace tool post-execution because only one user can operate it at a time . Leaving it on unnecessarily restricts others from using the tool, potentially delaying their development tasks and burdening system resources with overhead from continuous tracing operations, which can affect server performance . Neglecting this step could lead to inefficiencies and prolonged troubleshooting on shared systems.

Open SQL offers a unified SQL syntax and semantics, making ABAP programs independent of the underlying database system. It includes commands like SELECT, INSERT, UPDATE, DELETE, and more, but omits DDL and DCL statements, providing a safe and compatible way to access database tables . Native SQL consists of database-specific SQL statements, allowing access to tables not declared in the ABAP dictionary and the use of database-specific features . However, it lacks syntax checks and automatic client handling, making programs database-dependent and error-prone during migrations . Open SQL's advantage lies in portability and safety, whereas Native SQL allows for specificity and direct database optimization, albeit with portability trade-offs.

Runtime analysis examines transaction or program performance within the ABAP Workbench, revealing inefficient or resource-intensive statements, summarizing table accesses, and outlining the execution flow hierarchy . This analysis helps detect inefficiencies like excessive use of modularization units, CPU-heavy code, and unnecessary database accesses, enabling developers to streamline their programs . By showing resource utilization across SAP's distributed environment, it provides insights for optimizing distributed processing, leading to improved performance and lower operational costs .

The MODIFY statement in Open SQL acts like INSERT when a database table contains no line with the same primary key as the one being inserted, adding the new line . Conversely, it functions as UPDATE if the database already contains a line with the same primary key, modifying the existing entry . For optimal performance, developers should use MODIFY only when it's unclear if an INSERT or UPDATE operation is necessary, as it allows for streamlined single-operation logic while avoiding unnecessary database operations .

The Explain SQL function provides an analysis of a database's strategy for accessing ABAP Dictionary objects. It identifies which indexes are used during database access and helps developers understand the execution plan of SQL queries . This insight allows them to optimize query construction and improves performance by ensuring efficient use of available indexes, thus potentially reducing the execution times and resource usage of their ABAP applications .

A table should be buffered when it is small in size, primarily accessed for read operations, and is updated infrequently . Ideal candidates for buffering are control or customizing tables and "SMALL" master data tables due to their static nature and repetitive access pattern . Buffering is not beneficial for tables frequently altered or accessed with queries that bypass the buffer, such as when using DISTINCT or ORDER BY clauses not on the primary key .

You might also like