You define a variable in a calculation view when you want to pass dynamic values for filtering onattribute columns. They provide an excellent way of filtering data and there are many options that make implementing variables easy and flexible.
Upon execution of the Calculation View, variables are passed inside the SQL query using a WHERE clause, which is easily understood by most applications that call calculation views. For example:
SELECT <columns> FROM <calculation_view_name> WHERE (("COUNTRY" = 'JP')) GROUP BY <group_by columns>;
You define variables in the Semantics node of a Calculation View, in the Parameters tab.
The View/Table Value Help setting is used to define in which table/view SAP HANA will fetch the data to show in the prompt. The Reference Column defines which (unique) column in this table/view will provide the possible values for the variable.
By default, the View/Table Value Help setting refers to the current calculation view. This means that the values of the specified attribute column, for example CUSTOMER (customer ID), will be scanned in order to propose the various values in the prompt.
A different approach is to define a dedicated source table/view for the variable. For example, you could define the master data table CUSTOMERS as the Value Help source for the variable, and -of course- choose the column from this master data table that matches the column of your calculation view you want to filter on: the Customer ID in our example.
Once the Value Help table and one column are chosen, you assign the APPLY FILTER attribute. That is, you identify which attribute column will be filtered at runtime, based on the variable values chosen by the user.
You will learn more about Value Help later on in this lesson.
The behavior of variables at runtime depends on whether an entry is required for the variable or not. These scenarios can be defined as follows:
If a variable is defined as mandatory, the user needs to provide the values, ranges, or intervals at runtime.
For non-mandatory variables, if nothing is specified at runtime, all the data for the corresponding attributes is returned by the view without filtering.
Creating Variables (2)
Creating Variables (3)
More than one value can be chosen for a variable when you select the Multiple Entries checkbox.
In the data preview, From and To are displayed in the Variable Values dialog even when a variable has not been defined as range.
Value Help for Variables
When a dialog box appears to the user they must make a selection. However, rather than an empty field appearing and the user having to guess valid values or figure out the format for a value (for example, is the country code UK or GB?), we can have a dialog box populated with the run-time values available. To do this, you make a selection in the setting View/Table for value help. The default entry is the calculation view where the variable is being created. This means that you present all possible values from the column that is assigned to the Attribute setting in the variable definition.
While this might seem like a great idea, remember that the list may be huge and would be difficult for the user to navigate. Imagine presenting a list of every employee in a very large organization? If the list should be restricted to offer limited values (such as employees in your line of business or country) then you should reference an external calculation view or table that exposes a restricted list. It is also good practice, from a performance perspective, to refer to an external calculation view or table. This is because it means you are burdening the main calculation view with the task of providing value help for unfiltered columns.
Value Help Based on Hierarchies
When creating a variable on an attribute that is associated with one or several hierarchies, you can specify one of the hierarchies in the variable definition. With this option, the user can navigate the hierarchy, rather than a flat list, to select the values in the value help. This makes navigation much easier when there are a lot of values; imagine being able to first select your country, then your department, before the list of employees appears? You can use either parent-child or level hierarchies.
The following are some of the basic rules that apply when implementing value help based on hierarchies:
If you refer to a parent-child hierarchy, the variable attribute column must be defined as the parent attribute and not the child.
If you refer to a level hierarchy, the variable attribute column must be defined at the leaf level; that is, the bottom level.