Tips and Tricks For Implementing and Optimizing Formulas in SAP NetWeaver BI-Integrated Planning - Webinar Powerpoint - 2014

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 59

Marc F.

Bernard
Chief SAP NetWeaver Specialist
SAP NetWeaver RIG
2007-05-30
Ti ps and Tr i c k s f or
I mpl ement i ng and
Opt i mi zi ng For mul as i n
SAP Net Weaver BI
I nt egr at ed Pl anni ng
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 2
Pr er equi si t es
Required Knowledge:
General understanding of BI Integrated Planning in
SAP NetWeaver 7.0
Recommended Knowledge:
Some experience with implementing formulas in BI Integrated
Planning or BW-BPS
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 3
Lear ni ng Obj ec t i ves
Learn about planning functions in BI Integrated Planning and how
to decide which type of function you should use
Design formulas the right way
Understand how formulas are configured
Resolve performance problems or avoid them in the first place
Hear tips & tricks for impl ementing formulas
Configuring Formulas
Performance Tuning of Formulas
Planning Function Types
Designing Pl anning Functi ons
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 5
Enterpri se Reporting, Query and Anal ysis
Business Planning & Anal ytical Services
Enterpri se Data Warehousing
Planning Functions &
Sequences
Distribute
Formulas (FOX)
Copy
Revaluate
Repost
Forecast
Custom defined

Planni ng Modeler
Architected Data Marts
Operational
Data Store
Data Warehouse Layer
Master
Data
BEx Query Designer
BEx Web
Web Analyzer Web Application Designer
BEx Anal yzer
Anal ytical Engine
Caching services Plan data cache
OLAP services
Drill Down
Currencies/Units
Calculations/Formulas
Exceptions/Conditions
Vari ables
Hierarchies
Aggregation
Sort

