Examples for Using Variables
In this section you can find examples for using variables.
Examples for Offset Variables
You want to use a query to carry out a comparison of two years.
Year Comparison
You want to compare the costs of a year of your choice with the costs of the previous year.
- In the Query Designer, create a new structure and add a new selection for each year that you require.
- Only use one key figure (for example, sales) in this example query. Add this key figure to the filter or add it to the selection.
- Use a characteristic value variable for the characteristic Calendar Year (0CALYEAR):
Select the characteristic value variables for Calendar Year and choose New Variable from the context menu (secondary mouse button). The new variable is displayed. Choose Edit from the context menu of the new variable. The variables editor appears. For more information, seeDefining Variables.
If you always want to reference the current year automatically, use the SAP exit variable 0CALYEAR (or as appropriate for another time characteristic).
- Move the defined characteristic value variable into the selection.
- Select the characteristic value variable and choose Restrict from the context menu (secondary mouse button).
- Select the characteristic value variable and choose Enter Variable Offsets from the context menu (secondary mouse button).
- Enter -1 as the offset and choose OK.
- Choose OK.
- Enter a description.
- Create a second selection with the same characteristic value variable and do not set an offset here.
Also use a text variable in the description in this case.
- Move the required characteristic into the rows.
- Save the query.
After execution, the query should appear as follows:
Variable screen entry: 2002 (or no entry when using the SAP exit variable).
Year Comparison
| Characteristic | Sales 2001 | Sales 2002 |
|---|---|---|
|
Value 1 |
100,000 |
90,000 |
|
Value 2 |
200,000 |
180,000 |
|
Value 3 |
300,000 |
400,000 |
|
… |
… |
… |
Comparison with Cumulative Previous Year Period
Example: You want to compare the periods 1-8 of a particular year with the same periods for the previous year.
- Create a new structure in the Query Designer and add a new selection.
- Move a key figure, for example, sales, into the selection.
- Use a characteristic value variable for the characteristic Fiscal Year/Period (0FISCPER):
Select the characteristic value variables for Fiscal Year/Period and choose New Variable from the context menu (secondary mouse button). The new variable is displayed. Choose Edit from the context menu of the new variable. The variables editor appears. For more information, seeDefining Variables.
Use the SAP exit variable Current Fiscal Year/Period (0FPER) if you always want to reference the current year. If you set the variable as input-ready in the variables editor, the variables screen appears when you execute the query. You can change the default values here if necessary.
- Move the characteristic value variable (for example, OFPER) into the selection.
- Select the characteristic value variable and choose Restrict from the context menu (secondary mouse button).
- Under Selection, choose Value Area and then choose the Variables tab page.
- Add the characteristic value variable (for example, 0FPER) to the selection once again for the second value of the interval.
- Select the characteristic value variable and choose Enter Variable Offsets from the context menu (secondary mouse button).
- Enter -3 as the offset for the From value and 0 for the To value. Choose OK.
- Choose OK.
- Enter a description (for example, sales for the current year).
- Choose OK.
- Select the selection and choose Copy and then Paste from the context menu (secondary mouse button).
- Now select the second selection and choose Edit from the context menu.
- Select the characteristic value variable and choose Restrict from the context menu (secondary mouse button).
- Select the characteristic value variable again and choose Enter Variable Offsets from the context menu (secondary mouse button).
- Enter -15 as the offset for the From value and -12 for the To value. Choose OK.
- Choose OK.
- Enter a description (for example, sales for the previous year).
Also use a text variable in the description in this case.
- Choose OK.
- Move the required characteristic into the rows.
- Save the query.
When you execute it the query should appear as follows:
Variable screen entry: 01. 2002 to 08. 2002
Comparison with Cumulative Previous Year Period
|
Characteristic |
Sales 01. - 08. 2001 |
Sales 01. - 08. 2002 |
|
Value 1 |
100,000 |
90,000 |
|
Value 2 |
200,000 |
180,000 |
|
Value 3 |
300,000 |
400,000 |
|
... |
... |
... |
Comparison of Cumulated Values for Two Years
You may want to compare the cumulated values up to the current period of the current year with those of the previous year.
For this example, use the variable 0FPER (current fiscal year period) and the variable 0P_FPER (your chosen fiscal year period). You use these two variables to set the interval limits.
- In the Query Designer, create a structure with two selections:
- 1. Selection: Cumulative amount for current year
- 2. Selection: Cumulative amount for previous year
- For the first selection (cumulative amount for current year), move the time characteristic 0FISCPER into the selection and select it.
- Choose Restrict from the context menu (secondary mouse button).
- Choose Value Area between as the selection and go to the tab page Variables.
- Double click to choose the variable 0P_FPER as the From value and the variable 0FPER as the To value. The result is an interval from the chosen period to the current period.
- Define the second selection (cumulative amount for previous year) and proceed as for the first selection.
- Add the variable 0P_FPER as the From value and the variable 0FPER as the To value here.
- Set an offset of -12 for both the From and the To values:
Select the interval and choose Enter Variable Offsets from the context menu (secondary mouse button). Enter -12 for each.
The result is an interval that has been moved 12 periods ahead.
- Add the key figures and additional characteristics for the query.
When you execute the query, you get a variable screen for the variable 0P_FPER. You need to enter the start period in the current fiscal year here.
You have now defined a query that compares the cumulative values for two years.