You are on page 1of 34

How to Call BPC Data Manager Package from Visual Basic

Applies to:
SAP BusinessObjects Planning and Consolidation version 10 for NetWeaver BPC 10 SP7 & Above

EPM Add-In 10.0 SP 12 Patch 1 for .NET Summary


How to call BPC data manager package from Visual Basic Author: Tristan Colgate, Amaury Gruyelle, Muthu Ranganathan Company: Bluefin Solutions in collaboration with SAP Created on: 31 August 2012

Author Bio
Tristan Colgate, EPM Lead at Bluefin Solutions, UK Amaury Gruyelle, BPC Consultant at Bluefin Solutions, UK Muthu Ranganathan, EPM Product Management at SAP.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 1

How to Call BPC Data Manager Package from Visual Basic

Table of Contents
Scenario .............................................................................................................................................................. 3 Details and Usage .............................................................................................................................................. 6 Step by Step Instructions .................................................................................................................................... 7 Create the PARAMETERS Excel Name Range ............................................................................................. 7 Create the PACKAGE Excel Name Range ................................................................................................... 12 Add the Visual Basic code ............................................................................................................................ 15 Create the User Interface to perform the Copy ............................................................................................. 18 Appendix ........................................................................................................................................................... 21 How to display the Developer tab in the Excel Ribbon ................................................................................. 21
MS Office Excel 2010 ................................................................................................................................................ 21

VBA Code ..................................................................................................................................................... 24 Example XML Prompt File ............................................................................................................................ 31 Related Content ................................................................................................................................................ 33 Copyright........................................................................................................................................................... 34

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 2

How to Call BPC Data Manager Package from Visual Basic

Scenario
The Data Manager packages delivered as standard with BPC are sophisticated, having many different options. Consider the Copy DM Package.

Firstly, the user needs to specify how the records are handled during the copy.

Then the user specifies whether they want default logic to run after the copy is performed.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 3

How to Call BPC Data Manager Package from Visual Basic

Thirdly the user is asked whether they wish the copy to respect work status.

Fourthly, they must specify the source and destination data ranges.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 4

How to Call BPC Data Manager Package from Visual Basic

Finally, the user selects whether they want to run the copy immediately, or schedule it to run later.

These options can be confusing to an occasional user of BPC, such as a Cost Centre Manager preparing their annual budget. Many of the options are not relevant to what they are trying to achieve, and would actually cause errors in the way their data is processed if set incorrectly.

One solution is to copy the standard package and amend the Prompt script to default those options where appropriate and only present options that are pertinent to the user, in contextualised language that the user will understand.

This may, however, still leave the user navigating through a number of screens when they simply wish to perform a simple function, such as copying their data from one version to another. A common question from users in such a scenario is whether they can simply have drop-down boxes in two cells in the Excel spreadsheet where they can specify from and to Categories, and a button that executes the copy:

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 5

How to Call BPC Data Manager Package from Visual Basic

This paper will describe how to achieve this.

Details and Usage


The solution involves the following components.

An Excel sheet where the user can specify from and to versions and click the button to execute the copy.

A Name range called PARAMETERS in the Excel Workbook that specifies all of the parameters that the function in question (in our case, the Copy function) expects, along with the values that will be passed to them.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 6

How to Call BPC Data Manager Package from Visual Basic

A Name range called PACKAGE in the Excel workbook that defines the details of the package we wish to execute.

We also specify here the name of the Prompt File that is generated during the process.

Visual Basic code that, upon being invoked, calls the Data Manager Package specified in the PACKAGE Name range, passing the parameters specified in the PARAMETERS Name range.

Step by Step Instructions


Create the PARAMETERS Excel Name Range The standard Copy DM Package delivered in the EnvironmentShell BPC model expects the following parameters (as defined in the prompt script file). TARGETMODE contains a 0 or a 2 RUNLOGIC contains a 0 or a 1 CHECKLCK contains a 0 or a 1 SELECTION Dimension/ Member pairs defining the source data range. TOSELECTION Dimension/ Member pairs defining the target data range.

This information can be gleaned by looking at the DM Package prompt script file, which is accessed as follows:

Navigate to the DataManager tab on the Excel ribbon

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 7

How to Call BPC Data Manager Package from Visual Basic

Select Organize-->Organize Package List

In the Organize Package List pop-up, find the Copy Package, right-click and choose Modify Package.

Click on Modify Script in the subsequent pop-up:

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 8

How to Call BPC Data Manager Package from Visual Basic

Click on Advanced in the subsequent pop-up:

The final popup, Modify Script, shows the script used to pass parameters back to the DM Package Process Chain. Analyse this information to work out which parameters you need to include in the PARAMETERS Excel Name Range.

Now we will create the PARAMETERS Name range in Excel.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 9

How to Call BPC Data Manager Package from Visual Basic

