You are on page 1of 18

How to

Realize summarized display of stock values on


storage location level

BUSINESS INFORMATION WAREHOUSE

Applicable Releases: 3.0B >= SP19


Release date, March 2004

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 REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

1 Business Scenario
This how to paper fills the gap by providing queries with summarized display of stock values on
storage location level.
OSS note 589024 describes the solution to display stock values on storage location level mainly for
single material numbers. Such a solution cannot be applied to queries that have no drill down on
material number level because individual material prices are not considered.
The following steps describe a solution that considers individual material prices in such queries.

Please note that with this solution also the correct stock value on storage location for a single
material can be realized. This can be used as an alternative to the solution of OSS note 589024.
Also it is possible to apply this solution for reporting stock values on stock type level.
In both cases the following solution has to be changed accordingly.

2 Introduction
Calculating stock values on storage location level is done by virtual key figures using the BADI
"RSR_OLAP_BADI.
At first method "INITIALIZE executes a pre query that selects plant quantities and values of all
materials. With this a price factor for each material on plant level can be calculated that calculates the
storage location value by multiplying it with the storage location quantity (method COMPUTE).
This algorithm follow the R/3 design that evaluation is done on plant level and storage location values
are calculated in the runtime of corresponding reports (see OSS notes 322335 and 543188).
The following steps have to by done (example with Z0IC_C03 that is a copy of Business Content
InfoCube 0IC_C03):
1. Pre query with plant quantity/values of all materials: Z0IC_C03/MAT_PRICE
2. Main query that contains the summarized display of storage location stock values:
Z0IC_C03/VALUE_STORAGE_LOCATION
3. DDIC structure: ZZWREX
4. Function module: ZFM_IM_Z_MATERIAL_PRICE
5. Class: ZCL_IM_Z_MATERIAL_PRICE (BADI RSR_OLAP_BADI)
6. User Exit Include: ZXRSRU01 (User Exit RSR00001)

2004 SAP AMERICA, INC. AND SAP AG 1


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

3 The Step By Step Solution

1. Definition of pre query with plant quantity/values of all materials

1. Query Definition

2004 SAP AMERICA, INC. AND SAP AG 2


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

2. Main query that contains the summarized display of storage location stock
values

1. Query Definition, key figure


0VALSTCKVAL is used as
the virtual key figure

2. Variable for calendar month


general information

2004 SAP AMERICA, INC. AND SAP AG 3


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

3. Variable for calendar month


details

4. Variable for plant general


information

2004 SAP AMERICA, INC. AND SAP AG 4


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

5. Variable for plant details

3. DDIC stucture "ZZWREX"

1. Transaction SE11

2004 SAP AMERICA, INC. AND SAP AG 5


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

4. Function module "ZFM_IM_Z_MATERIAL_PRICE" (Function group "ZZIM")

1. Transaction FUNCTION-POOL zzim.


SE37 global TYPES:
data g_s_axis_info TYPE bapi6111axi,
g_t_axis_info TYPE bapi6111axi OCCURS 0,

* g_s_axis_dimensions TYPE bapi6111axd,


g_t_axis_dimensions TYPE bapi6111axd OCCURS 0,

* g_s_mndtry_prptys TYPE bapi6111mpp,


g_t_mndtry_prptys TYPE bapi6111mpp OCCURS 0,

* g_s_option_prptys_keys TYPE bapi6111opk,


* g_t_option_prptys_keys TYPE bapi6111opk OCCURS 0,

* g_s_axis_levels type BAPI6111AXL,


* g_t_axis_levels type BAPI6111AXL occurs 0,

g_s_option_prptys_vals TYPE bapi6111opv,


g_t_option_prptys_vals TYPE bapi6111opv OCCURS 0.

* g_s_dim_prptys type BAPI6111DPR,


* g_t_dim_prptys type BAPI6111DPR occurs 0,

* g_s_fltcolinfo type BAPI6111FCI,


* g_t_fltcolinfo type BAPI6111FCI occurs 0.

DATA:
l_t_mndtry_prptys TYPE g_t_mndtry_prptys,
* l_s_mndtry_prptys TYPE g_s_mndtry_prptys,

* l_t_option_prptys_keys TYPE g_t_option_prptys_keys,


* l_s_option_prptys_keys TYPE g_s_option_prptys_keys,

