Beyond the Book: SAP HANA native artifacts vs. ABAP artifacts for SAP HANA. What should I use?
This blog is for ABAP developers who use SAP HANA from an ABAP application server.
I am Peter Walters, Principal Education Consultant working for SAP America since 1997. I teach ABAP, HANA, SAPUI5, and WebDynpro ABAP/FPM.
Starting with Application Server ABAP 7.x, ABAP can access SAP HANA side-by-side Scenarios.
Starting with Application Server ABAP 7.31, ABAP can run on SAP NetWeaver BW on SAP HANA.
Starting with Application Server ABAP 7.40, optimized ABAP can run on SAP HANA Primary database for Application Server ABAP.
To improve the performance to the database, you will probably use the HANA artifacts, such as, attribute view, analytic views, calculation views, and database procedures. ABAP 7.40 provides more support in accessing the HANA artifacts, by allowing to use Open SQL to access the HANA view exposed to ABAP Dictionary. ABAP for SAP HANA artifacts, such as external view, database procedure proxies, Code Data Services (CDS), and ABAP Managed Database Procedures (AMDPs).
You might have to deal with different scenarios based on SAP HANA version, ABAP Application Server version (including different support packs), or SAP HANA being the primary or the secondary database, and questions like these will be asked by the ABAP developer:
- When should I use one artifact vs. the other one that seems similar
- What decides what I can use in the first place
- If I could use anyone of those SAP HANA or ABAP for HANA artifacts, what will be the recommendation?
This blog tries to answer the questions raised above. Sure, there are other artifacts provided by SAP HANA, but the blog will just focus on the following:
SAP HANA native artifacts (HANA Repository Objects)
HANA Database Procedure.
ABAP artifacts for SAP HANA (ABAP Repository Objects):
External Views Proxies
Database Procedures Proxies
ABAP Managed Database Procedures
ABAP artifacts for Any DB supported by SAP (ABAP Repository Objects):
Core Data Services (CDS)
Data Control Language (DCL)
CDS Table Functions
What artifacts you would use from the list above is decided, in the first place, by the version of your ABAP Application Server.
If your ABAP AS version is less than 7.40 SP02, you can use only the native SAP HANA artifacts (attribute view, analytic view, calculation view, database procedure) from an ABAP program. And you will use HANA Native SQL to do that.
To call them is recommended to use the ABAP Database Connectivity API, for short ADBC, instead of EXEC SQL…ENDEXEC. As an API, ADBC allows determining where native SQL calls are used and supports handling exceptions. It is flexible, object-oriented, and still not difficult to use as only three main classes are relevant in most cases.
To transport the native HANA artifacts together with the ABAP programs that use them,
follow these steps:
- Create aPackage (SAP HANA Modeler perspective – Eclipse plug in)
- Create the View and attach it to the Package (use SAP HANA Modeler perspective)
- Create aDelivery Unit and attach the Package to it (use SAP HANA Modeler perspective)
- Create aHANA Transport Container (use ABAP Development Tools perspective) and choose the ABAP Transport Request to attach it to it.
- Before releasing the ABAP Transport Request, take a snapshot of the HANA Transport Container (use ABAP Development Tools perspective)
Starting with ABAP 7.40 SP02, you can create External Views Proxies in the ABAP dictionary, exposing native HANA view to ABAP Dictionary.
To create an External View, you must use the ABAP Development Tools.
To call the native HANA View exposed by the External View you will use the new, extended ABAP Open SQL.
Starting with ABAP 7.40 SP02, you can create Database Procedure Proxies in the ABAP dictionary, exposing SAP HANA native database procedures to ABAP Dictionary.
To create a Database Procedure Proxy, you must use the ABAP Development Tools.
To call the SAP HANA native database procedure exposed by the Database Procedure Proxy you will use the new, extended ABAP Open SQL.
Starting with ABAP 7.40 SP05, Extended Open SQL, Core Data Services (CDS) and ABAP Managed Database Procedures (AMDP), are fully available.
Also, SAP HANA is the primary database for the ABAP system.
Core Data Services (CDS) Advantages:
- Use SQL expressions, grouping and filtering
- Use built-in SQL functions
- CDSs can be nested
- Use aggregations
- Use additional join types
- UNIONs and UNION ALL
- Use new, extended Open SQL to select data
- Input parameters
- Enhance CDS views
- Associations and path expressions are available
- Domain-specific Annotations to provide domain specific semantics, domains such as ABAP, BW, BO, BOL, BOPF, OData, SAPUI5, etc
- Link a CDS with Authorization rules
- Generate OData service
- Follows the standard ABAP transport (CTS)
To create and maintain Core Data Services you must use the ABAP Development Tools. The ABAP Dictionary exposed proxy is called a DDL SQL View.
ABAP-managed database procedures Advantages:
- Expression of complex logic (incl. if/else, FOR loops, …)
- Local variables
- Parameterized requests
- Multiple result sets
- AMDP classes and AMDP methods
- Called like any other regular ABAP methods
- Modification-free extension via AMDP BAdIs
- Procedure created at first AMDP call
- Detailed analysis of runtime errors in ST22
- Static syntax check and syntax coloring for SQLScript code
- Background coloring for embedded languages
- Debug the AMDP’s SQL Script
- Follows the standard ABAP transport (CTS)
If the current database of an AS ABAP is an SAP HANA database, creating SAP HANA native database procedure proxies is no more recommended. The feature becomes obsolete with ABAP 7.4 SP05 – instead, use AMDPs.
ABAP Managed Database Procedures are the replacement technology for database procedure proxies.
(Please remember that we are talking about ABAP for HANA, not the “native” HANA where all HANA artifacts are still created – HA300 – SAP HANA Modeling)
Database procedure proxies are still recommended when using a secondary database connection to access SQL Script procedures that exist in a secondary SAP HANA database.
The AMDP classes can only be edited with the ABAP Development Tools (ADT).
The AS ABAP logged on to the HANA requires the correct authorizations to manage database procedures using AMDP. Missing authorizations can be detected using transaction SICK.
Currently, AMDP only supports database procedures from the SAP HANA database.
Programming Guidelines for ABAP Application Server 7.40 support pack SP05 or higher
- Use Core Data Services views for reusability reasons and to provide domain-specific annotations
- If the previous approach is not enough, use ABAP Managed Database Procedures (AMDP) – For SAP HANA database specific)
- Use Extended ABAP Open SQL
In the end, I hope that the blog brings clarity to the multiple options ABAP developers have today to use SAP HANA.
SAP Education offers two classes for ABAP developers for SAP HANA:
HA400 – ABAP Programming for SAP HANA
For SAP HANA native developers we provide:
Feel free to ask questions or start a discussion about this subject.