Create the cells containing the specification of parameters as per the screenshot. Note: Prompt names should match those in the DM Prompt definition, with % before and after. Prompt Type is either Parameter or StringListPairs Dimension is only relevant for StringListPairs Value is the value you want to set this parameter to this can be hard coded (as is the case for the three Parameters), or can use an Excel formula, as is the case for the source and destination categories which look at the selection the user has made in the from and to version drop-downs.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 10

How to Call BPC Data Manager Package from Visual Basic

Select the cells (in our case, the range A1 to D20)

Enter PARAMETERS into the cell reference box to make the Name range.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 11

How to Call BPC Data Manager Package from Visual Basic

Create the PACKAGE Excel Name Range

Log on to the NetWeaver ABAP stack via SAPGUI.

Go to transaction SE16 (Data Browser)

Details about Data Packages are stored in table UJD_PACKAGES2. Enter this table name into the Table Name field and click on:

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 12

How to Call BPC Data Manager Package from Visual Basic

Enter the BPC Environment and Model IDs into the APPSET_ID and APP_ID fields respectively.

Click on:

In the table returned, identify the row containing the DM Package we are interested in and select it.

Click on:

The resulting screen contains all of the details you will need to populate the PACKAGE name range.

The following table indicates how you should map the values found in the UJD_PACKAGE2 table with the fields you need to populate in the Excel Name Range you will shortly create.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 13

How to Call BPC Data Manager Package from Visual Basic

Field from table UJD_PACKAGES2 CHAIN_ID GROUP_ID PACKAGE_ID PACKAGE_ID PACKAGE_TYPE TEAM_ID USER_GROUP

Field in Excel Name Range Filename GroupId PackageDesc PackageId PackageType TeamID UserGroup*

Example /CPMB/COPY Data Management Copy Copy Process Chain <blank> 0010

* Note that the number in the table must be entered with leading zeroes, as a four character field.

Additionally, field PromptFile will contain the name of a file that will be created as part of the process of launching the DM Package. Note that, if you are using this in an Enterprise environment, that youll need to decide on a file location that can be guaranteed to exist on all end users PCs. In our, example we use: C:\CopyDataManagerPromptFile.txt

Now we will create the Excel PACKAGE Name Range:

Create the cells containing the specification of parameters as per the screenshot.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 14

How to Call BPC Data Manager Package from Visual Basic

Select the cells in the data range (in our case cells F1:G9)

Enter PACKAGE into the cell reference and hit <enter>.

Add the Visual Basic code Note that you must have the Developer tab enabled in the Excel ribbon:

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 15

How to Call BPC Data Manager Package from Visual Basic

If you cannot see this tab in your ribbon in Excel, then you need to enable it. Follow the instructions in the Appendix to do so before moving on.

Click on the button in the Developer ribbon tab to open the Visual Basic editor.

Navigate to Tools--> References from the Visual Basic menu bar.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 16

How to Call BPC Data Manager Package from Visual Basic

Check the boxes as per the screenshot to the right. Note you may need to scroll down quite a long list to find some of these.

In the Project Explorer pane, right click on the VBAProject node for your Excel Workbook and choose:

Insert --> Module

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 17

How to Call BPC Data Manager Package from Visual Basic

Copy and Paste the code in Appendix 4.x into the newly created Module.

Create the User Interface to perform the Copy

Create the following cells.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 18

How to Call BPC Data Manager Package from Visual Basic

Use Data Validation in order to provide a drop-down on the Category dimension fields.

In the Developer ribbon tab, choose Insert-->Button Form Control

Use the lasso tool to draw out the rectangle for the button.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 19

How to Call BPC Data Manager Package from Visual Basic

The Assign Macro popup appears. Select existing Macro executeDmPackageWithParameter s.

Click OK.

The button is now displayed. To test the solution, click on the button.

In the Data Manager ribbon tab, click on:

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 20

How to Call BPC Data Manager Package from Visual Basic

The Package Status popup should appear and show your job in progress (or perhaps already completed).

Appendix
How to display the Developer tab in the Excel Ribbon MS Office Excel 2010 Here is the Excel 2010 Ribbon. Note that the Developer tab is not currently displayed.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 21

How to Call BPC Data Manager Package from Visual Basic

Select the File tab in the ribbon and click on Options.

The Options pop-up is displayed:

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 22

How to Call BPC Data Manager Package from Visual Basic

Select the Customize Ribbon option in the left pane.

In the right-hand panel, select the checkbox labelled Developer, and then click on OK.

The Developer tab is now displayed.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 23

How to Call BPC Data Manager Package from Visual Basic

VBA Code

Public Sub executeDmPackageWithParameters()

' '

Create the Answer Prompt file in the location specified in the Name Range "PACKAGE" createAnswerPromptFile "PACKAGE", "PARAMETERS"