l_t_option_prptys_vals TYPE g_t_option_prptys_vals,


l_s_option_prptys_vals TYPE g_s_option_prptys_vals,

l_t_axis_dimensions TYPE g_t_axis_dimensions,


* l_s_axis_dimensions TYPE g_s_axis_dimensions,

l_t_axis_info TYPE g_t_axis_info,

* l_t_axis_levels type g_t_axis_levels,

* l_t_dim_prptys type g_t_dim_prptys,

* l_t_FLTCOLINFO type g_t_fltcolinfo,

* l_s_axis_info_columns TYPE g_s_axis_info,


* l_s_axis_info_rows TYPE g_s_axis_info,

l_datasetid LIKE bapi6111gen-obj_handle,


l_start_cell LIKE bapi6111cd-cell_ordinal,
l_end_cell LIKE bapi6111cd-cell_ordinal,
g_t_cell_data TYPE bapi6111cd OCCURS 0,
g_s_cell_data LIKE bapi6111cd,
* g_t_cell_props type BAPI6111PRN occurs 0,
* g_s_cell_props like BAPI6111PRN,
l_s_return LIKE bapiret2,
* l_cell LIKE sy-tabix,
* l_tuple LIKE sy-tabix,
counter type i.

CONSTANTS:
* g_c_axis_columns TYPE g_s_axis_info-axis VALUE '000',
g_c_axis_rows TYPE g_s_axis_info-axis VALUE '001'.
* g_c_axis_slicer TYPE g_s_axis_info-axis VALUE '255'.

2004 SAP AMERICA, INC. AND SAP AG 6


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

2. Transaction
SE37
interfaces

3. Transaction
SE37
exceptions

2004 SAP AMERICA, INC. AND SAP AG 7


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

4. Transaction FUNCTION zfm_im_z_material_price.


*"--------------------------------------------------------------------
SE37 source --
code *"*"Local interface:
*" TABLES
*" I_COMMAND_TEXT STRUCTURE BAPI6111MDX
*" E_BW_DATA STRUCTURE ZZWREX
*" EXCEPTIONS
*" NOTHING_FOUND
*"--------------------------------------------------------------------
--

* 1. data selection with MDX BAPIs

CALL FUNCTION 'BAPI_MDDATASET_CREATE_OBJECT'


DESTINATION 'NONE'
IMPORTING
return = l_s_return
datasetid = l_datasetid
TABLES
command_text = i_command_text.

IF NOT l_s_return IS INITIAL.


RAISE nothing_found.
ENDIF.

CALL FUNCTION 'BAPI_MDDATASET_SELECT_DATA'


DESTINATION 'NONE'
EXPORTING
datasetid = l_datasetid
* suppress_empty_cells =
* use_scaling_factors =
* explainable =
importing
return = l_s_return.
* tables
* cmd =
* cmd_params =
* trace =

IF NOT l_s_return IS INITIAL.


RAISE nothing_found.
ENDIF.

CALL FUNCTION 'BAPI_MDDATASET_GET_AXIS_DATA'


DESTINATION 'NONE'
EXPORTING
datasetid = l_datasetid
axis = g_c_axis_rows
* start_tuple =
* end_tuple =
IMPORTING
return = l_s_return
TABLES
mndtry_prptys = l_t_mndtry_prptys
* option_prptys_keys =
option_prptys_vals = l_t_option_prptys_vals.

IF NOT l_s_return IS INITIAL.


RAISE nothing_found.
ENDIF.

CALL FUNCTION 'BAPI_MDDATASET_GET_AXIS_INFO'


DESTINATION 'NONE'
EXPORTING
datasetid = l_datasetid
IMPORTING
return = l_s_return
TABLES
axis_info = l_t_axis_info
axis_dimensions = l_t_axis_dimensions.
* axis_levels =
* dim_prptys =
* fltcolinfo =

2004 SAP AMERICA, INC. AND SAP AG 8


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

IF NOT l_s_return IS INITIAL.


RAISE nothing_found.
ENDIF.

CALL FUNCTION 'BAPI_MDDATASET_GET_CELL_DATA'


DESTINATION 'NONE'
EXPORTING
datasetid = l_datasetid
start_cell = l_start_cell
end_cell = l_end_cell
IMPORTING
return = l_s_return
TABLES
cell_data = g_t_cell_data.
* cell_props =

