How to consume HANA Calculation views in S/4HANA CDS views
In this blog you will learn how to consume the HANA Calculation Views inside a S/4HANA CDS views.
Consider a scenario where business already have report based Enterprise HANA calculation view and now they want to consume same view in S/4 HANA CDS view with additional functionalities and business logic. Below are the steps which we need to follow to achieve above use case.
Steps to be followed:
- Create Calculation view in E-HANA.
- Test view output in HANA using native SQL.
- Create CDS table function.
- Create AMDP function for calling HANA native query on calculation view.
- Expose result to outer CDS with business logic.
So, let’s start building:
Step 1: Create a Calculation View
- Open Eclipse/ HANA Studio
- Select system and expand content folder and choose package where calculation view needs to be created.
- Right Click and Create New Calculation View.
- Add required tables/ views and select columns as per logic. In the View Properties make Default Client = Cross Client and Apply privileges as blank if not required.
- Now save and activate the view.
Step 3: Creating CDS Table Function
- Open ABAP perspective from Eclipse/ HANA Studio
- Select system and choose package where CDS data definition of type table function needs to be created.
- Create a table function by right clicking on the Package and select New other ABAP Repository object-> Data Definition and provide name and description then select next
- Choose the template “Define Table Function with Parameters” and say finish.
- Add required fields from HANA calculation view with data type as below and give AMDP class and function name which will create in next step and activate it.
Step 4: Create AMDP function for calling HANA native query on calculation view
- Select package where AMDP Class needs to be created.
- Create AMDP Class by right clicking on the Package and select New ABAP Class and provide name and description then click finish.
- Write AMDP Class as below by specifying “interfaces if_amdp_marker_hdb” statement with addition of defining function in public section. In the return statement of function definition use the SQL query that we used in step 2 for displaying calculation view’s data and then activate AMDP ABAP Class.
Step 5: Expose table function results to outer CDS with business logic
- Select package where CDS data definition needs to be created.
- Create CDS View by right clicking on the Package and select New à other ABAP Repository object-> Data Definition and provide name and description then select next
- Choose the template “Define view with join” and say finish.
- Add required business logic to fetch data from table function and other views/ tables and activate it.
- Run the CDS View and see the results.
This concludes the above blog post. Hope the blog helped you. Please feel free to give feedback and comments.