The author provides her favorite methods for getting good results with BEx queries, including specifying a variable offset and using a customer exit as a variable.
Variables are very useful for manipulating a BEx query to get a specific result. Not only do variables allow you to enter your selection criteria for a query, they also allow you to re-use that input for another query (via the report/report interface). What follows are five of my favorite tips for using variables in BEx queries. They apply to both BW 2.x and 3.x unless otherwise noted.
Tip 1. Specify a Variable Offset
While in many cases the variables that SAP provides as standard Business Content serve the purpose as is, you often need to enhance them just a little bit to meet your requirement. A simple example is the variable for current fiscal period. You might wish you also had a variable for a previous fiscal period, which SAP does not provide. You can actually convert the current fiscal period variable to a previous fiscal period by setting a variable offset of -1.
Here is how to set a variable offset. Go to the BEx Analyzer or Query Designer and open your query. In Query Definition, restrict the Characteristic InfoObject with a variable as needed. Right-click on the variable, and then choose Specify Variable Offsets. (See Figure 1).

Figure 1
Setting a variable offset
Tip 2. Add a Customer Exit as a Variable
Sometimes, the variable you need is not part of standard Business Content, so you must create your own. This is usually as easy as typing in a default value, but you occasionally need a more complex variable that requires ABAP code in a customer exit. To do so, start by executing transaction code RSZV, Processing by: Customer Exit, for BW 2.x, or go to the Variables Wizard in BW 3.x.
Note
You can access the Variables Wizard in BW 3.x when you are restricting an InfoObject
(Figure 2).

Figure 2
Set up a customer exit as a variable using the Variables Wizard in BW 3.x
Then, go to transaction CMOD (Project) and create a project. Click on Enhancement assignment (Figure 3). At the next screen (Figure 4), enter RSR00001 under Enhancement and BW: Enhancements for global variables in reporting
under Text.

Figure 3
Create a project and then click on Enhancement assignment

Figure 4
Enter the enhancement name and description
Next, click on Components and double-click on EXIT_SAPLRRS0_001. This brings you to Function Builder (Figure 5). Now, double-click on the code INCLUDE ZXRSRU01
and enter your routine.

Figure 5
The Function Builder screen
When you finish, save your code and activate the project.
Tip 3. Find a List of SAP Exit Variables
Typically, you look for SAP exit variables when you are in the Query Definition trying to restrict an InfoObject with variables. In BW 2.0B, you look in transaction code RSZV. Both are very restrictive. In the Query Definition, you can see only a list of variables that is relevant to that InfoObject and no information about the properties of that variable. In RSZV, you have all the variables listed, but you must examine each variable one by one to find which InfoObject is relevant and what it does. It is a very tedious process. However, there is a way for you to see a list of SAP exit variables and to search through them based on the variable properties.

Figure 6
Use transaction code SE16 to locate table RSZGLOBV
First, go to table RSZGLOBV via SE16 (Figure 6). Then enter the value 4 (SAP exit) in the Processing Type field. A list of SAP customer exits like the one shown in Figure 7 should appear.

Figure 7
A list of SAP customer exits
Tip 4. Find ABAP Code Behind SAP Exit Variables
Now that you know how to create your own variables using a customer exit, you might wish to simply copy the code behind an SAP exit variable and modify it for your own purposes. This will save a lot of time during development. Here is how to find the ABAP code for an SAP exit variable.
All SAP exit variables are just function modules. Therefore, go to Function Builder (SE37) and enter RREX_VARIABLE_EXIT
in the Function Module field (Figure 8). Search the ABAP code for the name of the variable you need.

Figure 8
Use the Function Builder screen to locate ABAP code for exit variables
If not found, go back to the first screen of the Function Builder and enter RSVAREXIT_ * in the Function Module field and press the F4 key to find a list of all the other SAP exit variables.
Tip 5. Steps in Processing Variable Exits
To help you customize your variables to fit your business requirement, you need to know exactly when these ABAP code segments in your customer exit are executed during query execution. The variable value is checked in a customer exit. Every variable type (not only customer exit variable) can be checked. The customer exit for variables can be called up to three times:
- The first step (I_STEP = 1) is before the processing of the variable pop-up and is called for every variable of the processing type Customer exit. You can use this step to fill your variable with default values.
- The second step (I_STEP = 2) is called after the processing of the variable pop-up. This step is called only for those variables that are not marked as Ready for input and are set to Mandatory variable entry.
- The third step (I_STEP = 3) is called after all variable processing and is called only once and not per variable. Here you can validate the user entries.
Perhaps these five tips will inspire the BW reporting analysts among you to get more creative with your use of variables.
Note
I_STEP is the field name in the customer exit to specify where in the process you would like to check your variable.
July Hartono
July Hartono has more than six years of experience as an SAP BW consultant. Currently with Alpha Net Consulting, LLC, she has helped several large clients implement BW. Data conversion and extraction, development of custom DataSources, and data modeling are among her best skills. July received mySAP.com Delta Certification for Business Information Warehouse in 2003.
You may contact the author at julyhartono@sbcglobal.net.
If you have comments about this article or publication, or would like to submit an article idea, please contact the editor.