IF NOT l_s_return IS INITIAL.


RAISE nothing_found.
ENDIF.

CALL FUNCTION 'BAPI_MDDATASET_DELETE_OBJECT'


DESTINATION 'NONE'
EXPORTING
datasetid = l_datasetid
IMPORTING
return = l_s_return.

IF NOT l_s_return IS INITIAL.


RAISE nothing_found.
ENDIF.

* 2. creation of material plant quantities/values


* !!! adjust this accordingly to your query definitions !!!

LOOP AT l_t_option_prptys_vals INTO l_s_option_prptys_vals.


MOVE l_s_option_prptys_vals-tuple_ordinal TO e_bw_data-recno.
MOVE '0MATERIAL' TO e_bw_data-iobjnm.
MOVE l_s_option_prptys_vals-prpty_val TO e_bw_data-value.
APPEND e_bw_data.
ENDLOOP.

LOOP AT g_t_cell_data INTO g_s_cell_data.

IF g_s_cell_data-currency IS NOT INITIAL.


MOVE counter TO e_bw_data-recno.
MOVE '0VALSTCKVAL' TO e_bw_data-iobjnm.
MOVE g_s_cell_data-value TO e_bw_data-value.
MOVE g_s_cell_data-currency TO e_bw_data-unit.
APPEND e_bw_data.
ELSE.
MOVE counter TO e_bw_data-recno.
MOVE '0TOTALSTCK' TO e_bw_data-iobjnm.
MOVE g_s_cell_data-value TO e_bw_data-value.
counter = counter + 1.
APPEND e_bw_data.
ENDIF.
ENDLOOP.

SORT e_bw_data BY recno iobjnm.

ENDFUNCTION.

2004 SAP AMERICA, INC. AND SAP AG 9


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

5. BADI "RSR_OLAP_BADI"

1. Transaction
SE19

2004 SAP AMERICA, INC. AND SAP AG 10


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

2. Transaction
SE24 class
builder

3. Transaction
SE24 local
class
definitions/types

2004 SAP AMERICA, INC. AND SAP AG 11


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

4. Transaction
SE24
Attributes

5. Transaction method IF_EX_RSR_OLAP_BADI~DEFINE.


SE24 Method * 1. data declarations of BADI framework
IF_EX_RSR_
OLAP_BADI~ data: l_s_chanm type rrke_s_chanm,
l_kyfnm type rsd_kyfnm.
DEFINE field-symbols:
<l_s_chanm> type rrke_s_chanm.

* 2. mark as virtual characteristic/key figures


* !!! adjust this accordingly to your query definitions !!!

if i_s_rkb1d-compid = 'VALUE_STORAGE_LOCATION'.

l_s_chanm-chanm = '0MATERIAL'.
l_s_chanm-mode = rrke_c_mode-read.
append l_s_chanm to c_t_chanm.

l_s_chanm-chanm = '0LOC_CURRCY'.
l_s_chanm-mode = rrke_c_mode-no_selection.
append l_s_chanm to c_t_chanm.

append '0VALSTCKVAL' to c_t_kyfnm.


append '0TOTALSTCK' to c_t_kyfnm.

endif.

Endmethod.

2004 SAP AMERICA, INC. AND SAP AG 12


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

6. Transaction METHOD if_ex_rsr_olap_badi~initialize.


SE24 Method * 1. data declaration BADI framework
IF_EX_RSR_
OLAP_BADI~ DATA: l_global_name TYPE string.
INITIALIZE FIELD-SYMBOLS:
<l_global> TYPE i,
<l_s_sfc> TYPE rrkg_s_sfc,
<l_s_sfk> TYPE rrkg_s_sfk.

* 2. data declarations material plant quantities/values

DATA: l_s_command_text TYPE bapi6111mdx,


l_t_command_text TYPE STANDARD TABLE OF bapi6111mdx,
l_s_bw_data TYPE s_wrex,
l_t_bw_data TYPE STANDARD TABLE OF s_wrex,
l_s_stock TYPE s_stock.

* 3. create MDX statement


