20
How-to Guide SAP NetWeaver ‘04 How To… Use Reporting Variables in BW-BPS Version 1.00 – February 2005 Applicable Releases: SAP NetWeaver ’04 (SAP BW 3.5, SAP SEM 3.1 to 4.0)

How to...Use Reporting Variables in BW-BPS.pdf

Embed Size (px)

Citation preview

  • How-to Guide SAP NetWeaver 04

    How To Use Reporting Variables in BW-BPS Version 1.00 February 2005 Applicable Releases: SAP NetWeaver 04 (SAP BW 3.5, SAP SEM 3.1 to 4.0)

  • Copyright 2004 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data

    contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. 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. SAP NetWeaver How-to Guides 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 SAP NetWeaver. Should you wish to receive additional information, clarification or support, please refer to SAP Consulting. Any software coding and/or code lines / strings (Code) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

  • - 1 -

    Table of Contents 1 Business Scenario ..................................................................................................... 2 2 Introduction ................................................................................................................ 2 3 The Step By Step Solution......................................................................................... 3

    3.1 Mapping Table .................................................................................................... 3 3.2 Function Modules ............................................................................................... 4 3.3 BPS Variables..................................................................................................... 4

    4 Appendix A: Mapping Table....................................................................................... 5 5 Appendix B: Function Group...................................................................................... 6 6 Appendix C: SAP Exit Variables .............................................................................. 12 7 Appendix D: Examples............................................................................................. 13

    7.1 Mapping Table for the Examples ...................................................................... 13 7.2 Example for Global BPS Variable..................................................................... 14 7.3 Example for Characteristic Variable ................................................................. 14 7.4 Example for Attribute Variable .......................................................................... 14 7.5 Example for Numeric Variable .......................................................................... 15 7.6 Example for Hierarchy Node Variable .............................................................. 15 7.7 Example for Using the Variables ...................................................................... 16

  • - 2 -

    1 Business Scenario There are dozens of reporting variables delivered with SAP BI Business Content. For example, there are predefined variables for current and previous year, current date, current user ID, or the organizational unit assigned to the user. You want to use those reporting variables in you planning applications. Another scenario is that you want to define global variables that span across all planning applications. For example, instead of maintaining the planning version in each planning area, you define and maintain it on one planning area and reuse it on all other areas. Its works like a global variable. Standard BW-BPS functionality does not support reporting variables or global variables. This document describes a solution that addresses both issues.

    2 Introduction BW-BPS can be extended with so called exit variables. The solution described here provides a mapping table and generic function modules that can be used to link a BPS variable to BW reporting variables or other BPS variables. The implementation is straightforward. All that is required is one transparent table and four function modules, one for each type of BPS variables (characteristic values, attributes, hierarchy nodes, numeric values). There are no limitations for mapping to other BPS variables. However, only certain BW reporting variables may be mapped to. The reporting variable has to fulfill the following conditions:

    - Replacement by SAP exit, Customer exit, or fixed value - No user input - No dependencies on other reporting variables

    Appendixes A and B show the technical details of the implementation (DDIC table and ABAP coding for the function group). Appendix C contains a list of SAP exit reporting variables that have been tested and found to be useful for planning applications. Appendix D gives five examples that are based on standard business content.

  • - 3 -

    3 The Step By Step Solution There are three steps that need to be completed. First, define and maintain the mapping table. Then implement the ABAP function group with its four function modules. And finally create variables in BPS of type user exit that refer to one of the function modules.

    3.1 Mapping Table

    1. Define a transparent table YBW_BPS_VAR_MAP according to the specification in appendix A (transaction SE80). For performance reasons, it is recommended to set the table to be fully buffered (technical settings). Also define a table maintenance view so you can use transaction SM30 to enter and edit the mapping rules.

    2. Maintain the mapping table (transaction SM30). The table key lists the target variable that is supposed to be filled by the exit. There are two options for the source variable: a) BPS variable (fill in AREA2 / VAR2) b) BW variable (fill in INFOCUBE / VNAM)

  • - 4 -

    3.2 Function Modules

    3. Implement function group YBW_BPS_VARIABLES according to appendix B (transaction SE80).

    3.3 BPS Variables

    4. Create variables in BPS. You are free to define any type of variable in BPS (characteristic value, attribute, hierarchy node, or numeric). Select user exit as a replacement type and enter the function module that corresponds to the variable type. Save the model.

    5. You can new use these exit variables wherever you can put variables in BPS (level, layout, functions, etc.). Appendix D contains an example for each variable type.

  • - 5 -

    4 Appendix A: Mapping Table Define a transparent table using the following fields and data elements:

    For better performance, set the table to be fully buffered. Note: Changes to the table content will not become effective immediately unless you flush the buffer.

  • - 6 -

    5 Appendix B: Function Group Note: A quick way to implement these function modules is to make a copy of the following functions and then replace the coding: UPF_VARIABLE_USER_EXIT_ATTR YBW_BPS_VAR_ATTR UPF_VARIABLE_USER_EXIT_CHAR YBW_BPS_VAR_CHAR UPF_VARIABLE_USER_EXIT_HIER YBW_BPS_VAR_HIER UPF_VARIABLE_USER_EXIT_NUM YBW_BPS_VAR_NUM Function Group: YBW_BPS_VARIABLES FUNCTION-POOL ybw_bps_variables. TYPE-POOLS: rsr. TABLES: ybw_bps_var_map. DEFINE message_failed. if sy-subrc 0. message id sy-msgid type sy-msgty number sy-msgno with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 raising failed. endif. END-OF-DEFINITION. FUNCTION ybw_bps_var_attr. *"-------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA *" VALUE(I_VARIABLE) TYPE UPC_Y_VARIABLE *" VALUE(I_CHANM) TYPE UPC_Y_CHANM OPTIONAL *" VALUE(ITO_CHANM) TYPE UPC_YTO_CHA *" VALUE(ITO_ATTR) TYPE UPC_YTO_ATTR *" EXPORTING *" REFERENCE(ETO_CHARSEL) TYPE UPC_YTO_CHARSEL *" EXCEPTIONS *" FAILED *"-------------------------------------------------------------------- * Get variable INCLUDE ybw_bps_var_read. * Process selection REFRESH eto_charsel. IF lr_var IS BOUND. * BPS variable CALL METHOD lr_var->get_value RECEIVING rto_value = eto_charsel EXCEPTIONS error = 1 OTHERS = 2. message_failed. ELSE.

  • - 7 -

    * BW variable READ TABLE ito_attr INTO ls_attr INDEX 1. CHECK sy-subrc = 0. * Process attribute selection CLEAR ls_chasel. ls_chasel-chanm = ls_attr-atrnm. LOOP AT l_t_range INTO l_s_range. CLEAR ls_charng. ls_charng-sign = l_s_range-sign. ls_charng-option = l_s_range-opt. ls_charng-low = l_s_range-low. ls_charng-high = l_s_range-high. INSERT ls_charng INTO TABLE ls_chasel-t_charng. ENDLOOP. INSERT ls_chasel INTO TABLE lto_chasel. * Select characteristic values CALL FUNCTION 'UPC_CHA_VALUES_GET' EXPORTING i_area = i_area i_chanm = i_chanm ito_chasel = lto_chasel i_no_compound = 'X' IMPORTING eto_chavl = lto_chavl EXCEPTIONS OTHERS = 1. IF sy-subrc NE 0. RAISE failed. ENDIF. * Process base characteristic selection LOOP AT lto_chavl INTO ls_chavl. CLEAR ls_charsel. ls_charsel-chanm = i_chanm. ls_charsel-seqno = l_seqno. ls_charsel-sign = 'I'. ls_charsel-opt = 'EQ'. ls_charsel-low = ls_chavl-chavlint. INSERT ls_charsel INTO TABLE eto_charsel. l_seqno = l_seqno + 1. ENDLOOP. ENDIF. ENDFUNCTION.

  • - 8 -

    FUNCTION ybw_bps_var_char. *"-------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA *" VALUE(I_VARIABLE) TYPE UPC_Y_VARIABLE *" VALUE(I_CHANM) TYPE UPC_Y_CHANM OPTIONAL *" VALUE(ITO_CHANM) TYPE UPC_YTO_CHA *" EXPORTING *" REFERENCE(ETO_CHARSEL) TYPE UPC_YTO_CHARSEL *" EXCEPTIONS *" FAILED *"-------------------------------------------------------------------- * Get variable INCLUDE ybw_bps_var_read. * Process selection REFRESH eto_charsel. IF lr_var IS BOUND. * BPS variable CALL METHOD lr_var->get_value RECEIVING rto_value = eto_charsel EXCEPTIONS error = 1 OTHERS = 2. message_failed. ELSE. * BW variable LOOP AT l_t_range INTO l_s_range. CLEAR ls_charsel. ls_charsel-chanm = i_chanm. ls_charsel-seqno = l_seqno. ls_charsel-sign = l_s_range-sign. ls_charsel-opt = l_s_range-opt. ls_charsel-low = l_s_range-low. ls_charsel-high = l_s_range-high. INSERT ls_charsel INTO TABLE eto_charsel. l_seqno = l_seqno + 1. ENDLOOP. ENDIF. ENDFUNCTION.

  • - 9 -

    FUNCTION ybw_bps_var_hier. *"-------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_TYPE) TYPE UPC_Y_VAR_TYPE *" VALUE(I_AREA) TYPE UPC_Y_AREA *" VALUE(I_VARIABLE) TYPE UPC_Y_VARIABLE *" VALUE(IS_HIE_KEY) TYPE UPC_YS_HIE_KEY *" EXPORTING *" REFERENCE(ET_HIE_NODES) TYPE UPC_YT_HIESEL *" EXCEPTIONS *" FAILED *"-------------------------------------------------------------------- * Get variable INCLUDE ybw_bps_var_read. * Process selection REFRESH et_hie_nodes. IF lr_var IS BOUND. * BPS variable CALL METHOD lr_var->get_hie_nodes RECEIVING rt_value = et_hie_nodes EXCEPTIONS error = 1 OTHERS = 2. message_failed. ELSE. * BW variable LOOP AT l_t_range INTO l_s_range. CLEAR ls_hie_nodes. ls_hie_nodes-chanm = is_hie_key-chanm. ls_hie_nodes-hienm = is_hie_key-hienm. ls_hie_nodes-hiever = is_hie_key-hiever. ls_hie_nodes-dateto = is_hie_key-dateto. ls_hie_nodes-nodename = l_s_range-low. IF l_s_range-high IS INITIAL. ls_hie_nodes-hiecha = is_hie_key-chanm. ELSE. ls_hie_nodes-hiecha = l_s_range-high. ENDIF. ls_hie_nodes-dummy_leaf = ''. INSERT ls_hie_nodes INTO TABLE et_hie_nodes. ENDLOOP. ENDIF. ENDFUNCTION.

  • - 10 -

    FUNCTION ybw_bps_var_num. *"-------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" VALUE(I_AREA) TYPE UPC_Y_AREA *" VALUE(I_VARIABLE) TYPE UPC_Y_VARIABLE *" EXPORTING *" REFERENCE(E_NUM_VALUE) TYPE UPC_Y_VAR_NUMBER *" REFERENCE(E_NUM_NO_VALUE) TYPE BOOLE_D *" EXCEPTIONS *" FAILED *"-------------------------------------------------------------------- * Get variable INCLUDE ybw_bps_var_read. * Process selection CLEAR: e_num_value, e_num_no_value. IF lr_var IS BOUND. * BPS variable CALL METHOD lr_var->get_num_value RECEIVING r_value = e_num_value EXCEPTIONS error = 1 OTHERS = 2. message_failed. ELSE. * BW variable READ TABLE l_t_range INTO l_s_range INDEX 1. IF sy-subrc = 0. e_num_value = l_s_range-low. ENDIF. ENDIF. IF e_num_value IS INITIAL. e_num_no_value = 'X'. ENDIF. ENDFUNCTION.

  • - 11 -

    *&---------------------------------------------------------------------* *& Include YBW_BPS_VAR_READ *&---------------------------------------------------------------------* DATA: lr_var TYPE REF TO cl_sem_variable, ls_charng TYPE upc_ys_charng, ls_chasel TYPE upc_ys_chasel, lto_chasel TYPE upc_yto_chasel, ls_chavl TYPE upc_ys_chavl, lto_chavl TYPE upc_yto_chavl, l_seqno TYPE upc_y_seqno, ls_charsel TYPE upc_ys_charsel, lto_charsel TYPE upc_yto_charsel, ls_attr TYPE upc_ys_attr, ls_hie_nodes TYPE upc_ys_hiesel, l_s_range TYPE rsr_s_rangesid, l_t_range TYPE rsr_t_rangesid. * Get variable mapping SELECT SINGLE * FROM ybw_bps_var_map WHERE area = i_area AND var = i_variable. IF sy-subrc 0. MESSAGE e001(upf) WITH 'Variable not found in mapping table:' i_area i_variable RAISING failed. ENDIF. * What are we mapping to? IF NOT ybw_bps_var_map-vnam IS INITIAL. * BW variable CALL FUNCTION 'RRS_VAR_VALUES_EXIT_FILL' EXPORTING i_vnam = ybw_bps_var_map-vnam IMPORTING e_t_range = l_t_range EXCEPTIONS invalid_variable = 1 no_input_given = 2 x_message = 3 OTHERS = 4. message_failed. ELSE. * BPS variable? CALL METHOD cl_sem_variable=>get_instance EXPORTING i_area = ybw_bps_var_map-area2 i_variable = ybw_bps_var_map-var2 RECEIVING rr_variable = lr_var EXCEPTIONS not_existing = 1 OTHERS = 2. message_failed. ENDIF.

  • - 12 -

    6 Appendix C: SAP Exit Variables The following table lists BW variables that are delivered as business content (3.5.2). These variables are automatically replaced using an SAP exit function module. They have been tested in conjunction with this how-to paper and can therefore be used in BPS. Characteristic Variable Description Replacement 1 0CALDAY 0CWD Current Workday (SAP Exit) EQ 20050211 0CALDAY 0CYTCD Cumulated to Current Day (SAP Exit) BT 20050101 200502110CALDAY 0DAT Current Calendar Day (SAP Exit) EQ 20050211 0CALDAY 0DAY_CUM Cumulation of all Values to Key Date (SAP-Exit) LE 20050211 0CALDAY 0LYTCLD Cumulated to Current Day of Previous Year BT 20040101 200402110CALDAY 0LYTCLD Previous Year Cumulated to Current Day (SAP Exit) BT 20040101 200402110CALDAY 0L_DATE Last Calendar Date EQ 20050210 0CALDAY 0P_LY_R Comparative Period for Last Year BT 20040101 200402100CALDAY 0P_TY_R Period for Current Year up to Yesterday BT 20050101 200502100CALDAY 0S_KDATE Key Date Interval for Previous Year (SAP Exit) BT 20040101 200402110CALDAY 0S_KDAY Key Date Interval Current Year (SAP Exit) BT 20050101 200502110CALMONTH 0CMCMLY Current Month of Previous Year EQ 200402 0CALMONTH 0CMCQUAR Current Quarter BT 200501 2005030CALMONTH 0CMCQULY Current Quarter in Previous Year BT 200401 2004030CALMONTH 0CML12CM Last 12 Months Including Current Month BT 200403 2005020CALMONTH 0CML12LM Last 12 Months Excluding the Current Month BT 200402 2005010CALMONTH 0CML3CM Last 3 Months Including Current Month BT 200412 2005020CALMONTH 0CML3LM Last 3 Months Excluding the Current Month BT 200411 2005010CALMONTH 0CMLMLY Last Month of Previous Year EQ 200401 0CALMONTH 0CMLMON Last Month EQ 200501 0CALMONTH 0CMLYTCM Previous Year Cumulated to Current Month BT 200401 2004020CALMONTH 0CMLYTLM Previous Year Cumulated to Last Month BT 200401 2004010CALMONTH 0CMONTH Current Calendar Month EQ 200502 0CALMONTH 0CYTCM Cumulated to current month BT 200501 2005020CALMONTH 0CYTLM Cumulated to last month BT 200501 2005010CALMONTH 0I_CMY01 Current Year Cumulated to Current Month (SAP Exit) BT 200501 2005020CALMONTH 0LYM_CUM Cumulation of all Values to End of Previous Year LT 200501 0CALQUARTER 0CQUART Current Quarter EQ 20051 0CALQUARTER 0P_PRQUA Previous Calendar Quarter (SAP Exit) EQ 20044 0CALWEEK 0CWEEK Current calendar week EQ 200506 0CALWEEK 0PREVWK Previous Week EQ 200505 0CALYEAR 0CYEAR Current calendar year EQ 2005 0CRM_EXPEND 0I_CMDEX Current Month BT 20050201 200502280CRM_EXPEND 0I_MP1EX Current Month + 1 BT 20050301 200503310CRM_EXPEND 0I_MP2EX Current Month + 2 BT 20050401 200504300CRM_EXPEND 0I_MP3EX Current Month + 3 BT 20050501 200505310CRM_EXPEND 0I_MP4EX Current Month + 4 BT 20050601 200506300CRM_EXPEND 0I_MP5EX Current Month + 5 BT 20050701 200507310ORGUNIT 0ORGUNIT Organizational Unit for a Report User (Hierarchy node) EQ ROOT 0TCTUSERNM 0TCTUSEE User in the Business Information Warehouse EQ 1FORMULA 0F_ADAY Formula Variable for Current Calendar Day EQ 20050211

    1 The replacement is shown for an execution on February 11, 2005.

  • - 13 -

    7 Appendix D: Examples The examples shown here are fully based on business content. Therefore, it will be possible to make the same settings in any BPS system (as of SEM release 3.0).

    7.1 Mapping Table for the Examples

    Explanation of the mapping: EXITATTR Mapped to BW variable 0TCTUSEE, which returns the current user ID.

    This user ID is then used in the BPS variable for the looking up the cost centers based on the "responsible person" attribute.

    EXITBPS Mapped to another BPS variable, which is in a different planning area. EXITCHAR Mapped to BW variable 0CYEAR, which returns the current calendar year. EXITHIER Mapped to BW variable 0ORGUNIT, which returns the org. hiearchy node

    assigned to the current user. EXITNUM Mapped to BW variable 0F_ADAT, which returns the current date as a

    numeric value.

  • - 14 -

    7.2 Example for Global BPS Variable Variable EXITBPS will automatically be populated with the values of variabel 4EXP0005 / VERSI03. Therefore you have to maintain the variable only in one place.

    7.3 Example for Characteristic Variable Variable EXITCHAR will be filled by the current fiscal year (BW exit variable 0CYEAR).

    7.4 Example for Attribute Variable Variable EXITATTR will be filled by the cost centers that are assigned to the current user based on the "responsible person" attribute.

  • - 15 -

    7.5 Example for Numeric Variable Variable EXITNUM will be set to the current date. This allows you for example to create formula functions that depend on the system date.

    7.6 Example for Hierarchy Node Variable Variabel EXITHIER will be filled with the organizational unit that is assigned to the current user (master data table /BI0/PUSERNAME).

  • - 16 -

    7.7 Example for Using the Variables Setup a planning level with the following characteristics and variable restrictions:

    Use "Amount (Object Currency)" (0AMOCCC) as the only key figure for the level. Define a planning function of type "Formula" and select "Cost Center" and "Key figure name" as "Fields to be changed":

  • - 17 -

    Cut & paste the following formula: DATA VAR_EXITNUM TYPE I. DATA VAR_EXITCHAR TYPE 0FISCYEAR. DATA VAR_EXITATTR TYPE 0COSTCENTER. DATA INDEX TYPE I. DATA ENTRIES TYPE I. * This will return the current date (e.g. 20050211) VAR_EXITNUM = VARV('EXITNUM'). MESSAGE I001(UPF) WITH 'NUM=' VAR_EXITNUM. * This will return the current fiscal year (e.g. 2005) VAR_EXITCHAR = VARV('EXITCHAR'). MESSAGE I001(UPF) WITH 'CHAR=' VAR_EXITCHAR. * This will return a list of cost centers that are * assigned to this user (responsible person) ENTRIES = VARC('EXITATTR'). DO. INDEX = INDEX + 1. VAR_EXITATTR = VARI('EXITATTR',INDEX). MESSAGE I001(UPF) WITH 'ATTR=' VAR_EXITATTR. {0AMOCCC,VAR_EXITATTR} = 100. IF INDEX = ENTRIES. EXIT. ENDIF. ENDDO. When you run the function, it should produce a log that looks like the following output:

    In this case, the user ID was assigned to three cost centers (TMB001 to 003) and the system date was February 11, 2005.

  • www.sdn.sap.com/irj/sdn/howtoguides