'

Get the DM Automation class instance Dim objDMautomation As EPMAddInDMAutomation Set objDMautomation = New EPMAddInDMAutomation

' '

Run the package specified in Excel Name Range "PACKAGE", using the promtp file specified in Name Range "PACKAGE" objDMautomation.RunPackage objPackageFromSheet("PACKAGE"), _ strFilename("PACKAGE")

End Sub

Private Function strFilename(strRange As String) As String

'

Get the range in which the DM package paramteres is set Dim rngPackageRange As Range Set rngPackageRange = Application.Names(strRange).RefersToRange

'

Loop through the rows For i = 1 To rngPackageRange.Rows.Count If rngPackageRange(i, 1).Value = "PromptFile" Then strFilename = rngPackageRange(i, 2).Value Exit Function End If Next

End Function

Private Function strPackageDescription(strRange As String) As String

'

Get the range in which the DM package paramteres is set Dim rngPackageRange As Range Set rngPackageRange = Application.Names(strRange).RefersToRange

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 24

How to Call BPC Data Manager Package from Visual Basic ' Loop through the rows For i = 1 To rngPackageRange.Rows.Count If rngPackageRange(i, 1).Value = "PackageId" Then strPackageDescription = rngPackageRange(i, 2).Value Exit Function End If Next End Function

Private Function objPackageFromSheet(strRange As String) As ADMPackage

'

Get the range in which the DM package paramteres is set Dim rngPackageRange As Range Set rngPackageRange = Application.Names(strRange).RefersToRange

'

Create the ADM Package object Set objPackageFromSheet = New ADMPackage

'

Loop through the rows For i = 1 To rngPackageRange.Rows.Count

Select Case rngPackageRange(i, 1).Value

Case "Filename" objPackageFromSheet.Filename = rngPackageRange(i, 2).Value

Case "GroupId" objPackageFromSheet.GroupId = rngPackageRange(i, 2).Value

Case "PackageDesc" objPackageFromSheet.PackageDesc = rngPackageRange(i, 2).Value

Case "PackageId" objPackageFromSheet.PackageId = rngPackageRange(i, 2).Value

Case "PackageType" objPackageFromSheet.PackageType = rngPackageRange(i, 2).Value

Case "TeamId" objPackageFromSheet.TeamId = rngPackageRange(i, 2).Value

Case "UserGroup" objPackageFromSheet.UserGroup = rngPackageRange(i, 2).Value

End Select

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 25

How to Call BPC Data Manager Package from Visual Basic

Next

End Function

Private Sub createAnswerPromptFile(strPackageName As String, _ strParametersName As String)

'

Create a new XML document Dim objDOM As DOMDocument Set objDOM = New DOMDocument

'

Set the processing instruction of the XML document Dim objProcessingInstruction As IXMLDOMProcessingInstruction Set objProcessingInstruction = _ objDOM.createProcessingInstruction("xml", _ " version='1.0' encoding='utf-16'") objDOM.appendChild objProcessingInstruction

'

Create root element Dim objRootElem As IXMLDOMElement Set objRootElem = objDOM.createElement("ArrayOfAnswerPromptPersistingFormat") objDOM.appendChild objRootElem

'

XSI Attribute Dim objMemberRel As IXMLDOMAttribute Set objMemberRel = objDOM.createAttribute("xmlns:xsi") objMemberRel.NodeValue = "http://www.w3.org/2001/XMLSchema-instance" objRootElem.setAttributeNode objMemberRel

'

XSD Attribute Set objMemberRel = objDOM.createAttribute("xmlns:xsd") objMemberRel.NodeValue = "http://www.w3.org/2001/XMLSchema" objRootElem.setAttributeNode objMemberRel

'

Get the range of cells containing the parameters Dim rngParameters As Range Set rngParameters = ThisWorkbook.Names(strParametersName).RefersToRange 'Excel.Names(strParametersName).RefersToRange

' Dim objCurrentStringPairParent As IXMLDOMElement

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 26

How to Call BPC Data Manager Package from Visual Basic ' Loop through each row For i = 1 To rngParameters.Rows.Count

'

See which type of parameter is being passed Select Case rngParameters(i, 2).Value

'

If it is a single Parameter, then add a parameter node to the root node Case "Parameter" addSingleSelectionParameterToXML rngParameters(i, 1).Value, _ rngParameters(i, 4).Value, _ objRootElem, _ objDOM

'

If it is a list of values Case "StringListPairs"

'

If it's a new set of String List Pairs, then create a new parent If rngParameters(i, 1).Value <> strCurrentStringPair Then strCurrentStringPair = rngParameters(i, 1).Value Set objCurrentStringPairParent = _ getStringListPairParent(rngParameters(i, 1).Value, _ objRootElem, _ objDOM) End If