* !!! adjust this accordingly to your query definitions !!!
* MDX statement:
* SELECT [Measures].MEMBERS ON COLUMNS,
* NON EMPTY [0MATERIAL].[LEVEL01].MEMBERS
* properties member_name on rows
* FROM Z0IC_C03/MAT_PRICE SAP VARIABLES
* [0P_PLANT] INCLUDING [0PLANT].[1000]
* [0PCALMON] INCLUDING [0CALMONTH].[2003.12]

APPEND
'SELECT' TO l_t_command_text.
APPEND
'[Measures].MEMBERS ON COLUMNS,' TO l_t_command_text.
APPEND
'NON EMPTY' TO l_t_command_text.
APPEND
'[0MATERIAL].[LEVEL01].MEMBERS ' TO l_t_command_text.
APPEND
'properties member_name ' TO l_t_command_text.
APPEND
'on rows ' TO l_t_command_text.
APPEND
'FROM Z0IC_C03/MAT_PRICE ' TO l_t_command_text.
APPEND
'SAP VARIABLES' TO l_t_command_text.
CONCATENATE
'[0P_PLANT] INCLUDING [0PLANT].[' plant ']' INTO l_s_command_text.
APPEND l_s_command_text TO l_t_command_text.
CLEAR l_s_command_text.
CONCATENATE
'[0PCALMON] INCLUDING [0CALMONTH].[' month ']' INTO
l_s_command_text.
APPEND l_s_command_text TO l_t_command_text.

* 4. get material plant quantities/values for selected plant/month

IF first IS INITIAL.
FREE: l_t_bw_data, t_stock.

CALL FUNCTION 'ZFM_IM_Z_MATERIAL_PRICE'


TABLES
i_command_text = l_t_command_text
e_bw_data = l_t_bw_data
EXCEPTIONS
nothing_found = 1.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* 5. create price table


* !!! adjust this accordingly to your query definitions !!!

2004 SAP AMERICA, INC. AND SAP AG 13


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

DATA recno_save LIKE l_s_bw_data-recno.

LOOP AT l_t_bw_data INTO l_s_bw_data.


IF recno_save NE l_s_bw_data-recno.
CLEAR l_s_stock.
ENDIF.
CASE l_s_bw_data-iobjnm.
WHEN '0MATERIAL'.
l_s_stock-material = l_s_bw_data-value.
WHEN '0TOTALSTCK'.
l_s_stock-totalstck = l_s_bw_data-value.
WHEN '0VALSTCKVAL'.
l_s_stock-valstckval = l_s_bw_data-value.
l_s_stock-loc_currcy = l_s_bw_data-unit.
INSERT l_s_stock INTO TABLE t_stock.
ENDCASE.
recno_save = l_s_bw_data-recno.
ENDLOOP.

first = 'X'.

ENDIF.

* 6. BADI framework

* there's no need to change this method


* Just create attributes for each charactersitic
* with name P_CHA_<characteristic> TYPE i.
* and constants for each key figure with name
* P_KYF_<key figure> TYPE i.

CLASS cl_exm_im_rsr_olap_badi DEFINITION LOAD.

* get field postions for characteristics in structure


LOOP AT i_th_sfc ASSIGNING <l_s_sfc>
WHERE user_exit NE rrke_c_mode-none.
* field name in structure is keyreturnnm
* name of the global variable
CONCATENATE 'P_CHA' <l_s_sfc>-chanm
INTO l_global_name
SEPARATED BY '_'.
* fill the global variable
UNASSIGN <l_global>.
ASSIGN (l_global_name) TO <l_global>.
CHECK <l_global> IS ASSIGNED.
<l_global> = cl_exm_im_rsr_olap_badi=>get_field_position_d(
i_fieldnm = <l_s_sfc>-keyreturnnm
i_s_data = i_s_data ).
ENDLOOP.

* get field positions for key figures in structure


LOOP AT i_th_sfk ASSIGNING <l_s_sfk>.
* name of the global variable
CONCATENATE 'P_KYF' <l_s_sfk>-kyfnm
INTO l_global_name
SEPARATED BY '_'.
* fill the global variable
UNASSIGN <l_global>.
ASSIGN (l_global_name) TO <l_global>.
CHECK <l_global> IS ASSIGNED.
<l_global> = cl_exm_im_rsr_olap_badi=>get_field_position_d(
i_fieldnm = <l_s_sfk>-kyfnm
i_s_data = i_s_data ).
ENDLOOP.

ENDMETHOD.

2004 SAP AMERICA, INC. AND SAP AG 14


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

