+++> 5.Different Types of Variables

Types of Variables

                   
          'Variables' are parameters of a query that are set in the query definition and are not filled with values (processed) until the query is inserted into a workbook.

Variables enable you to customize queries flexibly (parameterize the query) possible.

Variables acts like a placeholders.
Variables enable us to use one query definition as the foundation for many different queries.
Example
If you want to create one query for all the people who are responsible for customer groups, who each only evaluate the data for one customer group.
In the Query Designer, you insert a variable for the characteristic ‘customer group’.
Just before the query is executed, decide for which customer group(s) you want the query to apply to.

Variables function as a store for diff types of Variables, and can be processed in different ways," according to SAP four variable types exist:
  • Variables for characteristic values
  • Variables for hierarchies and hierarchy nodes
  • Variables for formulas
  • Variables for texts
Characteristic value Variables
Characteristic value variables represent characteristic values and can be used wherever characteristic values are used.
If you restrict characteristics to specific characteristic values, you can also use characteristic value variables.
Steps for creating Characteristic Variable as processing type of user entry/default value:

Step1:

Go to BEx and select Query. In Query definition right click the Characteristic and select ‘Restrict’ then below screen will appear.

Click the ‘Variable’ tab and right click then select new variable.   


Step2:
Enter the variable name, description and processing type.





Step3:
Give variable represents and  variable entry.




Here we have choose the options for ‘variable represents’ like – ‘single value’ or ‘multiple single values’ or ‘interval’ or ‘selection option’ or ‘Precalculated value set’.

Single value- we can select single value for variable.
Multiple single values – Here we can select more than one single value for a variable.
Interval- The variable represents the interval between a specific ‘from’ value and a specific                            ‘to’ value
Selection option- Through this selection option we can select values for variable with more options.
Option and sign

Use this screen to specify the option (for example, single value, less than, pattern...) and the sign ('Incl' or 'Excl') for a line of a selection. There are ten options altogether, although whether all of them are available depends on the entries that you have made in the 'from' and 'to' fields.

Example:
    Supplier number      10
    Selection options
      Single value
      Greater than or equal
      Less than or equal
      Greater
      Less
      Unequal
      Select   Exclude from selection

    o   If you choose Single value and Select (green), the system selects
        supplier number 10.

    o   If you choose Unequal and Select (green), the system selects all
        Supplier numbers unequal to 10.

    o   If you choose Greater than or equal and Select (green), the system
        select all supplier numbers greater than 10.

Precalculated Value Set-

The variable represents a set of values that were precalculated with a query by the Reporting Agent. The available values are those values that were precalculated to the characteristic of the variable (for example 0SOLD_TO Sold-to Party) or its basic characteristic (for example 0CUSTOMER Customer). Such a variable can also be ready for input. During runtime you can select various value sets in the variable screen.
Please note that variables that represent a precalculated value cannot be used in restricted key figures or in selection structure elements for technical reasons.

Choose the options for Variable entry is ‘optional’ or ‘mandatory’ or ‘mandatory initial value not allowed’.

Ready for input - If you check this option it will be ask values before executing query. Otherwise query takes default values.
If the variable in not ready for input, you are not able to change the default value.

Step4:
Enter the default value.

Step5:

Click finish and execute query.





Steps for creating Characteristic Variable as processing type of Replacement path:

Replacement path processing is used to specify the value that automatically replaces the variable when the query is executed.

This processing type can be used with characteristic value variables, text variables, and formula variables.

Replacement path takes place automatically, meaning the variable is never ready for input when a query is executed.

As a result, when a master file description is created for a query that includes a variable whose processing type is defined as replacement path, there won't be any fields to represent this variable.

Example:
You want to insert the result for the query Top 5 products as a variable in the query Sales – Calendar year / month.
...
1.      Select the characteristic Product and from the context menu,  those                      New Variable. The Variable Wizard appears.
       2.      Enter a variable name and a description.
       3.      Choose the processing type Replacement Path.
       4.      Choose Next. You reach the Replacement Path dialog step.
       5.      Enter the query Top 5 Products.
       6.      Choose Next. You reach the Save Variable dialog step.
       7.      Choose Exit.

You are now able to insert the variable into the query Sales – Calendar year / month. This allows you to determine how the sales for these five, top-selling products has developed month for month.

Step1:

Go to BEx and select Query. In Query definition right click the Characteristic and select ‘Restrict’ then below screen will appear.
Click the ‘Variable’ tab and right click then select new variable.   


Step2:
Select processing type as Replacement path.


Step3: Enter query name and execute query. Then the variable replace with values of the given query.




Text Variables
Text variables represent a text and can be used in descriptions of queries, calculated key figures and structural components.
You can use text variables in the description of calculated key figures, restricted key figures, selections and formulas when you create them.
When the system is replacing text variables, if it finds no values or multiple values for the reference characteristic and is thus unable to determine a unique value, the technical name is output as the result: &<technical name of the text variable>&.

For Text variables User entry/default value, Replacement path, Customer exit, SAP exit Processing types are available.

Steps for creating text variable:

Step1:
In query designer right click on the key figure and click edit. Then we will get into the follow screen.




Step2:
Click button for select or create Text Variable.  



Step3:
Enter the variable name, description and Processing type.


Step 4:
Here select the Variable entry is ‘Optional’, ‘Mandatory’ or ‘Mandatory, initial value not allowed. And enter length of the field, it must be between 1 to 32 only. Finish it and execute query.




Step 5:
         Enter the default value. . Finish it and execute query.



Formula Variables
Formula variables represent numerical values and can be used in formulas.
In addition, numerical values are used for selecting exceptions and conditions and you can also use formula variables here.
You can use a formula variable for the interest rate in order to process the current interest rate, after you have executed the query or Web application.
First you can create formula for numerical values, in that screen you select and create formula variable. Remaining steps are same as creating text variable.


Hierarchies and Hierarchy nodes Variables
Hierarchy variables represent hierarchies and can be used wherever hierarchies can be selected.
If you restrict characteristics to specific hierarchies or select presentation hierarchies, you can also use hierarchy variables
Hierarchy node variables represent a node in a hierarchy and can be used wherever hierarchy nodes are used.
If you restrict characteristics to specific hierarchy nodes, you can also use hierarchy node variables.
For this variables User entry/default value, Customer exit, SAP exit and Authorization Processing types are available.

Steps for creating Hierarchies and Hierarchy nodes Variables:

Step1:
Go to BEx and select Query. In Query definition right click the Characteristic and select ‘Restrict’ then below screen will appear.

Select hierarchy name and Click the ‘Variable’ tab and right click then select new variable.   




Step2:

Enter variable name and select processing type.



Step3:

Here we have to choose the options for ‘variable represents’ like – ‘single value’ or ‘multiple single values.

Choose the options for Variable entry is ‘optional’ or ‘mandatory’ or ‘mandatory initial value not allowed’.

Ready for input - If you check this option it will be ask values before executing query. Otherwise query takes default values.
If the variable in not ready for input, you are not able to change the default value.


Step4:

Here we can enter the default and select node info object. Finish it and execute the query.