Tips and Tricks For
Tips and Tricks For
Tips and Tricks For
Implementing and
Optimizing Formulas in
SAP NetWeaver BI
Integrated Planning
Marc F. Bernard
Chief SAP NetWeaver Specialist
SAP NetWeaver RIG
2007-05-30
Prerequisites
Required Knowledge:
Recommended Knowledge:
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 2
Learning Objectives
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 3
Planning Function Types
Configuring Formulas
Enterprise Portal
Predefined Types of
Distribute
planned revenue
Planning Functions
Copy data from to different
actual version to products Delete the data
plan version in one plan
version
Increase the planned
revenue by 10% Convert from Euro to
USD
Formulas
Quantity times
Price Calculation Scheme for
Contribution Margin
Calculate Revenue
depending on number of
Customer defined workdays in company
Type of Planning calendar
Function
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 6
Predefined Planning Function Types
Distribution by Keys
Distribution by Reference Data
Currency Translation
Unit Conversion
Generate Combinations
Report to Valid Combinations
Deletion of Invalid Combinations
Tip
Try to use one of these types or a
combination of them first before
you implement formulas.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 7
Formulas (FOX)
Definition:
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 8
Complexity vs. Functionality
Customer
Predefined Defined
Function Types Formulas (FOX) Function
Types
Complexity, Functionality
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 9
When to Use Formulas (FOX)
Performance
Many times it is faster to have one formula doing the job than a
number of planning functions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 10
When to Use Customer Planning Function Types
Disadvantages
You need ABAP OO programming skills
Have to make sure there is someone in the project that can maintain the
planning function types (ABAP OO classes)
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 11
Planning Function Types
Configuring Formulas
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 13
Example for a Planning Function
Business Scenario
You want to copy the amount for each product from the current year to
the next year.
Aggregation Level
We use an InfoProvider with 0PRODUCT and 0FISCYEAR as
characteristics and 0AMOUNT as key figure.
Field(s) to be changed
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 14
Planning Functions – Subsets
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 15
Planning Functions – Subsets: Example
Sample data
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 16
Flowchart for Planning Functions
Start of Execution
FOREACH Subset.
ENDFOR.
End of Execution
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 17
How to Test Planning Functions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 18
Planning Function Types
Configuring Formulas
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 20
Configuring Formulas 2/3
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 21
Configuring Formulas 3/3
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 22
Formula Syntax
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 23
Formula Elements
Calculations Information
Access Data Records
Retrieval (e.g.
Variable Values)
String
Operations Call External
Formulas Functions
(FOX)
Foreach and Do
Loops
Predefined
Conditional Mathematical
Branching Programming Functions
Variables
Operands
The following syntax is use to access data records
– {key figure, field to be changed 1, field to be changed 2, …, field t.b.c. n}
To read data use the operands on the right side of an equation
To change data use the operands on the left side of an equation
You can read and change only records that are included in the filter
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 25
Access to Data Records – Example
Example
Business Scenario
– Copy data for each product from the current year to the next year
Fields to be changed
– Key Figure, 0FISCYEAR
Formula
– {0AMOUNT, 2008} = {0AMOUNT, 2007}.
Explanation
Amount for year 2007 is read
Amount for year 2008 is changed
You do not have to care about the product because of the subsets.
There's an automatic FOREACH product done by the system.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 26
Access to Reference Data
New Feature
Explanation
Version does not have to be in the fields to be changed but can be used
as reference characteristic
The filter the selection is set to version 1
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 27
Access to Reference Data
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 28
Variables
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 29
Loops
General Looping
Variable number of loops
– DO... EXIT… ENDDO
Predefined number of loops
– DO n TIMES... ENDDO
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 30
Loops – Example
Example
Fields to be changed
– Key Figure, 0FISCYEAR
Formula
DATA year TYPE 0FISCYEAR.
FOREACH year.
{0AMOUNT, year} = {0AMOUNT, 2007} * 1.05.
ENDFOR.
Explanation
The values for YEAR are taken from the records in the selection
Assume we have data records for year 2008 and 2009.
– First loop: YEAR is replaced with 2008 and system calculates
{0AMOUNT, 2008} = {0AMOUNT, 2007} * 1.05.
– Second loop: YEAR is replaced with 2009 and system calculates
{0AMOUNT, 2009} = {0AMOUNT, 2007} * 1.05.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 31
Conditional Branching
Example
Fields to be changed
– Key Figure, 0FISCYEAR
Formula
IF {0AMOUNT, 2007} > 1000.
{0AMOUNT, 2008} = {0AMOUNT, 2007} * 1.05.
ELSE.
{0AMOUNT, 2008} = {0AMOUNT, 2007} * 1.10.
ENDIF.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 32
Program Elements
Program Elements
Powerful macro language
Mathematical function library
Various financial calculations
Access to master data attributes
Access to BI variables
String operations
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 33
New Predefined Functions in Formulas
New Feature
String Operations
Get part of a value
– SUBSTR
Concatenate values
– CONCAT
Replace a part of a value with another one
– REPLACE
Determine length of a value
– STRLEN
Compare values
– CP, CO, CA, CS (contains pattern, only, any, string)
Financial Functions
Currency Translation
– CURC
Rounding
– ROUND
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 34
Calling ABAP Function Modules
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 35
Planning Function Types
Configuring Formulas
Less lines of FOX leads to less ABAP coding that the system has to
process and therefore faster execution times.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 37
Real-world Example
Fields to be changed:
Parameter group:
FOREACH C,V,P.
{0AMOUNT,0000415001,V,CASHDISC,PA000004} =
( {0AMOUNT,0000400001,V,CUSTSALES,PA000004} -
{0AMOUNT,0000410001,V,PRICADJDIS,PA000004} +
{0AMOUNT,0000405002,V,PRICADJBKT,PA000004} ) * 0.02.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 38
Optimization 1: "Fields to be changed"
Find all characteristics that are restricted to only one value in the
formula. This means that the characteristic is NOT being changed
and therefore should be remove from the "fields to be changed".
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 39
Optimization 1: Example
Fields to be changed:
{ Cost Element, Planning Item }
Parameter group:
* Cash Discount = (Base Revenue - Price Adjustment) * 2%
DATA C TYPE 0COSTELMNT.
DATA P TYPE ZPLANITEM.
FOREACH C,P.
{0000415001,CASHDISC} =
( {0000400001,CUSTSALES} -
{0000410001,PRICADJDIS} +
{0000405002,PRICADJBKT} ) * 0.02.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 40
Optimization 2: "Formula selection"
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 41
Optimization 2: Example
Optimization 2 A: "Formula selections (excl. reference data)" that are different than
filter
Optimization 2 B: "Formula selections (incl. reference data)" that are different than
filter
Optimization works same way as 2A but tries to combine two database selections.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 42
Optimization 3: "Conditions"
Optimization 3 A:
Optimization 3 B:
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 43
Optimization 4: "Formula operands"
Optimization 4 A:
Optimization 4 B:
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 44
Optimization 4: Example
Fields to be changed:
FOREACH M.
ENDFOR.
FOREACH M.
ENDFOR.
{M,TOTALSALES} = TOTAL.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 45
Optimization 5: "Operands in Foreach Loops"
Optimization 5 A:
Optimization 5 B:
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 46
Optimization 5: Example
Fields to be changed:
{ Cost Element, Planning Item }
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 47
Optimization 6: "Formulas on MultiProviders"
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 48
Optimization 7: "Nested Loops"
Example: Records
0002 2011 20
FOREACH product.
FOREACH year.
FOREACH product, year.
...
ENDFOR.
ENDFOR.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 49
Optimization 8: "If Statements"
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 50
Tip 9: "Naming Conventions"
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 51
Tip 9: Example
Fields to be changed:
{ Key figure name, Posting period, Version }
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 52
Tip 10: "Reference Data"
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 53
Tip 10: Example
Fields to be changed:
{ Company, Version }
FOREACH CHA_0COMPANY.
{CHA_0COMPANY,VAR_TVERSION} = {CHA_0COMPANY,ATR_SVERSION} .
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 54
Tip 11: "Endless Loops"
Save the formula before testing! Otherwise you loose your work if
the program goes into an endless loop and you have to stop the
program.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 55
Tip 12: "Performance Analysis"
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 56
Key Learnings
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 57
Contact Information
Marc F. Bernard
Chief SAP NetWeaver Specialist
SAP NetWeaver RIG
T 1.404.943.2725
F 1.404.943.4290
E marc.bernard@sap.com
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 58
Copyright 2007 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, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, System i, System i5, System p,
System p5, System x, System z, System z9, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, 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.
The information in this document is proprietary to SAP. No part of this document may be reproduced, copied, or transmitted in any form or for any purpose without the express prior
written permission of SAP AG.
This document is a preliminary version and not subject to your license agreement or any other agreement with SAP. This document contains only intended strategies, developments,
and functionalities of the SAP® product and is not intended to be binding upon SAP to any particular course of business, product strategy, and/or development. Please note that this
document is subject to change and may be changed by SAP at any time without notice.
SAP assumes no responsibility for errors or omissions in this document. SAP does not warrant the accuracy or completeness of the information, text, graphics, links, or other items
contained within this material. This document is provided 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 have no liability for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. This
limitation shall not apply in cases of intent or gross negligence.
The statutory liability for personal injury and defective products is not affected. 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 AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 59