Skip to Content
Technical Articles
Author's profile photo Abhishek Patel

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:

  1. Create Calculation view in E-HANA.
  2. Test view output in HANA using native SQL.
  3. Create CDS table function.
  4. Create AMDP function for calling HANA native query on calculation view.
  5. Expose result to outer CDS with business logic.

So, let’s start building:

Step 1:  Create a Calculation View

  1. Open Eclipse/ HANA Studio
  2. Select system and expand content folder and choose package where calculation view needs to be created.
  3. Right Click and Create New Calculation View.
  4. 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.
  5. Now save and activate the view.

Step 2: Test view output in HANA using native SQL.

Open a SQL console by selecting a system and clicking on open a SQL console for selected system and write a query to fetch data from the view and hit a execute button to see the view’s data.

Step 3: Creating CDS Table Function

  1. Open ABAP perspective from Eclipse/ HANA Studio
  2. Select system and choose package where CDS data definition of type table function needs to be created.
  3. 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
  4. Choose the template “Define Table Function with Parameters” and say finish.
  5. 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 

  1. Select package where AMDP Class needs to be created.
  2. Create AMDP Class by right clicking on the Package and select New ABAP Class and provide name and description then click finish.
  3. 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

  1. Select package where CDS data definition needs to be created.
  2. 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
  3. Choose the template “Define view with join” and say finish.
  4. Add required business logic to fetch data from table function and other views/ tables and activate it.
  5. 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.

Happy Learning!!!

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sven Knöpfler
      Sven Knöpfler

      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

      Author's profile photo Santosh Tankala
      Santosh Tankala

      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?

      Regards,

      Santosh T.

      Author's profile photo Abhishek Patel
      Abhishek Patel
      Blog Post Author

      Yes, as system connection is already there S4 can access HANA database catalog schemas and objects.

      Author's profile photo prem kumar
      prem kumar

      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.

       

      Regards,

      Prem

      Author's profile photo Thiago Teixeira de Carvalho Dias
      Thiago Teixeira de Carvalho Dias

      Hi prem kumar,

      FROM "_SYS_BIC"."<Calculation View Name>"(placeholder."$$P_MANDT$$"=>:p_client,

                                                       placeholder."$$P_FILIAL$$"=>:p_filial,

                                                       placeholder."$$P_DT_INI$$"=>:p_dt_ini,

                                                       placeholder."$$P_DT_FIN$$"=>:p_dt_fin,

                                                       placeholder."$$P_EMPRESA$$"=>:p_empresa);

      Regards,
      Thiago Dias.

      Author's profile photo prem kumar
      prem kumar

      Thank you Thiago Dias. Much appreciated.

      Author's profile photo Jose Guilas
      Jose Guilas

      how and where did you get the 'ZD_TABLE_FUNC_PUR'

      Author's profile photo Arsen Georgyan
      Arsen Georgyan

      Hi,

       

      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

       

      Best Regards,

      Arsen