'

Add the Dimension Name and Value to the parent addStringListPair rngParameters(i, 3).Value, _ rngParameters(i, 4).Value, _ objCurrentStringPairParent, _ objDOM

End Select Next

'

Create the File object Dim objFile As FileSystemObject Set objFile = New FileSystemObject

'

Create a stream to create and write to the file Dim objStream As TextStream Set objStream = objFile.OpenTextFile(strFilename(strPackageName), _ ForWriting, True)

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 27

How to Call BPC Data Manager Package from Visual Basic ' Write the name of the DM package first and then the XML output objStream.WriteLine strPackageDescription(strPackageName) & _ "{param_separator}" & _ objDOM.XML

'

Close the file objStream.Close

End Sub

Private Function addStringListPair(strVariableName As String, _ strValue As String, _ objParent As IXMLDOMElement, _ objDOM As DOMDocument)

'

Create the "StringListPair" node Dim objStringListPairElement As IXMLDOMElement Set objStringListPairElement = _ objDOM.createElement("StringListPair") objParent.appendChild objStringListPairElement

'

Create the "Str" element containing the variable name Dim objStrElement As IXMLDOMElement Set objStrElement = objDOM.createElement("str") objStringListPairElement.appendChild objStrElement objStrElement.Text = strVariableName

'

Create the "lst" element Dim objLstElement As IXMLDOMElement Set objLstElement = objDOM.createElement("lst") objStringListPairElement.appendChild objLstElement

'

Create the "string" element containing the variable value Dim objStringElement As IXMLDOMElement Set objStringElement = objDOM.createElement("string") objLstElement.appendChild objStringElement objStringElement.Text = strValue

End Function

Private Function getStringListPairParent(strVariableName As String, _ objParent As IXMLDOMElement, _ objDOM As DOMDocument) As IXMLDOMElement

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 28

How to Call BPC Data Manager Package from Visual Basic

'

Create the "AnswerPromptPersistingFormat" node Dim objAnswerPromptPersistingFormatElement As IXMLDOMElement Set objAnswerPromptPersistingFormatElement = _ objDOM.createElement("AnswerPromptPersistingFormat") objParent.appendChild objAnswerPromptPersistingFormatElement

'

Create the "_ap" node Dim objApElement As IXMLDOMElement Set objApElement = objDOM.createElement("_ap") objAnswerPromptPersistingFormatElement.appendChild objApElement

'

Create the parameter name element Dim objParameterElement As IXMLDOMElement Set objParameterElement = objDOM.createElement("Name") objApElement.appendChild objParameterElement objParameterElement.Text = strVariableName

'

Create the values element Dim objValuesElement As IXMLDOMElement Set objValuesElement = objDOM.createElement("Values") objApElement.appendChild objValuesElement

'

Create the "_apc" node Set getStringListPairParent = objDOM.createElement("_apc") objAnswerPromptPersistingFormatElement.appendChild getStringListPairParent

End Function

Private Function addSingleSelectionParameterToXML(strVariableName As String, _ strValue As String, _ objParent As IXMLDOMElement, _ objDOM As DOMDocument)

'

Create the "AnswerPromptPersistingFormat" node Dim objAnswerPromptPersistingFormatElement As IXMLDOMElement Set objAnswerPromptPersistingFormatElement = _ objDOM.createElement("AnswerPromptPersistingFormat") objParent.appendChild objAnswerPromptPersistingFormatElement

'

Create the "_ap" node Dim objApElement As IXMLDOMElement Set objApElement = objDOM.createElement("_ap") objAnswerPromptPersistingFormatElement.appendChild objApElement

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 29

How to Call BPC Data Manager Package from Visual Basic ' Create the parameter name element Dim objParameterElement As IXMLDOMElement Set objParameterElement = objDOM.createElement("Name") objApElement.appendChild objParameterElement objParameterElement.Text = strVariableName

'

Create the values element Dim objValuesElement As IXMLDOMElement Set objValuesElement = objDOM.createElement("Values") objApElement.appendChild objValuesElement

'

Create the string element with the value passed to the parameter Dim objStringElement As IXMLDOMElement Set objStringElement = objDOM.createElement("string") objValuesElement.appendChild objStringElement objStringElement.Text = strValue

End Function

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 30

How to Call BPC Data Manager Package from Visual Basic

Example XML Prompt File

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 31

How to Call BPC Data Manager Package from Visual Basic

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 32

How to Call BPC Data Manager Package from Visual Basic

Related Content
Enterprise Performance Management Community

Financial Excellence Community

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 33

How to Call BPC Data Manager Package from Visual Basic

Copyright
Copyright 2012 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, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. 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 Oracle Corporation. JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, 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 other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. 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.

SAP COMMUNITY NETWORK 2012 SAP AG

scn.sap.com 34

You might also like