When a report requires that one record be split into multiple records, the method often used is to modify the data in the source system. You can avoid this tedious process by using a hard-to-find BW option called the return table. It allows you to insert ABAP code within an update rule to split the record automatically.
Sometimes a report requires you to create multiple records from one record. People typically do this by modifying the data in the source system—a tedious process. You have a better alternative: the return table. This functionality is not well documented and, as a result, it is not widely used. It is also inconspicuous. To use return tables, you need to be aware of a little check box inside an update rule. Checking this box enables you or your technical team to insert ABAP code that actually splits your records.
I’ll show you an example of how return tables can help you with reports that require you to split records. You can easily apply the process I describe to other situations. My example involves data stored in InfoCubes, but result tables work equally well with data stored in an ODS.
Imagine this scenario: You need to create a report that distributes on-hand inventory per calendar week to all forecast weeks. For example, you have an actual inventory of 150 boxes in week 03/2003. Therefore, you have a record of on-hand inventory of 150 boxes in your inventory table for calendar week 03/2003. However, during week 01/2003, you predicted that you would have only 100 boxes in week 03/2003. In this case, you add a record to your forecast table: Week 03/2003 is the calendar week, week 01/2003 is the forecast week, and 100 boxes is your forecast amount. In week 02/2003, with better information, you predicted that you would have 150 boxes in week 03/2003 inventory. Thus, you add another record with week 03/2003 as the calendar week, 02/2003 as the forecast week, and 150 boxes as the predicted amount. You need to create a forecast accuracy report by comparing your actual inventory data to the forecast data.
The source system can provide the inventory data only for the current week, as shown in Table 1. However, the forecast amount is kept in a forecast week and calendar week combination in the source system, as shown in Table 2.
| Location |
Material |
Calendar Week |
On-hand Inventory |
| US01 |
10000011 |
01/2003 |
100 |
| US01 |
10000011 |
02/2003 |
200 |
| US01 |
10000011 |
03/2003 |
150 |
| Table 1 |
Inventory data layout
|
| Location |
Material |
Forecast Week |
Calendar Week |
On-hand Inventory |
| US01 |
10000011 |
01/2003 |
01/2003 |
100 |
| US01 |
10000011 |
01/2003 |
02/2003 |
150 |
| US01 |
10000011 |
01/2003 |
03/2003 |
100 |
| US01 |
10000011 |
02/2003 |
02/2003 |
200 |
| US01 |
10000011 |
02/2003 |
03/2003 |
150 |
| US01 |
10000011 |
02/2003 |
04/2003 |
100 |
| Table 2 |
Forecast data layout |
In an InfoCube, you want to analyze the data in the forecast week/calendar week combination. You then need to distribute the on-hand inventory data to match the forecast data using the calendar week as the common link. Therefore, you have to create new records in the InfoCube for every forecast week that has the same calendar week, as shown in Table 3.
| Location |
Material |
Forecast Week |
Calendar Week |
Forecast Amount |
On-hand Inventory |
| US01 |
10000011 |
01/2003 |
01/2003 |
100 |
100 |
| US01 |
10000011 |
01/2003 |
02/2003 |
150 |
200 |
| US01 |
10000011 |
01/2003 |
03/2003 |
100 |
150 |
| US01 |
10000011 |
02/2003 |
02/2003 |
200 |
200 |
| US01 |
10000011 |
02/2003 |
03/2003 |
150 |
150 |
| US01 |
10000011 |
02/2003 |
04/2003 |
100 |
1 |
| Table 3 |
InfoCube data layout |
You can accomplish this using return tables in just six steps.
1. Create an update rule for your InfoCube. In the maintenance screen of your update rule, click on Create Start Routine (Figure 1).

Figure 1
Create a start routine for your update rule
2. Look up the forecast data. Since you do not know how many forecast weeks for which you need to distribute the on-hand inventory data, the start routine must look up the forecast data that has been loaded to the system (in an InfoCube or, preferably, an ODS) and keep the information in an internal table. You create the internal table, which is just a temporary table that exists during run-time, in the update rules start routine, as shown in Figure 2. Once you’ve coded for this task, check and save the start routine.

