Beyond the Book: SAP HANA native artifacts vs. ABAP artifacts for SAP HANA.
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)
Attribute View,
Analytic View
Calculation View
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:
HA150 – SQL and SQL Script Basics for SAP HANA
HA400 – ABAP Programming for SAP HANA
For SAP HANA native developers we provide:
HA450 – Application Development for SAP HANA
Feel free to ask questions or start a discussion about this subject.
Great stuff Peter! Thanks for sharing!
Thank you Imran!
It was very helpful!
Thank you
Thank you Pablo!
Good overview! All options nicely summarized ...
perfect and to the point.
Thanks for sharing .
Good document ! Very helpful .. Please share your thoughts on ...
Can we create External view from HANA Artifact with Input parameters ?
External views can only be created using the ABAP Development Tools (ADT) and only if the current database is an SAP HANA database. When an external view is activated, an alias with the name of the view is created on the SAP HANA database that points to the SAP HANA view. The names of the view fields of the external view can be defined differently from the names of the view fields of the SAP HANA view. The runtime object of the external view accesses the alias on the SAP HANA database. This performs a mapping of HANA-specific data types to the predefined types in ABAP Dictionary.
The following restrictions currently apply to the use of external views in ABAP programs:
External views should only be used in those cases that are not covered by ABAP CDS or AMDP.
External Views with Input Parameters
The ALV optimized for HANA can work with External Views that have been published to the ABAP Dictionary. The HANA view on which the External View is based on may have input parameters that are used as filters, in calculations, or in scripted logic. 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. The query engine transforms these into suitable HANA placeholders and uses them during selection.
Thank you so much Peter !
I have tried external view with input parameters by passing name , value to the method SET_VIEW_PARAMETERS .It worked out . Have one question .
Do we need to pass the parameter value explicitly ? can't we get a pop up for choosing the parameter values like in HANA views ?
You can create a Selection Screen for the ABAP program that uses the view with PARAMETERS, and pass the parameter names to the internal table passed to SET_VIEW_PARAMETERS method instead of typed in values. This way you allow the user to choose the value.
Hi Peter
Can we achieve Interactive report with ALV IDA ? in SP10 release ?
Not yet. So far, ALV for HANA (ALV IDA) doesn't support double click.
Thank you Peter !
Thanks Peter ! I got it .
Hi Peter
I have few more questions ..
1. Can we perform CONDENSE operation inside select query ? if yes from which ABAP release it is supported ..
2. Suppose I have requirement to trigger outbound idoc and report output , can we achieve both using ALV with IDA ? Using ALV classes we can only pass table or view & Idoc can be triggered from internal table .. is there a way to achieve both ?
Regards
Satya
1. The CONDENSE ABAP statement and the condense Built-In Function are not part of the ABAP Open SQL. They are provided in ABAP language since SAP NetWeaver Application Server 7.02 version.
SQL Functions were expanded in the 7.50 version with:
- new numeric function - ROUND
- new STRING functions, such as CONCAT, LPAD, LENGTH, LTRIM, REPLACE, RIGHT, RTRIM and SUBSTRING (But NOT CONDENSE!)
- COLASCE function was extended to support 255 arguments instead of just 2.
2. This can be done in 2 steps:
a) The existing function modules that transport the outbound IDocs use internal tables. So you need to get data from HANA table(s) or view to populate the internal table that will be then passed to the IDoc function module.
b) Then you can use the SALV IDA methods to output the same data in ALV format from the same HANA table(s) or view. You don't need to (re)populate an internal table for the ALV list.
I'm not aware of any combination of this two steps.
Please take a look at the package SALV_IDA, and especially to its subpackage SALV_IDA_TEST. You'll find numerous demos provided by SAP development using the ALV optimized for HANA.
Thank you Peter
1. I have a situation CONDENSE the field in select query ( just like aggregation function SUM with alias name ) can be used further .. like in CASE statement .
In the 2 nd query , hitting the data base for the sames data twice will not be performance issue?
Could you please show me your SELECT statement?