Understanding evolution of CDS and AMDP in most simple way
After reading this blog reader would have a clear idea why SAP recommends CDS views, what is AMDP and what are the benefits of CDS and AMDP over other methods.
As we all know HANA works on Push down techniques means, to make HANA DB do the calculations which was earlier done by application layer in ECC.
Further, Push down technique can be achieved using two approaches:
- Bottom-Up approach
- Top-Down approach
1. Bottom-Up approach :
Here In Bottom-Up, we create views (Calculation view, Attribute view, Analytic view) at HANA DB layer with HANA Modelling and these views are later exposed and used in ABAP layer via external views.
External Views :
- Read only
- Monitored by ABAP dictionary
- Can be used in ABAP programs to access data available in the form of Information Views in SAP HANA DB.
- More optimized than stored procedures. (discussed below)
- Create HANA view in DB layer
- Create external view
- Use external view in application
So, this is how we use Bottom-Up approach.
Note: Before ABAP 7.4 we were using external view approach.
Question?? Why SAP recommends Top-Down approach
2. Top-Down approach :
In Top-Down, we create objects using ABAP code that can leverage power of SAP HANA. Here comes CDS and AMDP into picture.
What are we doing in Top-Down?…We are creating models in application layer and it is going to create same in DB layer. Its like, we are using door of application layer to create objects/models in HANA DB.
Drawbacks of Bottom-Up approach :
- Need additional license to create views in DB layer (For ABAP and HANA db both)
- Dual maintenance
- Synchronization of changes (If any change made in DB layer (models) it should be reflected in App. layer)
- Transport Management (need separate transports to move across ABAP and HANA db if any changes made in both)
- Additional license cost (maintaining both HANA and ABAP layer)
This answers to the question why SAP recommends Top-Down approach.
As we know now Top-Down has benefit over Bottom-Up. So, whatever we were achieving via Bottom-Up we will be achieving same by Top-Down.
In Bottom-Up, we were creating views and later using them in our application layer by exposing them i.e. creating external view. Now, in Top-Down, we achieve this via CDS. We create CDS views in ABAP layer and as we activate or execute the same 2 views created.
- ABAP View (at DDIC layer), also called DDL SQL view
- HANA View (at HANA DB layer)
Other part was Procedures, we were writing procedures in Bottom-Up approach, directly in HANA DB using native SQL query. Procedures are written if the business requirement is complex and same can’t be achieved via information views.
For exposing Procedures, we can’t use external views so for that we were using stored procedure proxy.
Bottom line :
- For views in Bottom-Up, replacement in Top-Down was CDS
- For Procedures in Bottom-up, replacement in Top-Down is AMDP
CDS (Core Data Services) :
- Defined in ABAP repository using SQL DDL syntax
- use open SQL language
- CDS is executed as a single statement, hence we can’t put a debugger inside.
AMDP (ABAP Managed Database Procedures) :
- Simple ABAP class method containing DB specific procedure coding.
- use native SQL language
- Activate AMDP debugger :: Terminate AMDP debugger
- The code within the method is pushed to the DB layer and executed within the DB
- Should be used only if DB specific functions that do not exist in open SQL needed to be accessed.
CDS VS AMDP :
- In AMDP, we can call one function inside the other, it is helpful in returning multiple result set on complex logics. Whereas, CDS is dedicated for single set of logic and return only one result set.
- CDS views can be created to read and process data at DB layer. Whereas AMDP can be created to process and modify data at DB layer.
- AMDP is used to work with stored procedures, which further go to HANA DB layer and execute that. This functionality can’t be achieved by Open SQL and CDS.
Common features/ Benefits of CDS and AMDP :
- We are creating/using DB Procedures in AMDP and views in CDS without having access of HANA DB layer.
- AMDP and CDS can be created in eclipse only not in GUI as ADT (ABAP Development Tool) plug-in is needed for this (also in HANA Studio).
- CDS and AMDP does not need HANA license, when it is executed first time, it automatically create views and procedures respectively in HANA DB. Next time it will take same from HANA DB buffer.
- Transferring data to other systems, CDS will create views and AMDP will create procedures automatically in the new system.
Note: CDS Views are compatible with any database whereas AMDP needs HANA as a database and this is the reason CDS is more popular and is in demand.