Figure 2
The start routine locates the forecast data and stores it in an internal table
3. Select the key figure and characteristic to distribute.On-Hand InventoryCharacteristicsFigure 3Forecast Week
Figure 3
The characteristic you want to distribute will be blank, as it has not yet been provided data
4. Create the routine for the return table. Click on the Key Fig. Calculation tab. Click on the Return Table button and then on the create routine icon, as shown in Figure 4. Enter the text description for the routine.

Figure 4
Click on the Return Table button and then the create routine icon
5. Enter the ABAP code. Remember to send over all the necessary key figures and characteristics (for example, Location, Material No., Calendar Week, and Forecast Week) of your record from the communication structure to RESULT_TABLE. Since you are distributing your data to all forecast weeks that exist in the forecast data, you look up the Forecast Week key figure from the internal table T_INVTRN26 (previously selected from the Forecast ODS in the start routine) and append records to RESULT_TABLE for each record you find. Figure 5 shows the ABAP code for this. When you are finished, check and save your routine.
Tip!
Each record you append to RESULT_TABLE means adding another record to your InfoCube. In the update rules, each record coming in gets only one record coming out. Using the result table, each append you perform results in an extra record created from just that one record coming in. This is how you control the number of records you want to create from that one record.
Tip!
If you have more than one key figure and you put a return table on only one of them, your result will be one record for all other key figures and x number of records for the distributed key figure. For example, say you have two key figures for your inventory data: On-Hand Inventory and Withdrawals. If you put the return table on On-Hand Inventory, the outcome of your update rule would look like Tables 4 and 5.

Figure 5
ABAP code to look up Forecast Week key figure
| Location |
Material |
Forecast Week |
On-hand Inventory |
Withdrawals |
| US01 |
10000011 |
01/2003 |
100 |
50 |
| US01 |
10000011 |
02/2003 |
200 |
45 |
| US01 |
10000011 |
03/2003 |
150 |
30 |
| Table 4 |
Data in communication structure |
| Location |
Material |
Forecast Week |
Calendar Week |
On-hand Inventory |
Withdrawals |
| US01 |
10000011 |
|
01/2003 |
|
50 |
| US01 |
10000011 |
01/2003 |
01/2003 |
100 |
|
| US01 |
10000011 |
01/2003 |
02/2003 |
200 |
|
| US01 |
10000011 |
01/2003 |
03/2003 |
150 |
|
| US01 |
10000011 |
|
02/2003 |
|
45 |
| US01 |
10000011 |
02/2003 |
02/2003 |
200 |
|
| US01 |
10000011 |
02/2003 |
03/2003 |
150 |
|
| US01 |
10000011 |
02/2003 |
04/2003 |
|
|
| US01 |
10000011 |
|
03/2003 |
|
30 |
| US01 |
10000011 |
03/2003 |
03/2003 |
150 |
|
| US01 |
10000011 |
03/2003 |
04/2003 |
|
|
| US01 |
10000011 |
03/2003 |
05/2003 |
|
|
| Table 5 |
Data after update rule |
6. Activate your update rule. Click on the activate icon on the update rules maintenance screen. After the update rule runs, the inventory data in the communication structure should look like Figure 6, and inventory data in the InfoCube should look like Figure 7. (Note that Figures 6 and 7 were taken using the simulation functionality of the PSA.)

Figure 6
Inventory data in the communication structure
If you want all your key figures distributed evenly, you need to create return tables for all of them. Then, your result would look like Table 6.
| Location |
Material |
Forecast Week |
Calendar Week |
On-hand Inventory |
Withdrawals |
| US01 |
10000011 |
01/2003 |
01/2003 |
100 |
50 |
| US01 |
10000011 |
01/2003 |
02/2003 |
200 |
45 |
| US01 |
10000011 |
01/2003 |
03/2003 |
150 |
30 |
| US01 |
10000011 |
02/2003 |
02/2003 |
200 |
45 |
| US01 |
10000011 |
02/2003 |
03/2003 |
150 |
30 |
| US01 |
10000011 |
02/2003 |
04/2003 |
|
|
| US01 |
10000011 |
03/2003 |
03/2003 |
150 |
30 |
| US01 |
10000011 |
03/2003 |
04/2003 |
|
|
| US01 |
10000011 |
03/2003 |
05/2003 |
|
|
| Table 6 |
Data when all key figures have return tables |
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.