How To Report Data in Alternate Units of Measure
How To Report Data in Alternate Units of Measure
Report Data in
Alternate Units of Measure
BUSINESS INFORMATION WAREHOUSE
SAP (SAP America, Inc. and SAP AG) assumes no responsibility for errors or omissions in these materials.
These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the
implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages
that may result from the use of these materials.
SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within
these materials. SAP has no control over the information that you may access through the use of hot links contained in these
materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party
web pages.
mySAP BI “How-To” papers are intended to simplify the product implementation. While specific product features and
procedures typically are explained in a practical business context, it is not implied that those features and procedures are the
only approach in solving a specific business problem using mySAP BI. Should you wish to receive additional information,
clarification or support, please refer to SAP Professional Services (Consulting/Remote Consulting).
HOW TO … REPORT DATA IN ALTERNATE UNITS OF MEASURE
Overview
1 BUSINESS SCENARIO .................................................................................................................. 2
2 SOLUTION ...................................................................................................................................... 4
4 PRESENTATION .......................................................................................................................... 25
5 COMMENTS ................................................................................................................................. 26
6 APPENDIX .................................................................................................................................... 26
1 Business Scenario
This document describes the how to report data in alternate units of measure. Data is stored in
InfoCubes in quantity key figures with the base unit of measure of materials. This data needs to be
converted dynamically into an alternate unit of measure, which is specified by the end user at query
execution.
The goal of this design is to enable flexible and user-friendly reporting in any alternate unit of
measure. There is no solution available in the Standard SAP BW releases 2.x and 3.x. Therefore a
new solution has been developed. This solution is based on a modification of SAP standard coding.
Note:
As of SAP NetWeaver 2004s, this how-to solution is obsolete since Quantity Conversion is
standard functionality. For more information, please refer to the online documentation:
http://help.sap.com/saphelp_nw04s/helpdata/en/27/b65c42b4e05542e10000000a1550b0/frames
et.htm
1.3 Benefits
Even though the solution might appear to be complex at first, it is very usable and maintainable for
the end users. Everything is a one-time setup. Only the conversion factors (InfoObject 0MAT_UNIT)
have to be loaded (and maintained on R/3) on a regular basis.
• Independent of data model (solution works with any Infocube and query).
• Low maintenance (one-time setup of calculated key figures which can be reused).
• Very easy to use (simple input of alternate unit of measure by user).
• Correct display of unit of measure in query result (important if you want to use result in further
calculations).
• Correct aggregation of converted quantities (totals and subtotals are calculated).
• Low performance impact (conversion factors are read once from master data table before
selection of transaction data).
• No impact on transaction data (aggregates, InfoSources, update rules, etc.).
• Can be implemented in SAP BW release 2.0A to 3.5.
2 Solution
The following objects need to be installed for this solution. With the exception of the modification only
standard functionality is used:
• Key figure: Conversion factor (attribute YUOMCNVF of characteristic 0MATERIAL)
• Characteristics: Material (0MATERIAL), Alternate Units of Measure (0MAT_UNIT)
• Variable: Alternate Unit of Measure (YTAUNIT)
• Formula Variable: Conversion factor (YFCONVF)
• Modification: Read attributes for formula variables (LRRSVF20)
• User Exit: Variable Enhancement (ZXRSRU01)
• Calculated Key Figures for Queries
In order to determine the conversion factor from the base unit of measure to an alternate unit of
measure the following formula has to be applied.
Pick the attribute that was added to Material in chapter 3.2 (YUOMCNVF).
3.6 Modification
Implement modification in program LRRSVF20.
*----------------------------------------------------------------------*
***INCLUDE LRRSVF20 .
*----------------------------------------------------------------------*
…
*&---------------------------------------------------------------------*
*& Form varchavl_atr_get
*&---------------------------------------------------------------------*
form varchavl_atr_get using i_t_sid type rrsi_t_sid
i_chanm type rsd_iobjnm
i_th_var_atr type rro01_th_var_lrech
i_srdate type sy-datum
i_mostrecent type rsr_mostrecent
changing c_th_varchavl type rrsv_th_varchavl.
*----------------------------------------------------------------------*
***INCLUDE YBW_AUNIT_ENHANCEMENT.
*----------------------------------------------------------------------*
TYPE-POOLS: rrs0.
DATA:
l_vnam LIKE rszglobv-vnam,
l_s_cob_pro TYPE rsd_s_cob_pro,
l_s_rkb1d TYPE rsr_s_rkb1d,
l_periv TYPE rro01_s_rkb1f-periv,
l_t_var_range TYPE rrs0_t_var_range,
l_s_var_range TYPE rrs0_s_var_range,
l_t_range TYPE rsr_t_rangesid,
l_s_range TYPE rsr_s_rangesid,
l_unit LIKE rszglobv-meeht,
l_currency LIKE rszglobv-waers.
FIELD-SYMBOLS:
<l_sx_atr> TYPE rsdm_sx_atr,
<l_s_var> TYPE rro01_s_var_lrech,
<l_s_atr> TYPE rsdm_s_atr,
<l_s_atr_cu> TYPE rsdm_s_atr.
* Attribute
READ TABLE <l_sx_atr>-t_atr ASSIGNING <l_s_atr>
WITH KEY attrinm = <l_s_var>-attrinm.
IF sy-subrc <> 0.
RAISE x_message.
ENDIF.
CLEAR l_s_var_range.
l_s_var_range-sign = 'I'.
l_s_var_range-opt = 'EQ'.
l_s_var_range-vnam = '1ATTRINM'.
l_s_var_range-iobjnm = <l_s_atr>-attrinm.
l_s_var_range-low = <l_s_atr>-attrivl.
APPEND l_s_var_range TO l_t_var_range.
CLEAR l_s_var_range.
l_s_var_range-sign = 'I'.
l_s_var_range-opt = 'EQ'.
l_s_var_range-vnam = '1CUNM'.
ENDIF.
* InfoObject properties
CALL FUNCTION 'RSD_COB_PRO_GET_ALWAYS'
EXPORTING
i_iobjnm = i_chanm
IMPORTING
e_s_cob_pro = l_s_cob_pro
EXCEPTIONS
infocube_not_found = 1
error_reading_infocatalog = 2
iobjnm_not_found = 3
illegal_input = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
l_vnam = <l_s_atr>-attrinm.
Program SAPLXRSR
|
+- Include LXRSRTOP
| |
| +- Include LXRSRTAP
| |
| +- Include ZXRSRTOP
|
+- Include LXRSRUXX
| |
| +- Include LXRSRU01
| | |
| | +- Include ZXRSRU01
| |
| +- Include LXRSRU02
| | |
| | +- Include ZXRSRU02
| |
| +- Include LXRSRU04
| | |
| | +- Include ZXRSRU04
| |
| +- Include LXRSRU05
| | |
| | +- Include ZXRSRU05
| |
| +- Include LXRSRU03
| |
| +- Include LXRSRU06
| | |
| | +- Include ZXRSRU06
| |
| +- Include LXRSRU07
| | |
| | +- Include ZXRSRU07
|
+- Include LXRSRF00
|
+- Include ZXRSRZZZ
|
+- Include ZXRSRF01
*----------------------------------------------------------------------*
***INCLUDE ZXRSRTOP.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
***INCLUDE ZXRSRU01.
*----------------------------------------------------------------------*
DATA:
l_factor TYPE f,
l_factor1 TYPE f,
l_factor2 TYPE f,
l_msgv1 LIKE sy-msgv1, "insert
l_msgv2 LIKE sy-msgv2, "insert
l_msgv3 LIKE sy-msgv3, "insert
l_material LIKE /bi0/pmaterial-material,
l_base_uom LIKE /bi0/pmaterial-base_uom.
ENDIF.
CLEAR l_s_range.
l_s_range-sign = 'I'.
l_s_range-opt = 'EQ'.
l_s_range-low = l_factor.
APPEND l_s_range TO e_t_range.
ENDIF.
*----------------------------------------------------------------------*
***INCLUDE ZXRSRZZZ
*----------------------------------------------------------------------*
INCLUDE zxrsrf01.
*----------------------------------------------------------------------*
***INCLUDE ZXRSRF01
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form get_factor
*&---------------------------------------------------------------------*
* Get conversion factor from /bi0/pmat_unit
*----------------------------------------------------------------------*
FORM get_factor USING i_material TYPE /bi0/oimaterial
i_mat_unit TYPE /bi0/oimat_unit
e_factor.
TYPES:
BEGIN OF ys_mat_unit,
material TYPE /bi0/oimaterial,
mat_unit TYPE /bi0/oimat_unit,
numerator TYPE /bi0/oinumerator,
denomintr TYPE /bi0/oidenomintr,
END OF ys_mat_unit.
DATA:
l_s_mat_unit TYPE ys_mat_unit.
STATICS:
s_t_mat_unit TYPE SORTED TABLE OF ys_mat_unit
WITH UNIQUE DEFAULT KEY.
IF l_s_mat_unit-denomintr <> 0.
e_factor = l_s_mat_unit-numerator / l_s_mat_unit-denomintr.
ENDIF.
Set the restricted key figure to "Always Hide“. It is used only to reference the input variable for Unit of
Measure.
4 Presentation
When you execute the query, the user will be prompted for the alternate unit of measure on the
variable selection screen.
The unit of measure can be entered or selected using the value help.
The query result will show the quantities converted into the unit of measure entered by the user. If no
conversion factor is available (in the master data for 0MAT_UNIT) then the result of the conversion is
equal to the original value.
Note: In this example, conversion factors have been maintained only for some materials. Therefore,
the some “converted values” are shown with the original amount and unit of measure.
5 Comments
• In BW release 3.x you have to delete the OLAP cache for the queries that use the
alternative unit of measure, whenever new conversion factors are loaded! Alternatively,
you can deactivate the OLAP cache for those queries (transaction RSRT).
• The "key to success" is to use a calculated key figure. Anything else like a formula in a
structure does not work! Also this calculated key figure must be defined based on the basic
key figure of the InfoCube and not based on other restricted or calculated key figures.
• Note: In order to return to the SAP Standard, simply remove the modification from program
LRRSVF20.
• If the units of measure are displayed as “ERR” in the result set, please implement SAP note
617048 or the corresponding support pack.
6 Appendix
Here are some hints for debugging in case the query is not showing the expected results:
1. Run transaction RSRT and select your query.
2. Edit Æ Technical Information
3. Check section “OLAP-Relevant Data”. “Calculation before Aggregation” and “Attributes in
Calculated Key Figures” both need to be “Y”. Otherwise the key figure(s) are not setup correctly.
Note: The red/yellow lights are OK and can be ignored.