7ab77256-5b7c-0010-82c7-eda71af511fa

Embed Size (px)

Citation preview

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    1/19

     

    SAP NetWeaver

    How-To Guide

    SAP NetWeaver

    How-To Guide

    How To...Execute a Planning

    Function on Selected Lines in an

    Analysis for Office Workbook

    Applicable Releases:

    SAP NetWeaver BW 7.00 and higher

    SAP BusinessObjects Analysis for Microsoft Office 1.1 and higher

    Topic Area:

    Business Information Management

    Version 1.0

    October 2011

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    2/19

     

    © Copyright 2011 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, Informix,

    i5/OS, POWER, POWER5, OpenPower and PowerPC are

    trademarks or registered trademarks of IBM Corporation.

     Adobe, the Adobe logo, Acrobat, PostScript, and Reader

    are either trademarks or registered trademarks of Adobe

    Systems Incorporated 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 withrespect 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 consequentialdamages 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 apractical 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 ofthe 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.

    Disclaimer

    Some components of this product are based on Java™. Any

    code change in these components may cause unpredictable

    and severe malfunctions and is therefore expressively

    prohibited, as is any decompilation of these components.

     Any Java™ Source Code delivered with this product is only

    to be used by SAP’s Support Services and may not be

    modified or altered in any way.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    3/19

     

    Document History

    Document Version Description

    1.00 First official release of this guide

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    4/19

     

    Typographic Conventions

    Type Style Description

    Example Text Words or characters quotedfrom the screen. These

    include field names, screen

    titles, pushbuttons labels,

    menu names, menu paths,

    and menu options.

    Cross-references to other

    documentation

    Example text Emphasized words or

    phrases in body text, graphic

    titles, and table titles

    Example text File and directory names and

    their paths, messages,

    names of variables and

    parameters, source text, and

    names of installation,

    upgrade and database tools.

    Example text User entry texts. These are

    words or characters that you

    enter in the system exactly as

    they appear in the

    documentation.

     

    Variable user entry. Angle

    brackets indicate that you

    replace these words and

    characters with appropriate

    entries to make entries in the

    system.

    EXAMPLE TEXT  Keys on the keyboard, for

    example, F2 or ENTER.

    Icons

    Icon Description

    Caution

    Note or Important

    Example

    Recommendation or Tip

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    5/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 1

    Table of Contents

    1.  Scenario ................................................................................................................................ 2 

    2.  General Description of the Solution .................................................................................. 2 

    3. 

    Step by Step Solution.......................................................................................................... 3 

    3.1  Create the Query and the Planning Function .............................................................. 3 

    3.2  Create the Workbook .................................................................................................... 4 

    3.3  Choose a Fitting Filter .................................................................................................. 7 

    3.4 

    Insert a Button with the VBA Coding ............................................................................ 9 

    4.  Appendix ............................................................................................................................ 12 

    4.1 

    Definition of Constants ............................................................................................... 12 

    4.2 

    Coding for Subroutine ................................................................................................. 12 

    4.3 

    Further Information ..................................................................................................... 14 

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    6/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 2

    1.  Scenario

    Planning functions in SAP NetWeaver BW are often used in two different ways. Either they are used inthe background to change large sets of data (for example preparing the planning process by copying

    last year ’s data) or they are used in a very interactive way to change data the user is also working on

    in an input enabled query. When running those planning functions from an interactive application the

    user often only wants to execute the planning functions on certain subsets of the visible set of data. In

    this How to Paper we want to show you how you can implement a solution that enables the user to

    mark some lines in a query and execute a planning function that changes the selected lines (aka the

    underlying records). For example a user only wants to revaluate the selected lines by a common

    factor.

    Important

    This How to Paper works with planning functions in SAP NetWeaver BW IntegratedPlanning as well as with planning functions designed with the Planning Applications Kitfor ABAP in SAP NetWeaver BW 7.30, SP5.

    2.  General Description of the Solution

    The idea behind our How to paper is that we use some Analysis for Office programming API methods

    to retrieve the characteristic values for the selected lines. We use another API method to then set the

    characteristic selection in a filter that is then used in the planning function. Generally not all

    characteristic values of the selected line are necessary to be set in the filter in order to define the

    selection. Usually the characteristics in the rows should do.

    Please be aware that if the user is allowed to select more than one record at a time the planning

    function nevertheless might change more records than expected. This is due to the fact that one

    planning function can only have one set of selection per characteristic.

    Example:

    Country Product Revenue

    USA P1 1000

    USA P2 1800

    Germany P2 2000

    France P2 1500

    Let us assume the user has selected line 1 and 3 and executes a revaluation function. Then the

    planning function receives the following selection:

    Country: USA, Germany

    Product: P1, P2.

    Thus also line 2 will be revaluated. If the user selects line 3 and 4 no such problem arises.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    7/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 3

     As a workaround one might make sure the a user is only allowed to select and revaluate one line at a

    time or might break down the selection into several smaller packages and execute the planning

    function several times using these smaller packages as selections.

    3.  Step by Step Solution

    Let us assume that you use a query with the characteristic ‘0D_MATERIAL’ in the rows. The user

    should select one or several lines (and thus materials) and run a planning function on this selection.

    We also assume that we do not have to set any other characteristic in the filter but all other

    characteristics are determined by some fixed filter values.

    3.1  Create the Query and the Planning Function

    Please use the BEx Query designer to create a suitable query. Keep in mind that you probably use

    other characteristics and thus will have to adapt the solution everywhere where we use ourcharacteristics.

    Please also create a suitable planning function. In our example we use a revaluation function with a

    fixed revaluation factor.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    8/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 4

     As we are using a MutliProvider in our example we use some conditions for the planning function.

    3.2  Create the Workbook

    Open SAP BusinessObjects Analysis for Microsoft Office. Please make sure you are using version 1.1

    or higher. Also please keep in mind that the planning capabilities are not switched on by default.

    Please check the settings:

    Go to the Analysis tab, and choose the entry ‘settings’. Check that the check box for the planning

    features is tagged.

     As a next step we insert your query into the workbook.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    9/19

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    10/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 6

    We are ready to insert our revaluation function. It is revaluating the records in the selection by a fixed

    value. Please display the Analysis panel and navigate to the components tab. On the name of the

    workbook use the context menu to use the planning function.

    Enter the name of your planning function.

    Now we have to choose a fitting filter for the planning function.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    11/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 7

    3.3  Choose a Fitting Filter

    We will use VBA API to set the filter from the selected line(s). Unfortunately changing a filter by the

     API is only possible in certain scenarios.

    Each planning function has a default filter that is fully accessible by the API. Unfortunately by default it

    does not contain any restrictions and need to be further restricted in the workbook to make sure that

    the planning function does not work on records outside the intended selection.

    When using the default filter you just leave the field for the linked filter empty and set the selection for

    the characteristics individually in the workbook

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    12/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 8

    We start with the characteristic we want to select from the line of the query. In our case it is

    ‘0D_MATERIAL’. You have to set the source for the characteristics to ‘link’ as it should be linked to the

    default filter changed by the API.

    For the other characteristics you have several choices. One option is to set them to some fixed values

    as we do with the InfoProvider.

     Another option is to use characteristic values from the selection of the query. You can set the value via

    the API in a similar way we do it below or use a link via Excel. We use the latter option for theselection for the country.

    In order to get the effective filter for the entire query just go to the Analysis menu and choose Info

    Field->Effective Filters. A list of all effective filters of the query will be filled into the spreadsheet.

    [You can also retrieve the selection just the characteristic 0D_MATERIAL via an Excel formula:

    =SAPGetDimensionEffectiveFilter("DS_1";"0D_MATERIAL";"KEY").

    For further information please have a look at the documentation.]

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    13/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 9

    We now simply link the filter for the country to the cell containing the value.

    Please proceed in a similar way with the other characteristics.

    Important

    Please note that if you want to set the filter via the API you cannot use a filter objectcreated in the planning modeler or the BEx Query Designer. You also cannot use thefilter from a Data Source (Query) in the workbook as a link.

    3.4  Insert a Button with the VBA Coding

    We finally create the button for executing the revaluation function. In the ‘Developer’ tab in the Excel

    ribbon choose the button ‘Insert’.

    If you cannot find this tab you have to enable it in Excel under ‘Options->Customize Ribbon’. 

    Now there choose ‘Form Control’ and insert a button. Excel will prompt you for a macro that is to be

    executed when the button is pressed.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    14/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 10

    If you want then change the name of the macro. In any case you have to press the ‘New’ button so

    Excel creates the macro for you. Excel will automatically jump to the Visual Basic editor. Now go to the

    appendix, copy the coding from appendix 4.1, and insert it BEFORE the definition of your subroutine.

    Then copy the coding from appendix 4.2 and paste it INTO your macro.

    In our example we use certain names and aliases for our planning function, characteristics, and name

    of the crosstab. We have used a variable for each of them at the beginning of our VBA coding so you

    can easily adapt it to your names:

    Coding from appendix 4.1

    Coding from appendix 4.2

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    15/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 11

    Now go back to the button and choose a fitting name.

    You are now able to use you application. Simply mark one or more cells or lines within your query and

    execute the planning function by pressing the button. If you mark a range outside the crosstab of your

    query the planning function will not be executed and an error will be sent. If you want to retrieve and

    set filters for other characteristics in your query then you can easily adapt the coding to your needs.

    You can also change the coding in such a way that only one line/cell can be selected.

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    16/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 12

    4.  Appendix

    4.1  Definition of ConstantsOption Explicit

    Public Enum AOCellInfo

    DataSource = 1

    Member = 2

    Value = 3

    End Enum

    4.2  Coding for SubroutineDim lResult As Variant

    Dim lValue As String

    Dim i As Integer

    Dim lLine As Variant

    Dim lRange As Object

    Dim lCell As Variant

    Dim lNamePF As String

    Dim lNameChar As String

    Dim lNameCrossTab As String

    ' Please adapt the names of the planning function (alias), the name of the characteristic, and the name

    of the crosstab.

    lNamePF = "PF_1"

    lNameChar = "0D_MATERIAL"

    lNameCrossTab = "SAPCrosstab1"

    ' We execute the planning function on all records in the query marked by the user. The user can mark

    either

    ' the cell or the entire row. We do not do anything if NO cell/line within the query is marked.

    ' Check that any cell or line in the crosstab (query) is marked.

    Dim d 'Create a variable

    Set d = CreateObject("Scripting.Dictionary")

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    17/19

    How To...Execute a Planning Function on Selected Lines in an Analysis for Office Workbook

    October 2011 13

    ' Does the marked range have an intersection with the crosstab for the query? If not, the we will raise

    an error popup.

    Set lRange = Application.Intersect(Selection, Range(lNameCrossTab))

    If lRange Is Nothing Then' application.run("SAPAddMessage","Could not retrieve any information for the active cell. Please

    select a cell in the planning grid.","WARNING")

    MsgBox ("Could not retrieve any information for the active cell. Please select a cell in the planning

    grid.")

    Exit Sub

    End If

    'We have marked some correct cells. Now get the selection for the chosen characteristic

    For Each lCell In lRange

    lResult = Application.Run("SAPGetCellInfo", lCell, "SELECTION", lNameChar)

    If Not IsError(lResult) Then

    On Error Resume Next

    i = 0

    Do

    i = i + 1

    lLine = ""

    lLine = WorksheetFunction.Index(lResult, i, 0)

    If IsArray(lLine) = False Then Exit Do

    ' we have a line - check the characteristic

    If lLine(AOCellInfo.Member) = lNameChar And Not d.exists(lLine(AOCellInfo.Value)) Then

    Call d.Add(lLine(AOCellInfo.Value), lLine)

    Exit Do

    End If

    Loop

    End If

    Next

    ' Did we find at least one characteristic value?

    If d.Count = 0 Then

    MsgBox ("Could not retrieve any information for the active cell. Please select a suitable cell in theplanning grid.")

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    18/19

  • 8/15/2019 7ab77256-5b7c-0010-82c7-eda71af511fa

    19/19

     

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