Skip to Content
Product Information
Author's profile photo Kai Mueller

SAP HANA Calculation View API – Introduction

Overview

To execute analytical workload on SAP HANA calculation views can be used. They are most of the time graphically modeled in the SAP HANA Studio (for repository-based calculation views in SAP HAN A on-premise) or the SAP Web IDE for SAP HANA (for HANA Deployment Infrastructure [HDI] based ones in SAP HANA on-premise and in SAP HANA Cloud ).

These tools are great for graphical modelling but have limitations when it comes to automation and dynamic changes. For example, to change a formula of a calculated column in a view, a user first needs to open the modelling tool and change the formula manually. With this API, a change can also be done programmatically and therefore dynamically.  Doing changes programmatically is especially helpful when the change should be applied to multiple views  at once.

Requirements and Installation

To use this API the SAP HANA Client 2.5 or higher is required. In the installed folder you will find another folder called “calcviewapi” which contains four jar files:

  • HANACalculationViewAPI-Cloud-XXXX.jar
  • HANACalculationViewAPI-Cloud-XXXX-javadoc.jar
  • HANACalculationViewAPI-OnPrem-XXXX.jar
  • HANACalculationViewAPI-OnPrem-XXXX-javadoc.jar

The API has two editions: one for SAP HANA Cloud and one for SAP HANA on-prem. In SAP HANA Cloud some features are not supported anymore (see SAP Note 2868742), therefore two editions exist.

To use the API, at least (JRE or JDK) is required. As the API has no other dependencies, you can just add the appropriate jar file into your class/build/module path. If your IDE supports Javadoc, you can also link the related Javadoc jar.

The API itself requires no database connection and is therefore independent from HANA. The generated calculation view itself depends on the database version and the API edition:

  • Cloud: The generated Calculation View can be deployed on the latest version offered by SAP HANA Cloud
  • On-Premise: Please refer to SAP Note 2869216

Scope and Limitations

Calculation views are stored during design time in an XML format, so this API generates and consumes this XML. Only the HDI-based calculation view XML is supported, not the repository-based one.

Additionally, the API is only capable to consume, modify and generate the calculation view XML. Any HANA side actions can be done with the HDI Administration SQL API or the HDI Deployment SQL API.

Use Cases

The API for example can be used for the following use cases:

  • Change or create calculation views dynamically
  • Mass-changes of calculation views
  • Mass-creation of calculation views (can be based on a “template” calculation view)

Especially, the API can be used when no UI access is possible. As an example,  the calculation view definition needs to be changed based on the user input, but this should not be done by the end-user in a UI.

Code Examples

To create a new calculation view from scratch, you can start with the following code. A full example can be found here.

ScenarioRoot root = new ScenarioRoot();
//add all needed data
String xml = root.toXMLWithValidation();

The API also offers to load an existing XML for modification or analysis:

ScenarioRoot root = new ScenarioRoot();
root.loadWithXSDValidation(<xml>);

With HDI properly setup, to write and make (deploy) the calculation view to SAP HANA you can use the following SQL:

CREATE LOCAL TEMPORARY COLUMN TABLE #FILESFOLDERS_WRITE LIKE _SYS_DI.TT_FILESFOLDERS_CONTENT;
CREATE LOCAL TEMPORARY COLUMN TABLE #FILESFOLDERS_PARAMETERS LIKE _SYS_DI.TT_FILESFOLDERS_PARAMETERS;
CREATE LOCAL TEMPORARY COLUMN TABLE #FILESFOLDERS LIKE _SYS_DI.TT_FILESFOLDERS;
CREATE LOCAL TEMPORARY COLUMN TABLE #FILESFOLDERS_MAKE LIKE _SYS_DI.TT_FILESFOLDERS;
INSERT INTO #FILESFOLDERS_WRITE (PATH, CONTENT) VALUES ('<name>.hdbcalculationview','<xml>');