7. Transaction method IF_EX_RSR_OLAP_BADI~COMPUTE.


SE24 Method * 1. data declarations
IF_EX_RSR_ * !!! adjust this accordingly to your query definitions !!!
OLAP_BADI~
FIELD-SYMBOLS <l_s_stock> TYPE s_stock.
COMPUTE -
Unit-InfoObject FIELD-SYMBOLS <l_0material> TYPE ANY.
"0LOC_ FIELD-SYMBOLS <l_0loc_currcy> TYPE ANY.
FIELD-SYMBOLS <l_0valstckval> TYPE ANY.
CURRCY has FIELD-SYMBOLS <l_0totalstck> TYPE ANY.
also to be
calculated in ASSIGN COMPONENT p_cha_0material
OF STRUCTURE c_s_data TO <l_0material>.
method
"COMPUTE, as ASSIGN COMPONENT p_cha_0loc_currcy
InfoCube records OF STRUCTURE c_s_data TO <l_0loc_currcy>.
are updated with ASSIGN COMPONENT p_kyf_0valstckval
storage location OF STRUCTURE c_s_data TO <l_0valstckval>.
values for
ASSIGN COMPONENT p_kyf_0totalstck
quantities and OF STRUCTURE c_s_data TO <l_0totalstck>.
without for
values and FREE: <l_0valstckval>.
storage location * 2. read price factor
is in drill down. * !!! adjust this accordingly to your query definitions !!!
This would lead READ TABLE t_stock ASSIGNING <l_s_stock>
the display of WITH table KEY material = <l_0material>.
unit ERROR of
* 3. calculate storage location values
virtual key figure * !!! adjust this accordingly to your query definitions !!!
"0VALSTCKVAL
IF sy-subrc = 0 AND <l_s_stock>-totalstck NE 0.
<l_0valstckval> = <l_s_stock>-valstckval /
<l_s_stock>-totalstck *
<l_0totalstck>.
<l_0loc_currcy> = <l_s_stock>-loc_currcy.
ENDIF.

endmethod.

2004 SAP AMERICA, INC. AND SAP AG 15


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

6. User Exit "RSR00001"

1. Implement this * !!! adjust this accordingly to your query definitions !!!
data: l_s_range type rrrangesid.
coding in the if i_s_rkb1d-compid = 'VALUE_STORAGE_LOCATION'.
user exit if i_step = 3.
loop at i_t_var_range into l_s_var_range.
if l_s_var_range-vnam = 'ZZMONTH'.
ZCL_IM_Z_MATERIAL_PRICE=>month = l_s_var_range-low.
elseif l_s_var_range-vnam = 'ZZPLANT'.
ZCL_IM_Z_MATERIAL_PRICE=>plant = l_s_var_range-low.
endif.
endloop.
endif.
endif.

4 Summary
Mandatory entries of query in step 2 are handed over in the user exit of step 6 to the instance of the
ABAP class in step 5. With this entries pre query of step 1 is executed.
All coding parts are using released BAPIs. Coding is as much as possible generic so that changes
due the changed query definitions are rather easy to implement. Coding parts that have to be
adapted are marked with the comment "* !!! adjust this accordingly to your query
definitions !!!".

5 Critical factors

1. Performance

The runtime of the pre query could become critical as in some cases a high volume of data has to be
selected.
If the pre query exeeds a cell size of 999.999 funktion module "ZFM_IM_Z_MATERIAL_PRICE has
to called several time in any case (current technical limitation), for instance for every material group.
Object and source code has to be adapted (see chapter 4).
In every case runtime of such queries are high due to reporting on mass data. Therefore it is
recommended to use pre-calculated queries instead of executing them online.

2004 SAP AMERICA, INC. AND SAP AG 16


HOW TO REALIZE SUMMARIZED DISPLAY OF STOCK VALUES ON STORAGE LOCATION LEVEL

2. Enhancements

It it is required to report on more than one plant variable restrictions have to be changed accordingly.
Pre query calls should then be realized individual per plant due to performance reasons (see above).

6 Attachments

Attached there are two transport files that contain:


- package ZZIM
- class ZCL_IM_Z_MATERIAL_PRICE
- fuction group ZZIM
- table zzwrex

2004 SAP AMERICA, INC. AND SAP AG 17

You might also like