Uploaded by Juan Pablo Zamichiei

HA400 EN Col18-ABAP Programming for SAP HANA

advertisement
HA400
ABAP Programming for SAP HANA
.
.
PARTICIPANT HANDBOOK
INSTRUCTOR-LED TRAINING
.
Course Version: 18
Course Duration: 3 Day(s)
Material Number: 50160485
SAP Copyrights, Trademarks and
Disclaimers
© 2022 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any
purpose without the express permission of SAP SE or an SAP affiliate company.
SAP and other SAP products and services mentioned herein as well as their
respective logos are trademarks or registered trademarks of SAP SE (or an SAP
affiliate company) in Germany and other countries. Please see https://
www.sap.com/corporate/en/legal/copyright.html for additional trademark
information and notices.
Some software products marketed by SAP SE and its distributors contain proprietary
software components of other software vendors.
National product specifications may vary.
These materials may have been machine translated and may contain grammatical
errors or inaccuracies.
These materials are provided by SAP SE or an SAP affiliate company for
informational purposes only, without representation or warranty of any kind, and SAP
SE or its affiliated companies shall not be liable for errors or omissions with respect
to the materials. The only warranties for SAP SE or SAP affiliate company products
and services are those that are set forth in the express warranty statements
accompanying such products and services, if any. Nothing herein should be
construed as constituting an additional warranty.
In particular, SAP SE or its affiliated companies have no obligation to pursue any
course of business outlined in this document or any related presentation, or to
develop or release any functionality mentioned therein. This document, or any related
presentation, and SAP SE’s or its affiliated companies’ strategy and possible future
developments, products, and/or platform directions and functionality are all subject
to change and may be changed by SAP SE or its affiliated companies at any time for
any reason without notice. The information in this document is not a commitment,
promise, or legal obligation to deliver any material, code, or functionality. All forwardlooking statements are subject to various risks and uncertainties that could cause
actual results to differ materially from expectations. Readers are cautioned not to
place undue reliance on these forward-looking statements, which speak only as of
their dates, and they should not be relied upon in making purchasing decisions.
Typographic Conventions
American English is the standard used in this handbook.
The following typographic conventions are also used.
This information is displayed in the instructor’s presentation
Demonstration
Procedure
Warning or Caution
Hint
Related or Additional Information
Facilitated Discussion
User interface control
Example text
Window title
Example text
© Copyright. All rights reserved.
iii
iv
© Copyright. All rights reserved.
Contents
vii
Course Overview
1
Unit 1:
Introduction
3
13
21
Lesson: SAP HANA Basics and Technical Concepts
Lesson: Introducing the SAP HANA Studio
Lesson: ABAP and SAP HANA
35
Lesson: Introducing the ABAP Development Tools (ADT)
47
Unit 2:
49
53
61
67
73
85
Lesson: SAP HANA as Secondary Database– Access via Open SQL
Lesson: Code Checks to Prepare ABAP Code for SAP HANA
Lesson: Tools to Analyse Potential Performance Issues
Lesson: Guided Performance Analysis
Lesson: SQL Performance Rules for SAP HANA
Unit 3:
87
91
97
109
115
131
Unit 4:
Unit 5:
Advanced Topics
Lesson: Transporting SAP HANA Objects with ABAP Transport
Requests
Lesson: Using SAP HANA Full Text Search
Lesson: ABAP List Viewer with Integrated Database Access (ALV
IDA)
189
199
215
SAP HANA specific Code-to-Data
Lesson: The Syntax of SAP HANA Native SQL
Lesson: ABAP Managed Database Procedures
Lesson: ABAP Database Connectivity (ADBC)
Lesson: Use of SAP HANA Information Models in ABAP
177
213
Database Independent Code-to-Data
Lesson: Classical Open SQL and Its Limitations
Lesson: Enhanced Open SQL
Lesson: The Basics of Core Data Services in ABAP
Lesson: Associations in Core Data Services
Lesson: Outlook: More Interesting Features of CDS
133
137
151
155
175
Taking ABAP to SAP HANA
Unit 6:
Case Study: Optimize a Report on Flight Customer Revenue
Lesson: Optimizing a Report with CDS View and ALV IDA
© Copyright. All rights reserved.
v
vi
© Copyright. All rights reserved.
Course Overview
TARGET AUDIENCE
This course is intended for the following audiences:
●
Developer
© Copyright. All rights reserved.
vii
viii
© Copyright. All rights reserved.
UNIT 1
Introduction
Lesson 1
SAP HANA Basics and Technical Concepts
3
Lesson 2
Introducing the SAP HANA Studio
13
Lesson 3
ABAP and SAP HANA
21
Lesson 4
Introducing the ABAP Development Tools (ADT)
35
UNIT OBJECTIVES
●
Understand the fundamental technical concepts of SAP HANA
●
Describe SAP HANA Application Scenarios
●
Describe SAP HANA Studio
●
Connect SAP HANA studio to an SAP HANA system
●
Understand SAP HANA catalog (schemas and tables)
●
Explain SAP HANA Content (Packages, Views, Procedures)
●
Explain the SAP HANA and ABAP evolution
●
Indentify SAP HANA-specific settings in ABAP Dictionary
●
Describe the various code-to-data concepts
●
Work with ABAP Development Tools
© Copyright. All rights reserved.
1
Unit 1: Introduction
2
© Copyright. All rights reserved.
Unit 1
Lesson 1
SAP HANA Basics and Technical Concepts
LESSON OVERVIEW
In this lesson, you learn how to describe SAP HANA goals, technical innovations, and
challenges; understand the fundamental technical concepts of SAP HANA; and determine if
SAP HANA’s row store or column store is used for an ABAP transparent table and which
indices are used on SAP HANA.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Understand the fundamental technical concepts of SAP HANA
●
Describe SAP HANA Application Scenarios
SAP HANA Goals
Figure 1: Today's Technology Requires Trade-off Decisions
Developing applications using technology that pre-dates SAP HANA typically required making
several trade-off decisions.
The figure, Today's Technology Requires Trade-off Decisions, shows the five dimensions of
requirements that are typical for business applications. So far, these dimensions have been in
conflict.
For example, you had to decide between providing a high-speed application and developing an
application that does not require special preparation of the data, such as calculating
aggregations beforehand and storing the results in addition to the base data. In addition, it
© Copyright. All rights reserved.
3
Unit 1: Introduction
was not possible to develop an application which is both real-time and able to analyze a large
amount of data, perhaps even unstructured data, simultaneously.
Figure 2: SAP HANA: Delivers Across Five Dimensions
SAP HANA tries to deliver across all these five dimensions, so that you no longer have to
make so many trade-off decisions. The goal is to enable the development of applications that
combine Online Transaction Processing (OLTP) and Online Analytical Processing (OLAP)
usage patterns.
SAP HANA Goals
●
Enable new applications and optimize existing applications.
●
High performance and scalability.
●
Hybrid data management system – combining different paradigms in one system.
●
Compatibility and standard Database Management System (DBMS) features.
●
Support for text analysis, indexing, and search.
●
Cloud support and application isolation.
●
Support for temporal tables.
●
Executing application logic inside the data layer.
SAP HANA has the following goals:
Enable new applications and optimize existing applications
SAP HANA is an in-memory data platform that is deployable as an appliance or in the
cloud and makes full use of the capabilities of current hardware to increase application
performance, reduce cost of ownership, and enable new scenarios and applications that
were not possible before.
High performance and scalability
4
© Copyright. All rights reserved.
Lesson: SAP HANA Basics and Technical Concepts
SAP HANA is designed to make full use of multi-core CPUs by parallelization of
execution. It can be distributed across multiple servers to achieve good scalability in
terms of both data volume and concurrent requests.
Hybrid data management system – combining different paradigms in one system
SAP HANA architecture integrates different in-memory storages (column-based, rowbased, and object-based), traditional disk-based tables, text analysis and search, and
built-in support for planning. Combining all these capabilities in a single product not only
improves performance but reduces overall complexity and cost.
Compatibility and standard DBMS features
An important goal is the possibility to use the SAP HANA database system as a
replacement for any standard relational database management system. The SAP HANA
database system is a full relational database management system with SQL interface,
transactional isolation, and recovery (ACID properties), and high availability. SAP
applications that use Open SQL should be able to run on SAP HANA without changes.
Support For text analysis, indexing and search
An important goal of SAP HANA is to provide powerful analysis, and text indexing and
search capabilities that support a state-of-the-art search experience. This includes full
text search with advanced features, such as freestyle search (without knowing the name
of attributes in the database), linguistic search, and fault-tolerant fuzzy search.
Cloud support and application isolation
In cloud deployments, a system must be shared – including physical servers and installed
software – between multiple customers. SAP HANA will support this in the future, with
the planned ability to host multiple isolated databases within a single SAP HANA system.
The databases inside one system will have their own data, metadata, and users, but will
share the same hardware, the same SAP HANA software installation, and the system
administration. This feature helps to support cloud scenarios – but it can also be used in
an on-premise deployment, for example, for running multiple unrelated applications in
one SAP HANA system with effective isolation and resource management.
Support for temporal tables
SAP applications that use Open SQL should run on SAP HANA without changes. In
temporal tables, update operations do not modify the existing records. Instead, new
versions of the data records are inserted. Applications may use temporal tables, for
example, for time-based reporting and analysis or for versioning and change recording
purposes.
Executing application logic inside the data layer
To benefit from the parallelization and optimization capabilities of SAP HANA,
applications must execute data intensive operations on the database level. Pushing
calculations to the database layer can also significantly reduce the amount of data that
needs to be transferred between the database and application server. SAP HANA allows
application developers to define application-specific functions that are executed inside
the database layer.
© Copyright. All rights reserved.
5
Unit 1: Introduction
SAP HANA Innovations and Challenges
Figure 3: What Made SAP HANA Possible?
Dramatically improved hardware economics and technology innovations in software made it
possible for SAP to deliver its vision of the real-time enterprise with in-memory business
applications. Understanding them is important to an understanding of SAP HANA’s
performance characteristics.
In-Memory Computing and the Shift of Performance Bottlenecks
Historically, database systems were designed to perform well on computer systems with
limited RAM. This had the effect that slow disk I/O was the main bottleneck in data
throughput. Consequently, the architecture of those systems was designed with a focus on
optimizing disk access, for example, by minimizing the number of disk blocks (or pages) to be
read into the main memory when processing a query. In addition, CPUs had a single core and
networks were far slower.
Figure 4: Shift of Performance Bottlenecks
6
© Copyright. All rights reserved.
Lesson: SAP HANA Basics and Technical Concepts
Computer architecture has changed in recent years. Multi-core CPUs (multiple CPUs on one
chip or in one package) are now standard, with fast communication between processor cores
enabling parallel processing. Main memory is no longer a limited resource, and modern
servers can have 2TB of system memory, which allows complete databases to be held in
RAM.
Currently, server processors have up to 64 cores and 128 cores will soon be available. With
the increasing number of cores, CPUs are able to process increased data per time interval.
This shifts the performance bottleneck from disk I/O to the data transfer between CPU cache
and main memory.
Figure 5: New Bottlenecks Become Important – How To Avoid Them
To get the best performance from current hardware, the new bottlenecks have to be avoided
by addressing the challenges as follows:
●
●
Avoid CPU cache misses and expensive data transfer from main memory into the CPU –
optimize loading the data into the CPU.
Avoid idling CPU cores – make use of parallelism by using all the cores of a CPU, and
several CPUs.
© Copyright. All rights reserved.
7
Unit 1: Introduction
Column Store Versus Row Store
Figure 6: Row Store
By accessing data in column-store order, you benefit immensely from simplified table scan
and data pre-caching. This can make all the difference in performance.
Figure 7: Column Store
8
© Copyright. All rights reserved.
Lesson: SAP HANA Basics and Technical Concepts
Data Compression
Figure 8: Columnar Dictionary Compression
SAP HANA uses different, efficient compression methods, such as dictionary encoding, runlength encoding, and more. This has the following benefits:
●
●
●
It reduces the amount of memory required.
It speeds up operations on columns because the columns can be loaded into the CPU
caches faster and with fewer loading cycles.
It speeds up operations on columns because many comparisons become integer value
comparisons. For example, these are faster than string comparisons.
© Copyright. All rights reserved.
9
Unit 1: Introduction
Partitioning and Parallel Processing
Figure 9: Parallel Processing
On SAP HANA and with column storage, data is only partially blocked. This makes parallel
processing possible. Even the same column can be split up and processed by different cores
at the same time.
Figure 10: Using Partitioning to Further Leverage Parallelism
The use of parallelism can be taken a step further by creating different partitions of the data
to be stored and processed on different blades. This allows for the management and
processing of huge amounts of data.
10
© Copyright. All rights reserved.
Lesson: SAP HANA Basics and Technical Concepts
SAP HANA – Architectural Scenarios
SAP HANA can be used in different architectural scenarios, which in turn provide the
technological base for the different application areas.
From an ABAP programmer’s point of view, there are two groups of scenarios:
Scenarios without ABAP
in which SAP HANA is used as a standalone server.
Scenarios with ABAP
in which SAP HANA serves as database for an Application Server ABAP.
Figure 11: Architectural Scenarios without ABAP
The first architectural scenario without ABAP is SAP HANA as data warehouse or data mart,
in which data is typically replicated from existing applications into a separate SAP HANA
database on top of which analytical content is developed and then consumed using business
intelligence tools or simply Microsoft Excel.
A second type of HANA-based application consists of native applications developed on SAP
HANA using SAP HANA extended application services (SAP HANA XSA).
Note:
Although the non-ABAP scenarios are mentioned here, they are not the focus of
this course.
© Copyright. All rights reserved.
11
Unit 1: Introduction
Figure 12: Architectural Scenarios with ABAP
The primary concern of this course is an architectural scenario in which ABAP applications
run on application servers that use SAP HANA as their primary database. For this scenario it
makes no difference whether the ABAP applications are only available with SAP HANA
database, which is the case for products like SAP S/4HANA, SAP C/4 HANA, and others, or
whether SAP HANA database is only an additional option, as in SAP Business Suite powered
by SAP, SAP CRM powered by SAP HANA, and so on. Read and write access to the database
is handled by SAP HANA.
The course also covers applications which use SAP HANA as a secondary database, so called
side-by-side scenarios. An example for a side-by-side scenario is the SAP Business
Application Accelerator powered by SAP HANA, an add-on to SAP ERP that SAP shipped till
the end of 2016 and which is still supported for existing customers. In this scenario, the ABAP
system is connected to two databases. Some of the ABAP system’s data is replicated from
the primary, non-SAP-HANA database into the secondary, SAP HANA database. Specific
reading database calls are then redirected to the secondary SAP HANA database to speed up
selected reports or transactions.
Note:
Today, we have to consider the side-by-side scenario as being outdated. The main
reason to still cover it in this course is the elegant possibility to directly compare
read accesses to a SAP HANA DB and to a non-SAP-HANA DB from within the
same system, the same program even.
LESSON SUMMARY
You should now be able to:
12
●
Understand the fundamental technical concepts of SAP HANA
●
Describe SAP HANA Application Scenarios
© Copyright. All rights reserved.
Unit 1
Lesson 2
Introducing the SAP HANA Studio
LESSON OVERVIEW
In this lesson, you learn how to explain the central functions of SAP HANA studio, switch
between different perspectives in SAP HANA studio, set up a connection to an SAP HANA
database, understand schemas and tables in SAP HANA studio, and analyze the definition of
tables in SAP HANA studio.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Describe SAP HANA Studio
●
Connect SAP HANA studio to an SAP HANA system
●
Understand SAP HANA catalog (schemas and tables)
●
Explain SAP HANA Content (Packages, Views, Procedures)
SAP HANA Studio – An Eclipse-Based Tool
Figure 13: SAP HANA Studio – An Eclipse-Based Development Environment
© Copyright. All rights reserved.
13
Unit 1: Introduction
When you start optimizing ABAP applications for SAP HANA, you may have to access the SAP
HANA layer or the SAP HANA database server itself to, for example, prototype native SQL
statements, to look at SAP HANA artifacts such as attribute views, column views, or database
procedures, or to debug database procedures.
The tool to perform such tasks on the SAP HANA layer is the SAP HANA studio.
SAP HANA studio is an Eclipse-based integrated development environment that provides
tools to administer, monitor, and configure SAP HANA systems.
These tools are based on existing Eclipse frameworks.
SAP chose Eclipse as the platform for an SAP HANA Integrated Development Environment
(IDE) because Eclipse is SAP’s strategic platform for integrated design-time and development
tools in general. The open Eclipse platform offers first-class user experience, powerful
platform capabilities, and a broad and vivid ecosystem that regularly contributes
enhancements and extensions.
Eclipse is a platform that has been designed for building integrated Web and application
development tools. The platform does not provide a great deal of end-user functionality by
itself. The value of the platform is what it encourages: rapid development of integrated
features based on a plug-in model.
SAP plays an active role in the Eclipse Foundation as one of its strategic members. Many of
the SAP design-time, development, and administration tools already use the Eclipse platform.
These include SAP NetWeaver Visual Composer, the Sybase Unwired Platform, and the SAP
HANA studio.
As a result of this SAP strategy, SAP also provides an Eclipse-based development
environment for ABAP called ABAP Development Tools for Eclipse (ADT). This makes it
possible to combine both development environments in a single, common IDE for both ABAP
and SAP HANA development.
Figure 14: SAP HANA Studio – Perspectives and Views
14
© Copyright. All rights reserved.
Lesson: Introducing the SAP HANA Studio
Like most Eclipse-based development environments, SAP HANA studio provides several
perspectives within the Eclipse workbench.
Each perspective is tailored for particular groups of tasks and is a pre-configured set of panes
called views. Examples of perspectives are as follows:
●
Administration Console – to administer, monitor and configure SAP HANA systems.
●
Modeler – to develop information models and database procedures.
●
SAP HANA development – to develop native SAP HANA-based applications using SAP
HANA extended application services.
Examples of views are as follows:
●
●
●
Systems – visible in most SAP HANA perspectives and showing the list of SAP HANA
systems the IDE is connected to.
Properties – showing properties of the currently selected object, for example, of a
configured SAP HANA system.
Job log – showing the list of recent jobs performed, for example, imports of development
objects and activations.
Details of SAP HANA Studio
Figure 15: Most Relevant Perspective For ABAP Developers: Modeler
The Modeler is the perspective most relevant for ABAP developers. It provides access to the
views and database procedures that you can consume in the ABAP environment. You can
open it using the menu item Window → → Open Perspective or the Open Perspective button
in the toolbar.
A central part of this perspective is the Systems view on the left-hand side. This view contains
a list of systems. Each system represents a logon to an SAP HANA system with a particular
user. Systems can be grouped in folders to structure the list.
© Copyright. All rights reserved.
15
Unit 1: Introduction
Figure 16: System View
Each system shows a hierarchy of objects visible to this user.
The catalog consists of one or several schemas, each containing a set of database objects,
such as database tables and database views.
The content contains models, which are specific objects that allow optimized access to the
database tables. Part of these models are SAP HANA views and database procedures. SAP
HANA views and database procedures are arranged in content packages, which are similar to
ABAP packages, as they group objects that logically belong together.
Systems – Access to SAP HANA Server
Figure 17: Connecting to an SAP HANA Database
To connect to an SAP HANA system and see the corresponding catalog and content, use the
Systems view, and the context menu item Add System.
To add a system, you need the following:
16
© Copyright. All rights reserved.
Lesson: Introducing the SAP HANA Studio
●
●
The host name, on which the SAP HANA system is installed. Note that this is typically
different from the host of the ABAP system.
The instance number of the SAP HANA system. Again, note that this is typically different
from the instance number of the ABAP system.
●
A description.
●
The database user – also different from your ABAP user.
●
The password for the database user.
Schemas and Tables
Figure 18: Table Definitions
Once connected, you can open the database catalog and look, for example, at the definition of
tables on the SAP HANA layer. The table editor also allows exporting the SQL statement used
to create the database table.
© Copyright. All rights reserved.
17
Unit 1: Introduction
SAP HANA Information Models
Figure 19: SAP HANA Information Models
Under the Content node, you find the SAP HANA information models. Information models
consist of SAP HANA specific views and SAP HANA procedures which are organized in a a
hierarchy of packages. Every package defines a name space, that is, views or procedures may
have identical names as long as they are located in different packages.
Note:
Originally. SAP HANA information models consisted of three types of views. But
attribute views and analytic views, still visible in the figure, became obsolete with
SAP HANA 1.0 SPS12. SAP strongly recommends not to create new attribute
views and analytic views. In addition, SAP HANA studio offers a tool to convert
existing attribute and analytic views into calculation views.
Search for SAP HANA objects
SAP HANA studio provides two different search dialogs: A global search and a local search in
a subtree of the content hierarchy.
18
© Copyright. All rights reserved.
Lesson: Introducing the SAP HANA Studio
Figure 20: Search Functions - Global Search
You perform a global search via the search field in the toolbar of SAP HANA Studio. The global
search covers not only information models in subtree Content but also the various schemas in
the Catalog.
Figure 21: Search Functions – Local Search in Content
You can perform a local search by right-clicking a content package and choosing Find. This
search covers only the selected content package and its subpackages.
© Copyright. All rights reserved.
19
Unit 1: Introduction
Delivery Units
Figure 22: Delivery Units for Transport of SAP HANA Content
You open the administration view for delivery units from the Quick Launch view.
Each delivery unit must have a unique name. When creating a new delivery unit, a vendor
name is automatically derived from the system settings and linked with this delivery unit. The
SAP vendor name is sap.com.
LESSON SUMMARY
You should now be able to:
20
●
Describe SAP HANA Studio
●
Connect SAP HANA studio to an SAP HANA system
●
Understand SAP HANA catalog (schemas and tables)
●
Explain SAP HANA Content (Packages, Views, Procedures)
© Copyright. All rights reserved.
Unit 1
Lesson 3
ABAP and SAP HANA
LESSON OVERVIEW
In this lesson you learn how SAP HANA influences the way we design and implement ABAP
applications. You get an overview of the strategies that exist for optimizing ABAP applications
based on SAP HANA. And you will see that starting with ABAP release 7.40, SAP introduced
new ABAP language features, repository object types, development tools and analysis tools in
order to support such optimizations.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Explain the SAP HANA and ABAP evolution
●
Indentify SAP HANA-specific settings in ABAP Dictionary
●
Describe the various code-to-data concepts
SAP NetWeaver AS ABAP Support for SAP HANA
Figure 23: Evolution of ABAP Programming for SAP HANA
© Copyright. All rights reserved.
21
Unit 1: Introduction
The support of SAP HANA by SAP NetWeaver AS ABAP evolved in three steps. At the
beginning, the only way to connect SAP HANA to an AS ABAP was in side-by-side scenarios,
that is, as secondary database. Then, with SAP HANA SPS05, SAP HANA was supported as
primary database of an ABAP system for the first time. This scenario, however, was only
available for SAP NetWeaver BW systems. In a last step, SAP HANA became generally
available as primary database of an AS ABAP system with SAP HANA SPS06 and NetWeaver
7.40.
Changes to SAP Tables when SAP HANA is the Primary Database
When using SAP HANA as primary database of AS ABAP systems, it turned out that some
techniques used in the ABAP Dictionary conflict with technical features of SAP HANA. One
example are table pools and table clusters with their one big binary VARDATA column. This
does not go together well with SAP HANA's column store and data compression. Another
example are secondary indexes, of which a majority becomes a waste of memory when SAP
HANA, with its in-memory technology, can perform full scans of database tables in sufficiently
short time.
Common Changes to SAP Tables when SAP HANA is the Primary Database
When you compare an SAP system with SAP HANA as its primary database to the same
system on another database, you may find the following differences:
De-Pooling and De-Clustering
Many tables that used to be pool tables and cluster tables are transparent tables if the
primary database is SAP HANA.
Deactivation of Secondary Indexes
Many secondary indexes that are required on other databases are not activated on SAP
HANA database.
Empty Aggregate Tables
Some aggregate tables are not needed on SAP HANA database and are therefore not
populated with data.
New Settings in ABAP Dictionary to Support SAP HANA DB
The following are settings in ABAP Dictionary to support SAP HANA:
Storage type for tables
Set storage type (column store or row store) in technical settings
Depooling and Declustering
Make pool and cluster tables transparent on certain databases.
Selective Activation of Secondary Indexes
Create secondary indexes only for certain databases.
Definition of Fulltext Indexes
Define secondary indexes as SAP HANA-specific fulltext indexes.
22
© Copyright. All rights reserved.
Lesson: ABAP and SAP HANA
Figure 24: Setting the Storage Type for a Table
To support setting the storage type for a table in ABAP Dictionary, a new tab has been added
to the Maintain Technical Settings form for database tables. The new tab is called DB-Specific
Properties and allows for switching between the following three storage types:
●
●
Storage type Column Store creates the database table in the SAP HANA column store, or
moves it there.
Storage type Row Store creates the database table in the SAP HANA row store, or moves it
there.
If the current database does not support a differentiation between column and row store, the
setting is ignored.
Note:
This setting can be changed after the table has been created, and the table will be
moved into the other store. Use this with caution, however, since it may involve
reorganizing table contents, should such content exist already.
© Copyright. All rights reserved.
23
Unit 1: Introduction
Figure 25: De-Clustering
To support depooling and declustering on SAP HANA, a new option has been added to the
Choose Table Category dialog. You find this dialog under Extras → → Change/Display Table
Category.
For pool or cluster tables, you can specify a list of databases on which these tables should be
considered transparent tables.
If you do so, the table will be created as a database object on the specified databases. On all
other databases, its content will be stored as usual in the corresponding table pool or table
cluster.
24
© Copyright. All rights reserved.
Lesson: ABAP and SAP HANA
Figure 26: Selective Activation of Secondary Indexes
You can activate secondary indexes selectively via the respective dialog in the index
definition.
Note:
Technically speaking, this is not a new feature in ABAP Dictionary. The selective
activation of secondary indexes has been available for some time, but it has only
been used widely as a standard setting with SAP HANA database.
© Copyright. All rights reserved.
25
Unit 1: Introduction
Figure 27: Secondary Index as Full-Text Index
To support the definition of SAP HANA-specific full text indexes in the ABAP Dictionary, the
new dialog Full Text Index has been added to the menu that is available when editing a
secondary index.
Note:
We will discuss SAP HANA full text search and SAP HANA full text index in a later
unit of this course.
What does it mean for ABAP Developers?
The new capabilities of SAP HANA offer a huge variety of opportunities for ABAP Developers.
26
© Copyright. All rights reserved.
Lesson: ABAP and SAP HANA
What's in it for ABAP developers?
Figure 28: What's in It for ABAP Programmers?
Accelerate
By optimizing the coding of long-running background jobs for SAP HANA, the runtime for
these jobs can be reduced. More jobs can be executed in the same time, and particularly
costly tasks are possible in one go, rather than splitting them up.
Extend
In the past, some reports had to be executed in the background, simply because their
runtime was too long for dialog processing. Consequently, users worked on snapshots or
pre-aggregated data sets. By optimizing these reports with SAP HANA, they can be
offered as online reports again, displaying real-time data with full drill-down capability.
Innovate
With SAP HANA's analysis and calculation capabilities, ABAP developers can design new
applications that would not have been possible in the past.
SAP NetWeaver AS ABAP Support for Optimizing Applications
Starting with release 7.4, ABAP provides support for optimizing ABAP applications running on
SAP HANA.
© Copyright. All rights reserved.
27
Unit 1: Introduction
Figure 29: SAP NetWeaver AS ABAP Support for Optimizing Applications
There are transparent optimizations you do not see as an application developer, but which
you benefit from because they happen under the hood. An example is the SELECT… FOR ALL
ENTRIES… statement in Open SQL, the implementation of which has been improved.
New performance analysis tools are available and existing tools, such as static code checks
and the runtime analysis, have been improved to effectively support the optimization of
existing ABAP code.
The ABAP language and the Open SQL language have been extended. For example, OpenSQL
now supports more complicated joins and sub-queries, and there are ways to integrate SAP
HANA stored procedures in ABAP code.
The use of SAP HANA artifacts has been simplified. For example, you can access SAP HANA
column views through the ABAP Dictionary using Open SQL.
Some re-use components have been extended or optimized for SAP HANA, such as the SAP
List Viewer (ALV).
On top of all this, the ABAP platform team provides guidelines for optimizing ABAP code
running on SAP HANA.
Transition ABAP Code to SAP HANA
A good practice when transitioning and optimizing ABAP applications to SAP HANA is to
follow a three-step approach.
28
© Copyright. All rights reserved.
Lesson: ABAP and SAP HANA
Figure 30: Steps to Transition ABAP Code for SAP HANA
The first step is to detect those places where performance can or should be improved, and to
analyze and prioritize the findings based on the importance of the places detected. The next
step is to optimize the existing code, using the prioritized list. An optional last step is to use
SAP HANA’s new features to redesign and innovate your business processes.
A New Programming Approach
Figure 31: New Programming Approach
The arrival of in-memory technology on the database layer also requires a change in the way
we design and implement applications.
The basic approach of classic ABAP programming was as follows:
Keep the load from the database.
Get all the data you need on the application server.
© Copyright. All rights reserved.
29
Unit 1: Introduction
Do your processing in ABAP.
In order to benefit the most from SAP HANA's capabilities, it is better to do expensive
calculations and aggregations on the database itself, rather than transferring huge amounts
of data onto the ABAP application server. This is a fundamental change to the ABAP
programming paradigm. It is very often referred to as “Code-to-Data” as opposed to the
classic “Data-to-Code” approach.
Bottom-Up Approach for Code-to-Data
One way of approaching the code-to-data paradigm is to use native SQL to access SAP
HANA-specific functionality, such as built-in functions. Encoding all computations in native
SQL statements has a drawback, however, in that you have to get the SQL statements right,
for example the join conditions, the built-in functions, and so on. In addition, encoding
everything in native SQL statements makes reusing parts of the computations difficult.
Bottom-Up Approach with Direct Access to SAP HANA Artefacts (Native SQL)
Figure 32: Possible Approaches with AS ABAP < 7.4 SP02
An alternative approach makes use of the fact that SAP HANA provides advanced view
modeling capabilities through SAP HANA column views. Modeling such views leads to more
reusable results and requires less programming.
If the computations are too complex to be modeled using SAP HANA views, using database
procedures implemented in SAP HANA SQL script is another alternative.
Both options can be interpreted as bottom-up approaches, because you first model and
respectively implement an artefact on the SAP HANA layer, and then call the existing SAP
HANA artefact in ABAP. In ABAP releases below ABAP 7.4 SP02, or in scenarios with SAP
HANA as secondary database, such calls always require using native SQL.
30
© Copyright. All rights reserved.
Lesson: ABAP and SAP HANA
Bottom-Up Approach with Proxy Objects
Figure 33: Bottom-Up Approach with AS ABAP 7.4 ≥ SP02
Starting with ABAP 7.4 SP02, ABAP provides new repository objects to simplify the bottomup approach. These new objects are created in the ABAP repository as representatives or
proxy objects for the objects created on SAP HANA. Access to the proxy objects does not
require the use of native SQL.
You can use existing SAP HANA artefacts natively in ABAP by doing the following:
●
●
Create so-called external views in the ABAP Dictionary to represent native SAP HANA
column views.
Create so-called database procedure proxies in the ABAP Dictionary to represent SAP
HANA native database procedures.
There is also a proxy object for SAP HANA delivery units, the so-called SAP HANA Transport
Container. It helps to synchronize the otherwise separated lifecycle managements of ABAP
objects and SAP HANA artefacts.
Caution:
Creating database procedure proxies is not recommended. It is covered in the
course only in case you encounter such proxies in your ABAP system.
© Copyright. All rights reserved.
31
Unit 1: Introduction
Top-Down-Approach for Code-to-Data
Figure 34: Top-Down Approach with AS ABAP 7.4 SP05
Since release 7.40 SP05, ABAP provides additional capabilities to support the code-to-data
paradigm. This new approach can be called the top-down approach. Compared to the
bottom-up approach, the ABAP stack manages all entities and deploys all artefacts from the
ABAP layer into the database.
Figure 35: Code-to-Data Capabilities as of ABAP 7.40
Using SAP HANA-specific features is improved by introducing a new concept called ABAPManaged Database Procedures.
A database-oriented programming model is supported better through the following:
●
32
An advanced Open SQL, supporting more of the SQL-92 standard
© Copyright. All rights reserved.
Lesson: ABAP and SAP HANA
●
New capabilities for defining views using a common set of domain-specific languages and
services for defining and consuming semantically rich data models called Core Data
Services
Transparent optimizations are improvements in the ABAP stack itself. Your code directly
benefits from this without any adjustments. The following are examples of transparent
optimizations:
●
Fast Data Access, a new data exchange protocol between the ABAP stack and the
database
●
Optimizations of SELECT ... INTO ITAB and of SELECT SINGLE
●
Optimizations of SELECT ... FOR ALL ENTRIES
Performance Improvement Versus Code Adjustments
Figure 36: Performance Improvement Versus Code Adjustments
The different code-to-data options correlate with the potential gain in performance. However,
the complexity of the resulting code may also increase as more code is moved to the
database or made database-specific, as follows:
●
●
●
Transparent optimizations in principle improve performance without any code
adjustments. Some code adjustments may be necessary while migrating to SAP HANA,
however, to profit from the adjustments.
Using enhanced Open SQL and the advanced view definition capabilities, you can create
new data models and consume them in ABAP, thereby improving the productivity and
performance without database-specific artefacts.
Using native database features may be necessary to achieve the best performance, but
the code adjustment effort might increase.
LESSON SUMMARY
You should now be able to:
●
Explain the SAP HANA and ABAP evolution
© Copyright. All rights reserved.
33
Unit 1: Introduction
34
●
Indentify SAP HANA-specific settings in ABAP Dictionary
●
Describe the various code-to-data concepts
© Copyright. All rights reserved.
Unit 1
Lesson 4
Introducing the ABAP Development Tools
(ADT)
LESSON OVERVIEW
As an open framework, Eclipse can host a whole range of development tools. As well as the
SAP HANA studio environment, SAP also provides a suite of tools known as the ABAP
Development Tools. These enable you to develop ABAP resources using Eclipse as a frontend development environment.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Work with ABAP Development Tools
Knowing ABAP Development Tools
Figure 37: ABAP Development Tools for SAP NetWeaver – Architecture
© Copyright. All rights reserved.
35
Unit 1: Introduction
ABAP Development Tools provides the following:
●
A brand new ABAP development experience on top of the Eclipse platform.
●
An open platform for developing new ABAP-related tools.
●
A set of open, language and platform-independent APIs that developers can use to build
new custom tools for the ABAP environment
Benefits of Eclipse
With ABAP Development Tools in Eclipse you benefit from the usability, speed, and flexibility
of Eclipse, while also benefiting from proven ABAP Workbench features.
ABAP Development Tools improves developer productivity by offering better refactoring
functionality, code completion, auto-insertion, and code templates. It also includes an
invaluable Quick Fix feature and is highly navigable.
ABAP Development Tools allows you to connect to multiple ABAP systems and provides
session failover, reducing the impact of lost connections. It also enables cross-platform
development by integrating ABAP and non-ABAP development tools in a single, powerful
integrated development environment (IDE).
Note:
In addition, ABAP Development Tools is tightly integrated with SAP HANA studio,
SAP UI5 tools, and Java.
The architecture of ABAP Development Tools for SAP NetWeaver is an architecture designed
for ease of use and flexibility. It is designed to allow developers to use a single Eclipse client,
installed locally, that connects to several ABAP back-end systems of different releases using a
Remote Function Call (RFC)/Representational State Transfer (REST)-based protocol.
This allows developers to control all activities in a central location and helps avoid timeconsuming context switches. The client provides a set of standard Eclipse development tools,
such as the project explorer for system browsing and search views.
When you use ABAP Development Tools, you log on to an SAP back-end system and work
directly with its repository objects. In this sense, the development process is exactly the same
as when you use the ABAP Workbench, in that there is no check-out and check-in of the
objects. Each connection that you make is represented in Eclipse by an ABAP project.
An ABAP project serves as the container for the development objects that are stored in the
particular ABAP back-end system containing the logon parameters for a particular system
logon, such as the following:
●
System
●
Client
●
User and language
You must be logged on to the system in order to edit a particular resource. Within the project,
you can access any development object in the repository. However, to make it easier to
manage the objects you use regularly, you can set up favorite packages for each project.
Within the project, there is a navigation view similar to the one in the ABAP Workbench. The
source library contains not only programs, but also classes, interfaces, and function modules,
which you edit in a source code editor rather than in the traditional form-based mode.
36
© Copyright. All rights reserved.
Lesson: Introducing the ABAP Development Tools (ADT)
Note:
You can create multiple ABAP projects in Eclipse, each related to a different
system.
Figure 38: ABAP Development Tools – Editors
There are two kinds of editors in ABAP Development Tools – those for which there is a native
Eclipse implementation and those that appear in-place in the SAP GUI. The figure, ABAP
Development Tools – Editors, shows each kind – the ABAP Editor as an example of an Eclipse
editor and the ABAP Dictionary showing how the classic SAP GUI visualization appears within
the Eclipse environment.
Generally speaking, there is no requirement to use ABAP Development Tools for ABAP
development, and each developer is free to choose whether to use ABAP Development Tools
or the classic ABAP Workbench. The functions and features of Eclipse in general and ABAP
Development Tools in particular lend themselves particularly well to object-oriented
programming, with various built-in refactoring functions and support for unit testing. There
are other tasks to which the ABAP Workbench is better suited, in particular working with
module pools and the Screen Painter.
Some new functions, however, are only provided within ABAP Development Tools, and do not
have an equivalent function in the ABAP Workbench. Several of these pertain to ABAP
development for SAP HANA.
© Copyright. All rights reserved.
37
Unit 1: Introduction
Working with ABAP Development Tools
Figure 39: ABAP Project
Editing ABAP Code
Figure 40: Editing Source Code
The source code editor in ABAP Development Tools provides many helpful features, such as
the following:
●
38
Code completion, which includes keyword completion, using code templates for
completion and Content Assist to suggest completions for variable names, method names,
and so on, while typing.
© Copyright. All rights reserved.
Lesson: Introducing the ABAP Development Tools (ADT)
●
Quick Fix, which allows you to quickly resolve errors or warnings reported about the code.
There are many quick fixes available for ABAP, such as the following:
-
Creating method implementations from the method definition.
-
Creating method definitions from implementation parts.
-
Creating implementation parts for interface methods.
-
Creating method definitions from method calls.
-
Creating ABAP classes or ABAP interfaces from the source code.
For a complete list, check the documentation.
Figure 41: ABAP Development Tools Quick Reference Card
ABAP Development Tools provides a large number of keyboard shortcuts that can make you
more productive. You can download a quick reference card with the most important shortcuts
from the following SCN page: https://blogs.sap.com/2012/07/02/adt-quick-referencecard/.
Examples of keyboard shortcuts ABAP developers new to ABAP Development Tools often do
not find quickly are as follows:
●
●
●
Shift + F1 to format the source code, that is, use the Pretty Printer.
Ctrl + < and Ctrl + > to turn a line of code into a comment or to remove a comment, or Ctrl
+ 7 to toggle between commenting/de-commenting a line.
F3 to navigate to the definition of the currently selected object (forward navigation).
Selecting the Ctrl key while positioning the mouse over an object, such as a class or
method name, adds a link and allows you to navigate to the definition or implementation of
the object.
© Copyright. All rights reserved.
39
Unit 1: Introduction
Debugging ABAP Code
Figure 42: Troubleshooting Tools – ABAP Debugger in Eclipse
The latest ABAP Debugger is completely integrated into the Eclipse debug framework.
Although it is an ABAP debugger, it behaves like all other debuggers in Eclipse you might be
familiar with because the look, feel, and functionality are all Eclipse. In other words, you can
now debug your reports, transactions, classes, Web Dynpro applications, and so on, natively
in Eclipse.
The ABAP Debugger in the ABAP Development Tools can satisfy most of your debugging
requirements. For special purposes – other than observing running code – you may still want
to use the new ABAP Debugger in the SAP GUI.
Note:
The Run → Debug menu function in Eclipse is not enabled in the ABAP
perspective.
You start the debugger by setting a breakpoint in your code and then running the ABAP
program. You can start it directly with F8.
The debugger offers, among other features, editing in the debugger. You can correct a bug
when you find it. Debugging in the IDE is not supported if you are working with a 7.0 EHP3
back-end system. For more information, find the latest information on the SAP Service
Marketplace.
40
© Copyright. All rights reserved.
Lesson: Introducing the ABAP Development Tools (ADT)
Information Sources
Figure 43: Information Sources
If you want to get a local installation of the SAP Development Tools for Eclipse, there are
several sources you can choose from, such as the following:
●
●
The SAP Software Download Center: https://support.sap.com/en/my-support/softwaredownloads.html, part of the SAP Support Portal.
The SAP Development Tools for Eclipse Web site: http://tools.hana.ondemand.com
You can also find other products like the SAP HANA studio or the tools for SAP UI5
development via this site. It describes how to install or update the SAP Development Tools for
Eclipse using the SAP Development Tools for Eclipse update Web site.
Hint:
For more information, see the following SAP Community Network page: https://
www.sap.com/community/topic/abap.html and documentation and support on
how to install the SAP Development Tools for Eclipse.
LESSON SUMMARY
You should now be able to:
●
Work with ABAP Development Tools
© Copyright. All rights reserved.
41
Unit 1: Introduction
42
© Copyright. All rights reserved.
Unit 1
Learning Assessment
1. Which of the following SAP HANA-based scenarios involve ABAP applications?
Choose the correct answers.
X
A Data marts based on SAP HANA.
X
B AS ABAP with SAP HANA as primary database.
X
C Native SAP HANA applications.
X
D SAP HANA as Business Accelerator.
2. On SAP HANA, tables are stored in row store by default.
Determine whether this statement is true or false.
X
True
X
False
3. Which of the following entries are required when creating a system in the SAP HANA
Studio?
Choose the correct answers.
X
A Host name
X
B Instance number
X
C Client ID
X
D User name
X
E Logon Language
© Copyright. All rights reserved.
43
Unit 1: Learning Assessment
4. Which of the following entities can be found under the Catalog node, and not under the
Content node?
Choose the correct answers.
X
A Package
X
B Schema
X
C Table
X
D Calculation View
5. It is not possible to create secondary indexes on SAP HANA.
Determine whether this statement is true or false.
X
True
X
False
6. Which of the following new repository objects belong to the so-called “Top-Down
Approach” for Code-to-Data?
Choose the correct answers.
44
X
A External view
X
B CDS view
X
C Database procedure proxy
X
D ABAP-managed database procedure
© Copyright. All rights reserved.
Unit 1
Learning Assessment - Answers
1. Which of the following SAP HANA-based scenarios involve ABAP applications?
Choose the correct answers.
X
A Data marts based on SAP HANA.
X
B AS ABAP with SAP HANA as primary database.
X
C Native SAP HANA applications.
X
D SAP HANA as Business Accelerator.
Correct. AS ABAP with SAP HANA as primary database and SAP HANA as Business
Accelerator involve ABAP applications.
2. On SAP HANA, tables are stored in row store by default.
Determine whether this statement is true or false.
X
True
X
False
Correct. On SAP HANA, tables are stored in column store by default.
3. Which of the following entries are required when creating a system in the SAP HANA
Studio?
Choose the correct answers.
X
A Host name
X
B Instance number
X
C Client ID
X
D User name
X
E Logon Language
Correct. When creating a system in the SAP HANA Studio, host name, instance number,
user name, and logon language are required.
© Copyright. All rights reserved.
45
Unit 1: Learning Assessment - Answers
4. Which of the following entities can be found under the Catalog node, and not under the
Content node?
Choose the correct answers.
X
A Package
X
B Schema
X
C Table
X
D Calculation View
Correct. Schema and Table can be found under the Catalog node, and not under the
Content node.
5. It is not possible to create secondary indexes on SAP HANA.
Determine whether this statement is true or false.
X
True
X
False
Correct. It is possible to create secondary indexes on SAP HANA.
6. Which of the following new repository objects belong to the so-called “Top-Down
Approach” for Code-to-Data?
Choose the correct answers.
X
A External view
X
B CDS view
X
C Database procedure proxy
X
D ABAP-managed database procedure
Correct. The CDS view and ABAP-managed database procedure repository objects belong
to the so-called “Top-Down Approach” for Code-to-Data.
46
© Copyright. All rights reserved.
UNIT 2
Taking ABAP to SAP HANA
Lesson 1
SAP HANA as Secondary Database– Access via Open SQL
49
Lesson 2
Code Checks to Prepare ABAP Code for SAP HANA
53
Lesson 3
Tools to Analyse Potential Performance Issues
61
Lesson 4
Guided Performance Analysis
67
Lesson 5
SQL Performance Rules for SAP HANA
73
UNIT OBJECTIVES
●
Access a secondary database via Open SQL
●
Use Code Inspector and ABAP Test Cockpit
●
Understand the Runtime Check Monitor
●
Understand the reason for potential performance issues
●
Use analysis tools to measure and compare runtime consumption
●
Search for potential performance issues with Code Inspector and ABAP Test Cockpit
●
Use SQL Trace (ST05) for in-depth analysis of database accesses
●
Understand the SQL Monitor (SQLM)
●
Use the SQL Performance Tuning Worklist (SWLT)
●
Know the performance rules and guidelines for SAP HANA
© Copyright. All rights reserved.
47
Unit 2: Taking ABAP to SAP HANA
48
© Copyright. All rights reserved.
Unit 2
Lesson 1
SAP HANA as Secondary Database– Access
via Open SQL
LESSON OVERVIEW
In this lesson, you learn how to access the SAP HANA database by using Open SQL and a
secondary database connection.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Access a secondary database via Open SQL
Secondary Database Connections
Each Application Server ABAP is connected to a database management system (DBMS) that
contains the ABAP Repository and the database tables and views defined in this system's
ABAP Dictionary. This DBMS is referred to as its primary database. Aside from this primary
database connection, it is possible to establish connections to additional database
management systems or secondary database connections. In the scenario, SAP HANA as
Accelerator, where SAP HANA is used as a secondary DBMS, it is necessary to establish such
a secondary database connection to SAP HANA.
Secondary database connections, among other things, are created and maintained via
transaction DBACOCKPIT. Each database connection is identified by a name that must be
unique within the application server.
© Copyright. All rights reserved.
49
Unit 2: Taking ABAP to SAP HANA
Figure 44: Transaction DBACOCKPIT
Figure 45: Database Connection Details
Inside the connection, the DBMS is identified by a hostname and an instance number, which
relates to an SQL port. Furthermore, a database user (with password) has to be maintained.
Any access to the database via this secondary database connection is equivalent to a log on
to the database with this user.
50
© Copyright. All rights reserved.
Lesson: SAP HANA as Secondary Database– Access via Open SQL
Access to a Secondary Database with Open SQL
Once the secondary database connection is established, it is easy to use it in ABAP programs.
Open SQL offers an additional CONNECTION, which has to be followed by the name of the
secondary database connection.
Figure 46: Open SQL Using Secondary Database Connection
However, some restrictions apply when using Open SQL to access a secondary database.
Figure 47: Open SQL Over Secondary Database Connection – Restrictions
Due to the syntax check for Open SQL statements, the tables and fields the statement refers
to must exist in the ABAP Dictionary of the application server.
This implies that objects only known to SAP HANA (such as SAP HANA views or procedures)
are not accessible by Open SQL.
© Copyright. All rights reserved.
51
Unit 2: Taking ABAP to SAP HANA
Note:
We learn later in this course that in order to access these objects, either native
SQL has to be used or new objects have to be created in the ABAP Dictionary that
make the SAP HANA objects visible for the syntax check.
Finally, Open SQL access to a secondary database is restricted to the default schema of the
database user in the connection. Normally, the name of this schema is identical to the user
name.
LESSON SUMMARY
You should now be able to:
●
52
Access a secondary database via Open SQL
© Copyright. All rights reserved.
Unit 2
Lesson 2
Code Checks to Prepare ABAP Code for SAP
HANA
LESSON OVERVIEW
This lesson introduces some tools to analyze potential functional and performance issues in
ABAP programs when migrating to SAP HANA.
Business Example
You want to run existing ABAP code on SAP HANA. You heard of functional issues and
performance problems that might occur. You want to analyze whether this is the case and
what you can do to make your coding SAP HANA-ready.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Use Code Inspector and ABAP Test Cockpit
●
Understand the Runtime Check Monitor
Considerations Before Migrating to SAP HANA
ABAP Developer’s Questions: SAP HANA Impact on Custom ABAP Code
●
●
●
●
Which of my ABAP code must be changed to avoid potential functional issues when
migrating to SAP HANA?
Which of my ABAP code shall be optimized to ensure good performance?
Which of my main business processes have potential for SAP HANA so that I can speed
those up massively?
How can I find all this ABAP code easily and do the adaption efficiently?
Most likely, you use SAP HANA because you want to improve the performance of your ABAP
applications. If you consider fully migrating to SAP HANA, you may also ask how to prepare
your ABAP code to avoid functional issues after the migration, and to what extent you have to
rewrite ABAP code.
SAP tools and guidelines help with these issues, and enable you to get your custom code
ready and optimized for SAP HANA.
For more information about the details, see OSS note 1785057.
© Copyright. All rights reserved.
53
Unit 2: Taking ABAP to SAP HANA
Potential Functional Issues
Figure 48: Potential Functional Issues: Native SQL and DB Hints
Standard ABAP code is fully portable between different database types. However, it is also
possible to use database-specific features explicitly or implicitly. In such situations, the code
has to be revisited when migrating to SAP HANA.
Some concrete scenarios are as follows:
●
●
54
If ABAP code uses native SQL (for example, via EXEC SQL), this code must be checked
and adapted.
A second example are hints to the database, respectively the database interface. These
enable optimization of query execution for specific databases. In the example shown in the
figure, Potential Functional Issues: Native SQL and DB Hints, a specific behavior for
treating the SELECT statement is defined for SAP Sybase ASE database. Such hints are
ignored after a database migration, for example, to SAP HANA. In general, it should be
checked if a hint is still needed for the target database. In almost all cases, the default
behavior of SAP HANA should be sufficient.
© Copyright. All rights reserved.
Lesson: Code Checks to Prepare ABAP Code for SAP HANA
Figure 49: Potential Functional Issues: Relying on Undocumented Behavior
There are more subtle scenarios. Although Open SQL is database-independent, it is possible
to rely on unspecified behavior or internals.
If for example an ABAP program accesses physical clusters and pools, or depends explicitly
on the existence of a particular secondary index. Such cases must be checked and most likely
adapted before or after migration.
More common – and more difficult to identify – are scenarios where an existing ABAP
program relies on the fact that some databases tend to return the result of a certain SELECT
statements in a given sort order (for example, by primary key or by a secondary key) although
the statement does not include an ORDER BY clause.
But this behavior is neither documented nor guaranteed, and SAP HANA, with its internal data
processing specialties such as, for example, parallel processing and partitioning, is much
more likely to return the data in an arbitrary order than other databases.
For example, subtle problems can occur when accessing such a SELECT result with a READ
TABLE statement, using a BINARY SEARCH addition assuming a sorted table.
In principle, the following options exist to tackle this problem:
1. Use the ORDER BY addition in the SELECT statement.
2. Use a sorted table in the INTO clause of the SELECT statement.
3. Explicitly sort the internal table using the SORT statement.
4. Use an internal table with a sorted secondary key.
Code Inspector and ABAP Test Cockpit
Before migrating to SAP HANA, a static code analysis should be performed to identify
functional issues and potential impairments of performance.
© Copyright. All rights reserved.
55
Unit 2: Taking ABAP to SAP HANA
Figure 50: ABAP Code Inspector
With the ABAP Code Inspector you can perform a whole range of static functional and
performance checks.
Of course, the ABAP Code Inspector has been in use long before SAP HANA and most of the
checks are not SAP HANA-specific. The rules and guidelines checked by them are also valid
for any database.
However, since SAP NetWeaver 7.40, SAP continuously extended the range of available
checks, and some of the new checks are particularly important with regard to SAP HANA
(although they are valid for other databases, too). Many of these checks have been
downported into lower releases.
Code Inspector Checks to Search for Potential Functional Issues
Critical Statements
Search for DB hints and native SQL (EXEC SQL ... ENDEXEC).
Use of ADBC Interface
Search for native SQL that is sent to the DB via the ADBC framework (see later in this
course).
Search DB Operations in Pool/Cluster Tables
Search for direct accesses to table pools and table clusters.
Search problematic statements for result of SELECT/OpenCursor without ORDER BY
Search for statements that rely on implicit sorting of SELECT results.
Find ABAP Statement Pattern
Search for an arbitrary pattern; use it with search string “CALL FUNCTION
'DB_EXISTS_INDEX' *”to find static usage of function module DB_EXISTS_INDEX.
56
© Copyright. All rights reserved.
Lesson: Code Checks to Prepare ABAP Code for SAP HANA
All these checks have documentation available describing how the check works, and the
meaning of the check parameters that can be maintained.
Note:
In order to support customers during database migration, SAP shipped global
check variant FUNCTIONAL_DB that contains the checks listed above.
Inspection Results
The figure, Code Inspector – Inspection Results, shows an example of the inspection result,
where two of the new checks have resulted in an error message. Remember, you can doubleclick the message to navigate to the problem code.
Figure 51: Code Inspector – Inspection Results
Code Inspector As a Part of ABAP Test Cockpit (ATC)
Figure 52: ABAP Test Cockpit
© Copyright. All rights reserved.
57
Unit 2: Taking ABAP to SAP HANA
With ABAP 7.02, ABAP Test Cockpit (ATC) was introduced as a holistic quality assurance
tool. The ATC integrates the Code Inspector, including the configuration of Code Inspector
check variants. Compared to the stand-alone Code Inspector, ATC offers the following
additional functions:
●
Flexible scheduling of check runs.
●
Distribution of results.
●
General support for quality management processes.
ATC is available in SAP GUI (transaction code ATC) but it is also integrated into ABAP
Development Tools and into SAP Solution Manager.
Runtime Check Monitor
Figure 53: Runtime Check Monitor - Setup
You cannot expect to detect all functional issues by static code checks. If, for example, your
code uses dynamic programming techniques, not all the details are visible to the code check
and it depends on the program behavior at runtime whether there is an issue or not.
The Runtime Check Monitor allows you to execute a limited range of runtime checks. In each
specific check, you can collect runtime-relevant information during program execution. In
addition, you will be provided with specialized views for data analysis.
You can use these specific runtime checks to perform a final, remaining cleanup of the ABAP
code - for example, following the corresponding static code checks.
Currently, two individual runtime checks are available:
Empty table in FOR ALL ENTRIES clause
58
© Copyright. All rights reserved.
Lesson: Code Checks to Prepare ABAP Code for SAP HANA
This check records all events where the internal table itab in the clause ...FOR ALL
ENTRIES IN itab... within the SELECT statement is empty.
Missing ORDER BY or SORT after SELECT
This check records every SELECT in an unsorted internal table without the clause ORDER
BY or subsequent SORT and followed - either immediately or later on - by a statement
that assumes the internal table to be sorted.
Using transaction SRTCM, you can activate each of these checks individually - either on a
specific server or globally.
The Runtime Check framework is designed in a way that it has minimum impact on the overall
system performance. This allows for switching it on in productive systems, too.
Figure 54: Runtime Check Monitor -Result Display
To display Runtime Check results, you can either use the respective button in transaction
SRTCM or launch transaction SRTCMD, directly.
Note:
To minimize the effect on overall performance, runtime check results are not
persisted at real time. You have to schedule executable program
RTM_COLLECT_ALL (or execute it manually) before you can analyze the check
results.
LESSON SUMMARY
You should now be able to:
●
Use Code Inspector and ABAP Test Cockpit
© Copyright. All rights reserved.
59
Unit 2: Taking ABAP to SAP HANA
●
60
Understand the Runtime Check Monitor
© Copyright. All rights reserved.
Unit 2
Lesson 3
Tools to Analyse Potential Performance Issues
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Understand the reason for potential performance issues
●
Use analysis tools to measure and compare runtime consumption
●
Search for potential performance issues with Code Inspector and ABAP Test Cockpit
●
Use SQL Trace (ST05) for in-depth analysis of database accesses
Performance Considerations when Migrating to SAP HANA
Besides the functional issues we already discussed, you have to keep an eye on the runtime of
your ABAP programs. The new database will have a noticeable effect on the performance of
existing ABAP code.
Performance of Existing ABAP Code After a Migration
●
Some code immediately runs faster.
●
Some code might be negatively impacted and should be revisited.
It can be hoped that some code immediately runs faster on SAP HANA. This is particularly
true for coding that follows the classical ABAP performance recommendations.
However, there can also be situations in which existing code is negatively impacted. In most of
these cases the classical performance recommendations were not taken into account.
Note:
In general, well-written ABAP code has a good chance of experiencing
performance improvements on SAP HANA.
Runtime Analysis
Before starting to optimize ABAP code detected with Code Inspector or ABAP Test Cockpit,
you may have to perform a detailed runtime analysis to better understand the origin of the
performance issue.
© Copyright. All rights reserved.
61
Unit 2: Taking ABAP to SAP HANA
Runtime Analysis in the ABAP Workbench
Figure 55: Runtime Analysis: ABAP Trace
One of the tools to perform such a runtime analysis in the classical SAP GUI is the ABAP trace
(transaction code SAT), which replaces the older ABAP runtime analysis (SE30).
ABAP runtime analysis and ABAP trace have the following characteristics:
●
●
●
62
The functions of the classic ABAP runtime analysis (SE30) and the new ABAP trace (SAT)
can be completely used in the SAP HANA context.
Both tools measure runtime of processing blocks (methods, functions, and subroutines)
or single statements.
No database-specific functions are available.
© Copyright. All rights reserved.
Lesson: Tools to Analyse Potential Performance Issues
Runtime Analysis in ABAP Development Tools
Figure 56: Runtime Analysis: ABAP Profiling Perspective in ABAP Development Tools
When using the ABAP Development Tools in Eclipse, an alternative to using the SAP GUIbased ABAP trace is to use a dedicated perspective in ABAP Development Tools, called the
ABAP Profiling perspective. With this perspective, you can also create ABAP traces. The trace
files are the same as those created using the ABAP trace, which means that a trace created
using any of the two tools can also be analyzed in the other tool.
Depending on which configuration is used to generate a trace, the ABAP Profiling perspective
provides different views, including the following:
●
An overview that shows, for example, which percentage of the execution time was spent in
ABAP, and which percentage on the database.
●
A hit list of the most time-consuming programs or methods.
●
Database accesses.
●
An ABAP trace call tree view to analyze the execution path of a program. You can use the
call tree to do the following:
-
-
●
Analyze the flow of a program as part of the analysis of an error. You can see which
ABAP programs are involved in the error and easily find useful places to set
breakpoints.
Understand how an unfamiliar program works and which ABAP programs play a role in
its execution.
A Call Timeline view, which visualizes the trace events and time consumed in the form of a
diagram. In general, information shown in this graphical view corresponds to the one in the
Call Tree view. The horizontal axis of the diagram displays the temporal sequence of each
trace event measured, whereas the vertical axis represents the call depth within a call
hierarchy. In contrast to the Call Tree, the trace events are represented not as discrete
© Copyright. All rights reserved.
63
Unit 2: Taking ABAP to SAP HANA
tree nodes, but as a continuous sequence. The advantage lies in the graphical
representation and a quick detection of eye-catching patterns.
Call Tree and Call Timeline are only shown if the call tree was created when tracing (no
aggregated measurement).
Performance Checks in Code Inspector and ABAP Test Cockpit
When migrating to SAP HANA database, Code Inspector can not only help you to identify
functional issues. It also offers a large variety of checks that search for patterns that are
known to cause performance problems. The following checks are particularly important for
SAP HANA migration:
Code Inspector Checks to Search for Potential Performance Issues
Search problematic SELECT * statements
Search for SELECT * statements where less than a certain percentage of the fields are
used later on.
Search DB operations in loops across modularization units
Search for repeated identical selects.
Search SELECT ... FOR ALL ENTRIES-clauses to be transformed
Search for SELECT statements with FOR ALL ENTRIES that can be replaced by a SELECT
statement with a join.
The checks listed above were developed and shipped in SAP NetWeaver AS ABAP 7.40 to
improve the support for SAP HANA database migration.
Note:
In order to support customers during database migration, SAP shipped global
check variant PERFORMANCE_DB. This check variant contains the checks listed
above, some other performance checks and a search function that provides
statistics of database accesses.
In-Depth Analysis of Performance Issues
Before starting to optimize ABAP code detected with Code Inspector or ABAP Test Cockpit,
you may have to perform a detailed SQL analysis to better understand the origin of the
performance issue.
64
© Copyright. All rights reserved.
Lesson: Tools to Analyse Potential Performance Issues
Figure 57: Runtime Analysis: SQL Trace
Uses of SQL Trace (ST05)
●
Display record of all database access (including SQL calls over a secondary database
connection).
●
Detect redundant or identical SELECT statements.
●
Locate database-related performance issues.
●
Display database execution plan for statements.
Another tool for runtime performance analysis is the SQL Trace (transaction ST05). This tool
in particular analyses database accesses. It can be used for a deeper analysis once an
analysis with the ABAP trace or the ABAP Profiling perspective indicates that database
access could be the cause of the performance issues.
Figure 58: Performance Trace
© Copyright. All rights reserved.
65
Unit 2: Taking ABAP to SAP HANA
Figure 59: Execution Plan
Hint:
Note that the Explain function in the SQL Trace is database-specific. Hence, a
database execution plan looks different for each database platform supported by
SAP.
LESSON SUMMARY
You should now be able to:
66
●
Understand the reason for potential performance issues
●
Use analysis tools to measure and compare runtime consumption
●
Search for potential performance issues with Code Inspector and ABAP Test Cockpit
●
Use SQL Trace (ST05) for in-depth analysis of database accesses
© Copyright. All rights reserved.
Unit 2
Lesson 4
Guided Performance Analysis
LESSON OVERVIEW
In this lesson, you learn how to use the SQL Monitor (SQLM) to identify the most important
database access, use the Performance Tuning Worklist (SWLT) to combine static and dynamic
performance analysis results, and use SQL Trace (ST05) for in-depth analysis of database
accesses.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Understand the SQL Monitor (SQLM)
●
Use the SQL Performance Tuning Worklist (SWLT)
Guided Performance Optimization When Migrating to SAP HANA
Figure 60: Steps of the Guided Performance Optimization
The first two steps are supported by several tools, which in total result in a guided
performance optimization procedure, as follows:
●
Static code check tools such as Code Inspector and ABAP Test Cockpit (ATC) to find
pieces of code using known critical constructs, such as deviations from the classical
performance recommendations.
© Copyright. All rights reserved.
67
Unit 2: Taking ABAP to SAP HANA
●
●
●
Tools analyzing performance at runtime, to determine if critical constructs really cause
issues at runtime, for example, the ABAP Trace.
A new tool called SQL Monitor to determine the priority if different programs access the
database intensively.
A new tool called SQL Performance Tuning Worklist, which combines the results of static
and runtime analyses to create a prioritized worklist.
SQL Monitor (SQLM)
Figure 61: New ABAP SQL Monitor
The new SQL Monitor is a powerful tool for capturing the SQL profile of a system or
transaction. SQL profile refers to aggregated data about all SQL requests executed in the
context of a certain business process, application, and so on. This includes how often each
request is executed, which tables are accessed, the total runtime, how many records are
fetched, and more.
The SQL Monitor is a new development with ABAP 7.4. However, in order to support its use
before a migration, it is also offered as part of the so-called ST-PI support Add-On provided by
SAP Active Global Support.
68
© Copyright. All rights reserved.
Lesson: Guided Performance Analysis
Figure 62: The New ABAP SQL Monitor – Architecture
A central design goal was to ensure that the SQL Monitor can run in the productive
environment because this is where the real SQL profile of an application can be observed. The
SQL Monitor introduces only a minimal performance overhead and all data collection is done
asynchronously without additional database interaction affecting the runtime of the actual
business processes.
When the SQL Monitor is enabled, the ABAP kernel logs information about database accesses
(for example, transaction, source code position, accessed tables, and so on) using the
runtime monitor infrastructure (file-based). This data is transferred periodically to the SQL
Monitor database tables (every 24 hours, with manual refresh possible). The transfer is
required for data analysis and to store the results permanently.
The SQL Monitor provides a dedicated transaction for displaying and analyzing the data,
which in turn reads from the respective database tables containing the collected data.
© Copyright. All rights reserved.
69
Unit 2: Taking ABAP to SAP HANA
Figure 63: Switching the SQL Monitor On and Viewing SQL Monitor Data
After the initial setup of the SQL Monitor, you can activate or deactivate the monitor via
transaction SQLM. When you launch it, it displays the current status. You can activate it for all
application servers or for specific application servers. You can also specify an expiration date
and an upper limit for the number of records.
After data has been collected, you can view the collected SQL profile either by navigating from
transaction SQLM or by launching transaction SQLMD.
You can specify a number of filter criteria. For instance, you can filter by development objects,
such as package, object type, and name, or by request (transaction VA01, Web Dynpro
Application <ABC>), and the respective request type (for example, URL, RFC, report). You
can also define a filter for looking into accesses to concrete database tables.
You can select a certain aggregation type and a sorting of the result list.
Figure 64: Exporting and Importing SQL Monitor Snapshots
70
© Copyright. All rights reserved.
Lesson: Guided Performance Analysis
Exporting and Importing SQL Monitor Snapshots
Transaction SQLM offers a simple management of SQL Monitor snapshots.
●
●
●
Snapshots can be as follows:
-
Created based on local data
-
Imported from a file (for example, from other systems)
-
Exported to a file
-
Removed
To reduce data volume, basic filter criteria can be applied before snapshot creation.
As the SQL Monitor should collect data in a productive system, and the code optimizations
are usually planned in another system, such as a development system or sandbox
environment, it is desirable to be able to export and import the collected data. The SQL
Monitor supports exporting and importing snapshot data for this purpose. These tasks can
also be performed using the SQLM transaction.
Note that the exported data can also be analyzed via other tools, such as a SAP Lumira,
allowing visualizations and more complex analytical operations.
Performance Tuning Worklist (SQLT)
Figure 65: SQL Performance Tuning Worklist – Motivation
For performance optimization, combine the results of both static source code analysis
(carried out via the ATP or Code Inspector) and the SQL Monitor runtime data.
This correlation can be done in another new tool, the SQL Performance Tuning Worklist. This
tools can be used to create a ranking based on the cost and benefit of a potential
optimization.
© Copyright. All rights reserved.
71
Unit 2: Taking ABAP to SAP HANA
Figure 66: SQL Performance Tuning Worklist – Usage
LESSON SUMMARY
You should now be able to:
72
●
Understand the SQL Monitor (SQLM)
●
Use the SQL Performance Tuning Worklist (SWLT)
© Copyright. All rights reserved.
Unit 2
Lesson 5
SQL Performance Rules for SAP HANA
LESSON OVERVIEW
In this lesson, you learn about the performance rules and guidelines for ABAP on SAP HANA.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Know the performance rules and guidelines for SAP HANA
Performance Guidelines for ABAP on SAP HANA
The classic performance guidelines for using Open SQL and for ABAP programming
essentially remain valid. These guidelines can be called the five golden rules.
Figure 67: Golden Rules for Open SQL
The five golden rules are as follows:
Keep the result set small
This reduces both the amount of memory used in the database system and the network
load when transferring data to the application server. To reduce the size of your result
© Copyright. All rights reserved.
73
Unit 2: Taking ABAP to SAP HANA
sets, use the WHERE and HAVING clauses. Do not retrieve rows and discard them later
using CHECK or EXIT statements, for example, in loops.
Minimize the amount of data transferred
To only transfer the columns you really need, use SELECT with a field list, instead of
SELECT *.
Minimize the number of database accesses
On all database systems, there is a small performance overhead associated with every
request for connection handling, SQL parsing, execution plan determination, and so on.
Avoiding such frequent single database requests is more important on SAP HANA. You
can, therefore, minimize the load on the network and the database system by minimizing
the number of times you access the database. Use JOINs and/or sub-queries instead of
nested SELECT loops.
Minimize the search overhead
Minimize the size of the result set by using the WHERE and HAVING clauses. To increase
the efficiency of these clauses, formulate them to fit with the database table indexes.
Reduce the database load
Unlike application servers and presentation servers, there is only one database server in
your system. Therefore, you should still aim to reduce the database load as much as
possible. Use the following methods: avoid reading data redundantly, use table buffering
(if applicable) and do not bypass it, and sort data in your ABAP programs.
Figure 68: Guidelines that Become More Important
Some guidelines become even more important with SAP HANA.
Minimize the amount of data transferred
With column store tables on SAP HANA, this rule is actually not only about data transfer
between database and application server. When reading from a column store table, the
more fields you use in the field list, the more columns that have to be loaded into CPU
cache and unpacked. This additional effort increases the importance of this rule.
Reduce the number of database accesses
On SAP HANA, the overhead for a single DB access is larger than on other databases.
Therefore it becomes more important to bundle your database accesses. Avoid nested
74
© Copyright. All rights reserved.
Lesson: SQL Performance Rules for SAP HANA
SELECTs and use array variants of INSERT, UPDATE, MODIFY, and DELETE wherever
possible.
Figure 69: Guidelines that are Changed
Some guidelines lose importance when SAP HANA is your database
Minimize the search overhead
A WHERE clause not containing indexed fields is not bad when executed on SAP HANA
because the in-memory full table scan is fast. Besides, fewer secondary indexes exist on
SAP HANA than on other databases. SAP removed most non-unique secondary database
indices on column-store tables to reduce main memory consumption and to improve
insert performance,.
Keep unnecessary load away from the DB
Calculations and aggregations on SAP HANA are very efficient. With SAP HANA it is
beneficial to move data-intensive calculations into the database. Therefore the new rule
is to push as many time consuming calculations to the database as possible.
Note:
Nevertheless, executing the same operations redundantly is not
recommended.
LESSON SUMMARY
You should now be able to:
●
Know the performance rules and guidelines for SAP HANA
© Copyright. All rights reserved.
75
Unit 2: Taking ABAP to SAP HANA
76
© Copyright. All rights reserved.
Unit 2
Learning Assessment
1. When using a secondary database connection, the default schema is derived from the
database user, which is stored in the secondary database connection.
Determine whether this statement is true or false.
X
True
X
False
2. Which of the following are potential functional issues when migrating ABAP code to SAP
HANA?
Choose the correct answers.
X
A Use of native SQL or DB Hints.
X
B Use of secondary database connections.
X
C Coding that assumes that a SELECT result is always sorted.
X
D The existence of customer-specific cluster tables.
X
E The existence of table appends.
3. Where do you define a set of Code Inspector checks that you want to perform?
Choose the correct answer.
X
A In a Code Inspector object list.
X
B In a Code Inspector object check variant.
X
C In a Code Inspector inspection.
4. When migrating to SAP HANA, every SELECT statement immediately becomes faster.
Determine whether this statement is true or false.
X
True
X
False
© Copyright. All rights reserved.
77
Unit 2: Learning Assessment
5. Because SAP HANA stores all data in memory, buffering of data on the application server
becomes less important.
Determine whether this statement is true or false.
X
True
X
False
6. Which of the following patterns are known to potentially cause performance issues when
accessing an SAP HANA database?
Choose the correct answers.
X
A Use of SELECT ... FOR ALL ENTRIES
X
B Use of joins with more than three tables
X
C Use of SELECT statements in loops
X
D Use of SELECT * for tables with many fields
7. Which of the following are steps in the recommended sequence for a guided performance
analysis?
Choose the correct answers.
X
A Do static code checks with Code Inspector or ABAP Test Cockpit.
X
B Collect runtime data with SQL Monitor.
X
C Collect runtime data with Runtime Analysis.
X
D Combine runtime data and static check result in SQL Performance Tuning Worklist
8. Which part of a guided performance analysis is done with the SQL Monitor tool?
Choose the correct answer.
X
A Collect runtime data in the productive system.
X
B Do static SQL checks in the productive system.
X
C Do static SQL checks in the development system.
X
D Combine runtime data and static check results.
9. Why are SQL Monitor measurements not immediately visible?
78
© Copyright. All rights reserved.
Unit 2: Learning Assessment
10. Which of the SQL performance rules become more important with SAP HANA?
Choose the correct answers.
X
A Keep the result set small.
X
B Minimize amount of transferred data.
X
C Minimize number of database accesses.
X
D Minimize search overhead.
X
E Keep unnecessary load away from the DB.
11. Which of the SQL performance rules become less important with SAP HANA?
Choose the correct answers.
X
A Keep the result set small.
X
B Minimize amount of transferred data.
X
C Minimize number of database accesses.
X
D Minimize search overhead.
X
E Keep unnecessary load away from the DB.
© Copyright. All rights reserved.
79
Unit 2
Learning Assessment - Answers
1. When using a secondary database connection, the default schema is derived from the
database user, which is stored in the secondary database connection.
Determine whether this statement is true or false.
X
True
X
False
Correct. When using a secondary database connection, the default schema is derived
from the database user, which is stored in the secondary database connection.
2. Which of the following are potential functional issues when migrating ABAP code to SAP
HANA?
Choose the correct answers.
X
A Use of native SQL or DB Hints.
X
B Use of secondary database connections.
X
C Coding that assumes that a SELECT result is always sorted.
X
D The existence of customer-specific cluster tables.
X
E The existence of table appends.
Correct. The use of native SQL or DB Hints and coding that assumes that a SELECT result
is always sorted are both potential functional issues when migrating ABAP code to SAP
HANA.
3. Where do you define a set of Code Inspector checks that you want to perform?
Choose the correct answer.
X
A In a Code Inspector object list.
X
B In a Code Inspector object check variant.
X
C In a Code Inspector inspection.
Correct. You define a set of Code Inspector checks that you want to perform in a Code
Inspector object check variant.
80
© Copyright. All rights reserved.
Unit 2: Learning Assessment - Answers
4. When migrating to SAP HANA, every SELECT statement immediately becomes faster.
Determine whether this statement is true or false.
X
True
X
False
Correct. When migrating to SAP HANA, every SELECT statement does not immediately
become faster.
5. Because SAP HANA stores all data in memory, buffering of data on the application server
becomes less important.
Determine whether this statement is true or false.
X
True
X
False
Correct. SAP HANA stores all data in memory, but buffering of data on the application
server does not become less important.
6. Which of the following patterns are known to potentially cause performance issues when
accessing an SAP HANA database?
Choose the correct answers.
X
A Use of SELECT ... FOR ALL ENTRIES
X
B Use of joins with more than three tables
X
C Use of SELECT statements in loops
X
D Use of SELECT * for tables with many fields
Correct. The use of SELECT ... FOR ALL ENTRIES, the use of SELECT statements in loops,
and the use of SELECT * for tables with many fields are all known to potentially cause
performance issues when accessing an SAP HANA database.
© Copyright. All rights reserved.
81
Unit 2: Learning Assessment - Answers
7. Which of the following are steps in the recommended sequence for a guided performance
analysis?
Choose the correct answers.
X
A Do static code checks with Code Inspector or ABAP Test Cockpit.
X
B Collect runtime data with SQL Monitor.
X
C Collect runtime data with Runtime Analysis.
X
D Combine runtime data and static check result in SQL Performance Tuning Worklist
Correct. The sequence for a guided performance analysis is 1) Do static code checks with
Code Inspector or ABAP Test Cockpit, 2) Collect runtime data with SQL Monitor, and 3)
Combine runtime data and static check result in SQL Performance Tuning Worklist.
8. Which part of a guided performance analysis is done with the SQL Monitor tool?
Choose the correct answer.
X
A Collect runtime data in the productive system.
X
B Do static SQL checks in the productive system.
X
C Do static SQL checks in the development system.
X
D Combine runtime data and static check results.
Correct. Collecting runtime data in the productive system is done with the SQL Monitor
tool.
9. Why are SQL Monitor measurements not immediately visible?
To minimize impact on overall system performance, the writing of measurements to the
database is done asynchronously.
Correct.
10. Which of the SQL performance rules become more important with SAP HANA?
Choose the correct answers.
X
A Keep the result set small.
X
B Minimize amount of transferred data.
X
C Minimize number of database accesses.
X
D Minimize search overhead.
X
E Keep unnecessary load away from the DB.
Correct. Minimizing the amount of transferred data and minimizing the number of
database accesses both become more important with SAP HANA.
82
© Copyright. All rights reserved.
Unit 2: Learning Assessment - Answers
11. Which of the SQL performance rules become less important with SAP HANA?
Choose the correct answers.
X
A Keep the result set small.
X
B Minimize amount of transferred data.
X
C Minimize number of database accesses.
X
D Minimize search overhead.
X
E Keep unnecessary load away from the DB.
Correct. Minimizing the search overhead and keeping unnecessary load away from the DB
both become less important with SAP HANA.
© Copyright. All rights reserved.
83
Unit 2: Learning Assessment - Answers
84
© Copyright. All rights reserved.
UNIT 3
Database Independent Code-toData
Lesson 1
Classical Open SQL and Its Limitations
87
Lesson 2
Enhanced Open SQL
91
Lesson 3
The Basics of Core Data Services in ABAP
97
Lesson 4
Associations in Core Data Services
109
Lesson 5
Outlook: More Interesting Features of CDS
115
UNIT OBJECTIVES
●
Know the limitations of classical Open SQL
●
Describe the motivation for enhanced Open SQL
●
Use the new syntax of Open SQL
●
Use new features of Open SQL in SELECT statements
●
Describe the concept of ABAP Core Data Services
●
Use expressions, joins, aggregations, grouping and filtering in CDS views
●
Use Open SQL to select data based on CDS views
●
Use CDS views with associations
●
Explain CDS view extensions
●
Define and use CDS views with input parameters
●
Explain authorization checks with CDS
© Copyright. All rights reserved.
85
Unit 3: Database Independent Code-to-Data
86
© Copyright. All rights reserved.
Unit 3
Lesson 1
Classical Open SQL and Its Limitations
LESSON OVERVIEW
In this lesson you learn about the limitations of classical Open SQL and why it can only be
used to a limited extent to follow the code-to-data paradigm and benefit from the potential of
SAP HANA.
Business Example
Your company ITeLO wants you to improve the performance of some ABAP applications
considerably by making use of SAP HANA, installed as a secondary database side-by-side
with the ABAP system.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Know the limitations of classical Open SQL
Standard SQL
Structured Query Language (SQL) is a language for accessing a database management
system. Although it is largely standardized (for example, as ANSI SQL), each vendor adds its
own features. The language can be divided into three parts, as follows:
Standard SQL – Much More Than Open SQL
Structured Query Language (SQL)
●
Largely standardized.
●
Three sub-languages.
Data Manipulation Language (DML)
●
Statements for reading and changing data in database tables.
●
Examples include SELECT, INSERT, UPDATE, DELETE.
Data Definition Language (DDL)
●
Statements for creating and administering database tables.
●
Examples include CREATE, ALTER, DROP.
Data Control Language (DCL)
●
Statements for authorization and transaction control.
●
Examples include GRANT, REVOKE, COMMIT, ROLLBACK.
© Copyright. All rights reserved.
87
Unit 3: Database Independent Code-to-Data
Database Integration in AS ABAP
The SQL variant known to ABAP programmers is called Open SQL. This Open SQL covers only
a small fraction of the SQL language. In fact, it only covers a small part of the DML sublanguage.
SQL in ABAP (Before 7.40 SP05)
Open SQL
●
Database independent syntax.
●
Database independent semantics (= same result).
●
Covers only a small part of standard DML.
●
No DDL or DCL statements.
ABAP Dictionary
●
Database independent tool (mostly graphical).
●
Create and maintain definitions of database objects (tables, views).
●
Covers only a small part of standard DDL features.
And DCL?
●
No access control on DB level. In ABAP systems, the DB only knows one user.
●
No transaction control on DB level. DB commit after each dialogue step.
Open SQL, Native SQL and the Database Interface
Figure 70: Open SQL, Native SQL and the Database Interface
The database independence of Open SQL is ensured by the following two layers:
●
88
The database interface (DBI) provides a database independent interface and additional
services, such as automatic client handling or the ABAP table buffer.
© Copyright. All rights reserved.
Lesson: Classical Open SQL and Its Limitations
●
The database specific library (DBSL) connects to the respective database and translates
Open SQL statements into the respective native SQL dialect. When using the primary
database connection, the following occurs:
The ABAP system runs with a single database user (by default, SAP<SID> or SAPR3).
This user has many database privileges.
-
The ABAP system stores all data in the database schema corresponding to this user.
-
Figure 71: Example: Translation of Open SQL to Native SQL
Limitations of Classical Open SQL
One of the most important characteristics of Open SQL is its database independence. This is
not restricted to a database-independent syntax which is integrated into the ABAP language.
Open SQL is also semantically independent from the database that is used in a given ABAP
system.
The common syntax and semantics for all databases is only one reason why Open SQL covers
only a small part of standard DML functionality.
Another reason is the fact that “Keep unnecessary load from the database” has always been
one of the golden SQL performance rules of ABAP. One way of enforcing this rule had been
not to offer too many SQL features that would have allowed developers to push calculationintense logic down to the database.
Limitations of Classical Open SQL (before 7.40 SP05)
With respect to standard DML
●
No fixed-values and computed columns.
●
No CASE expression.
●
No right outer joins.
●
No UNIONs.
●
No sub-queries in SELECT or FROM clauses.
With respect to SAP HANA DML
© Copyright. All rights reserved.
89
Unit 3: Database Independent Code-to-Data
●
No access to SAP HANA built-in functions, for example, DAYS_BETWEEN( ).
●
No access to SAP HANA views and procedures.
LESSON SUMMARY
You should now be able to:
●
90
Know the limitations of classical Open SQL
© Copyright. All rights reserved.
Unit 3
Lesson 2
Enhanced Open SQL
LESSON OVERVIEW
In this lesson, you learn about the new features and possibilities with which SAP enhanced
Open SQL starting with ABAP 7.40 SP05. You will see how, step by step, classical Open SQL
overcomes its old limitations in order to better support the code-to-data approach.
Business Example
Your company ITeLO wants you to improve the performance of some ABAP applications
considerably by making use of SAP HANA, installed as a secondary database side-by-side
with the ABAP system.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Describe the motivation for enhanced Open SQL
●
Use the new syntax of Open SQL
●
Use new features of Open SQL in SELECT statements
Motivation for Enhanced Open SQL
Figure 72: What is Open SQL? Why Enhance It?
© Copyright. All rights reserved.
91
Unit 3: Database Independent Code-to-Data
ADBC and Native SQL can be used to get around the limitations of classic Open SQL.
However, working with Native SQL can be quite clumsy and prone to errors. Using Open SQL
would be more desirable in most cases.
Open SQL in the ABAP language is a database abstraction layer with an SQL-like syntax that
defines a common SQL semantics for all databases supported by SAP. It is not a simple
subset of SQL commands. The common semantics ensures that the result of an Open SQL
query is independent of the underlying database.
One of the reasons for using Native SQL was that the SQL-92 standard defines features that
were not previously available in Open SQL. For example, Open SQL lacked expressions and
had only limited JOIN types. ABAP developers may have wondered why SAP does not
minimize these limitations.
As of SAP NetWeaver 7.40 SP05, the scenarios in which Native SQL are necessary are
reduced, because Open SQL has been extended. These extensions are relevant regardless of
the database, but some of them are of particular importance when we think about the
performance guidelines for SAP HANA.
New Syntax of Open SQL
In order to be able to enhance the functional scope of Open SQL, SAP had to adjust the syntax
of Open SQL first.
Figure 73: New Open SQL Syntax in ABAP 7.40 SP05
The figure, New Open SQL Syntax in ABAP 7.40 SP05, illustrates the difference between old
and new syntax with an example. The first thing to notice is the comma-separated field list
after key word SELECT. This new syntax is a prerequisite to allow for more sophisticated
expressions in the SELECT clause.
Note:
With the new syntax, lists after additions ORDER BY and GROUP BY become
comma-separated too.
The second difference is the “@” symbol for escaping so-called host variables. The ABAP
language is considered the host of the embedded Open SQL, so host variable means ABAP
92
© Copyright. All rights reserved.
Lesson: Enhanced Open SQL
variable or constant inside the Open SQL statement. Every host variable except literals must
be escaped with a preceding “@” sign at every position in the statement.
Note:
Classical Open SQL syntax is still valid for “old” statements, that is, statements
that only use features that existed before release 7.40 SP05. As soon as a
statement uses a single new feature, the new syntax becomes mandatory.
It is not possible to mix old and new syntax in the same Open SQL statement.
Figure 74: New Open SQL Syntax in ABAP 7.50
With ABAP 7.50, a different order of some of the clauses of Open SQL statements is
supported.
The INTO clause no longer has to precede the WHERE clause, but can follow it. Additions such
as UP TO ... ROWS still have to follow the INTO clause.
The FROM clause can now be the first, followed by the column list starting with the explicit
keyword FIELDS. This does not only increase the readability and supportability of SELECT
statements, but also enables code completion in the ABAP Development Tools (ADT).
© Copyright. All rights reserved.
93
Unit 3: Database Independent Code-to-Data
New Features of Open SQL
Figure 75: New Features in Open SQL
As of release 7.40 SP05, Open SQL supports the use of arithmetic and string expressions, as
well as the CASE conditional expressions shown in the example.
A key point in the introduction of arithmetic expressions in Open SQL is their common
semantics. For example, the SQL standard does not specify the overflow behavior when
adding two integers or two P-type variables. This had to be accomplished in the definition of
the Open SQL semantics for such an operation.
Therefore, not all arithmetic expressions are available for all types of variables. Basic features
like ADDITION, SUBTRACTION, MULTIPLICATION, or the calculation of the absolute value
(ABS) are available for I-types and P-types with and without decimals. The MOD function is
only available for I- and P-types without decimals and FLOOR and CEIL can be used for all Ptypes with decimals (even mixed with I- and P-types without decimals).
In addition to arithmetic expressions, Open SQL now also features string expressions, and
string concatenation using the && operator.
94
© Copyright. All rights reserved.
Lesson: Enhanced Open SQL
Figure 76: Further Limitations Removed
RIGHT OUTER JOIN is now available in Open SQL. In addition, the limited support for using
brackets in JOIN expressions with more than two tables has been enhanced. Previously, the
JOIN had to be performed left-to-right, that is, the left-most tables always had to be joined
first. This limitation no longer applies.
New functionality with regard to the ON conditions of JOIN expressions is now also possible,
for example, as follows:
●
●
●
●
The previous restriction that a field of the right table is present in the ON condition has
been dropped.
Operators like BETWEEN or “greater than” or “less than” can be used in the ON condition
now.
Fields of the right table can also be used in the WHERE clause of a LEFT OUTER JOIN
statement.
Client handling in JOINs has been improved: if both sides of a JOIN are client-dependent,
the ON condition is enhanced automatically with a filter on equal clients. Additionally, the
client dependency is propagated to the top of the JOIN tree and applied in the WHERE
clause of the query statement. There is no need to contend with client fields in JOINs any
longer.
Apart from these new features, the following restrictions have been removed:
●
●
The maximum number of tables supported in Open SQL JOIN clauses has been increased
to fifty.
The maximum number of sub-queries supported in an Open SQL statement has been
increased from nine to fifty.
As usual, further details of the new features can be found on help.sap.com and in the ABAP
Keyword documentation in an SAP NetWeaver 7.40 SP05 system.
© Copyright. All rights reserved.
95
Unit 3: Database Independent Code-to-Data
Figure 77: New in Open SQL in ABAP 7.5: UNION / UNION ALL
The syntax option to place the INTO clause at the end of the SELECT statement enables
support for forming the union of Open SQL SELECT statement results using UNION or UNION
ALL, as with ANSI SQL. Note that the SELECT statements comprised in the UNION [ALL]
must use explicit column lists, as an asterisk * is not supported. Additionally, the result of
UNION ALL can contain duplicates, whereas UNION implies DISTINCT.
LESSON SUMMARY
You should now be able to:
96
●
Describe the motivation for enhanced Open SQL
●
Use the new syntax of Open SQL
●
Use new features of Open SQL in SELECT statements
© Copyright. All rights reserved.
Unit 3
Lesson 3
The Basics of Core Data Services in ABAP
LESSON OVERVIEW
In this lesson, you learn how to define database views using Core Data Services (CDS) in
ABAP. You also learn to use expressions, joins, aggregations, grouping, and filtering in CDS
views; to use union in CDS views; to use Open SQL to select data based on CDS views; and to
enhance a CDS view.
Business Example
Your company ITeLO wants you to improve the performance of some ABAP applications
considerably by making use of SAP HANA. The ABAP system has been migrated to use SAP
HANA as its primary database already.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Describe the concept of ABAP Core Data Services
●
Use expressions, joins, aggregations, grouping and filtering in CDS views
●
Use Open SQL to select data based on CDS views
The Concept of Core Data Services (CDS)
SAP HANA supports SQL as a means to define, read, and manipulate data. On top of SQL,
many technologies introduce higher-level models to add semantics and ease consumption,
such as Open Data Protocol (OData), the Energy Data Management (EDM) models, the
semantic layer in the Business Intelligence (BI) platform, Java Persistence API (JPA),
enterprise objects in Java, and the business objects frameworks in ABAP. These higher-level
models share many commonalities, but are usually specific to their technology. This prevents
their re-use across stacks and increases effort for application developers. To address this,
SAP introduces a set of domain-specific languages and services, called CDS, for defining and
consuming semantically rich data models.
© Copyright. All rights reserved.
97
Unit 3: Database Independent Code-to-Data
Figure 78: CDS: Domain-Specific Languages
The CDS consists of the following three sub-languages addressing the different sub-domains
of data modeling and access:
Data Definition Language (DDL)
The DDL part of CDS can be considered an enhancement of SQL that allows you to define
semantically rich database tables and views, often referred to as CDS entities, and userdefined types in the database. This allows you to simplify and harmonize the way you
define and consume your data models. The enhancements include annotations to enrich
the data models with additional (domain-specific) metadata and associations on a
conceptual level, replacing joins with simple path expressions in queries.
Query Language (QL)
Views defined using the CDS DDL can be consumed in ABAP programs using the Open
SQL query language, as well as in other CDS views. Open SQL has been extended to
provide support for CDS entities. In addition, it is possible to query the CDS features
supported by the underlying database before executing the Open SQL statement to
enable alternative implementations.
Data Control Language (DCL)
The DCL is used to define authorizations for CDS entities in a declarative way. The ABAP
CDS authorization concept is a new concept and can be used independently or in
combination with the classic concept. Whereas the classic authorization concept is
based on authorization objects and the authorizations are checked either implicitly (when
transactions are called) or explicitly (using the statement AUTHORITY CHECK), the CDS
authorization concept is based on implicit checks automatically performed by the ABAP
runtime when the CDS entity is accessed using Open SQL.
98
© Copyright. All rights reserved.
Lesson: The Basics of Core Data Services in ABAP
Figure 79: Core Data Services in ABAP
CDS are not only an integral part of SAP HANA, but can also be leveraged in the ABAP stack
and are optimally integrated into the ABAP Dictionary and language. The corresponding new
ABAP Repository object types Data Definition (also known as DDL Source) and Access
Control (also known as DCL Source), for defining enhanced view entities in ABAP, allow you to
push more data-intensive calculations to the database than is possible using classical ABAP
Dictionary views.
You can use ABAP CDS views to read data and calculate additional information while reading
data. ABAP CDS views do not support data modifications.
© Copyright. All rights reserved.
99
Unit 3: Database Independent Code-to-Data
CDS Views and Classical Dictionary Views
Figure 80: Benefits of CDS Views Compared to ABAP Dictionary Views
ABAP CDS share views with ABAP Dictionary that are supported on all database systems and
supported by the ABAP stack. However, ABAP CDS views provide the following additional
capabilities:
●
●
●
100
Enhanced support for combining queries, such as UNION and outer joins.
Support for calculations that use expressions in the column list and for selection, as well as
aggregation and grouping in the data model.
Ability to be nested, which allows for more design for reuse.
© Copyright. All rights reserved.
Lesson: The Basics of Core Data Services in ABAP
Figure 81: Advanced View Definition in ABAP 7.4 SP2 and higher
Support for CDS in ABAP begins with ABAP 7.4 SP2, as follows:
●
CDS view definitions support more features than ABAP Dictionary views.
●
CDS leverages the ABAP Dictionary-type system.
●
●
CDS leverages the ABAP infrastructure to ensure Open SQL-like behavior and support for
all database platforms supported by the ABAP stack.
CDS does not support the full SQL-92 standard or SAP HANA-specific features.
With SAP NetWeaver AS ABAP 7.40 SP5, associations between entities add a new conceptual
level. They can be used to replace joins with simple path expressions in queries to ease the
consumption of data models. Associations go beyond the traditional ABAP Dictionary view
and SQL92 capabilities.
The goal of ABAP CDS is to fully support the SQL-92 standard, and, beyond that, additional
features such as associations, entities, Create, Read, Update, Delete (CRUD), and OData
services.
© Copyright. All rights reserved.
101
Unit 3: Database Independent Code-to-Data
Basic CDS View Definition
Figure 82: Basic CDS View Definition
To create CDS views, do the following:
●
Use the ABAP Development Tools. The ABAP Workbench does not support the new type of
ABAP repository objects called data definitions.
Note:
Data definitions were first introduced under the name of DDL Sources.
●
●
In the ABAP project tree, select the package to contain the CDS view and choose the
context menu entry New → Other ABAP Repository Object → Dictionary → Data
Definition.
Use the DDL statement DEFINE VIEW and SQL-like syntax to define the view.
Each active ABAP CDS view has a corresponding SQL view. The SQL view is the CDS view’s
representation on the database but it can also be found in ABAP Dictionary as a view
definition. The SQL view in the Dictionary and on the database is generated, updated, and
deleted automatically when activating the data definition.
102
© Copyright. All rights reserved.
Lesson: The Basics of Core Data Services in ABAP
Figure 83: CDS SQL View in the ABAP Dictionary and on the Database
You can display the (native) SQL statement that is sent to the database to create the view as
follows:
●
●
In the data definition, place the cursor on the value of the AbapCatalog.sqlViewName
annotation, select F3 or Control to turn the value into a link, and select the link. This opens
the ABAP Dictionary view.
In the menu of the ABAP Dictionary screen, choose Extras → CREATE statement to see the
native SQL statement used by the system to create the corresponding database view.
© Copyright. All rights reserved.
103
Unit 3: Database Independent Code-to-Data
Figure 84: Use of Annotations in CDS Views
Annotations allow for the specification of ABAP-specific additional information, such as how
records of the view should be buffered by the ABAP table buffer, or whether the view is clientdependent or not. By default, CDS views are considered client-dependent, and you do not
have to include client fields explicitly in the field list or in the join conditions.
The annotation @AbapCatalog.sqlViewName is mandatory, and specifies the name of the
representation of the CDS View in the ABAP Dictionary and the database.
SQL Features in CDS Views
Figure 85: Select List – Support for Expressions in CDS Views
104
© Copyright. All rights reserved.
Lesson: The Basics of Core Data Services in ABAP
Like enhanced Open SQL, CDS supports various expressions, such as the following:
●
●
●
●
●
●
●
●
The simplest form of expression is a numerical or string literal.
Arithmetic expressions using operators +, -, *, / or the unary -, or using built-in functions
such as CEIL and MOD.
String expressions, including the string concatenation operator &&, or built-in functions,
such as LPAD, CONCAT, REPLACE, and SUBSTRING.
Special built-in functions can be used: COALESCE to replace null values in results,
CURRENCY_CONVERSION, and UNIT_CONVERSION to convert between currencies,
respectively units.
Some built-in functions and the division operator are available only from ABAP 7.40 SP08
onwards.
CAST expressions, with which the data type of values can be converted.
CASE expressions, which can be nested. An alias name is required for the resulting
column, except for nested CASE. The resulting column type is derived from expressions
after the THEN and ELSE clause.
Functions for calculations with dates and timestamps (as of ABAP 7.50).
Figure 86: Support for Joins, WHERE, Aggregations, Grouping, and Filtering in CDS Views
Like (Open) SQL, ABAP CDS supports the following:
●
●
A WHERE clause in a view definition.
INNER joins, LEFT OUTER and RIGHT OUTER joins. The join condition can be specified
after the projection list when using the Open SQL-like syntax, or before the projection list
when using the curly bracket syntax. If joins are used, no asterisk is supported on SELECT
statements.
© Copyright. All rights reserved.
105
Unit 3: Database Independent Code-to-Data
●
The calculation of aggregations, grouping records, and filtering groups. The GROUP BY
and HAVING clauses may be familiar from Open SQL or standard SQL aggregations.
Figure 87: Unions
Using the UNION and UNION ALL keywords, you can define views that merge the results of
two or more queries. This may be known from standard SQL. Similar to standard SQL, the
following occurs:
●
●
●
Using keyword UNION, the combined result contains no duplicate rows, that is, UNION
implies DISTINCT.
Using keyword UNION ALL, the results are basically combined immediately, and duplicate
rows are not removed.
Matching columns must be in the same order and of a compatible type.
CDS Views in Open SQL SELECT Statements
Figure 88: CDS Views in ABAP Programming
To select data from a CDS view, use the CDS View name in the FROM clause of an Open SQL
SELECT statement. If the FROM clause of an Open SQL SELECT statement contains a CDS
view name, the statement has to follow the new Open SQL syntax rules, that is, commaseparated field lists and escape character “@” for ABAP data objects are mandatory.
106
© Copyright. All rights reserved.
Lesson: The Basics of Core Data Services in ABAP
Note:
Although it is also possible to use the SQL View name, this is not recommended
and became fully deprecated with AS ABAP 7.50.
LESSON SUMMARY
You should now be able to:
●
Describe the concept of ABAP Core Data Services
●
Use expressions, joins, aggregations, grouping and filtering in CDS views
●
Use Open SQL to select data based on CDS views
© Copyright. All rights reserved.
107
Unit 3: Database Independent Code-to-Data
108
© Copyright. All rights reserved.
Unit 3
Lesson 4
Associations in Core Data Services
LESSON OVERVIEW
In this lesson, you learn how to use associations in Core Data Services (CDS).
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Use CDS views with associations
Associations to Express Relationships
Core Data Services (CDS) provide extended support for treating relationships between
entities. Such relationships are often reflected as foreign key relationships in the database,
but they are not treated as first-class citizens in SQL, especially in the Data Manipulation
Language (DML). As a consequence, using them to query data from several tables often
requires writing non-trivial join conditions. This is cumbersome and error-prone for
application developers, and requires considerable effort when joins are to be reused.
Figure 89: CDS Associations: Concept
CDS treat relationships, called associations, as first-class citizens to simplify reading
relationships between entities, using them, and defining CDS views for reuse.
Associations are defined within CDS views using the ASSOCIATION TO syntax, followed by
the target entity and an ON condition specifying how the entities are related. The syntax of the
© Copyright. All rights reserved.
109
Unit 3: Database Independent Code-to-Data
ON condition is similar to the syntax for JOINs, making it easy to refactor JOINs into
associations. Specifying an alias for the target entity and a cardinality are optional.
Associations can be used in all places where column names or tables names can be used.
Ad-Hoc Associations vs. Exposed Associations
Figure 90: CDS Association Types
If the data definition that defines the association uses an individual field of the associated
table or CDS view, we call this an ad-hoc association. Ad-hoc associations are immediately
translated into a JOIN clause in the SQL create statement that is sent to the database.
The benefit of associations becomes much clearer when looking at exposed associations.
Instead of addressing individual fields of the associated table or CDS view, it is also possible to
add the entire association as a single element into the field list. This is called an exposed
association.
If an association is exposed, the SQL CREATE statement does not contain the corresponding
JOIN clause, yet. The join is only constructed if the consumer of the view actually uses this
particular exposed association. This can be considered JOIN on demand.
Note:
A view definition can only expose an association if its field list also contains all its
fields that are mentioned in the ON condition. In the example above, this is field
CUSTOMID of table SBOOK.
110
© Copyright. All rights reserved.
Lesson: Associations in Core Data Services
Using Exposed Associations
Figure 91: Using Exposed Associations
Exposed associations are helpful for the following reasons:
●
●
The Data Preview in the ABAP Development Tools (ADT) supports navigation along the
association.
CDS views defined on the basis of the view that exposes the association can use any
column of the associated entity. This can simplify defining views on top of other views.
© Copyright. All rights reserved.
111
Unit 3: Database Independent Code-to-Data
Path Expressions in Open SQL
Figure 92: Consuming Associations in Open SQL
Beginning with ABAP 7.50, Open SQL supports path expressions to allow consuming
associations in CDS views. Only simple path expressions without filter expressions are
supported so far, but they are supported in all clauses of the SELECT statement, such as the
field list, WHERE clause, ORDER BY clause, and so on.
Association names must be prefixed with a backslash.
112
© Copyright. All rights reserved.
Lesson: Associations in Core Data Services
Filtered Associations
Figure 93: Filtered Associations
A third type of association is the filtered association. These are based on associations of
cardinality “to-N” and can be used both in the CDS view defining their base association as well
as in CDS views defined on top. To define a filtered association, you add a filter expression in
square brackets to the path expression. The filter expression is a conditional expression with
the following constraints:
●
●
●
The left-hand side of each condition must be a field of the target of the association.
The right-hand side of each condition must be a field of the target of the association, a
literal, or a parameter.
No path or other expressions or functions can be used.
A “1:” preceding the filter expression declares that the filter turns a “to-N” association into a
“to-1” association.
LESSON SUMMARY
You should now be able to:
●
Use CDS views with associations
© Copyright. All rights reserved.
113
Unit 3: Database Independent Code-to-Data
114
© Copyright. All rights reserved.
Unit 3
Lesson 5
Outlook: More Interesting Features of CDS
LESSON OVERVIEW
In this lesson, you learn how to incorporate authorization checks when querying data from a
Core Data Services (CDS) view using Open SQL.
Business Example
You want to improve the performance of an application using the code-to-data approach with
CDS views in ABAP. The application reads a large number of database records from the CDS
view, and also has to consider if the end user is authorized to see each record retrieved.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Explain CDS view extensions
●
Define and use CDS views with input parameters
●
Explain authorization checks with CDS
CDS View Extensions
Figure 94: CDS View Extends
As of ABAP 7.40 SP08, you can extend an ABAP CDS view without making modifications. To
enhance a CDS view, do the following:
© Copyright. All rights reserved.
115
Unit 3: Database Independent Code-to-Data
You can extend a CDS view with literals, additional fields of the base table(s), expressions and
functions.
When displaying the extended CDS view, the editor shows a spiral-like symbol next to the
DEFINE VIEW statement to indicate that one or more extensions exist. Select the symbol to
display a list of the existing extensions. Choose a list entry to navigate to the definition of the
CDS view extend.
Note:
Before ABAP 7.51 you can not extend CDS Views that contain a GROUP BY clause
or a UNION (ALL).
CDS Views with Input Parameters
So far, results sets based on a Core Data Services (CDS) view could only be filtered using the
WHERE clause of the corresponding query. This requires that the filter criterion is an element
of the view's projection list. However, in some cases, it is desirable to pass filter criteria or
parameterize a query in a different way, for example, if the filter condition cannot be based on
the projection list, or if an expression used within the CDS view is to be parameterized.
This need is addressed by CDS views with input parameters.
Defining CDS Views with Input Parameters
Figure 95: Defining CDS Views with Input Parameters
The WITH PARAMETERS( )... syntax in the CDS Data Definition Language (DDL) allows for the
definition of a CDS view with a comma-separated list of scalar input parameters, as follows:
●
116
Each parameter is either typed with a built-in ABAP type, such as abap.dec or abap.char,
or with an ABAP Dictionary data element.
© Copyright. All rights reserved.
Lesson: Outlook: More Interesting Features of CDS
●
●
●
The parameters can be used in the projection list of the CDS view, simply as elements or in
expressions.
The parameters can also be used in the JOIN condition of the FROM clause, in conditions in
the WHERE and the HAVING clauses.
A parameter can be referenced using the syntax $parameter.<parameter name>
or :<parameter name>.
Hint:
As of ABAP 7.50, CDS views with input parameters are supported on all database
management systems supported by the ABAP stack. In ABAP 7.40, however,
CDS views with input parameters were only supported on SAP HANA.
Binding Input Parameters of CDS Views to System Fields
Figure 96: Binding Input Parameters of CDS Views to System Fields
As of ABAP 7.50 you can use the annotation @Environment.systemField to bind an input
parameter to one of the ABAP system fields. Currently supported are the system date and
time, the user name, logon language and logon client of the current user. Using this
annotation makes the input parameter optional when the view is accessed in an Open SQL
SELECT.
Note:
When using the view in Data Preview or another CDS view, this annotation has no
effect and the parameter remains mandatory.
© Copyright. All rights reserved.
117
Unit 3: Database Independent Code-to-Data
Using a CDS View with Input Parameters in a Data Definition
Figure 97: Using a CDS View with Input Parameters in a Data Definition
When accessing a CDS view with input parameters from within another CDS view definition,
the parameter values have to be passed in the FROM clause of the SELECT statement, as a
comma-separated list of parameter name: value pairs, enclosed in parentheses and following
the name of the CDS view used.
Using a CDS View with Input Parameters in Open SQL
Figure 98: Using a CDS View with Input Parameters in Open SQL
CDS views with input parameters can be used in Open SQL queries using a very similar
syntax. Note the slight difference: in Open SQL, the equals sign is used to separate the
parameter names from their values (and spaces matter, as usual in ABAP and Open SQL).
Implicit Authorization Checks Through CDS Roles
What if an application logic reads multiple database records, but requires that authorizations
are checked on the level of individual database records? CDS views may seem less useful in
this case. Considering classical AUTHORITY-CHECKs only, the application would have to read
a larger dataset from the database, ignoring authorizations, and then perform the
authorization checks on the application server to reduce the dataset. This would correspond
to a partial code-to-data approach only, giving up some of the benefits of pushing the data
retrieval logic down to the database as much as possible.
118
© Copyright. All rights reserved.
Lesson: Outlook: More Interesting Features of CDS
Figure 99: Do Authorization Checks Conflict with Code-to-Data?
Fortunately, classical AUTHORITY-CHECKs are not the only option any longer.
Figure 100: CDS DCL: Declare Authorizations and Have Them Checked Implicitly
Beginning with ABAP 7.40 SP10, CDS DCL can be used to define authorizations for CDS views
in a declarative way. A new type of ABAP repository object, DCL source, is introduced for this
purpose. Each such access control object allows declaring (that is, modeling) a role based on
a related CDS entity. Conditions specify how the user’s permissions are checked against field
values of the individual records at runtime.
© Copyright. All rights reserved.
119
Unit 3: Database Independent Code-to-Data
Note:
Access controls only take effect in a direct access to the CDS view, that is when
the CDS view is directly used in an Open SQL SELECT statement or accessed
through SADL. If the CDS view is accessed indirectly, for example, via another
CDS view, the access controls for this CDS view are ignored.
The ABAP layer cannot distinguish between non-existent data and data not read
due to lack of permissions.
Access Conditions in CDS Roles
Figure 101: Literal and Aspect Conditions
The following two types of conditions can be used in a role definition:
Literal conditions
To compare an element of the CDS view with a literal value.
Aspect conditions
Only one aspect, pfcg_auth, is supported. This aspect allows the reuse of authorizations,
based on classical authorization objects and PFCG roles. The left-hand side of a PFCG
condition contains the list of view fields in parentheses. The list on the right-hand side
begins with the name of the authorization object. It continues with the list of
authorization object fields the view elements of the left-hand side are matched against,
optionally followed by a list of authorization object fields to be compared with literal
values.
The two types of conditions can be combined in the same role definition.
Annotations Related to Access Controls
Two annotations are relevant in the context of DCL sources:
120
© Copyright. All rights reserved.
Lesson: Outlook: More Interesting Features of CDS
Figure 102: Most Important Annotations for Access Control Objects
In a DCL source itself, annotation @MappingRule specifies that the role is automatically and
implicitly assigned to all users. Only the value true is supported as of now. Every definition of a
CDS role must currently contain the ABAP annotation MappingRole with the value true.
In a DDL source, that is in a CDS view definition, the annotation
@AccessControl.authorizationCheck specifies if a corresponding DCL role should be defined
and if the access conditions should be checked automatically at runtime. The following values
are supported for the annotation:
CHECK
During the authorization runtime, an authorization check is executed if a DCL role exists
for the entity. If no role exists, there is no check and no protection. The design time issues
a warning when activating the entity if no DCL role exists, although an authorization
check is required. This is the default value for the ABAP implementation.
NOT_REQUIRED
During the authorization runtime, an authorization check is executed if a DCL role exists
for the entity. If no role exists, there is no check and no protection. This is the same
behavior at runtime as for value CHECK. However, the design time issues no warning
when activating the entity, even if no corresponding mapping role is defined yet. This
value should be used when a mapping role is intended and planned to be defined, but no
mapping role exists yet.
NOT_ALLOWED
During the authorization runtime, no authorization check is executed. During the
authorization design time, a warning occurs when activating a role for an entity with this
annotation value.
LESSON SUMMARY
You should now be able to:
●
Explain CDS view extensions
●
Define and use CDS views with input parameters
© Copyright. All rights reserved.
121
Unit 3: Database Independent Code-to-Data
●
122
Explain authorization checks with CDS
© Copyright. All rights reserved.
Unit 3
Learning Assessment
1. Which of the following are tasks of the database interface (DBI) and database-specific
library (DBSL)?
Choose the correct answers.
X
A Translate Open SQL syntax into native SQL syntax.
X
B Add client handling to the statement.
X
C Check user authorizations.
X
D Handle SAP table buffering.
X
E Transaction handling.
2. New Open SQL syntax is mandatory as of SAP NetWeaver AS ABAP 7.40 SP05.
Determine whether this statement is true or false.
X
True
X
False
3. The Open SQL syntax is a prerequisite for the new Open SQL features.
Determine whether this statement is true or false.
X
True
X
False
4. Classical Open SQL syntax and new Open SQL syntax must not be used in the same ABAP
processing block.
Determine whether this statement is true or false.
X
True
X
False
© Copyright. All rights reserved.
123
Unit 3: Learning Assessment
5. Which of the following entities can be found in the object list of the ABAP Workbench or
the Project Explorer of ADT?
Choose the correct answers.
X
A Data definition (also known as DDL source)
X
B CDS view
X
C SQL view
6. Which of the following entities corresponds to an object Created on the database?
Choose the correct answer.
X
A Data definition (aka DDL source)
X
B CDS view
X
C SQL view
7. If you use a CDS view name in the FROM clause of an Open SQL SELECT statement, the
new Open SQL syntax is mandatory.
Determine whether this statement is true or false.
X
True
X
False
8. ASSOCIATION TO is just another way of saying LEFT OUTER JOIN TO.
Determine whether this statement is true or false.
X
True
X
False
9. Which of the following are prerequisites for exposing an association?
Choose the correct answers.
124
X
A The association points to a table, not to another CDS View.
X
B The association has cardinality “to-N.”
X
C All fields mentioned in the ON condition are part of the field list.
X
D The association is the only association in this view definition.
© Copyright. All rights reserved.
Unit 3: Learning Assessment
10. Where can you evaluate an exposed association?
Choose the correct answers.
X
A In the Data Preview of ADT .
X
B In the Data Browser (transaction SE16) .
X
C In another CDS view .
X
D In an Open SQL SELECT statement.
11. CDS views that define associations cannot be extended.
Determine whether this statement is true or false.
X
True
X
False
12. An import parameter that is annotated with @Environment.systemField: becomes optional
in the following places:
Choose the correct answers.
X
A In Data Preview in ADT.
X
B In the Data Browser (SE16).
X
C In ABAP Open SQL.
X
D In the definition of another CDS view.
13. An access control (DCL source) defines access restrictions for a given CDS view. These
restrictions are implicitly evaluated when the CDS view is accessed in the following places:
Choose the correct answers.
X
A In Data Preview in ADT.
X
B In the Data Browser (SE16).
X
C In ABAP Open SQL.
X
D In the definition of another CDS view.
© Copyright. All rights reserved.
125
Unit 3
Learning Assessment - Answers
1. Which of the following are tasks of the database interface (DBI) and database-specific
library (DBSL)?
Choose the correct answers.
X
A Translate Open SQL syntax into native SQL syntax.
X
B Add client handling to the statement.
X
C Check user authorizations.
X
D Handle SAP table buffering.
X
E Transaction handling.
Correct. Translating Open SQL syntax into native SQL syntax, adding client handling to the
statement, and handling SAP table buffering are tasks of the database interface (DBI) and
database-specific library (DBSL).
2. New Open SQL syntax is mandatory as of SAP NetWeaver AS ABAP 7.40 SP05.
Determine whether this statement is true or false.
X
True
X
False
Correct. New Open SQL syntax is not mandatory as of SAP NetWeaver AS ABAP 7.40
SP05.
3. The Open SQL syntax is a prerequisite for the new Open SQL features.
Determine whether this statement is true or false.
X
True
X
False
Correct. The Open SQL syntax is a prerequisite for the new Open SQL features.
126
© Copyright. All rights reserved.
Unit 3: Learning Assessment - Answers
4. Classical Open SQL syntax and new Open SQL syntax must not be used in the same ABAP
processing block.
Determine whether this statement is true or false.
X
True
X
False
Correct. Classical Open SQL syntax and new Open SQL syntax need not be used in the
same ABAP processing block.
5. Which of the following entities can be found in the object list of the ABAP Workbench or
the Project Explorer of ADT?
Choose the correct answers.
X
A Data definition (also known as DDL source)
X
B CDS view
X
C SQL view
Correct. Data definition (DDL source) and SQL view can be found in the object list of the
ABAP Workbench or the Project Explorer of ADT.
6. Which of the following entities corresponds to an object Created on the database?
Choose the correct answer.
X
A Data definition (aka DDL source)
X
B CDS view
X
C SQL view
Correct. SQL view corresponds to an object Created on the database.
7. If you use a CDS view name in the FROM clause of an Open SQL SELECT statement, the
new Open SQL syntax is mandatory.
Determine whether this statement is true or false.
X
True
X
False
Correct. If you use a CDS view name in the FROM clause of an Open SQL SELECT
statement, the new Open SQL syntax is mandatory.
© Copyright. All rights reserved.
127
Unit 3: Learning Assessment - Answers
8. ASSOCIATION TO is just another way of saying LEFT OUTER JOIN TO.
Determine whether this statement is true or false.
X
True
X
False
Correct. ASSOCIATION TO is not the same as LEFT OUTER JOIN TO.
9. Which of the following are prerequisites for exposing an association?
Choose the correct answers.
X
A The association points to a table, not to another CDS View.
X
B The association has cardinality “to-N.”
X
C All fields mentioned in the ON condition are part of the field list.
X
D The association is the only association in this view definition.
Correct. A prerequisites for exposing an association is that all fields mentioned in the ON
condition are part of the field list.
10. Where can you evaluate an exposed association?
Choose the correct answers.
X
A In the Data Preview of ADT .
X
B In the Data Browser (transaction SE16) .
X
C In another CDS view .
X
D In an Open SQL SELECT statement.
Correct. You evaluate an exposed association in the Data Preview of ADT, in another CDS
view, or in an Open SQL SELECT statement.
11. CDS views that define associations cannot be extended.
Determine whether this statement is true or false.
X
True
X
False
Correct. CDS views that define associations can be extended.
128
© Copyright. All rights reserved.
Unit 3: Learning Assessment - Answers
12. An import parameter that is annotated with @Environment.systemField: becomes optional
in the following places:
Choose the correct answers.
X
A In Data Preview in ADT.
X
B In the Data Browser (SE16).
X
C In ABAP Open SQL.
X
D In the definition of another CDS view.
Correct. An import parameter that is annotated with @Environment.systemField: becomes
optional in ABAP Open SQL.
13. An access control (DCL source) defines access restrictions for a given CDS view. These
restrictions are implicitly evaluated when the CDS view is accessed in the following places:
Choose the correct answers.
X
A In Data Preview in ADT.
X
B In the Data Browser (SE16).
X
C In ABAP Open SQL.
X
D In the definition of another CDS view.
Correct. Access restrictions for a given CDS view are implicitly evaluated when the CDS
view is accessed in Data Preview in ADT and in ABAP Open SQL.
© Copyright. All rights reserved.
129
Unit 3: Learning Assessment - Answers
130
© Copyright. All rights reserved.
UNIT 4
SAP HANA specific Code-toData
Lesson 1
The Syntax of SAP HANA Native SQL
133
Lesson 2
ABAP Managed Database Procedures
137
Lesson 3
ABAP Database Connectivity (ADBC)
151
Lesson 4
Use of SAP HANA Information Models in ABAP
155
UNIT OBJECTIVES
●
Know the basics of SAP HANA native SQL syntax
●
Understand ABAP Managed Database Procedures
●
Create an ABAP Managed Database Procedure
●
Call an ABAP Managed Database Procedure in ABAP
●
Debug an ABAP Managed Database Procedure
●
Know how AMDP enhancement works
●
Understand ABAP Database Connectivity (ADBC)
●
Use ADBC to execute native SQL statements
●
Analyze and Test SAP HANA Information Models
●
Access SAP HANA information models using native SQL
●
Describe Proxy Objects for SAP HANA views and procedures
© Copyright. All rights reserved.
131
Unit 4: SAP HANA specific Code-to-Data
132
© Copyright. All rights reserved.
Unit 4
Lesson 1
The Syntax of SAP HANA Native SQL
LESSON OVERVIEW
In this lesson, you learn about the main differences between native SQL syntax and Open SQL
syntax and how to write syntactically correct native SQL statements.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Know the basics of SAP HANA native SQL syntax
SAP HANA SQL and Open SQL
For even more sophisticated code pushdown, ABAP developers need to access SAP HANAspecific functionality directly. This usually involves the use of SAP HANA’s own native SQL
dialect because such functionality is not accessible through database-independent
techniques such as Open SQL and CDS view definition.
In a first step, we will discuss the common ground and the major differences between Open
SQL syntax and (SAP HANA) native SQL syntax.
Common Ground Between SAP HANA SQL and Open SQL
●
●
Key words are not case-sensitive.
Table names and column names are translated to upper case (in SAP HANA SQL: if not
quoted).
In Open SQL, you can only access table names and column names defined in the ABAP
Dictionary. Such table names and column names are always in upper case.
In SAP HANA SQL, you may need to access table names and column names that include
lower case characters. Place those names in double-quotes (“”) to keep SAP HANA from
translating them to upper case.
Important Syntax Differences Between SAP HANA SQL and Open SQL
SAP HANA Native
SQL
Classic Open SQL
Enhanced Open
SQL
Element List Separator
Comma (,)
Blank ( )
Comma (,)
Position of Element List
Before FROM clause
Before FROM
clause
Before or after
FROM clause(key
word FIELDS)
Separator between table
and field name
Period ( . )
Tilde (~)
Tilde (~)
© Copyright. All rights reserved.
133
Unit 4: SAP HANA specific Code-to-Data
SAP HANA Native
SQL
Classic Open SQL
Enhanced Open
SQL
Schema handling
Implicit default
schema (user
schema) or schema
name before table
name
Only default
schema
Only default
schema
Client Handling
No implicit client
handling. Client
needs to be specified
in WHERE-clause and
join conditions.
Implicit client
handling by DB
interface. Explicit
client via addition
CLIENT SPECIFIED.
Implicit client
handling by DB
interface. Explicit
client via addition
USING CLIENT.
Delimitate number of
rows
TOP ...
UP TO … ROWS
UP TO … ROWS
Access to CDS Views
Only SQL view visible Only access to SQL
on database
view supported.
Access to CDS view
possible.
CORRESPONDING
FIELDS
Not supported
Supported
Supported
FOR ALL ENTRIES
Not supported
Supported
Supported
Figure 103: Example 1: Classical Open SQL Syntax and Native SQL Syntax
134
© Copyright. All rights reserved.
Lesson: The Syntax of SAP HANA Native SQL
Figure 104: Example 2: Joins in Open SQL and Native SQL
Test of SAP HANA SQL Statements in SAP HANA Studio
As there is no syntax check for native SQL statements in ABAP, it can be very difficult to
ensure correct syntax. A convenient solution can be to use the SQL Console view of the SAP
HANA studio.
Figure 105: SQL Console
You can open the SQL Console as follows:
1. Select the SAP HANA system.
2. Choose the Open SQL Console button.
Here you can enter SQL statements (SAP HANA syntax) and execute them.
© Copyright. All rights reserved.
135
Unit 4: SAP HANA specific Code-to-Data
Figure 106: Enter SQL Statement and Execute
You can test an SQL statement as follows:
1. Enter a statement in the SQL Console.
2. Choose the Execute button.
If the statement is not yet correct, error messages are displayed that can be used to locate
and correct the error.
Caution:
Be careful with statements that change the content of database tables.
LESSON SUMMARY
You should now be able to:
●
136
Know the basics of SAP HANA native SQL syntax
© Copyright. All rights reserved.
Unit 4
Lesson 2
ABAP Managed Database Procedures
LESSON OVERVIEW
This lesson explains the benefits of and how to develop and use ABAP-Managed Database
Procedures.
Business Example
Your company ITeLO wants you to improve the performance of some ABAP applications
considerably by making use of SAP HANA. The ABAP system is on release 7.4 SP05 or higher
and uses SAP HANA as its primary database. You realize that the performance improvement
you aim for cannot be reached using Open SQL, Core Data Services (CDS), or native SQL.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Understand ABAP Managed Database Procedures
●
Create an ABAP Managed Database Procedure
●
Call an ABAP Managed Database Procedure in ABAP
●
Debug an ABAP Managed Database Procedure
●
Know how AMDP enhancement works
Motivation for AMDPs
Figure 107: ABAP 7.4 SP05: ABAP-Managed Database Procedures
© Copyright. All rights reserved.
137
Unit 4: SAP HANA specific Code-to-Data
The most powerful means of SAP HANA-specific code-to-data are ABAP-managed database
procedures (AMDPs). AMDPs are available as off ABAP 7.4 SP05 and together with Open SQL
and ABAP CDS they are part of the top-down approach to code-to-data.
From a technical point of view, AMPDs are procedures stored and executed on the database,
which you implement in a script language provided and understood by the database.
Note:
At the moment, AMDPs are only supported with SAP HANA as database and the
only script language available for customers is SAP HANA's version of SQL Script.
“ABAP-managed” in the term “AMDP” means, that for these database procedures, editing,
activation, transport, and lifecycle management are performed on the ABAP application
server. This distinguishes AMDP from the procedures that you find in SAP HANA information
models.
Using the AMDP framework has the following advantages:
●
Full access to SAP HANA specific functionality.
●
SQL Script Source code is edited and managed in an ABAP repository object
●
SQL Script syntax check is integrated into the ABAP syntax check
●
SQL Script debugging is integrated into ABAP debugging
●
Stored procedures are automatically created (deployed) on the SAP HANA database
Note:
Using ABAP-managed database procedures is the recommended way for
accessing SAP HANA-specific functionality from within an ABAP program.
138
© Copyright. All rights reserved.
Lesson: ABAP Managed Database Procedures
AMDPs Creation
Figure 108: AMDPs: Integration of Database Procedures into ABAP
ABAP Managed Database Procedures (AMDPs) are created as methods of ABAP classes. But
in contrast to “normal” methods, they are not implemented with ABAP source code but with a
database specific programming language, such as SAP HANA SQL script.
Whether a method is implemented in ABAP or another language is specified with addition BY
DATABASE PROCEDURE in the method implementation part. But the class definition part has
to fulfill some prerequisites before the method can be used as an AMDP method.
© Copyright. All rights reserved.
139
Unit 4: SAP HANA specific Code-to-Data
Prerequisites in Class Definition
Figure 109: AMDPs: Prerequisites in Class Definition
Classes that are to act as a container for AMDPs have to implement a so-called “marker
interface” IF_AMDP_MARKER_HDB.
AMDP method parameters are allowed to be import, export, or changing parameters.
Returning parameters cannot be used.
All AMDP method parameters have to be passed by value, and must be of either table or
scalar types.
For parameters of table types, the line types have to consist of elementary components,
because nested tables are not supported. ABAP Dictionary structure types are not allowed.
Scalar importing parameters can have default values.
AMDP methods can be defined in the public, protected, or private visibility section of the
class. ABAP classes can contain a mixture of ABAP methods and AMDP methods.
Note:
Although you can define AMDP methods as instance methods, they are always
executed like static methods.
140
© Copyright. All rights reserved.
Lesson: ABAP Managed Database Procedures
Implementing AMDP Methods
Figure 110: Implementation of AMDP Methods
You turn a normal ABAP method into an AMDP method by adding BY DATABASE
PROCEDURE to the METHOD statement (beginning of the method implementation). This is
followed by the database system (for example, HDB) and the implementation language (for
example, SQLScript).
The method body of such a method is implemented using SQLScript source code. Almost the
full SQLScript reference can be used in the method body, except the CE function
CE_COLUMN_TABLE.
If the method implementation uses ABAP objects (ike tables, views, other AMDPs) it is
mandatory to list these objects after addition USING.
Via the addition OPTIONS, the AMDP method can be marked as a READ-ONLY database
procedure. This is optional.
© Copyright. All rights reserved.
141
Unit 4: SAP HANA specific Code-to-Data
Figure 111: AMDP Method – SQLScript Example
Some basic characteristics of SAP HANA SQLScript are as follows:
●
●
●
●
●
Statements are ended with semicolon (;).
Comments can be marked by using two dashes (--), but asterisk (*) at position 1 is also
supported.
In SQL-statements, host variables (variables, parameters, constants) are escaped with
double-point (:).
There is no INTO clause for SELECT. Results are retrieved by using SELECT as an
expression on the right-hand side of a value assignment.
Built-in function SESSION_CONTEXT( ) provides values of session variables (like for
example the logon client from the ABAP server.
Note:
Comments in SQLScript can be marked by using two dashes (--), but asterisk (*)
at position 1 is also supported – just like in ABAP.
142
© Copyright. All rights reserved.
Lesson: ABAP Managed Database Procedures
Figure 112: AMDP Method – SQLScript Examples
Temporary data objects, like for example temporary tables to store SELECT-results, you don't
have to declare in advance. In the example, data object lt_customers is declared in-line to
store the result of the query.
All ABAP Dictionary tables or views, and other AMDP methods that will be called in the
procedure body, must be declared with the USING keyword. In the procedure body, these
objects are addressed without the need for the SAP<SID> prefix. AMDP methods called inside
an AMDP body have to be declared with their full names (that is, the class they belong to as
well as the method name, as you can see from the figure). When they are called in the
procedure body, they must be addressed with double quotes and in uppercase. Any objects
outside of the SAP<SID> schema are not ABAP-managed, and therefore are not part of the
USING clause. Developers have to make sure that they are available at runtime.
Editor Support for AMDP Methods
To get full editor support, it is mandatory to use ADT to edit AMDP methods. The classical
ABAP Workbench only supports display of ABAP Managed Database Procedures.
The tool support in ADT includes the following functions:
●
Semantic code completion for the ABAP part (BY DATABASE PROCEDURE addition).
●
Syntax check for SQLScript code.
●
Syntax highlighting for SQLScript code.
●
Debugging of AMDP methods.
© Copyright. All rights reserved.
143
Unit 4: SAP HANA specific Code-to-Data
Figure 113: AMDP Methods – Syntax Check in ADT
The syntax check can detect the following types of syntax errors:
●
Database-independent syntax errors: parameters not passed by value, wrong parameter
types, or cyclic method calls.
●
SAP HANA-specific syntax errors: Type mapping checks or wrong default values.
●
SQLScript errors.
With any of these syntax errors, an AMDP class is not syntactically correct.
Note:
The syntax checks depend on the underlying database system. You need an SAP
HANA as primary database to get SQLScript syntax checks.
144
© Copyright. All rights reserved.
Lesson: ABAP Managed Database Procedures
AMDP Use
Figure 114: Calling AMDP Methods
An AMDP method is called like any ABAP method, as follows:
●
●
AMDP methods are executed like static methods, even if they are defined as instance
methods.
When an AMDP is processed, the ABAP kernel calls the corresponding database
procedure in SAP HANA.
AMDP makes sure that a database procedure is available at runtime:
●
The database procedure is created at first use (lazy approach).
●
It exists in the SAP<SID> schema.
●
●
A new version of the database procedure is created each time the source code or
dependent objects change.
Obsolete versions are deleted asynchronously.
Debugging ABAP-Managed Database Procedures in SAP NetWeaver 7.50
When ABAP code using ABAP-managed database procedures does not work as expected, you
may want to debug into the database procedure similarly to how you can debug the ABAP
code itself. With ABAP 7.4 SP05 and SAP HANA Studio version 1.70 or higher, ABAP managed
database procedures can be debugged. The level of integration into the ABAP debugging
process and exact procedure depends on the ABAP release.
© Copyright. All rights reserved.
145
Unit 4: SAP HANA specific Code-to-Data
Figure 115: Setting Breakpoints In ABAP-Managed Database Procedures
With ABAP 7.5, an AMDP can be debugged in a fully-integrated way using the ABAP
Development Tools. Simply open the AMDP method in an ABAP editor view and set
breakpoints as usual.
Note:
Breakpoints in AMDPs can only be set in lines in which statements begin, and only
if the procedure really exists on the database. Since the ABAP stack creates the
procedure on the DB on-demand only (the first time the procedure is really
executed), a procedure must have been executed at least once in the system
before you can set a breakpoint in it.
When the program calling the AMDP is executed and the break points are reached, the Debug
view opens.
146
© Copyright. All rights reserved.
Lesson: ABAP Managed Database Procedures
Figure 116: Debugging AMDPs with ABAP 7.5
If breakpoints are set both in usual ABAP code as well as in AMDPs, two debug sessions are
created: an ABAP Debugger session and a Database Server session. The latter is the one used
for the AMDPs. Note that the AMDP debugger is in fact executed on the HANA database and
does not provide all the options to step through the code you are used to from the ABAP
debugger. For example, you can mainly resume execution until the next breakpoint is
reached. You can add breakpoints while debugging, including on ENDMETHOD lines to inspect
the exporting parameters before execution is returned back from the database server to the
ABAP stack.
© Copyright. All rights reserved.
147
Unit 4: SAP HANA specific Code-to-Data
AMDP Enhancement
Figure 117: AMDP BAdI Concept
Similar to regular ABAP code, AMDP can be enhanced if the original software provider
foresees this. To allow for the enhancement of AMDP, the following must apply:
●
148
The software provider has created an Enhancement Spot and a Business Add-In (BAdI)
definition.
●
The BAdI definition is marked as AMDP BAdI.
●
The software provider has provided a fallback class (mandatory for an AMDP BAdI).
●
The AMDP method of the software provider calls the AMDP method of the BAdi definition.
© Copyright. All rights reserved.
Lesson: ABAP Managed Database Procedures
Figure 118: AMDP BAdI Calls and Implementation
The AMDP method that calls the AMDP BAdI, has to declare its use with the USING clause.
As long as there is active BAdI implementation, the system executes the implementation in
the fallback class when the AMDP BAdI is called. As soon as there is an active BAdI
implementation, the SQLScript coding from the implementation class is executed, instead.
Hint:
If an AMDP BAdI allows for multiple use, each implementation has to merge its
own results with the results of potential coexisting implementations. This can be
done, for example, with a UNION (ALL) clause.
LESSON SUMMARY
You should now be able to:
●
Understand ABAP Managed Database Procedures
●
Create an ABAP Managed Database Procedure
●
Call an ABAP Managed Database Procedure in ABAP
●
Debug an ABAP Managed Database Procedure
●
Know how AMDP enhancement works
© Copyright. All rights reserved.
149
Unit 4: SAP HANA specific Code-to-Data
150
© Copyright. All rights reserved.
Unit 4
Lesson 3
ABAP Database Connectivity (ADBC)
LESSON OVERVIEW
In this lesson, you learn about ABAP Database Connectivity (ADBC) and use it to execute
native SQL statements.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Understand ABAP Database Connectivity (ADBC)
●
Use ADBC to execute native SQL statements
Basic Features of ADBC
Figure 119: Basic Features of ADBC
ABAP Database Connectivity, or ADBC for short, is an API to access database-specific
functionality in native SQL calls. It was introduced as an alternative for native SQL via the
EXEC SQL statement. It allows for the determination of where native SQL calls are used and
supports exception handling. It is flexible, object-oriented, and not difficult to use, as only two
or three main classes are relevant in most cases.
While the use of ABAP-managed Database Procedures (AMDPs) is restricted to a primary
SAP HANA database, you can use ADBC to access any DB management system and you can
also use it to access a secondary database.
© Copyright. All rights reserved.
151
Unit 4: SAP HANA specific Code-to-Data
Note:
Before the introduction of AMDPs, ADBC was an important technique for SAP
HANA-specific code-to-data. Today, we recommend to use it only for access to
SAP HANA as secondary database.
Usage of ADBC
Logical Sequence for Reading Data with ADBC
1. Choose database connection (only when accessing secondary DB): Call method
get_connection() of class CL_SQL_CONNECTION.
2. Create a statement object: Instantiation of class CL_SQL_STATEMENT.
3. Fill string variable with SQL syntax: Use either CONCATENATE or string templates/string
expressions.
4. Issue native SQL call: Call method execute_query() of class CL_SQL_STATEMENT.
5. Assign target variable for result set: Call method set_param() or set_param_table() of
class CL_SQL_RESULT_SET.
6. Retrieve result set: Call method next_package() of class CL_SQL_RESULT_SET.
7. Close result and release resources: Method close() of class CL_SQL_RESULT_SET.
The logical sequence to issue a native SQL query using ADBC is shown above. Some steps
can be combined in practice when chaining method calls in ABAP or when using string
expressions or string templates. In addition, the first step, getting a database connection, is
necessary only when using a secondary database connection for the native SQL call. A typical
piece of code using ADBC and classical string concatenation to construct the native SQL
string is shown in the figure Coding Example: ABAP Database Connectivity (ADBC).
152
© Copyright. All rights reserved.
Lesson: ABAP Database Connectivity (ADBC)
Figure 120: Coding Example: ABAP Database Connectivity (ADBC)
Figure 121: Important Points when Using ADBC
When using native SQL, you should be aware of several pitfalls, such as the following:
●
●
The syntax of a native SQL string is not checked by the ABAP compiler. Handle exception
CX_SQL_EXCEPTION to be able to analyze messages returned by the database if the native
SQL string contains an error. This may be especially helpful because the syntax of native
SQL differs from the syntax of Open SQL.
Native SQL calls bypass the ABAP database interface. As a consequence, the following
occurs:
-
The ABAP table buffer is bypassed. This can make some native SQL calls slower than
Open SQL statements. In addition, changing data via native SQL is not recommended
because the ABAP table buffer gets out of sync.
© Copyright. All rights reserved.
153
Unit 4: SAP HANA specific Code-to-Data
-
WHERE conditions, JOIN conditions, and so on, have to include the client field explicitly.
LESSON SUMMARY
You should now be able to:
154
●
Understand ABAP Database Connectivity (ADBC)
●
Use ADBC to execute native SQL statements
© Copyright. All rights reserved.
Unit 4
Lesson 4
Use of SAP HANA Information Models in ABAP
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Analyze and Test SAP HANA Information Models
●
Access SAP HANA information models using native SQL
●
Describe Proxy Objects for SAP HANA views and procedures
SAP HANA Views
Figure 122: Open Definition and Data Preview
To open the definition of a SAP HANA view, double-click its name in the System Navigator
Alternatively, open the context menu and choose Open. Choose Data Preview to analyze the
data returned by the view.
The data preview tool allows for three different approaches:
The Raw Data view displays the data in a table.
The Distinct values view allows you to analyze the distinct values in the various columns of a
view.
Finally, the Analysis view provides a tool for an interactive graphical analysis.
© Copyright. All rights reserved.
155
Unit 4: SAP HANA specific Code-to-Data
SAP HANA Procedures
Figure 123: Parameters of a Procedure
Figure 124: Parameter Details
156
© Copyright. All rights reserved.
Lesson: Use of SAP HANA Information Models in ABAP
Figure 125: Source Code of Procedure
Access to SAP HANA objects using Native SQL
You learned that you can access SAP HANA-specific functionality by developing ABAPmanaged database procedures (AMDPs) or by implementing native-SQL queries with ADBC.
In both cases you might be able to reduce your effort by accessing the views and stored
procedures of existing SAP HANA Information models.
Figure 126: Native SQL Syntax for Consuming SAP HANA Views
© Copyright. All rights reserved.
157
Unit 4: SAP HANA specific Code-to-Data
Each SAP HANA view and SAP HANA stored procedure has a runtime object that is stored in
the dedicated schema _SYS_BIC. To ensure uniqueness, the name for generated runtime
object, is derived from the relative name of the object and the full path of the package in the
SAP HANA content. Let's consider a calculation view CA_BOOKINGS_COUNT in subpackage
primdb of top-level package ha400. The name of the generated runtime object in schema
_SYS_BIC for this view is ha400.primdb/CA_BOOKINGS_COUNT.
As illustrated in figure Native SQL Syntax for Consuming SAP HANA Views, you can read from
a SAP HANA in a native SQL statement by directly addressing the runtime object in schema
_SYS_BIC.
Note:
Remember to include the name of the runtime object in quotes. If you don't, SAP
HANA will translate the lower case letters in the object name to upper case.
The lower example illustrates an SAP HANA specific notation that hides the technical
_SYS_BIC schema. If you use this notation, SAP HANA will use content path before :: and the
relative view name after :: to identify the runtime object in schema _SYS_BIC.
Figure 127: Native SQL Syntax for Calling an SAP HANA Procedure
You can call a SAP HANA stored procedure using the native SQL statement CALL followed by
the name of the procedure. Again, you can either directly address the runtime object in
schema _SYS_BIC or use the simplified notation. The latter is illustrated in figure As
illustrated in figure Native SQL Syntax for Calling a SAP HANA Procedure.
The formal parameters of the procedure are supplied with a comma-seperated list of actual
parameters inside a pair of brackets.
158
© Copyright. All rights reserved.
Lesson: Use of SAP HANA Information Models in ABAP
Note:
The parameter sequence is derived from the procedure definition. You always
have to supply all input parameters first and then all output parameters.
If you use the CALL statement in the SQL console, use literals to supply the input parameters
and keyword NULL as a placeholder for all output parameters. After the execution of the
statement, the content of each output parameter is displayed on different tab.
When calling the SAP HANA procedure inside the SQL script body of an AMDP, you have
many more options.
You can store the output of a procedure in temporary data objects or transfer it to exporting
parameters of the AMDP, directly. To supply input parameters with values there are even
more possibilities. The lower example in figure Native SQL Syntax for Calling a SAP HANA
Procedure uses importing parameter number of the AMDP method to supply the first
parameter and HANA-specific function session_context('CLIENT') for the second parameter.
External Views
As of ABAP 7.4 SP02, a new repository object type called “external view” is available in the
ABAP Dictionary.
External views can only be created in ABAP systems that use SAP HANA as primary database.
Figure 128: What Is an External View?
An external view represents an SAP HANA view on the ABAP side. It serves as a proxy for the
SAP HANA view in the ABAP Dictionary. It makes the view and its field list visible to the ABAP
stack and allows for access to the SAP HANA view via Open SQL.
External views have some things in common with Database views created in the ABAP
Dictionary: Both can be used as data types in ABAP programs and in the FROM clause of
Open SQL SELECT statements. But where a Database view completely defines the
corresponding database object, an external view only represents the SAP HANA view. It does
not contain the information about the underlying tables and join conditions.
© Copyright. All rights reserved.
159
Unit 4: SAP HANA specific Code-to-Data
External Views in ABAP Development Tools (ADT)
Figure 129: Create External View – New ABAP Repository Object
External views are not supported by the ABAP Workbench. To create or analyze an external
view, you have to use ADT.
In your ABAP project, open the context menu and choose New → Other or New → Other ABAP
Repository Object. Open the folder ABAP Dictionary and select Dictionary View. Specify the
following:
●
The ABAP package to which the external view is to belong.
●
The ABAP name and description.
●
Choose External View.
●
160
The full name, including the SAP HANA content package name, of the SAP HANA column
view for which the external view is to be created.
© Copyright. All rights reserved.
Lesson: Use of SAP HANA Information Models in ABAP
Figure 130: Create External View – Adjust Dictionary Types
Adjust the mapping from the SAP HANA types used in the SAP HANA column view to the
ABAP types used in the ABAP representation.
External Views in Open SQL SELECT Statements
Figure 131: Using External View in ABAP
Once the external view is created and activated, you can declare local variables and internal
ABAP tables using it as a structured data type, and you can retrieve data from the view using
regular Open SQL SELECT statements.
Problems When Using External Views
No Data Elements for View Components
●
Only technical information. No labels, documentation, and so on.
© Copyright. All rights reserved.
161
Unit 4: SAP HANA specific Code-to-Data
●
Avoid using external views as data type for UI fields.
Danger of Runtime Errors
●
●
●
Changes to SAP HANA view interface require manual synchronization of external
view.
Syntax check only ensures existence of external view not existence of stored
procedure.
Runtime errors occur if the SAP HANA view does not exist, does not match external
view interface, or if database is not SAP HANA.
Traceability Issues
The SAP HANA studio will not tell you which ABAP external views refer to a particular
SAP HANA view.
Database Procedure Proxies
Figure 132: Using Stored Procedures in ABAP 7.40 SP02 – SP04
ABAP-Managed Database Procedures (ADMPs) are only supported starting with ABAP 7.4
SP05. But ABAP release 7.40 supports another, now outdated, way to simplify the bottom-up
approach of consuming SAP HANA database procedures: a dedicated ABAP Dictionary object
type called Database Procedure Proxy.
162
© Copyright. All rights reserved.
Lesson: Use of SAP HANA Information Models in ABAP
Figure 133: Database Procedure Proxy in ABAP Dictionary
A Database Procedure Proxy represents a SAP HANA stored database procedure inside the
ABAP system. It has import and export parameters that are mapped to the parameters of the
procedure.
A Database Procedure Proxy allows you to call the SAP HANA stored procedure it represents
without using native SQL. A new ABAP statement CALL DATABASE PROCEDURE is
introduced for this purpose.
© Copyright. All rights reserved.
163
Unit 4: SAP HANA specific Code-to-Data
Database Procedure Proxies in ABAP Development Tools (ADT)
Figure 134: Create Database Procedure Proxy Using ABAP Development Tools
Database Procedure Proxies are not supported by the ABAP Workbench. To create a
Database Procedure Proxy, you have to use ADT.
In the ABAP project, open the context menu and choose New → Other or New → Other ABAP
Repository Object. Open the Dictionary folder and select Database Procedure Proxy. Specify
the following:
●
The ABAP package to which the proxy is to belong.
●
The ABAP name of the database procedure proxy and its description.
●
●
164
The name of an ABAP OO interface to be created. This interface holds the definition of the
database procedure proxy parameters with their types, mapped to ABAP Dictionary types.
The full name, including the SAP HANA content package name, of the database procedure
for which a proxy is to be created.
© Copyright. All rights reserved.
Lesson: Use of SAP HANA Information Models in ABAP
Figure 135: Create Database Procedure Proxy – Adjust Types
Adjust the mapping from the SAP HANA types used in the original database procedure
interface to the ABAP types used in the ABAP representation.
Calling Database Procedure Proxies in ABAP
Figure 136: Using Database Procedure Proxies
To call a stored procedure using a Database Procedure Proxy, use the new statement CALL
DATABASE PROCEDURE. The syntax is similar to function calls. For the importing and
exporting parameters, use ABAP variables typed with the types defined in the ABAP OO
interface generated for the procedure proxy.
© Copyright. All rights reserved.
165
Unit 4: SAP HANA specific Code-to-Data
Problems When Using Database Procedure Proxies
No Optional Parameters
All parameters of procedure proxy are mandatory.
Potential Runtime Errors
●
●
●
Changes to the interface of the stored procedure require manual synchronization of
the procedure proxy.
Syntax check only ensures existence of procedure proxy, not existence of the stored
procedure.
Runtime errors occur if SAP HANA procedure does not exist, does not match proxy
interface, or if database is not SAP HANA.
Traceability Issues
The SAP HANA studio will not tell you which database procedure proxies refer to a
particular SAP HANA stored procedure.
No Extensibility Mechanism
There is no extensibility mechanism for database procedure proxies (like for AMDPs).
LESSON SUMMARY
You should now be able to:
166
●
Analyze and Test SAP HANA Information Models
●
Access SAP HANA information models using native SQL
●
Describe Proxy Objects for SAP HANA views and procedures
© Copyright. All rights reserved.
Unit 4
Learning Assessment
1. Which of the following are common ground between SAP HANA syntax and Open SQL
syntax (as of ABAP 7.40 SP05)?
Choose the correct answers.
X
A Key words are not case-sensitive.
X
B Table names have to be upper-case.
X
C Identical client handling.
X
D Comma-separated field lists.
X
E Field list after FROM clause is supported.
2. In SAP HANA SQL, it is mandatory to specify a schema before the table name.
Determine whether this statement is true or false.
X
True
X
False
3. Which of the following are supported types for parameters of AMDP methods?
Choose the correct answers.
X
A Numeric or character-like scalar types.
X
B Structure types with only scalar components.
X
C Table types with only scalar columns.
X
D Nested table types without secondary keys.
4. All ABAP objects used within the body of an AMDP method have to be listed after the
USING addition.
Determine whether this statement is true or false.
X
True
X
False
© Copyright. All rights reserved.
167
Unit 4: Learning Assessment
5. Any AMDP method shipped by SAP can be extended using the AMDP BAdI technique.
Determine whether this statement is true or false.
X
True
X
False
6. What can you do in ADT (ABAP in Eclipse) but not in the classical ABAP Workbench?
Choose the correct answers.
X
A Display an AMDP method implementation.
X
B Edit an AMDP method implementation.
X
C Test an AMDP method implementation.
X
D Debug an AMDP method implementation.
7. When executing a native SQL query via ABAP Database Connectivity (ADBC), which of the
following steps is optional?
Choose the correct answer.
X
A Create an instance of CL_SQL_CONNECTION.
X
B Create an instance of CL_SQL_STATEMENT.
X
C Create an instance of CL_SQL_RESULT_SET.
X
D None, all three are mandatory.
8. What happens if you forget to call method close( ) at the end of your query?
Choose the correct answers.
X
A You don’t forget a result.
X
B An exception is raised.
X
C DB resources remain blocked.
X
D Nothing.
9. The search function in the toolbar of SAP HANA studio searches in SAP HANA content
and in the SAP HANA catalog.
Determine whether this statement is true or false.
168
X
True
X
False
© Copyright. All rights reserved.
Unit 4: Learning Assessment
10. You can use Data Preview in SAP HANA studio to test SAP HANA views and SAP HANA
stored procedures.
Determine whether this statement is true or false.
X
True
X
False
11. You want to access SAP HANA view CA_BOOKINGS_COUNT in package ha400.primdb via
a native SQL query. Which of the following are correct ways of specifying package path
and object name in the FROM clause?
Choose the correct answers.
X
A FROM _SYS_BIC.“ha400.primdb.::CA_BOOKINGS_COUNT”
X
B FROM “ha400.primdb::CA_BOOKINGS_COUNT”
X
C FROM _SYS_BIC.“ha400.primdb/CA_BOOKINGS_COUNT”
X
D FROM “ha400.primdb/CA_BOOKINGS_COUNT”
12. Which of the following object types in ABAP repository are proxy objects for SAP HANA
objects?
Choose the correct answers.
X
A Procedure Proxy
X
B Database View
X
C SQL View
X
D External View
13. When creating a proxy object for an SAP HANA view, it is possible to specify data
elements for the view fields.
Determine whether this statement is true or false.
X
True
X
False
© Copyright. All rights reserved.
169
Unit 4
Learning Assessment - Answers
1. Which of the following are common ground between SAP HANA syntax and Open SQL
syntax (as of ABAP 7.40 SP05)?
Choose the correct answers.
X
A Key words are not case-sensitive.
X
B Table names have to be upper-case.
X
C Identical client handling.
X
D Comma-separated field lists.
X
E Field list after FROM clause is supported.
Correct. In both SAP HANA syntax and Open SQL syntax (as of ABAP 7.40 SP05), key
words are not case-sensitive, client handling is identical, and comma-separated field lists
are used.
2. In SAP HANA SQL, it is mandatory to specify a schema before the table name.
Determine whether this statement is true or false.
X
True
X
False
Correct. A schema is not mandatory. If no schema is specified, the user’s default schema
is used.
3. Which of the following are supported types for parameters of AMDP methods?
Choose the correct answers.
X
A Numeric or character-like scalar types.
X
B Structure types with only scalar components.
X
C Table types with only scalar columns.
X
D Nested table types without secondary keys.
Correct. Numeric or character-like scalar types and table types with only scalar columns
are supported types for parameters of AMDP methods.
170
© Copyright. All rights reserved.
Unit 4: Learning Assessment - Answers
4. All ABAP objects used within the body of an AMDP method have to be listed after the
USING addition.
Determine whether this statement is true or false.
X
True
X
False
Correct. All ABAP objects used within the body of an AMDP method have to be listed after
the USING addition
5. Any AMDP method shipped by SAP can be extended using the AMDP BAdI technique.
Determine whether this statement is true or false.
X
True
X
False
Correct. Not all AMDP methods shipped by SAP can be extended using the AMDP BAdI
technique.
6. What can you do in ADT (ABAP in Eclipse) but not in the classical ABAP Workbench?
Choose the correct answers.
X
A Display an AMDP method implementation.
X
B Edit an AMDP method implementation.
X
C Test an AMDP method implementation.
X
D Debug an AMDP method implementation.
Correct. In ADT (ABAP in Eclipse), you can edit an AMDP method implementation and
debug an AMDP method implementation. You cannot do either of these in the classical
ABAP Workbench.
7. When executing a native SQL query via ABAP Database Connectivity (ADBC), which of the
following steps is optional?
Choose the correct answer.
X
A Create an instance of CL_SQL_CONNECTION.
X
B Create an instance of CL_SQL_STATEMENT.
X
C Create an instance of CL_SQL_RESULT_SET.
X
D None, all three are mandatory.
Correct. When executing a native SQL query via ABAP Database Connectivity (ADBC),
creating an instance of CL_SQL_CONNECTION is optional.
© Copyright. All rights reserved.
171
Unit 4: Learning Assessment - Answers
8. What happens if you forget to call method close( ) at the end of your query?
Choose the correct answers.
X
A You don’t forget a result.
X
B An exception is raised.
X
C DB resources remain blocked.
X
D Nothing.
Correct. If you forget to call method close( ) at the end of your query, DB resources remain
blocked.
9. The search function in the toolbar of SAP HANA studio searches in SAP HANA content
and in the SAP HANA catalog.
Determine whether this statement is true or false.
X
True
X
False
Correct. The search function in the toolbar of SAP HANA studio searches in both SAP
HANA content and the SAP HANA catalog.
10. You can use Data Preview in SAP HANA studio to test SAP HANA views and SAP HANA
stored procedures.
Determine whether this statement is true or false.
X
True
X
False
Correct. You do not use Data Preview in SAP HANA studio to test SAP HANA views and
SAP HANA stored procedures.
172
© Copyright. All rights reserved.
Unit 4: Learning Assessment - Answers
11. You want to access SAP HANA view CA_BOOKINGS_COUNT in package ha400.primdb via
a native SQL query. Which of the following are correct ways of specifying package path
and object name in the FROM clause?
Choose the correct answers.
X
A FROM _SYS_BIC.“ha400.primdb.::CA_BOOKINGS_COUNT”
X
B FROM “ha400.primdb::CA_BOOKINGS_COUNT”
X
C FROM _SYS_BIC.“ha400.primdb/CA_BOOKINGS_COUNT”
X
D FROM “ha400.primdb/CA_BOOKINGS_COUNT”
Correct. The correct ways of specifying package path and object name in the FROM clause
are FROM “ha400.primdb::CA_BOOKINGS_COUNT” and FROM _SYS_BIC.
“ha400.primdb/CA_BOOKINGS_COUNT”.
12. Which of the following object types in ABAP repository are proxy objects for SAP HANA
objects?
Choose the correct answers.
X
A Procedure Proxy
X
B Database View
X
C SQL View
X
D External View
Correct. The Procedure Proxy and External View object types in ABAP repository are
proxy objects for SAP HANA artefacts.
13. When creating a proxy object for an SAP HANA view, it is possible to specify data
elements for the view fields.
Determine whether this statement is true or false.
X
True
X
False
Correct. When creating a proxy object for an SAP HANA view, it is not possible to specify
data elements for the view fields.
© Copyright. All rights reserved.
173
Unit 4: Learning Assessment - Answers
174
© Copyright. All rights reserved.
UNIT 5
Advanced Topics
Lesson 1
Transporting SAP HANA Objects with ABAP Transport Requests
177
Lesson 2
Using SAP HANA Full Text Search
189
Lesson 3
ABAP List Viewer with Integrated Database Access (ALV IDA)
199
UNIT OBJECTIVES
●
Know the techniques for ABAP transport of SAP HANA objects
●
Understand SAP HANA Transport Container (HTC)
●
Use SAP HANA Transport for ABAP (HTA)
●
Use SAP HANA full-text search
●
Enable proposal search and fulltext search in a dictionary search help
●
Understand the vasics of SAP List Viewer with Integrated Data Access (ALV with IDA)
●
Describe the differences between ALV with IDA and classical ALV
●
Display data with ALV with IDA
●
Use select options in the data retrieval of ALV with IDA
●
Supply values for input parameters of views
© Copyright. All rights reserved.
175
Unit 5: Advanced Topics
176
© Copyright. All rights reserved.
Unit 5
Lesson 1
Transporting SAP HANA Objects with ABAP
Transport Requests
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Know the techniques for ABAP transport of SAP HANA objects
●
Understand SAP HANA Transport Container (HTC)
●
Use SAP HANA Transport for ABAP (HTA)
ABAP Transport of HANA Objects – Overview
Figure 137: Transport of SAP HANA Content – Delivery Units
One way to transport SAP HANA content is via a delivery unit (DU).
Each delivery unit must have a unique name and one or more content packages can be
assigned to the same delivery unit. When you create a new delivery unit, a vendor name is
automatically derived from the system settings and linked to the delivery unit. The SAP
vendor name is sap.com.
© Copyright. All rights reserved.
177
Unit 5: Advanced Topics
Figure 138: First Approach: Manual Synchronization of ABAP Transport and Delivery Unit
As soon as ABAP repository objects depend on SAP HANA objects, it becomes important to
synchronize the transport of SAP HANA content with the ABAP transport. Otherwise you risk
syntax errors or even runtime errors in the target system.
The usual means for transporting SAP HANA objects is the delivery unit. This approach has
two major problems:
●
●
178
The import of the delivery unit into the target system has to be synchronized manually. If it
is imported too early or too late or not at all, there will be inconsistencies in the target
system.
A delivery unit always transports complete SAP HANA content packages. It is not possible
to transport individual objects and packages – for example, only those that are new or
were changed since the last transport.
© Copyright. All rights reserved.
Lesson: Transporting SAP HANA Objects with ABAP Transport Requests
Figure 139: Approach as of Release 7.31: HANA Transport Container (HTC)
In release 7.31, SAP introduced the SAP HANA Transport Container (HTC). This new ABAP
repository object functions as a proxy object for an SAP HANA delivery unit. If an HTC is
included in the object list of an ABAP transport request, the corresponding delivery unit is
linked to the transport request too.
This allows you to synchronize the import of an ABAP transport request and the import of a
delivery unit into the target system.
Note:
The problem that there is no transport of individual SAP HANA objects remains. A
delivery unit always contains a set of complete content packages – whether the
objects were changed or not.
© Copyright. All rights reserved.
179
Unit 5: Advanced Topics
Figure 140: Approach as of Release 7.40 SP11: SAP HANA Transport for ABAP (HTA)
As of release 7.40 SP11, SAP offers the SAP HANA Transport for ABAP (HTA). The HTA
framework allows you to include individual SAP HANA objects to your ABAP transport
request. Of course, it is also possible to transport a complete SAP HANA package with all
contained objects and subpackages.
Note:
If you use HTA you can transport SAP HANA content without defining Delivery
Units.
Figure 141: HTC and HTA – Important Differences
180
© Copyright. All rights reserved.
Lesson: Transporting SAP HANA Objects with ABAP Transport Requests
Note:
If you are using HTC, you can continue to use it in a transition period. SAP
recommends, however, that you use HTA for transports of mixed ABAP and SAP
HANA content from Release 7.40 SP11.
SAP HANA Transport Container
SAP HANA Transport Container is an ABAP repository object introduced with SAP NetWeaver
7.31 that allows for the transport of SAP HANA content with an ABAP transport request,
provided the ABAP system uses SAP HANA as its primary database. Basically, it points to,
and represents, a delivery unit.
Figure 142: SAP HANA Transport Container – The Principle
Usage of SAP HANA Transport Containers
If you want to create or maintain an SAP HANA Transport Container (HTC), you have to use
the ABAP Development Tools (ADT) as follows:
●
●
In the context menu of the ABAP project or of an ABAP package, select New → [Other]
ABAP Repository Object.
Choose Others → HANA Transport Container.
Hint:
You can use the filter field to quickly find the correct repository object type.
© Copyright. All rights reserved.
181
Unit 5: Advanced Topics
●
Specify the ABAP package and the name of the SAP HANA delivery unit for which you want
to create the transport container. Note that the HTC name is automatically derived from
the name of the delivery unit.
When you create a SAP HANA Transport Container, you take a snapshot of the full contents of
the corresponding SAP HANA delivery unit and store a copy of it in the ABAP transport
request.
Figure 143: SAP HANA Transport Container – Snapshots
The snapshot is not updated automatically each time the contents of the delivery unit in SAP
HANA changes. The snapshot stored in the SAP HTC has to be kept in sync manually. To do
so, open the SAP HTC and choose Take Snapshot and Save.
As with most ABAP repository objects, you have to activate the SAP HTC before you can
transport it. The SAP HTC is inactive after you create it and each time you edit it, if you take a
new snapshot.
182
© Copyright. All rights reserved.
Lesson: Transporting SAP HANA Objects with ABAP Transport Requests
Figure 144: SAP HANA Transport Container – Unpacking in Target System
When transported and imported into a target ABAP system, the snapshot is unpacked, and
the SAP HANA content is deployed into the SAP HANA database and activated, provided the
following apply:
●
●
The importing ABAP system runs on SAP HANA as the primary database.
The software component to which the SAP HTC belongs is configured for automatic SAP
HTC deployment in the importing ABAP system, which means that it is listed in table
SNHI_DUP_PREWORK.
© Copyright. All rights reserved.
183
Unit 5: Advanced Topics
HANA Transport for ABAP (HTA)
Figure 145: HANA Transport for ABAP – Transaction SCTS_HTA
Use transaction SCTS_HTA to add SAP HANA content to an ABAP Workbench request.
First select an SAP HANA content package to get a list of the objects inside this package.
Choose Include subpackages if you want to see the objects in subpackages too.
The list provides a status icon for each package and object. A yellow triangle indicates that an
object is new or has been changed since last synchronization. A green rectangle shows that
this SAP HANA object is in sync. This means that it either has been transported or is already
included in the transport request and has not changed since then.
Choose either complete packages or individual objects to be synchronized. As a result, the
selected SAP HANA content is added to your transport request.
184
© Copyright. All rights reserved.
Lesson: Transporting SAP HANA Objects with ABAP Transport Requests
Figure 146: HANA Transport for ABAP – Objects in Workbench Request
In the transport request, three different types of objects can appear:
●
FULL PACKAGE (R3TR HOTA):
A complete package with all containing elements gets transported.
●
PACKAGE METADATA (LIMU HOTP):
A package gets transported but only with selected content or without any content at all.
●
SINGLE OBJECT (LIMU HOTO):
A single view or procedure gets transported.
Note:
It is not possible to transport a single object without the metadata of the
containing package. If you choose to transport a single object for which the
containing package has not yet been transported, the tool automatically adds the
package metadata to the transport request, as well.
Note:
The OBJECT NAME in the transport request is the package path plus object name
in SAP HANA content. If the package path exceeds a length of 40 characters, it
gets truncated. This can make it difficult to identify the objects in the transport
request. To avoid this, SAP recommends short package names and paths (shorter
than forty characters).
© Copyright. All rights reserved.
185
Unit 5: Advanced Topics
Figure 147: HANA Transport for ABAP – Deployment of imported Objects to SAP HANA DB
The following are the two options:
●
Option 1: Implicit deployment during import (default)
Prerequisite: Deployment mode of SAP HANA package is “A”
●
Option 2: Manual Deployment (TA SCTS_HTA_DEPLOY)
This may become necessary if the following are true:
-
-
Deployment mode of SAP HANA package is “P” (which means “requires prework
before deployment”).
Errors occurred during implicit deployment.
If an ABAP transport request contains HTA entries, the SAP HANA objects must be copied
from the application server to the database when the transport request is imported onto the
application server.
This is called deployment of the SAP HANA objects and it is done automatically as part of the
import of the transport request.
If this is not wanted (for example, because additional prework and checks are required on the
database), you can inhibit implicit deployment by setting the deployment mode of an SAP
HANA package to “P”.
Note:
You find the dialog for setting the deployment mode of a package in transaction
SCTS_HTA using the menu path Utilities → Set Deployment Mode.
For packages with deployment mode “P” and for the case of wrong or incomplete
deployments, you can use transaction SCTS_HTA_DEPLOY to execute or repeat a
deployment manually.
LESSON SUMMARY
You should now be able to:
186
●
Know the techniques for ABAP transport of SAP HANA objects
●
Understand SAP HANA Transport Container (HTC)
© Copyright. All rights reserved.
Lesson: Transporting SAP HANA Objects with ABAP Transport Requests
●
Use SAP HANA Transport for ABAP (HTA)
© Copyright. All rights reserved.
187
Unit 5: Advanced Topics
188
© Copyright. All rights reserved.
Unit 5
Lesson 2
Using SAP HANA Full Text Search
LESSON OVERVIEW
In this lesson, you learn the prerequisites for using full text search in SAP HANA, how to
configure a particular table column for full text search, and how to use the contains() and
score() functions in the SELECT statement to control the “Fuzzy” logic of full text search.
You also learn how you can enable automatic value proposals, called type-ahead, for input
fields on SAP GUI screens.
Business Example
Your company ITeLO wants you to improve the performance of some ABAP applications
considerably by making use of SAP HANA. The ABAP system has been migrated to use SAP
HANA as its primary database. In particular, your company wants you to improve the usability
of searches in string-like database columns.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Use SAP HANA full-text search
●
Enable proposal search and fulltext search in a dictionary search help
Fuzzy Search: Motivation and Prerequisites
Searching for particular strings in the database is often difficult for any kind of search other
than simple key values. Different ways of writing names, non-standardized abbreviations, and
the mere distinction between upper and lowercase letters render precise searching with the
equals operator ineffective.
© Copyright. All rights reserved.
189
Unit 5: Advanced Topics
Figure 148: Fuzzy Search – Sometimes Equals Is Not Enough
The search with equals returns none of the listed table entries in the figure, Fuzzy Search –
Sometimes Equals is Not Enough. This is a frequent problem with names of people and
companies – many names have a significant number of spelling variants, especially if they
have been transcribed into Latin script from a different system. The names of companies
often contain their legal form. The company name SAP Deutschland AG & Co KG is
particularly difficult to find, as it is not clear if it is SAP Deutschland or SAP Germany.
Figure 149: Fuzzy Search – Sometimes LIKE Is Not Enough
190
© Copyright. All rights reserved.
Lesson: Using SAP HANA Full Text Search
The LIKE operator provides us with a partial solution to the problem. However, it can still lead
to unsatisfactory results because matching table entries have to contain the exact search
term enclosed in wildcards. If you do not have a meaningful and 100% correct snippet of a
word or phrase, the result set can either be full of irrelevant hits (the snippet is too small to be
properly selective) or empty (the snippet did not completely match any of the records at all).
In our example, you will see that we have increased our hit ratio from 0 to one third.
Given the increasing amounts of unstructured data that are now being stored in databases,
both as text and as binary content, we need an effective way to search that provides us with a
degree of error-tolerance. It must be possible to find information even if there are slight
misspellings or many different ways of spelling a particular name. We even require searches
that identify the words going and went as related. All of this is possible using SAP HANA full
text search, supporting the options fuzzy (error-tolerant) search or linguistic (languagespecific) search.
Figure 150: Fuzzy Search – An Error-Tolerant Search
A fuzzy search for the name Schwartz finds not only the precise match, but also further
reasonable matches. A reasonable match would be the name Schwartz, followed by other
words in the same field, but also variations on the name itself – perhaps without the letter t at
the end. To do this, SAP HANA uses an algorithm that calculates the closeness of the match
to the original search string and represents it as a score between zero and one, where one is a
perfect match. In the fuzzy search itself, you can specify the lower threshold, below which hits
are no longer displayed, or you can use the default setting of 0.8.
© Copyright. All rights reserved.
191
Unit 5: Advanced Topics
Figure 151: Prerequisites for Fuzzy Search
To use to fuzzy search with good performance (and to use all other SAP HANA text search
features), full text indexes are required for the relevant table and columns.
To create a full-text index, the table in question must be column-stored. The most common
data type for which you will want to create such an index is NVARCHAR.
Creation of a Full-Text Index for Fuzzy Search
Figure 152: Creating the Index
The full-text index is a hidden column attached to the table that SAP HANA uses to perform
the search. SAP HANA can keep full-text indexes up to date either synchronously or
asynchronously. Asynchronous means that the index is only updated after a certain time
192
© Copyright. All rights reserved.
Lesson: Using SAP HANA Full Text Search
elapsed. Synchronous means that the index is updated immediately when inserting, updating,
or deleting a record, which also means that the insert, update, and delete statement
execution takes longer.
Hint:
Each full-text index that you create increases the footprint of the table in
memory. As an example, the database table SCUSTOM (around 4,000 entries)
requires approximately 25% more memory when the NAME column (type C
length 25) is fully indexed.
The index update mode also affects the index creation. Activating a full text index
with synchronous update mode for a table containing many entries already may
take a while.
Figure 153: Creating the Index in an ABAP 7.4 System
The most common data type for which you will want to create a full text index is NVARCHAR
(CHAR, STRING or SSTRING in ABAP). In this case, you can create the full text index as
follows:
●
●
In an ABAP release 7.4 SP03 or higher using SAP HANA as its primary database, you can
create the full text index using the ABAP Dictionary. Create an index as usual. Then choose
menu item Goto → Full Text Index. Select Full Text Index. Choose Fuzzy Search on if you
create the index to enable fuzzy search.
When using SAP HANA as a secondary database, you cannot create a full-text index in the
ABAP Dictionary, but must create it in the SAP HANA studio or using native SQL. To use
the SAP HANA studio, open the table definition in the SAP HANA studio. On the Indexes
tab, create a new index of type Full-Text. In the pane below, you then select whether the
index should be updated synchronously or asynchronously. Select the column that you
© Copyright. All rights reserved.
193
Unit 5: Advanced Topics
want to index, and select the Fuzzy Search checkbox. You then need to deploy the index by
choosing Execute.
Once the index has been created in the database, you can use it to perform a fuzzy search in
the SELECT statement.
Fuzzy Search Usage
You implement a fuzzy search using the CONTAINS() function in the WHERE clause of your
SELECT statement.
Figure 154: The CONTAINS() Function
The arguments of the function are the name of the column in which you want to search, the
search string itself, and the search type FUZZY. The search type itself may also take an
argument – a decimal value between zero and one denoting the minimum tolerance allowed.
FUZZY(1.0) would be an exact search. If you omit the argument, the default threshold of 0.8 is
used. The results are returned in the order in which they are found in the database, and not in
ranked order with the best match first.
Note:
The fuzzy search (and later the linguistic search) is only available in native SQL.
A further function that can be useful in the fuzzy search is SCORE().
194
© Copyright. All rights reserved.
Lesson: Using SAP HANA Full Text Search
Figure 155: The SCORE() Function
SCORE() is the ranking of each result in the result set. You can select the value into the result
set to display on the screen, or use it in the background in the ORDER BY clause to ensure that
the best hits appear at the top of the list.
Proposal Search and Fulltext Search
Figure 156: Search Helps with Proposal Search and Fulltext Search
Starting with ABAP 7.4 SP03, ABAP Dictionary search helps can be enhanced to support
proposal search. If this is enabled for an input field on a screen, the system automatically
proposes matching values when an end user starts entering a few characters. You can easily
identify input fields with proposal search: the system displays a magnifying glass in them.
© Copyright. All rights reserved.
195
Unit 5: Advanced Topics
Note:
If the cursor is already placed in the input field, the usual value help button may
shadow the magnifying glass.
Proposal search is available on all database systems supported by ABAP. However, it
provides most value if combined with a (fuzzy) fulltext search. Fulltext search is currently only
supported on SAP HANA databases.
A prerequisite for enabling proposal search is a system based on ABAP 7.4 SP05 or higher
and SAP GUI 7.30 Patch Level 05 or higher. In addition, no PROCESS ON VALUE-HELP event
must exist that overrides the search help attached to the field.
A prerequisite for enabling fulltext search is a SAP HANA database and an elementary search
help based on a column-store table or a CDS view.
Figure 157: Enabling Proposal Search With Fulltext Search for SAP GUI
To enable proposal search for an input field on a screen, first identify the ABAP Dictionary
search help attached to the field. To do so, you can use the field help, navigate to the
Technical Information and on to the Dictionary. If you find a collective search help attached,
navigate to the first suitable elementary search help contained in the collective search help.
Adjust the elementary search help, as follows:
●
●
●
196
Switch on Proposal Search for Input Fields to enable proposal search. This works on all
database systems, and leads to proposals based on the existing values of the field itself
and an exact search using a LIKE query with wildcards.
Switch on Multi-Column Fulltext Search (Database-Specific) to make value proposals
based on a fuzzy search.
Adjust the Accuracy Value for Error-Tolerant Full Text Search if necessary.
© Copyright. All rights reserved.
Lesson: Using SAP HANA Full Text Search
Note:
In ABAP systems before 7.4 SP06, you have to enable proposal search explicitly in
the screen. This is done by calling method
cl_dsh_dynpro_properties=>enable_type_ahead(...) in a PBO module
of the screen, or by adding attribute typeahead with value X directly to the
custom properties of the input field.
LESSON SUMMARY
You should now be able to:
●
Use SAP HANA full-text search
●
Enable proposal search and fulltext search in a dictionary search help
© Copyright. All rights reserved.
197
Unit 5: Advanced Topics
198
© Copyright. All rights reserved.
Unit 5
Lesson 3
ABAP List Viewer with Integrated Database
Access (ALV IDA)
LESSON OVERVIEW
In this lesson, you learn the benefits of SAP List Viewer with Integrated Data Access (ALV with
IDA), which is optimized for SAP HANA, and to describe the differences between ALV with IDA
and classical ALV. You also learn to display data in ALV with IDA, use select options in the data
retrieval of ALV with IDA, and supply values for input parameters of the external view.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Understand the vasics of SAP List Viewer with Integrated Data Access (ALV with IDA)
●
Describe the differences between ALV with IDA and classical ALV
●
Display data with ALV with IDA
●
Use select options in the data retrieval of ALV with IDA
●
Supply values for input parameters of views
SAP ABAP List Viewer (ALV) with Integrated Data Access
We already know that in-memory databases like SAP HANA can lead to significant
performance improvements when processing large quantities of data. Users should benefit
from the required data being displayed more quickly, and the ability to manipulate their view
of that data in different ways.
Sometimes you have user interfaces producing larger lists of objects, for example a UI listing
all open invoices. Generating such lists can be time-consuming, especially if they include
calculated columns, and end users may also need patience when working interactively with
the lists to group or sort entries or include aggregates.
This leads to the question: how can the user experience be improved?
In order to make this possible, SAP has designed a special version of the ALV, the SAP List
Viewer with Integrated Data Access (ALV with IDA). This variation of the ALV is optimized for
use with SAP HANA.
© Copyright. All rights reserved.
199
Unit 5: Advanced Topics
Basic Principles and Advantages
What is SAP List Viewer with Integrated Data Access (ALV with IDA)?
●
●
Basic principles:
-
Only retrieve, from the database, data which is to be displayed on the screen.
-
Use database services where possible – ALV features pushed down to the database.
-
Data described declaratively instead of passing big internal tables.
Advantages:
-
Retrieval of results is much faster.
-
Better performance and reduced memory consumption.
-
Improved user experience.
How ALV Works
Figure 158: ALV Optimized for SAP HANA
The SAP List Viewer with Integrated Data Access (ALV with IDA) offers ABAP developers the
option to take advantage of SAP HANA, without having to present the user with a new or
different interface. Using the ALV with IDA, it is possible to display huge amounts of data, with
the expected sorting and grouping functions that users are familiar with, but without big
performance issues. Other functions that have been used in the ALV for a long time, such as
the ability to aggregate data, are still available in the ALV with IDA. From the perspective of
the user, the familiar ALV functions are therefore enhanced by the advantages of using SAP
HANA.
The ALV with IDA is based on the following principles:
200
© Copyright. All rights reserved.
Lesson: ABAP List Viewer with Integrated Database Access (ALV IDA)
●
●
Only select the data in the database that is supposed to be displayed. That is, apply data
filtering, even paging, in the database, so that only a small data set is returned to the ABAP
stack and passed through, more or less unchanged, to the UI.
In addition, all calculations such as aggregating and grouping data, or adding columns
whose values are computed from the other columns, should be performed in the database.
The latter can be achieved by using CDS-based views.
The figure, Classical ALV, illustrates how these principles are quite different from how
classical ALV works.
In order to ensure that only the data to be displayed is retrieved from the database, it is
necessary to specify the constraints or conditions that should be used to restrict the data
before it is selected. This is made possible by using dedicated methods that allow you to
declare these constraints in the form of parameters, for example, classical ABAP ranges.
However, more complex conditions can also be expressed.
As a result, the data is retrieved much faster on SAP HANA, and you also need far less
memory on the ABAP stack.
Figure 159: Classical ALV
The figure, Classical ALV, shows the approach to displaying data using the classical ALV. The
steps shown provide an example of what the ABAP application would typically do, as follows:
1. The application performs authorization checks and extracts relevant data from the
database into an internal table.
2. Business data, such as calculated fields, can then be added to the internal table contents.
3. UI information (icons, links, and so on) may also be added.
4. The internal table is passed to the ALV services, which then manipulate the data according
to user requirements.
5. The required data is displayed on the screen.
© Copyright. All rights reserved.
201
Unit 5: Advanced Topics
Technical Differences Between ALV with IDA and Classical ALV
Figure 160: Problems with Classical ALV
For an end user, working with large amounts of data in a classical ALV can be cumbersome
and time-consuming. The issue is that it is optimized for the old paradigm and constraints,
where the database is considered the bottleneck. Behind the scenes, the classical ALV
requires all data to be first loaded into an internal table in order to display it, and typically this
is larger than what is actually displayed to the user in the end. This initial load can lead to very
long waiting times for the end user, or even short dumps due to memory consumption. Due to
these issues, the user may restrict the amount of data beforehand, leading to incomplete data
sets.
Once the data is loaded, all processing takes place in the ABAP stack on the internal table, for
example, sorting the data set, filtering the data set, grouping, aggregating, or adding
calculated columns. Even paging through the result set happens in the ABAP stack. All of
these processing steps can take a long time, and again consume a large amount of memory
when dealing with large amounts of data.
Clearly, the way in which the classical ALV works contradicts how you can benefit most from
SAP HANA, namely by performing the data-intensive calculation close to the data, in the
database. This is the reason for the new variant of the SAP List Viewer.
202
© Copyright. All rights reserved.
Lesson: ABAP List Viewer with Integrated Database Access (ALV IDA)
Figure 161: ALV Optimized for HANA
The ALV with IDA, optimized for HANA, is significantly different to the classical ALV.
Authority checks, table functions, and other processes that were previously carried out by the
application are now performed by the database. The application only has to pass the details to
the new ALV API (IDA – Integrated Data Access); for example, a WHERE clause can be sent to
the database by calling relevant methods.
Additional UI information is still handled by the application.
The amount of data is severely restricted by the database before it is displayed on the UI, and
there is no longer a need to store the displayed data inside an internal table.
Package SALV_IDA_TEST contains sample programs using the ALV with IDA.
© Copyright. All rights reserved.
203
Unit 5: Advanced Topics
End User Perspective
Figure 162: ALV with IDA: End User Perspective
The ALV with IDA will look and feel familiar to end users who have worked with the classical
ALV, but there are some small differences in functionality and behavior.
Figure 163: Feature Availability in ALV with IDA
204
© Copyright. All rights reserved.
Lesson: ABAP List Viewer with Integrated Database Access (ALV IDA)
Figure 164: Feature Availability in ALV for SAP HANA II
Instantiation of ALV with IDA
Figure 165: Coding Example Instantiation of ALV Optimized for HANA
The example in the figure, Coding Example: Instantiation of ALV with IDA, shows how you can
instantiate ALV IDA. Two different factory methods exist, depending on the data source the
ALV instance should read data from. Use method CREATE for database tables, database
views and external views. Use method CREATE_FOR_CDS_VIEW to specify a CDS view.
Note that, rather than passing an internal table containing the data to be displayed, only the
name of the database table (or external view/CDS view) needs to be supplied via the import
parameter.
© Copyright. All rights reserved.
205
Unit 5: Advanced Topics
Display of ALV with IDA
Figure 166: Display of ALV with IDA
There are two different ways to invoke the display of ALV with IDA.
You can use import parameter IO_GUI_CONTAINER of the CREATE-methods to link the ALV
with IDA instance to a container control. In that case, you have to create an instance of the
container control class BEFORE you instantiate the ALV with IDA class. To invoke the display,
you have to call the DISPLAY method of the ALV with IDA instance once.
ALV with IDA also offers a stand-alone display. In this case you don't have to instantiate a
container control. Simply call method FULLSCREEN( ) of your ALV with IDA instance and
method DISPLAY of the instance this method returns.
Select Options
For large amounts of data, it is important that a user has the option to restrict the amount of
data that is displayed using a selection screen.
The data retrieval (using selection options) and display are done by ALV with IDA. The
selection made by the user is transferred to the list using method set_select_options. Use
method add_ranges_for_name of class CL_SALV_RANGE_TAB_COLLECTOR to convert the
selection of the user to the format that is needed for the method set_select_options.
206
© Copyright. All rights reserved.
Lesson: ABAP List Viewer with Integrated Database Access (ALV IDA)
Figure 167: Select Options
Views with Input Parameters
ALV with IDA can work with CDS views that have input parameters. In order for the ABAP
application to supply values for these input parameters, they must be passed to the ALV as
name-value pairs by calling the method SET_VIEW_PARAMETERS.
Figure 168: ALV with IDA Using a View with Parameter
© Copyright. All rights reserved.
207
Unit 5: Advanced Topics
Using Fuzzy Search
You may want to provide a selection screen in the ABAP application that provides the user
with the ability to enter a search term for which they wish to perform a fuzzy search. The ALV
API provides methods to do this, as shown in the figure, Fuzzy Search Functionality in ALV
with IDA.
Figure 169: Fuzzy Search Functionality in ALV with IDA
This type of search was not possible with the classical ALV.
LESSON SUMMARY
You should now be able to:
208
●
Understand the vasics of SAP List Viewer with Integrated Data Access (ALV with IDA)
●
Describe the differences between ALV with IDA and classical ALV
●
Display data with ALV with IDA
●
Use select options in the data retrieval of ALV with IDA
●
Supply values for input parameters of views
© Copyright. All rights reserved.
Unit 5
Learning Assessment
1. To include SAP HANA content into an ABAP transport request, SAP recommends using an
SAP HANA Transport Container (HTC) instead of the SAP HANA Transport for ABAP
(HTA) technique.
Determine whether this statement is true or false.
X
True
X
False
2. You want to perform an SAP HANA full-text search on column COL of database table TAB.
Which of the following conditions have to be fulfilled?
Choose the correct answers.
X
A Table TAB is located in column store.
X
B Column COL is of type TEXT or SHORTTEXT.
X
C A full text index exists for column COL of table TAB.
X
D The application server release is 7.40 SP05 or higher.
3. Proposal search (= type ahead search) is supported on all database systems.
Determine whether this statement is true or false.
X
True
X
False
4. ABAP List Viewer with Integrated Data Access (ALV with IDA) is only supported for SAP
HANA database.
Determine whether this statement is true or false.
X
True
X
False
© Copyright. All rights reserved.
209
Unit 5: Learning Assessment
5. Which of the following ABAP repository objects can be the data source for ALV with IDA?
Choose the correct answers.
X
A Transparent table
X
B Database view
X
C CDS view
X
D External view
6. Which of the following features are NOT supported by ALV with IDA?
Choose the correct answers.
210
X
A Personalization
X
B Editing values
X
C Excel export
X
D Double-click
© Copyright. All rights reserved.
Unit 5
Learning Assessment - Answers
1. To include SAP HANA content into an ABAP transport request, SAP recommends using an
SAP HANA Transport Container (HTC) instead of the SAP HANA Transport for ABAP
(HTA) technique.
Determine whether this statement is true or false.
X
True
X
False
Correct. To include SAP HANA content into an ABAP transport request, SAP recommends
using the SAP HANA Transport for ABAP (HTA) technique.
2. You want to perform an SAP HANA full-text search on column COL of database table TAB.
Which of the following conditions have to be fulfilled?
Choose the correct answers.
X
A Table TAB is located in column store.
X
B Column COL is of type TEXT or SHORTTEXT.
X
C A full text index exists for column COL of table TAB.
X
D The application server release is 7.40 SP05 or higher.
Correct. To perform an SAP HANA full-text search on column COL of database table TAB,
table TAB must be located in column store, and a full text index must exist for column COL
of table TAB.
3. Proposal search (= type ahead search) is supported on all database systems.
Determine whether this statement is true or false.
X
True
X
False
Correct. Proposal search (= type ahead search) is supported on all database systems.
© Copyright. All rights reserved.
211
Unit 5: Learning Assessment - Answers
4. ABAP List Viewer with Integrated Data Access (ALV with IDA) is only supported for SAP
HANA database.
Determine whether this statement is true or false.
X
True
X
False
Correct. ABAP List Viewer with Integrated Data Access (ALV with IDA) is supported for
multiple databases.
5. Which of the following ABAP repository objects can be the data source for ALV with IDA?
Choose the correct answers.
X
A Transparent table
X
B Database view
X
C CDS view
X
D External view
Correct. All of these ABAP repository objects can be the data source for ALV with IDA.
6. Which of the following features are NOT supported by ALV with IDA?
Choose the correct answers.
X
A Personalization
X
B Editing values
X
C Excel export
X
D Double-click
Correct. Personalization, Microsoft Excel support, and double-click are supported by ALV
with IDA. Editing values is not supported.
212
© Copyright. All rights reserved.
UNIT 6
Case Study: Optimize a Report
on Flight Customer Revenue
Lesson 1
Optimizing a Report with CDS View and ALV IDA
215
UNIT OBJECTIVES
●
Optimizing a report with CDS view and ALV with IDA
© Copyright. All rights reserved.
213
Unit 6: Case Study: Optimize a Report on Flight Customer Revenue
214
© Copyright. All rights reserved.
Unit 6
Lesson 1
Optimizing a Report with CDS View and ALV
IDA
LESSON OVERVIEW
In this lesson, you learn how to optimize a classical report for SAP HANA.
Business Example
Your company has recognized SAP HANA as an important strategic topic and has asked you
to refresh your ABAP skills, paying particular attention to those required to develop or review
code that leverages the strengths of SAP HANA.
LESSON OBJECTIVES
After completing this lesson, you will be able to:
●
Optimizing a report with CDS view and ALV with IDA
LESSON SUMMARY
You should now be able to:
●
Optimizing a report with CDS view and ALV with IDA
© Copyright. All rights reserved.
215
Download