Planning specific
services
Enqueue
Validations
Data slices
Characteri stic relations
Pattern
Information Broadcasti ng
Enterpri se Portal
Report Designer
MS Excel
Add-in
Focus for this webinar
SAP Net Weaver BI Ar c hi t ec t ur e f or Busi ness Pl anni ng
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 6
Var i ous Busi ness Requi r ement s and Thei r Sol ut i ons
Copy data from
actual version to
plan version
Increase the planned
revenue by 10%
Distribute
planned revenue
to different
products
Quanti ty times
Pri ce
Delete the data
in one plan
version
Convert from Euro to
USD
Calculation Scheme for
Contribution Margin
Calcul ate Revenue
depending on number of
workdays in company
calendar
Formulas
Customer defined
Type of Planning
Function
Predefined Types of
Planning Functions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 7
Pr edef i ned Pl anni ng Func t i on Types
Predefined Planning Function Types
Copy
Delete
Repost
Revalue
Distribution by Keys
Distri buti on 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 / 8
Definition:
Formulas define how the transaction data is to be processed in
order to generate plan data. Formula functions enable you to use
extended mathematical functions to calculate plan data.
In addition to different calculation functions, which you can use for
value assignment in formulas, there is also the possibility to model
complex flow structures with the formula language FOX (FOrmula
eXtensions).
For mul as (FOX)
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 9
Compl ex i t y vs. Func t i onal i t y
Predefined
Function Types
Formulas (FOX)
Customer
Defined
Function
Types
Complexity, Functionality
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 10
When t o Use For mul as (FOX)
Create a formula if
There is no predefined planning function type that does the job
The task cannot be done i n one predefined planning function
type but several planning functions/sequence are needed
The customizing of a standard planning function type gets to
complicated
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 / 11
When t o Use Cust omer Pl anni ng Func t i on Types
Create a custom planning function type if
The logic in FOX would be very complicated
You need several complex FOX formulas for doing the job
You need syntax elements that are not contained in FOX
You need the same planning function in different levels. You can use the
same function type in several places instead of copying a predefined or
formula function to the different aggregation levels.
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)
Configuring Formulas
Performance Tuning of Formulas
Planning Function Types
Designing Pl anning Functi ons
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 13
How t o Desi gn a Pl anni ng Func t i on
The following holds for EVERY planning function:
Define the business scenario for the planning function.
Determine the proper level i.e. the level of aggregation in the
InfoProvider that is needed for the business scenario. You have
to identify the proper characteristics and key figures.
Write down some sample records in that level.
Write down how the data records should look like after executing
the planning function.
Identify the fields in the data records that are changed or used
for calculation by the planning function. These are the fields to
be changed in the planning function.
Identify the type of planning function (predefined type, formula
(FOX), exit) and configure the planning function.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 14
Ex ampl e f or a Pl anni ng Func t i on
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.
200 2007 0002
100 2007 0001
0AMOUNT 0FISCYEAR 0PRODUCT
200 2008 0002
200 2007 0002
100 2008 0001
100 2007 0001
0AMOUNT 0FISCYEAR 0PRODUCT
Field(s) to be changed
Before
After
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 15
Pl anni ng Func t i ons Subset s
To make it easier to configure planning functions, the systems
packages the plan data into smaller subsets.
Packaging into subsets is based on what fields are changed by the
function
The more fields that can be change, the lower the number of subsets
All fields can be changed = One subset with all data
No fields can be changed = One subset per record
The plan data for each subset is processed separately
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 16
Pl anni ng Func t i ons Subset s: Ex ampl e
Sample data
records:
200 2008 0002
200 2007 0002
100 2008 0001
100 2007 0001
0AMOUNT 0FISCYEAR 0PRODUCT
Empty
Year
Product
All
Fields for grouping
2 calls,
records (1+3) and (2+4)
Product
1 call,
all records
All
2 calls,
records (1+2) and (3+4)
Year
4 calls,
one record per call
Empty
Number of calls/records Fields to be changed
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 17
Reference Data (based on Function)
Start of Execution
End of Execution
Data Selecti on (based on Fil ter)
Execute Function
Buil d Subsets from Selected Data
Add Subsets for Reference Data
FOREACH Subset.
ENDFOR.
Phase 1
Phase 2
Fl ow c har t f or Pl anni ng Func t i ons
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 18
How t o Test Pl anni ng Func t i ons
Tips for Testing Planning Functions
Create filters for small packages of plan data (e.g. 2 records)
Create a test query for your filter
Put the fields to be changed in the rows, the key figure(s) in the
columns, and the remaining characteristics in the header (free
characteristics). As a result, the query output looks like the data
records that are processed by the formula.
Execute the planning function using the trace (" execute with
trace" )
In formulas you can send messages with the relevant values to
the message log of the planning function
Configuring Formulas
Performance Tuning of Formulas
Planning Function Types
Designing Pl anning Functi ons
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 20
Conf i gur i ng For mul as 1/3
3. Sel ect the type Formula, enter techni cal name and
description, and pick the aggregation level
4. Choose Transfer
1. Start the Planning Model and go to the Planning Function tab
2. Choose Create
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 21
Conf i gur i ng For mul as 2/3
5. Select whi ch fields should
be changed (mandatory) and
which fields should be used
for conditions (optional)
6. Enter the conditions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 22
Conf i gur i ng For mul as 3/3
Control display showing
which fields can be changed
in the formula.
Various forms of input help and
documentation of program
elements are available
{SEMPS_003, Mango J uice}={SEMPS_003, Apple J uice}+{SEMPS_003,
Orange J uice}.
7. For each condition, enter
the formula (FOX) in the
editor
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 23
For mul a Synt ax
Syntax for formulas (FOX)
A formula consists of one or many statements
Each statement needs to be concluded by a period " ."
Among others a statement can contain
one or several operands for reading data
one operand for changing data
various functions for calculations and information retrieval
various program elements
Choose Check button in the editor to verify syntax of formula.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 24
For mul a El ement s
Formulas
(FOX)
Access Data Records
Calculations
Information
Retrieval (e.g.
Vari able Val ues)
Foreach and Do
Loops
Conditional
Branching
Programming
Vari ables
Predefined
Mathematical
Functions
String
Operations
Call External
Functions
FOX = Formula Extensions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 25
Ac c ess t o Dat a Rec or ds
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 onl y records that are included in the filter
You can use the input help for
entering operands into the editor
Note: In contrast to BW-BPS, for BI-Integrated Planning " key figure"
is always a field to be changed
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 26
Ac c ess t o Dat a Rec or ds Ex ampl e
Exampl e
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 / 27
Ac c ess t o Ref er enc e Dat a
Reference Characteristics in Operands
Business Scenario
We are calculating the revenue from the planned quantities and the prices.
Revenue and quantity are stored i n the plan version 1 whereas the prices
come from the actual version 0.
Fields to be changed
Key Figure
Formula
{0REVENUE} = {0QUANTITY} * {0PRICE | 0VERSION = 0}.
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
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 28
Ac c ess t o Ref er enc e Dat a
Input Help for Operands with Reference Fields
You can pick additional
reference characteristics
{SEMPS_003, Apple J uice | Z_PRODLIN =J uice }


Result of operand in editor:
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 29
Var i abl es
Local variables are
used to store temporary results
defined using the DATA statement
always referencing a data type
usable only in a given formula
You can use the input help for
variable definitions into the editor
Global BI variables are
used to integrate with analytical engine
defined in Planning Modeler or BEx Query Designer
referencing characteristic or numeric values
usable system-wide
accessed using VARV and VARC functions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 30
Loops
General Looping
Variable number of loops
DO... EXITENDDO
Predefined number of loops
DO n TIMES... ENDDO
Looping over Certain Values
Plan data values (only existing records)
FOREACH <Vari abl e>... ENDFOR
Reference data values
FOREACH <Variable> IN REFDATA... ENDFOR
Selection criteria (filter)
FOREACH <Variable> IN SELECTION... ENDFOR
BI Variable
FOREACH <Vari abl e> IN VARIABLE... ENDFOR
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 31
Loops Ex ampl e
Exampl e
Fields to be changed
Key Figure, 0FISCYEAR
Formula
DATA year TYPE 0FI SCYEAR.
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 cal culates
{0AMOUNT, 2008} = {0AMOUNT, 2007} * 1. 05.
Second loop: YEAR is replaced with 2009 and system calcul ates
{0AMOUNT, 2009} = {0AMOUNT, 2007} * 1. 05.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 32
Condi t i onal Br anc hi ng
Program Flow Based on Conditions
Single condition
IFENDIF.
Single condition and others
IFELSEENDIF.
Multiple conditions
IFELSEIFELSEENDIF.
Exampl e
Fields to be changed
Key Figure, 0FISCYEAR
Formula
I F {0AMOUNT, 2007} > 1000.
{0AMOUNT, 2008} = {0AMOUNT, 2007} * 1. 05.
ELSE.
{0AMOUNT, 2008} = {0AMOUNT, 2007} * 1. 10.
ENDI F.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 33
Pr ogr am El ement s
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 / 34
New Pr edef i ned Func t i ons i n For mul as
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
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 35
Cal l i ng ABAP Func t i on Modul es
You can call selected ABAP function modules
within a formula
Enter the name of the function module
in the table RSPLF_FDIR
Use CALL FUNCTION in the formula
You can use importing, exporting and
changing parameters
Restriction on types for parameters
F, I, D, or STRING
Types of characteristics and attributes
No structures or tables
If the ABAP function module needs to raise an exception you have to
use the construct MESSAGE...RAISING
New Feature
Configuring Formulas
Performance Tuning of Formulas
Planning Function Types
Designing Pl anning Functi ons
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 37
How t o Opt i mi ze For mul as (FOX)
The idea is to reduce the complexity of the formula, without
changing the result of the calculation.
Less lines of FOX leads to less ABAP coding that the system has to
process and therefore faster execution times.
There are two main targets for optimization:
1. Formula Operands
2. Foreach Loops
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 38
Real -w or l d Ex ampl e
Fi el ds t o be changed:
{ Key f i gur e, Cost El ement , Ver si on, Pl anni ng I t em, I nf oPr ovi der }
Par amet er gr oup:
* Cash Di scount = ( Base Revenue - Pr i ce Adj ust ment ) * 2%
DATA C TYPE 0COSTELMNT.
DATA V TYPE 0VERSI ON.
DATA P TYPE ZPLANI TEM.
FOREACH C, V, P.
{0AMOUNT, 0000415001, V, CASHDI SC, PA000004} =
( {0AMOUNT, 0000400001, V, CUSTSALES, PA000004} -
{0AMOUNT, 0000410001, V, PRI CADJ DI S, PA000004} +
{0AMOUNT, 0000405002, V, PRI CADJ BKT, PA000004} ) * 0. 02.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 39
Opt i mi zat i on 1: " Fi el ds t o be c hanged"
Find all characteristics that are restricted to onl y 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 / 40
Opt i mi zat i on 1: Ex ampl e
Opt i mi zat i on 1: " Fi el ds t o be changed" t hat ar e not changed
Remove f r om" Fi el ds t o be changed" : Key f i gur e = 0AMOUNT
Remove f r om" Fi el ds t o be changed" : Ver si on = V
Remove f r om" Fi el ds t o be changed" : I nf oPr ovi der = ' PA000004'
Fi el ds t o be changed:
{ Cost El ement , Pl anni ng I t em}
Par amet er gr oup:
* Cash Di scount = ( Base Revenue - Pr i ce Adj ust ment ) * 2%
DATA C TYPE 0COSTELMNT.
DATA P TYPE ZPLANI TEM.
FOREACH C, P.
{0000415001, CASHDI SC} =
( {0000400001, CUSTSALES} -
{0000410001, PRI CADJ DI S} +
{0000405002, PRI CADJ BKT} ) * 0. 02.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 41
Opt i mi zat i on 2: " For mul a sel ec t i on"
Determine the selections i.e. the characteristic combinations that
are changed by the formula and compare it against the fi lter.
There can be several cases:
Perfect match (best case)
Filter selection is equal to the formula selection. The system will read
only data that is actually being changed.
Filter selection is bigger (worst case)
The system will read more data than required by the function.
Filter selection is smaller (error)
The formula potentially generates records that are not part of the filter,
which could lead to an error message.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 42
Opt i mi zat i on 2: Ex ampl e
Opt i mi zat i on 2 A: " For mul a sel ect i ons ( excl . r ef er ence dat a) " t hat ar e di f f er ent t han
f i l t er
Rest r i ct l evel / f i l t er t o f or mul a sel ect i on: Key f i gur e
Level / Fi l t er :
= 0AMOUNT, ZPRI CEADJ , ZUNCOLLAR
For mul a:
= 0AMOUNT
Rest r i ct l evel / f i l t er t o f or mul a sel ect i on: Cost El ement
Level / Fi l t er :
No r est r i ct i on
For mul a:
= ' 0000415001'
Opt i mi zat i on 2 B: " For mul a sel ect i ons ( i ncl . r ef er ence dat a) " t hat ar e di f f er ent t han
f i l t er
Opt i mi zat i on wor ks same way as 2A but t r i es t o combi ne t wo dat abase sel ect i ons.
Level contains more key
figures than necessary
Level is not restricted on Cost
Element but formula changes
only one Cost Element
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 43
Opt i mi zat i on 3: " Condi t i ons"
Optimization 3 A:
If the condition is equal to the filter restriction, then the condition
can be removed.
Optimization 3 B:
If there's only one condition it can be merged with the filter
selection.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 44
Opt i mi zat i on 4: " For mul a oper ands"
It is not necessary to write to the same result operand several times.
It's also not necessary to read the same reference operand several
times. Instead, the operands should be stored temporarily using
local variables (DATA).
Optimization 4 A:
Based on result data only
Optimization 4 B:
Based on reference data only
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 45
Opt i mi zat i on 4: Ex ampl e
Fi el ds t o be changed:
{ Mat er i al , Pl anni ng I t em}
Par amet er gr oup ( BEFORE) :
DATA M TYPE 0MATERI AL.
{M, TOTALSALES} = 0.
FOREACH M.
{M, TOTALSALES} = {M, TOTALSALES} + {M, CUSTSALES}.
ENDFOR.
Par amet er gr oup ( AFTER) :
DATA M TYPE 0MATERI AL.
DATA TOTAL TYPE F.
TOTAL = 0.
FOREACH M.
TOTAL = TOTAL + {M, CUSTSALES}.
ENDFOR.
{M, TOTALSALES} = TOTAL.
If there are 1,000 materials,
then TOTALSALES has to be
read and updated 1,000 times
There's only one update of
TOTALSALES independent of
the number of materials
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 46
Opt i mi zat i on 5: " Oper ands i n For eac h Loops"
If an operand is used in an foreach loop but does not depend on any
foreach variable, then the operand is being processed too often and
therefore should be moved before (reference data) or after (result
data) the foreach loop.
Optimization 5 A:
Based on result data only
Optimization 5 B:
Based on reference data only
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 47
Opt i mi zat i on 5: Ex ampl e
Fi el ds t o be changed:
{ Cost El ement , Pl anni ng I t em}
Par amet er gr oup ( BEFORE) :
* Cash Di scount = ( Base Revenue - Pr i ce Adj ust ment ) * 2%
DATA C TYPE 0COSTELMNT.
DATA P TYPE ZPLANI TEM.
FOREACH C, P.
{0000415001, CASHDI SC} =
( {0000400001, CUSTSALES} -
{0000410001, PRI CADJ DI S} +
{0000405002, PRI CADJ BKT} ) * 0. 02.
ENDFOR.
Par amet er gr oup ( AFTER) :
{0000415001, CASHDI SC} =
( {0000400001, CUSTSALES} -
{0000410001, PRI CADJ DI S} +
{0000405002, PRI CADJ BKT} ) * 0. 02.
CASHDISC is updated inside
the loop although it does not
depend on C or P.
The other operands are read
inside the loop although they
don't depend on C or P.
Ultimately the complete
Foreach loop can be
removed.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 48
Opt i mi zat i on 6: " For mul as on Mul t i Pr ovi der s"
If the formulas is using data of only one InfoProvider but is defined
on a MultiProvider, then the complete formula should be moved to
the single base InfoProvider.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 49
Opt i mi zat i on 7: " Nest ed Loops"
Use nested FOREACH statements only if necessary.
Use FOREACH VAR1, VAR2, . . . , VARn wherever it is possible.
Example: Records
2011
2010
0FISCYEAR
20
10
0AMOUNT
0002
0001
0PRODUCT
2011
2010
0FISCYEAR
20 0002
10 0001
0AMOUNT 0PRODUCT
2011
2010
2011
2010
0FISCYEAR
20
0
0
10
0AMOUNT
0002
0002
0001
0001
0PRODUCT
FOREACH pr oduct .
FOREACH year .
. . .
ENDFOR.
ENDFOR.
FOREACH pr oduct , year .
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 50
Opt i mi zat i on 8: " I f St at ement s"
If Statements versus Conditions - when to use which:
When the logic depends on variables with ranges, several values or
hierarchy nodes, then use conditions.
When using if-statements you onl y have one planning function and thus
only one formula. Therefore the formula is easier to understand.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 51
Ti p 9: " Nami ng Convent i ons"
Use naming conventions for local FOX variables, e.g.:
CHA_for characteristics,
KYF_for key figure values,
VAR_for global BI variables,
ATR_... for attributes,
INT_for integer numbers,
DAT_... for dates,
TIM_... for times.
Add comments to the formula.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 52
Ti p 9: Ex ampl e
Fi el ds t o be changed:
{ Key f i gur e name, Post i ng per i od, Ver si on }
* Post i ng per i od and t ot al amount
DATA CHA_0FI SCPER3 TYPE 0FI SCPER3.
DATA KYF_TOTAL TYPE F.
* Pl anni ng ver si on ( vi a var i abl e)
DATA VAR_ZPLNVER TYPE 0VERSI ON.
* Act ual per i od ( at t r i but e of pl an ver si on)
DATA ATR_ZACTPER TYPE 0FI SCPER3.
* Get act ual per i od f r ompl an ver si on ( vi a var i abl e)
VAR_ZPLNVER = VARV( ' ZPLNVER' ) .
ATR_ZACTPER = ATRV( ' ZACTPER' , VAR_ZPLNVER ) .
* Get t ot al t o be di st r i but ed gr eat er t han act ual per i od
KYF_TOTAL = 0.
FOREACH CHA_0FI SCPER3.
I F CHA_0FI SCPER3 > ATR_ZACTPER.
KYF_TOTAL = KYF_TOTAL + {0AMOUNT, CHA_0FI SCPER3, VAR_ZPLNVER}.
ENDI F.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 53
Ti p 10: " Ref er enc e Dat a"
If you set a local variable for a characteristic using TMVL, ATRV, or
ATRVT and use this variable in a reference data operand (right side
of formula), then the system ignores any restrictions for this
characteristic when reading the reference data from the database.
This can lead to performance problems. Check the BI statistics for
long database selection for reference data.
Try to use the new syntax for reference data in operands:
{key figure, field 1, field 2, , field n | ref. field 1 = value 1, ref. field 2 =
value 2, , ref. field m = value m}
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 54
Ti p 10: Ex ampl e
Fi el ds t o be changed:
{ Company, Ver si on }
* Company
DATA CHA_0COMPANY TYPE 0COMPANY.
* Sour ce ver si on ( at t r i but e of company)
DATA ATR_SVERSI ON TYPE SVERSI ON.
* Tar get ver si on ( var i abl e)
DATA VAR_TVERSI ON TYPE 0VERSI ON.
* Get t ar get ver si on f r omvar i abl e
VAR_TVERSI ON = VARV( ' TVERSI ON' ) .
* Copy dat a f r omsour ce t o t ar get ver si on
FOREACH CHA_0COMPANY.
ATR_SVERSI ON = ATRV( ' SVERSI ON' , CHA_0COMPANY ) .
{CHA_0COMPANY, VAR_TVERSI ON} = {CHA_0COMPANY, ATR_SVERSI ON} .
ENDFOR.
Business Case: Copy data
into a target version and each
company potentially has a
different source version.
Source version is set via attribute
(ATRV) and then used in operand
to read reference data.
System will read ALL
versions since it can't know
which ones would be required!
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 55
Ti p 11: " Endl ess 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.
To stop a modus after having programmed an " endless loop" (for
example a do loop without exit statement) go to transaction SM50
and choose Program/Mode Program Cancel.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 56
Ti p 12: " Per f or manc e Anal ysi s"
Always do a performance analysis before you start optimizing.
Use various statistics to determine the cause of performance
issues:
BI Statistics (table RSDDSTAT_OLAP, event ids 15000 - 15999)
SQL Trace (transaction ST05)
ABAP Performance Trace (transaction SE30)
Add planning function to planning sequence
Save variant for planning sequence
Run function RSPLSSE_PLSEQ_EXECUTE via SE30
(Note: Parameter I_VARIANT requires the technical name of the variant, which
can be found in table RSRPARAMETRIZA field PARAMNM)
Workload Statistic (transaction STAD)
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 57
Key Lear ni ngs
Follow the steps on " how to design a planning function"
Use subsets to your advantage
Remember the tips for implementing and optimizing FOX
formulas
Always determine the root cause first before starting to optimize
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 58
Mar c F. Ber nar d
Chief SAP NetWeaver Specialist
SAP NetWeaver RIG
SAP Labs, LLC
20 Perimeter Summit Boulevard
Atlanta, GA 30319
T 1.404.943.2725
F 1.404.943.4290
E marc.bernard@sap.com
Cont ac t I nf or mat i on
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 59
Copyr i ght 2007 SAP AG. Al l Ri ght s Reser ved
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.


J ava is a registered trademark of Sun Microsystems, Inc.
J avaScript 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 SAPproduct 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.

You might also like