You are on page 1of 26

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
BUSINESS INFORMATION WAREHOUSE

ASAP How to Paper

Applicable Releases: SAP BW 2.0A to 3.5
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
1998 SAP AMERICA, INC. AND SAP AG TABLE OF CONTENTS
November 2004
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 1
Overview
1 BUSINESS SCENARIO.......................................................................................................... 2
1.1 Key findings................................................................................................................................................................ 2
1.2 Data Flow Diagram.................................................................................................................................................... 2
1.3 Benefits........................................................................................................................................................................ 3
1.4 Version History.......................................................................................................................................................... 3
2 SOLUTION............................................................................................................................ 4
3 THE STEP-BY-STEP SOLUTION ............................................................................................ 5
3.1 Key Figure for Conversion Factor .......................................................................................................................... 5
3.2 Characteristic Material............................................................................................................................................ 6
3.3 Characteristic for Alternate Units of Measure.................................................................................................... 7
3.4 Variable for Alternate Unit of Measure................................................................................................................. 9
3.5 Formula Variabl e for Conversion Factor ............................................................................................................11
3.6 Modification..............................................................................................................................................................13
3.7 User Exit for Variables ...........................................................................................................................................16
3.8 Calculated Key Figures for Conversion ..............................................................................................................19
3.9 Restricted Key Figure for Input............................................................................................................................21
3.10 Create a Query.........................................................................................................................................................22
4 PRESENTATION.................................................................................................................. 23
5 COMMENTS........................................................................................................................ 24
6 APPENDIX .......................................................................................................................... 24

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 2
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.
1.1 Key findings
A dynamic unit conversion as with currencies in BEx context menus is not possible.
A calculated key figure with a variable based on it can be used to represent all units of
measurement for which conversion factors in the material master exist.
At the start of a query, the user enters the alternate unit of measure as a text variable. The
system then reads the necessary conversion factors and dynamically converts the quantities
into the alternate unit of measure.
The solution is based on a small modification of standard SAP code.
1.2 Data Flow Diagram

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 3
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.

1.4 Version History

January 2003 Initial release of How-to paper.
March 2003 Improved handling of inexistent conversion factors (see section 3.7, include
ZXRSRU01).
Correction of user exit coding (for example missing ABAP variables). May 2003
Added reference to SAP note 617048: Unit of measure displayed as ERR in BEx.
Changed variable type from text to characteristic value, which allows usage of
OLAP cache and also enables the value help for unit of measure.
Note: If the old solution with a text variable is already in place, you have to use a
different variable name (for example YCAUNIT instead of YTAUNIT). The ABAP
coding does not have to be adjusted since the checking routine (I_STEP = 3) will be
obsolete.
How-to paper is also relevant for SAP BW release 3.5.
November 2004
Added table of contents.
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 4
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

When a query is executed, then following steps are processed:
1. User enters Alternate Unit of Measure on variable selection screen for variable YTAUNIT.
2. Text variable is being validated in user exit ZXRSRU01. If input is OK, the alternate unit of
measure is stored in a global program variable. Otherwise an error message is displayed and
the user has to correct the entry.
3. The system starts the query program and reads all values for attribute YUOMCNVF of
characteristic 0MATERIAL in order to determine the formula variable YFCONVF.
4. This is the point where the modification is processed. The modification will call the user exit
ZXRSRU01 once for each value of 0MATERIAL that is selected in the query. This allows
determining the conversion factor based on user input of the alternate unit of measure (instead
of using the attribute value from the material master data). The actual value of attribute
YUOMCNVF is ignored.
5. In the user exit ZXRSRU01 for each material the conversion factor from the base unit of measure
to the alternate unit of measure will be determined from the master data table of characteristic
0MAT_UNIT. If a conversion factor cannot be determined (does not exist or division by zero),
it is set to zero. The conversion factors are buffered in memory in order to minimize database
selections.
6. The system continues processing the query. The transaction data is selected from the
InfoCube. Then the system determines the result of each calculated key figure based on the
formula variable.


HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 5
3 The Step-By-Step Solution
3.1 Key Figure for Conversion Factor
Create key figure YUOMCNVF for conversion factor.

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 6
3.2 Characteristic Material
Activate InfoObject 0MATERIAL from business content.
Add key figure YUOMCNVF as an attribute to InfoObject 0MATERIAL.
Note: This attribute can be left empty (initial value) and does not need to be filled with any conversion
factor!


HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 7
3.3 Characteristic for Alternate Units of Measure
Activate InfoObject 0MAT_UNIT from business content.
Load conversion factors from R/3 into InfoObject 0MAT_UNIT.
Note: The numerator and denominator attributes need to be filled in the master data table.


HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 8


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.

UoM) (Alternate r Denominato UoM) (Alternate Numerator
UoM) (Base r Denominato UoM) (Base Numerator
Factor Conversion =

Quantity (Alternate UoM) = Quantity (Base UoM) * Conversion Factor



HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 9
3.4 Variable for Alternate Unit of Measure
Note: The screen shots show the variable wizard of release 3.x. In release 2.x, you have to use
transaction RSZV to create variables.
Create variable YTAUNIT for characteristic Unit of Measure (0UNIT).



HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 10
Optionally, enter a default value.




HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 11
3.5 Formula Variable for Conversion Factor
Create formula variable YFCONVF.




HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 12
Pick the attribute that was added to Material in chapter 3.2 (YUOMCNVF).




HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 13
3.6 Modification
Implement modification in program LRRSVF20.

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
***I NCLUDE LRRSVF20 .
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

*&- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
*& For m var chavl _at r _get
*&- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
f or mvar chavl _at r _get usi ng i _t _si d t ype r r si _t _si d
i _chanm t ype r sd_i obj nm
i _t h_var _at r t ype r r o01_t h_var _l r ech
i _sr dat e t ype sy- dat um
i _most r ecent t ype r sr _most r ecent
changi ng c_t h_var chavl t ype r r sv_t h_var chavl .

cal l met hod l _r _r eader - >si d_r ead_mast er
expor t i ng
i _r eadat r = r sdm_c_r eadat r - speci f i ed
i _t _r eq_at r = l _t _r eq_at r
i _dat e = i _sr dat e
i _most r ecent = i _most r ecent
i mpor t i ng
e_t x_at r = l _t x_at r
changi ng
c_t _chavl i nf o = l _t _chavl i nf o
except i ons
ot her s = 1.
i f sy- subr c <> 0.
r ai se i nher i t ed_er r or .
endi f .
*{ I NSERT
*** Enhancement Al t er nat e U. o. M.
I NCLUDE ybw_auni t _enhancement .
*
*} I NSERT
PERFORM var chavl _at r _f i l l USI NG i _t h_var _at r
l _t x_at r
CHANGI NG c_t h_var chavl .
. . .
endf or m. " var chavl _at r _get

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
***I NCLUDE YBW_AUNI T_ENHANCEMENT.
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

TYPE- POOLS: r r s0.

DATA:
l _vnam LI KE r szgl obv- vnam,
l _s_cob_pr o TYPE r sd_s_cob_pr o,
l _s_r kb1d TYPE r sr _s_r kb1d,
l _per i v TYPE r r o01_s_r kb1f - per i v,
l _t _var _r ange TYPE r r s0_t _var _r ange,
l _s_var _r ange TYPE r r s0_s_var _r ange,
l _t _r ange TYPE r sr _t _r angesi d,
l _s_r ange TYPE r sr _s_r angesi d,
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 14
l _uni t LI KE r szgl obv- meeht ,
l _cur r ency LI KE r szgl obv- waer s.

FI ELD- SYMBOLS:
<l _sx_at r > TYPE r sdm_sx_at r ,
<l _s_var > TYPE r r o01_s_var _l r ech,
<l _s_at r > TYPE r sdm_s_at r ,
<l _s_at r _cu> TYPE r sdm_s_at r .

* Loop over al l char act er i st i c val ues
LOOP AT l _t x_at r ASSI GNI NG <l _sx_at r >.

* Loop over al l var i abl es t o be r epl aced by at t r i but es
LOOP AT i _t h_var _at r ASSI GNI NG <l _s_var >.

* Fi l l addi t i onal i nf or mat i on i nt o pseudo var i abl es
REFRESH l _t _var _r ange.

* I nf oObj ect ( i . e. char act er i st i c)
CLEAR l _s_var _r ange.
l _s_var _r ange- si gn = ' I ' .
l _s_var _r ange- opt = ' EQ' .
l _s_var _r ange- vnam = ' 1CHANM' .
l _s_var _r ange- i obj nm= i _chanm.
l _s_var _r ange- l ow = <l _sx_at r >- chavl .
APPEND l _s_var _r ange TO l _t _var _r ange.

* At t r i but e
READ TABLE <l _sx_at r >- t _at r ASSI GNI NG <l _s_at r >
WI TH KEY at t r i nm= <l _s_var >- at t r i nm.
I F sy- subr c <> 0.
RAI SE x_message.
ENDI F.

CLEAR l _s_var _r ange.
l _s_var _r ange- si gn = ' I ' .
l _s_var _r ange- opt = ' EQ' .
l _s_var _r ange- vnam = ' 1ATTRI NM' .
l _s_var _r ange- i obj nm= <l _s_at r >- at t r i nm.
l _s_var _r ange- l ow = <l _s_at r >- at t r i vl .
APPEND l _s_var _r ange TO l _t _var _r ange.

* Uni t of measur e ( onl y f or amount s and quant i t i es)
I F ( <l _s_var >- mwkz = ' M' OR <l _s_var >- mwkz = ' Q' ) AND
( <l _s_var >- f i xcudi mI S I NI TI AL ) .

CLEAR l _s_var _r ange.
l _s_var _r ange- si gn = ' I ' .
l _s_var _r ange- opt = ' EQ' .
l _s_var _r ange- vnam = ' 1CUNM' .

READ TABLE <l _sx_at r >- t _at r ASSI GNI NG <l _s_at r _cu>
WI TH KEY at t r i nm= <l _s_var >- cunm.
I F sy- subr c = 0.
l _s_var _r ange- i obj nm= <l _s_at r _cu>- at t r i nm.
l _s_var _r ange- l ow = <l _s_at r _cu>- at t r i vl .
APPEND l _s_var _r ange TO l _t _var _r ange.
ENDI F.

ENDI F.

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 15
* Key dat e of quer y
CLEAR l _s_var _r ange.
l _s_var _r ange- si gn = ' I ' .
l _s_var _r ange- opt = ' EQ' .
l _s_var _r ange- vnam = ' 1DATE' .
l _s_var _r ange- i obj nm= ' 0DATE' .
l _s_var _r ange- l ow = i _sr dat e.
APPEND l _s_var _r ange TO l _t _var _r ange.

* I nf oObj ect pr oper t i es
CALL FUNCTI ON ' RSD_COB_PRO_GET_ALWAYS'
EXPORTI NG
i _i obj nm = i _chanm
I MPORTI NG
e_s_cob_pr o = l _s_cob_pr o
EXCEPTI ONS
i nf ocube_not _f ound = 1
er r or _r eadi ng_i nf ocat al og = 2
i obj nm_not _f ound = 3
i l l egal _i nput = 4
OTHERS = 5.
I F sy- subr c <> 0.
MESSAGE I D sy- msgi d TYPE sy- msgt y NUMBER sy- msgno
WI TH sy- msgv1 sy- msgv2 sy- msgv3 sy- msgv4.
ENDI F.

l _vnam= <l _s_at r >- at t r i nm.

* Cal l var i abl e exi t t o get vi r t ual at t r i but e
CALL FUNCTI ON ' EXI T_SAPLRRS0_001'
EXPORTI NG
i _vnam = l _vnam
i _var t yp = r r kg_c_var t yp- f or mul a
i _i obj nm = i _chanm
i _s_cob_pr o = l _s_cob_pr o
i _s_r kb1d = l _s_r kb1d
i _per i v = l _per i v
i _t _var _r ange = l _t _var _r ange
I MPORTI NG
e_t _r ange = l _t _r ange
e_meeht = l _uni t
e_waer s = l _cur r ency
EXCEPTI ONS
OTHERS = 1.
I F sy- subr c = 0.
READ TABLE l _t _r ange I NTO l _s_r ange I NDEX 1.
I F sy- subr c = 0.
* At t r i but e val ue
<l _s_at r >- at t r i vl = l _s_r ange- l ow.
* At t r i but e uni t of measur e ( onl y f or amount s and quant i t i es)
I F <l _s_var >- mwkz = ' M' AND <l _s_var >- f i xcudi mI S I NI TI AL.
<l _s_at r _cu>- at t r i vl = l _uni t .
ELSEI F <l _s_var >- mwkz = ' W' AND <l _s_var >- f i xcudi mI S I NI TI AL.
<l _s_at r _cu>- at t r i vl = l _cur r ency.
ENDI F.
ENDI F.
ENDI F.

ENDLOOP. " var i abl es f or at t r i but es

ENDLOOP. " char act er i st i c val ues
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 16
3.7 User Exit for Variables
Implement user exit for variables and activate enhancement RSR00001.

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
***I NCLUDE ZXRSRTOP.
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

*** Enhancement : Al t er nat e U. o. M.
DATA: g_auni t TYPE / bi 0/ oi mat _uni t .

*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
***I NCLUDE ZXRSRU01.
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

*** Enhancement : Al t er nat e U. o. M.
DATA:
l _s_r ange TYPE r sr _s_r angesi d,
l _s_var TYPE r r s0_s_var _r ange.
* l _dummy( 72) TYPE c. "del et e

DATA:
l _f act or TYPE f ,
l _f act or 1 TYPE f ,
l _f act or 2 TYPE f ,
l _msgv1 LI KE sy- msgv1, "i nser t
l _msgv2 LI KE sy- msgv2, "i nser t
l _msgv3 LI KE sy- msgv3, "i nser t
l _mat er i al LI KE / bi 0/ pmat er i al - mat er i al ,
l _base_uom LI KE / bi 0/ pmat er i al - base_uom.

* Cal l ed af t er user i nput
I F i _st ep = 3.

* Get var i abl e f or al t er nat i ve uni t ent er ed by user
* Val i dat e ent r y and st or e as gl obal var i abl e
READ TABLE i _t _var _r ange WI TH KEY vnam= ' YTAUNI T' I NTO l _s_var .
I F sy- subr c = 0.
TRANSLATE l _s_var- l ow TO UPPER CASE. "#EC TRANSLANG
CALL FUNCTI ON ' CONVERSI ON_EXI T_CUNI T_I NPUT'
EXPORTI NG
i nput = l _s_var - l ow
l anguage = sy- l angu
I MPORTI NG
out put = g_auni t
EXCEPTI ONS
uni t _not _f ound = 1
OTHERS = 2.
I F sy- subr c <> 0.
* Er r or : Pl ease ent er a val i d uni t of measur e
l _msgv1 = ' Unknown uni t of measur e: ' .
l _msgv2 = l _s_var - l ow. "i nser t
l _msgv3 = ' . Pl ease ent er a val i d uni t of measur e. ' .
CALL FUNCTI ON ' RRMS_MESSAGE_HANDLI NG'
EXPORTI NG
i _cl ass = ' R9'
i _t ype = ' E'
i _number = ' 000'
i _msgv1 = l _msgv1
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 17
i _msgv2 = l _msgv2 "change
i _msgv3 = l _msgv3
EXCEPTI ONS
dummy = 0
OTHERS = 0.
CALL FUNCTI ON ' RRMS_MESSAGES_SHOW' .
CALL FUNCTI ON ' RRMS_MESSAGES_DELETE' .
sy- subr c = 4.
RAI SE agai n. "#EC *
ENDI F.
ENDI F.

ENDI F.

* Cal l ed f r om"Get At t r i but e" Funct i on ( Modi f i cat i on)
* I _VNAM At t r i but e ( not t he name of t he f or mul a var i abl e)
* I _I OBJ NM I nf oObj ect
* I _T_VAR_RANGE Cont ai ns char act er i st i c val ue, at t r i but e val ue,
* uni t of measur e, quer y key dat e
I F i _st ep = 0 AND i _vnam= ' YUOMCNVF' AND i _i obj nm= ' 0MATERI AL' .

* r ead mat er i al and base uomf r omvar i abl es
LOOP AT i _t _var _r ange I NTO l _s_var .
CASE l _s_ var - i obj nm.
WHEN ' 0MATERI AL' . l _mat er i al = l _s_var- l ow.
WHEN ' 0BASE_UOM' . l _base_uom= l _s_var- l ow.
ENDCASE.
ENDLOOP.

* get f act or f or base UoM
PERFORM get _f act or USI NG l _mat er i al l _base_uoml _f act or 1.

* get f act or f or al t er nat e UoM
PERFORM get _f act or USI NG l _mat er i al g_auni t l _f act or 2.

* r et ur n conver si on f act or f or var i abl e
I F l _f act or 2 <> ' 0. 0' .
l _f act or = l _f act or 1 / l _f act or 2.
e_meeht = g_auni t . "i nser t
ELSE.
* When t he UoM conver si on i s not mai nt ai ned, i nst ead of showi ng 0, t he
* base UoM wi t h a f act or of 1 i s used. Ther ef or e, t he user sees MI XED
* VALUES i n t he t ot al l i ne and knows r i ght away t hat t her e i s somet hi ng
* wr ong. That way i t s easi er t o t r ack i nexi st ent conver si on f act or s.
* l _f act or = 0. "del et e
l _f act or = 1. "i nser t
e_meeht = l _base_uom. "i nser t
ENDI F.

CLEAR l _s_r ange.
l _s_r ange- si gn = ' I ' .
l _s_r ange- opt = ' EQ' .
l _s_r ange- l ow = l _f act or .
APPEND l _s_r ange TO e_t _r ange.

* e_meeht = g_auni t . "del et e

ENDI F.

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 18
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
***I NCLUDE ZXRSRF01.
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *

*&- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
*& For m get _f act or
*&- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
* Get conver si on f act or f r om/ bi 0/ pmat _uni t
*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
FORM get _f act or USI NG i _mat er i al TYPE / bi 0/ oi mat er i al
i _mat _uni t TYPE / bi 0/ oi mat _uni t
e_f act or .

TYPES:
BEGI N OF ys_mat _uni t ,
mat er i al TYPE / bi 0/ oi mat er i al ,
mat _uni t TYPE / bi 0/ oi mat _uni t ,
numer at or TYPE / bi 0/ oi numer at or ,
denomi nt r TYPE / bi 0/ oi denomi nt r ,
END OF ys_mat _uni t .

DATA:
l _s_mat _uni t TYPE ys_mat _uni t .

STATI CS:
s_t _mat _uni t TYPE SORTED TABLE OF ys_mat _uni t
WI TH UNI QUE DEFAULT KEY.

CLEAR: l _s_mat _uni t , e_f act or .

READ TABLE s_t _mat _uni t I NTO l _s_mat _uni t WI TH KEY
mat er i al = i _mat er i al
mat _uni t = i _mat _uni t .
I F sy- subr c <> 0.
SELECT SI NGLE * FROM / bi 0/ pmat _uni t
I NTO CORRESPONDI NG FI ELDS OF l _s_mat _uni t
WHERE mat er i al = i _mat er i al
AND mat _uni t = i _mat _uni t
AND obj ver s = ' A' .
I F sy- subr c = 0.
I NSERT l _s_mat _uni t I NTO TABLE s_t _mat _uni t .
ENDI F.
ENDI F.

I F l _s_mat _uni t- denomi nt r <> 0.
e_f act or = l _s_mat _uni t - numer at or / l _s_mat _uni t - denomi nt r .
ENDI F.

ENDFORM. " get _f act or

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 19
3.8 Calculated Key Figures for Conversion
For each basic key figure that should be shown with the alternate unit of measure, create a matching
calculated key figure.
Note: The solution works only if you build calculated key figures. You must not use the conversion
factor (formula variable) directly in structure formulas.

The generic formula for the conversion is:
= NODIM( Quantity ) * 'Conversion Factor to Alternative Unit of Measure'



HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 20


HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 21
3.9 Restricted Key Figure for Input
To activate the input of the "Alternative Unit of Measure, create one restricted key figure. Restrict the
selection for Unit of Measure to the variable that was created in step 3.4.


HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 22
3.10 Create a Query
Now you can add the calculated key figures and the restricted key figure to the query.

Set the restricted key figure to "Always Hide. It is used only to reference the input variable for Unit of
Measure.

HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 23
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.
HOW TO REPORT DATA IN ALTERNATE UNITS OF MEASURE
2002-04 SAP AMERICA, INC. AND SAP AG 24
5 Comments
In BW release 3.x you have to delete the OLAP cache for the queriesthat 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!
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. Go to Display gen. report
4. Scroll down to "FORM SELECT_0 ..."
5. In this form routine you should find the following lines:
PERFORM VARCHAVL_INIT in program (...) USING '0MATERIAL' L_T_0MATERIAL.
LOOP AT I_T_DATA INTO G_S_DATA.
6. If the PERFORM VARCHAVL_INIT does not exist, the query definition is not correct. There is no
calculated key figure in this query using the formula variable, which is replaced by the attribute.
Check the query definition.
7. If the PERFORM VARCHAVL_INIT exists, put a break-point on that line and run the query (via
RSRT). After you entered the query variable on the popup, the system will stop on this line and if
you step through the code it will reach the point of the modification. In addition you might want to
put another break-point into the user exit for the variable replacement.

You might also like