How to Create and Use Characteristic Value and Text Variables in SAP BW/4HANA Queries with Examples

How to Create and Use Characteristic Value and Text Variables in SAP BW/4HANA Queries with Examples

SAP BW/4HANA is a data warehouse solution that allows you to analyze and report on large volumes of data from various sources. One of the features of SAP BW/4HANA is the ability to create and use variables in queries. Variables are placeholders that can be replaced by values at query runtime, depending on the user input or system settings. Variables can help you to make your queries more flexible, dynamic and user-friendly.

In this blog post, we will explain how to create and use two types of variables in SAP BW/4HANA queries: characteristic value variables and text variables. Characteristic value variables represent characteristic values and can be used wherever characteristic values can be used. For example, you can use a characteristic value variable to restrict a characteristic to a specific value or a range of values. Text variables represent a text and can be used in descriptions of queries, calculated key figures and structural components (selections and formulas). For example, you can use a text variable to display the current date or the user name in the query title.

We will also show you some examples of how to use these variables in different scenarios, such as filtering, calculating, displaying or referencing data.

Creating Variables in SAP BW/4HANA Queries

To create and use variables in queries in SAP BW/4HANA, you need to use the Query Designer tool. The Query Designer allows you to drag and drop InfoObjects or reusable query elements from the InfoProvider screen to the query rows and columns. You can also edit the properties of the variables using the Properties pane.

Here are the steps to create and use variables in queries in SAP BW/4HANA:

  1. Open the Query Designer and select the InfoProvider that you want to use for your query.
  2. Click on Variables on the toolbar to open the Variables screen.
  3. Click on Create Variable to create a new variable, or select an existing variable and click on Edit Variable to modify it.
  4. In the Create Variable or Edit Variable dialog box, enter a name and a description for the variable.
  5. Select the variable type from the drop-down list. For characteristic value variables, select Characteristic Value. For text variables, select Text.
  6. Select the reference characteristic from the drop-down list. The reference characteristic determines which values can be assigned to the variable at runtime.
  7. Select the processing type from the drop-down list. The processing type determines how the variable is filled at runtime. You can choose from different options, such as Manual Input/Default Value, Replacement Path, Customer Exit, Authorization or SAP HANA Exit.
  8. Depending on the processing type, enter or select additional settings for the variable, such as default value, replacement path, exit name or authorization object.
  9. Click on OK to save the variable.

Using Characteristic Value Variables in SAP BW/4HANA Queries

After creating a characteristic value variable, you can use it in your query by dragging and dropping it from the Variables screen to the query rows or columns. You can also use it as a filter or a formula element.

Here are some examples of how to use characteristic value variables in SAP BW/4HANA queries:

  • To restrict a characteristic by a characteristic value variable, drag and drop the variable from the Variables screen to the Filters screen. In the Properties pane, select Single Value or Interval as the selection type and enter or select a comparison operator. For example, if you want to filter your query by fiscal year using a characteristic value variable called FY_VAR, you can drag and drop FY_VAR to the Filters screen and select Single Value as the selection type and Equal To as the comparison operator. image
  • To use a characteristic value variable in a calculated key figure formula, drag and drop the variable from the Variables screen to the Calculated Key Figures screen. In the Properties pane, enter a formula for the calculated key figure and include the variable name enclosed by & signs (for example, &VAR_NAME&). For example, if you want to calculate the sales growth rate using a characteristic value variable called PREV_YEAR_VAR that represents the previous fiscal year, you can drag and drop PREV_YEAR_VAR to the Calculated Key Figures screen and enter a formula like this:
  • To use a characteristic value variable in a selection or a formula of a structural component, drag and drop the variable from the Variables screen to the Selections or Formulas screen. In the Properties pane, enter a selection or a formula for the structural component and include the variable name enclosed by & signs (for example, &VAR_NAME&). For example, if you want to create a selection that shows the sales for the current fiscal year and the previous fiscal year using two characteristic value variables called CURR_YEAR_VAR and PREV_YEAR_VAR, you can drag and drop CURR_YEAR_VAR and PREV_YEAR_VAR to the Selections screen and enter a selection like this:

Using Text Variables in SAP BW/4HANA Queries

After creating a text variable, you can use it in your query by dragging and dropping it from the Variables screen to the query rows or columns. You can also use it as a filter or a formula element.

Here are some examples of how to use text variables in SAP BW/4HANA queries:

  • To display a text variable in the query title, drag and drop the variable from the Variables screen to the Title screen. In the Properties pane, enter a prefix or a suffix for the variable if needed. For example, if you want to display the current date in the query title using a text variable called DATE_VAR, you can drag and drop DATE_VAR to the Title screen and enter a prefix like “Sales Report as of “. image
  • To use a text variable in a calculated key figure description, drag and drop the variable from the Variables screen to the Calculated Key Figures screen. In the Properties pane, enter a formula for the calculated key figure and include the variable name enclosed by & signs (for example, &VAR_NAME&). For example, if you want to display the user name in the calculated key figure description using a text variable called USER_VAR, you can drag and drop USER_VAR to the Calculated Key Figures screen and enter a formula like this:

And then enter a description like this:

  • To use a text variable in a selection or a formula of a structural component, drag and drop the variable from the Variables screen to the Selections or Formulas screen. In the Properties pane, enter a selection or a formula for the structural component and include the variable name enclosed by & signs (for example, &VAR_NAME&). For example, if you want to create a formula that shows the sales growth rate with a text variable called GROWTH_RATE_VAR that represents the growth rate percentage, you can drag and drop GROWTH_RATE_VAR to the Formulas screen and enter a formula like this:

And then enter a description like this:

Conclusion

In this blog post, we have shown you how to create and use characteristic value and text variables in SAP BW/4HANA queries with examples. By using variables, you can make your queries more flexible, dynamic and user-friendly. You can also reduce maintenance efforts by reusing variables across different queries.

We hope you found this blog post helpful and informative. If you have any questions or feedback, please feel free to leave a comment below.

Disclaimer: This content is generated by