How to Define the Output Structure and Semantics of SAP HANA Calculation Views

How to Define the Output Structure and Semantics of SAP HANA Calculation Views

SAP HANA calculation views are powerful tools to model complex business scenarios and perform advanced data analysis. They allow you to combine data from multiple sources, apply various calculations and transformations, and define the output structure and semantics of your data.

However, not all calculation views have the same output structure and semantics. Depending on the data category and the type of calculation view, you may need to define different aspects of your output, such as measures, attributes, semantic types, or hierarchies.

In this blog post, we will show you how to use the semantics node in graphical calculation views to define the output structure and semantics of your data. We will also explain how to use different semantic types for measures and attributes, and how to extract and copy semantics from underlying data sources.

What is a Semantics Node?

A semantics node is a mandatory node that is present in every graphical calculation view. It is always the top node in the calculation view editor, regardless of the data category or the type of calculation view.

The purpose of a semantics node is to define the output structure and semantics of your data. In this node, you assign measures or attributes to each column in order to define its role and behavior. You also assign semantic types to each column in order to define its meaning and format.

The semantics node is important information used by consuming clients so that they are able to display and process the columns appropriately. For example, if you define a column as a date semantic type, the client application can then format the value with separators rather than a simple string.

How to Use a Semantics Node in Graphical Calculation Views?

To use a semantics node in graphical calculation views, you need to follow these steps:

  1. Launch SAP HANA Studio and open the content node.
  2. In the navigation pane, select a package where you want to create the new calculation view.
  3. In the context menu of the package, select New Calculation View.
  4. Provide name and description. Select calculation view type as Graphical and data category as Cube or Dimension.
  5. Choose Finish. The modeler launches a new graphical calculation view editor with the semantics node and default projection or aggregation node.
  6. Drag and drop the necessary data sources from the tool palette to the scenario area. You can add one or more data sources depending on your business scenario.
  7. Connect the data sources to the projection or aggregation node. You can use join nodes or union nodes to combine multiple data sources before defining their output.
  8. Select the projection or aggregation node. In the Details pane, select the columns that you want to add to the output of the node. In the context menu, choose Add To Output.
  9. Select the semantics node. In the Details pane, select an output column. In the Type dropdown list, select Measure or Attribute.
  10. If the column is a measure, you can also specify the aggregation type in the Aggregation column. You can choose from SUM (the default function), MIN, MAX, COUNT, AVERAGE, VARIANCE, STANDARD DEVIATION, or MEDIAN.
  11. If you want to assign a semantic type to your column, select Assign Semantics from the context menu of your column. In the Assign Semantics dialog box, select a semantic type from the Semantic Type dropdown list. You can choose from different semantic types depending on whether your column is a measure or an attribute.
  12. Save and activate your calculation view.

How to Use Different Semantic Types for Measures and Attributes?

Semantic types are optional settings that describe the specific meaning of each column in your calculation view. They can be helpful to any client that consumes your calculation view by enabling it to represent your columns in an appropriate format.

There are different semantic types available for measures and attributes in SAP HANA calculation views.

For measures, you can use semantic types such as:

  • Amount: A numeric value that represents an amount of money in a specific currency.
  • Quantity: A numeric value that represents a quantity of items in a specific unit of measure.
  • Percentage: A numeric value that represents a percentage or ratio.
  • Key Figure: A numeric value that represents any other measure that is not an amount, quantity, or percentage.

For attributes, you can use semantic types such as:

  • Date: A date value that represents a calendar date in YYYY-MM-DD format.
  • Time: A time value that represents a clock time in HH:MM:SS format.
  • Timestamp: A timestamp value that represents a date and time in YYYY-MM-DD HH:MM:SS format.
  • Text: A text value that represents any other attribute that is not a date, time, or timestamp.

You can also use custom semantic types for attributes that have specific meanings in your business domain, such as:

  • Customer ID: A numeric or alphanumeric value that uniquely identifies a customer.
  • Product ID: A numeric or alphanumeric value that uniquely identifies a product.
  • Country Code: A two-letter code that represents a country according to the ISO 3166-1 standard.

How to Extract and Copy Semantics from Underlying Data Sources?

If your data sources already have semantics defined for their columns, you can extract and copy them to your calculation view without manually assigning them in the semantics node.

To extract and copy semantics from underlying data sources, you need to follow these steps:

  1. Open the calculation view in the view editor.
  2. Select the projection or aggregation node that contains your data source.
  3. In the Details pane, select Extract Semantics from the context menu of your data source.
  4. In the Extract Semantics dialog box, select the columns that you want to extract semantics from. You can also select All Columns to extract semantics from all columns in your data source.
  5. Choose OK. The extracted semantics are copied to the output columns of your node and propagated to the semantics node of your calculation view.

Conclusion

In this blog post, we have learned how to use the semantics node in graphical calculation views to define the output structure and semantics of your data. We have also explained how to use different semantic types for measures and attributes, and how to extract and copy semantics from underlying data sources.

We hope this post has helped you understand how to use this feature of SAP HANA calculation views and how to provide meaningful and consistent information to your clients.

If you have any questions or feedback, please leave a comment below.

Disclaimer: This content is generated by AI.