Programming

ABAP SQL Versus CDS Views and AMDPs: What to Use?

There are several code pushdown techniques, namely, ABAP SQL, CDS views, and AMDPs. You may wonder which technique is the best.

 

First, let’s be clear that ABAP SQL, CDS views, and AMDPs are not competitors. All these techniques are available for an ABAP developer to use as needed, and all these techniques can help achieve the shift to the code-to-data paradigm.

 

All these techniques are for data retrieval from databases. An important question arises when to use a certain technique, under certain circumstances. Let’s discuss several different scenarios best suited for each technique. If the data fetch is for a specific object and will not be used/reused elsewhere, we recommend using ABAP SQL.

9

CDS Views

Core data services (CDS) are used in the next generation of data definitions, capable of defining semantically rich database tables/views (CDS entities) and providing access for database-centric applications. These views are technically extensions of SQL where expressions can be used on fields, domain-specific metadata can be defined, and associations created between related tables. Newly defined CDS entities and their metadata are extensible and optimally integrated into the ABAP Dictionary and the ABAP language.

 

Thus, when required to fetch data related to an entity from related tables with foreign key relationships, a best practice is to create a CDS view. This CDS view could simply involve joins on the related tables. CDS views involve the least amount of coding and can be reused in multiple objects across developments. In other words, a CDS view is a database artifact that can be consumed across objects/applications.

 

ABAP-Managed Database Procedures (AMDP)

An AMDP is a piece of code executed in the SAP HANA layer. The data it fetches includes some part of business logic to be performed on the fetched data. Usually, the business logic will be performed on vast amounts of data.

 

As shown in the figure below, when multiple result sets are needed and are part of the functionality, the fetches on the database table might or might not be related. In other words, independent SQL statements are not often used in other objects.

 

Flow Chart for Selecting the Relevant Code Pushdown Technique

 

The powerful features of native SQL, such as currency conversion and CE functions, can be leveraged.

 

Editor’s note: This post has been adapted from a section of the book ABAP Development for SAP HANA by Mohd Mohsin Ahmed and Sumit Dipak Naik.

Recommendation

ABAP Development for SAP HANA
ABAP Development for SAP HANA

This step-by-step developer’s guide has everything you need to build SAP HANA-optimized ABAP applications. Explore the environment and tools you’ll be using and master development techniques that govern the code-to-data paradigm in SAP HANA. Then jump into backend programming using ABAP Database Connectivity, SQLScript, ABAP-managed database procedures, core data services, and more. Once you’ve coded your apps, maintain them with runtime statistics, traces, and code analysis. Build it your way!

Learn More
SAP PRESS
by SAP PRESS

SAP PRESS is the world's leading SAP publisher, with books on ABAP, SAP S/4HANA, SAP CX, intelligent technologies, SAP Business Technology Platform, and more!

Comments