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.
Thanks for the How-to. That is especially interesting if you want to map input parameters from the calculation views. If you dont need that, you could also use an external view: https://help.sap.com/viewer/6811c09434084fd1bc4f40e66913ce11/1709.000/en-US/4ec059036e391014adc9fffe4e204223.html
Thanks for great explanation!
I have a query, will S/4 system able to identify SYS_BIC schema directly when we are calling it AMDP class?
Yes, as system connection is already there S4 can access HANA database catalog schemas and objects.
Nice but how do we call calculation view with input parameter? The sql view of HANA model generates place holders for input parameter to which am unable to pass the importing parameter of the class.
Hi prem kumar,
FROM "_SYS_BIC"."<Calculation View Name>"(placeholder."$$P_MANDT$$"=>:p_client,
Thank you Thiago Dias. Much appreciated.
how and where did you get the 'ZD_TABLE_FUNC_PUR'
do you know , How I can Abap CDS View integreat in Hana Studio and use it in my Calculation View in Hana. I do not know why, but I can not see the Data in mein Calculation view , wenn I call the CDS view it show me just empty data. I proof in Backend , CDS view is not empty, but in Hana it says that there is no data. Can you help me to know this Problem. Thanks