CALL <container>#DI.WRITE(#FILESFOLDERS_WRITE, _SYS_DI.T_NO_PARAMETERS, ?, ?, ?);

INSERT INTO #FILESFOLDERS_MAKE (PATH) VALUES ('<name>.hdbcalculationview');

CALL <container>#DI.MAKE(#FILESFOLDERS_MAKE, #FILESFOLDERS, #FILESFOLDERS_PARAMETERS, _SYS_DI.T_NO_PARAMETERS, ?, ?, ?);

DROP TABLE #FILESFOLDERS_WRITE;
DROP TABLE #FILESFOLDERS_PARAMETERS;
DROP TABLE #FILESFOLDERS;
DROP TABLE #FILESFOLDERS_MAKE;

You can learn more about the HDI SQL API in this blog.

References

SAP HANA Calculation View API Documentation

SAP HANA Client Installation and Update Guide

Assigned Tags

      10 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Michael Eaton
      Michael Eaton

      When I click on the API Documentation link I get a 403:Not Authorised error.

       

      Author's profile photo Kai Mueller
      Kai Mueller
      Blog Post Author

      Hello Michael,

      thanks for the feedback. It seems like it will take some time till the 2.5 version is publicly released.

      Best regards,

      Kai

      Author's profile photo Denys van Kempen
      Denys van Kempen

      The SPS 05 documentation will become publicly available once SPS 05 is officially released. End of June , according to the latest information, i.e. today, Monday or Tuesday.

      Author's profile photo Michael Eaton
      Michael Eaton

      Thanks both. I can see it now. I should have waited until my afternoon coffee to read the documentation, rather than at breakfast! ?

      Author's profile photo Suchen Oguri
      Suchen Oguri

      Hi Kai Mueller,

      Thanks for the very useful blog.

      I have been able to generate some basic calculation views and build them successfully in WebIDE.

      But I see some minor differences in XML generated by API and XML generated by WebIDE (If I create same simple calculation view manually in WebIDE). You can refer the below comparison.

      Whether these can be ignored?

      Also, If possible, could you try to post some more samples with example of calculated columns, input parameters.. etc.,

      Thanks in advance.

      Regards,

      Suchen.

      XML%20Comparison

      XML Comparison

       

       

      Author's profile photo Kai Mueller
      Kai Mueller
      Blog Post Author

      Hello Suchen,

      thanks for your comment.

      It can happen that the WebIDE sometimes explicitly sets attributes to a default value, while the API will omit them. As long as this doesn't lead to a behavior change I don't see an issue. The xmlns:xxx thing is by the way just XML namespacing and shouldn't lead to any changes.

      In regards to the examples: We are currently busy with other items, but I'll add this to the backlog.

      Best regards, Kai

      Author's profile photo Kai Mueller
      Kai Mueller
      Blog Post Author

      Hello Suchen,

      for your information. the SAP HANA Calculation View API Reference was just published.

      Best regards, Kai

      Author's profile photo PRUDHVI RAJ VARMA KUMARA APPALA NARASHIM
      PRUDHVI RAJ VARMA KUMARA APPALA NARASHIM

      Hi Kai,

      Great Blog! Thank you.

      You have mentioned that Calculation views are stored during design time in an XML format, Can you please let me know if this XML can be retrieved from any table ?

      Regards,

      Prudhvi

      Author's profile photo Kai Mueller
      Kai Mueller
      Blog Post Author

      Hello Prudhvi,

      that is not directly possible but can done via the HDI SQL API: READ and READ_DEPLOYED.

      If you need some basic information about the SQL API, I recommend you this blog.

      Best regards, Kai

      Author's profile photo Mathias Klare-Dobberkow
      Mathias Klare-Dobberkow

      Hi,

      it is possible to get this information via the table _sys_bi.bimc_all_sources; The SOURCE-column can be transformed via bintostr(cast(source as binary)).

      Best regards,
      Mathias