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.
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.
The powerful features of native SQL, such as currency conversion and CE functions, can be leveraged.
Editor’s note: This content was originally posted on the SAP PRESS Blog and has been adapted from a section of the book ABAP Development for SAP HANA by Mohd Mohsin Ahmed and Sumit Dipak Naik. Used with permission of SAP PRESS. All rights reserved.
Comments