
Introduction
In my previous post, "Checklist to make your SAP BW queries flexible", I have showed you the problem of the constant values used in queries. I hope, I could convince you that the variables are the solution. The variables keep your queries flexible.
Variables as Placeholders
But what are the variables? They are certainly not constants. They are the placeholders for constant values. You can replace a year restriction of 2015 to a variable reference.

You can also replace a part of your description to a variable name.

And you can introduce a variable for your values in a formula, exception or condition.

Types of Variables
We call the placeholders for the restrictions as characteristic variables. Text variables are for the descriptions. And we use formula variables in a formula, exception or condition.

How to fill them?
So we discussed 3 types of variables. Characteristic, text and formula variables. But the question arises. If the variables are not constants, when and how can we fill them? The answer is. It depends. It depends on the processing type of the variable. There are variables with manual entry, replacement path, customer exit and authorization processing types.

Manual Entry
The manual entry is the simplest case. When you execute a query, first a popup screen will appear.

This is called variable screen. With the manual entry, you will fill the variables on this screen with values based on your interest. You can enter 2015 and November. But next time, you can use another year and month. You don’t need to change the design of the query. You give meaning to the variables during the query execution. Based on your current selection, the system will call the database. Then it will collect the data and finally show it in a table. This approach is much more flexible than the constants.
Replacement with a variable
The manual entry is not the only way we can fill a variable. Manual entries give task to the user. More variables you have on the screen, you need to work more before getting the result. This is a drawback. But we can help. There is a method like the replacement path. We can also create hidden variables and fill them from another variable. This processing type is called replacement path with a variable.

For example, we can introduce a "Month2" variable and fill its value from the "Month" variable. "Month2" will not appear on the variable screen. But why do we need duplicate entries for the month? Because the first variable is a characteristic variable. We can use it only for filtering, but we cannot use it for a dynamic description. That’s why we need a second month variable as a text variable. With manual entry, we would ask to enter the same information twice on the screen. But with the replacement path, we can hide a variable and copy its value from another variable. The rest of the process is the same. The query passes the values to the database. The database collects the data. And finally the table appears with the result.
Replacement with infoobject
We can use replacement with infoobject also.

The result and the process is similar. Just we refer to one of the fields in the query, instead of to another variable. In this case, this variable gets its value from the query result. Maybe we want to refer to a book type, but we didn’t use any variable for it. In this case we can use the replacement with infoobject. The variable can read the result values of the book type. If there are more possible values to replace, it can copy the first or the last value from the query.
Customer Exit Variables
The next processing type is the customer exit variable. It still works mainly with hidden variables like the replacement path. The difference is in the complexity.

For example, if we need to search in several database tables, this is already complex. In this case the replacement path is not enough. But we can write a logic in ABAP. ABAP is the programming language of SAP. We write ABAP code parts to handle more complex scenarios. SAP has predefined places where we can develop our custom logic. We call these places, customer exits. And there is a place also for customer exit variables. The system will run our logic as part of the variable screen processing and will fill our variable. The rest of the process is the same as before. If you are curious how to implement custom logic in ABAP for customer exit variables, I have created a course about that on Pluralsight training site. In the course Introduction to ABAP for SAP Business Warehouse Developers, I discuss in detail the possible scenarios for the customer exit variables and I show code examples for them. This course is also useful, if you want to get familiar with the basics of the ABAP language and with the implementation scenarios in the SAP BW system.
Authorization Variables
The last processing type is the authorization variable. Its name refers to the security system of SAP BW. Let’s say we have a variable Region that we can fill from the authorizations. How does this work?

If you are an SAP BW user, you will have a user id in the system. Like Tom. Tom is the regional manager of Europe. From the authorization system point of view, he has a user id in the system. Tom can have one or several roles belonging to his user id. He can have a role, called Regional Manager. An SAP role defines the set of activities that a user can perform in the system. It can also define data slices that he can analyze with a query. We call this authorized data slices, Analyses authorization. Tom can have a restricted access only to the Region Europe. So if he tried to fill the variable for America, he would get an authorization error. To avoid this, we can help him with the authorization variable. The variable can read the selection from his analyses authorization. Now it will be Europe. So the authorization variables are a special processing type. They can read the restrictions from the user roles in the security system.
Summary
That's it about the important variable types. The list of variables and their processing types is not complete, but I wanted to show you the types that I use most often. As you can see, there are so many places where we can improve our query design with the variables. There is no query without a filter, so you will meet the characteristic variables. Once you start using restricted key figures, you will need dynamic descriptions. Text variables will help in this case. And don't forget the formula variables in calculated key figures. The variable processing types give you methods to fill these variables during the query runtime. Use manual entry for single scenarios, but you can solve more complex processing with replacement path. Your options are limitless with the ABAP in customer exit variables and with the authorisation variables.
Do you want to practice?
I plan to launch soon a new SAP BW training in email, "Practice the SAP BW query variables". With this SAP BW training, I want to help you in getting practical experience with the variables.
What will you get during the SAP BW training?
I want to show you the basic techniques how to create the most important query variables.
You will get...
- an exercise book with step by step instructions,
- real life examples for creating different variables,
- and solutions with screenshots from the system.
Will be the SAP BW training FREE?
Yes. It will be free.
But almost free...
If you feel, my work helped you in understanding the variables, I only want to ask you to share this post with your friends.
Do you want to attend?
Subscribe to the "Practice the SAP BW query variables SAP BW training"
What do you think? Is this training a good idea? If yes and you want to attend on this training, then you just need to opt in here. Just click on the button below. I will inform you about the details soon via email. Stay tuned.