T i p s a n d T r ic ic k s f o r I m p l e m e n t i n g a nd nd Op t i m i z zii n g Fo Fo r m u l a s i n SA P N e t We a v e r B I I n t e g r a t e d Pl P l a n ni ni n g
Marc F. Bernard Chief SAP NetWeaver Specialist SAP NetWeaver RIG
2007-05-30
Prerequisites
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 BI-IP / Marc F. Bernard / 2
L e a r n i n g Ob Ob j e c t i v e s
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 implementing impl ementing formulas
SAP AG 2007, Tips and Tricks for Formulas in BI-IP BI-IP / Marc F. Bernard / 3
Planning Function Types Designing Planning Functions Configuring Formulas Performance Tuning of Formulas
S A P Ne N e t W e a v e r B I A r c h i t e c t u r e f o r B u s i n e s s P l an an n i n g Enterprise Portal Enterprise Reporting, Query and Analysis Information Broadcasting BEx Analyzer
BEx Web Pattern Web Analyzer
Web Application Designer
Report Designer
MS Excel Add-in
BEx Query Designer Business Planning
& Analytical Services Planning Modeler
Analytical Engine OLAP services • Drill Down • Currencies/Units • Calculations/Formulas • Exceptions/Conditions • Variables • Hierarchies • Aggregation • Sort •…
Planning specific services • Enqueue • Validations • Data slices • Characteristic relations
Caching services
Plan data cache
Planning Functions & Sequences • Distribute • Formulas (FOX) • Copy • Revaluate • Repost • Forecast • Custom defined •…
Enterprise Data Warehousing Operational Data Store
SAP AG 2007, Tips and Tricks for Formulas in BI-IP BI-IP / Marc F. Bernard / 5
Architected Data Marts Data Warehouse Layer
Master Data
Focus for this webinar
V a r i o u s B u s i n e s s Re q u i r e m e n t s a n d T h e i r S o lu t i o n s
Copy data from actual version to plan version
Distribute planned revenue to different products
Increase the planned revenue by 10%
Predefined Types of Planning Functions Delete the data in one plan version
Convert from Euro to USD
Formulas Quantity times Price
Calculation Scheme for Contribution Margin
Customer defined Type of Planning Function
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 6
Calculate Revenue depending on number of workdays in company calendar
Pr e d e f i n e d P l a n n i n g Fu n c t i o n T y p e s
Predefined Planning Function Types Copy Delete Repost Revalue
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
Fo r m u l a s ( FO X )
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).
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 8
Co m p l e x i t y v s . Fu n c t i o n a l 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 / 9
Wh e n t o U s e F o r m u l a s (FOX )
Create a formula if…
There is no predefined planning function type that does the job
The task cannot be done in 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 / 10
Wh e n t o U s e Cu s t o m e r Pl a n n i n g Fu n c t i o n T y p e s
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)
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 11
Planning Function Types Designing Planning Functions Configuring Formulas Performance Tuning of Formulas
H o w t o De s i g n a Pl a n n i n g Fu n c t i o n
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 / 13
Ex a m p l e f o r a Pl a n n i n g F u nc t i o n
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. 0PRODUCT
0FISCYEAR
0AMOUNT
0001
2007
100
0002
2007
200
0PRODUCT
0FISCYEAR
0AMOUNT
0001
2007
100
0001
2008
100
0002
2007
200
0002
2008
200
Field(s) to be changed
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 14
Before
After
Pl a n n i ng F u nc t i o n s – Su b s e t 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 / 15
Pl a n n i n g Fu n c t i o n s – Su b s e t s : Ex a m p l e Sample data records:
0PRODUCT
0FISCYEAR
0AMOUNT
0001
2007
100
0001
2008
100
0002
2007
200
0002
2008
200
Fields to be changed
Fields for grouping
Number of calls/records
Empty
All
4 calls, one record per call
Year
Product
2 calls, records (1+2) and (3+4)
Product
Year
2 calls, records (1+3) and (2+4)
All
Empty
1 call, all records
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 16
Fl o w c h a r t f o r Pl a n n i n g Fu n c t i o n s
Start of Execution Data Selection (based on Filter) Build Subsets from Selected Data Phase 1
Reference Data (based on Function) Add Subsets for Reference Data FOREACH Subset.
Phase 2
Execute Function ENDFOR. End of Execution
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 17
H o w t o T e s t P la n n i n g Fu n c t i o n s
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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 18
Planning Function Types Designing Planning Functions Configuring Formulas Performance Tuning of Formulas
Co n f i g u r i n g F o r m u l a s 1 /3 1. Start the Planning Model and go to the Planning Function tab 2. Choose Create
3. Select the type Formula , enter technical name and description, and pick the aggregation level 4. Choose Transfer
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 20
Co n f i g u r i n g F o r m u l a s 2 /3
5. Select which 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 / 21
Co n f i g u r i n g F o r m u l a s 3 /3
{SEMPS_003, Mango Juice} = {SEMPS_003, Apple Jui ce} + {SEMPS_003, Orange Juice}.
7. For each condition, enter the formula (FOX) in the editor Various forms of input help and documentation of program elements are available
Control display showing which fields can be changed in the formula.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 22
Fo r m u l a Sy n t a x
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 / 23
Fo r m u l a El e m e n t s
Access Data Records
String Operations
Calculations
Formulas (FOX)
Foreach and Do Loops Conditional Branching
FOX = Formula Extensions
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 24
Programming Variables
Information Retrieval (e.g. Variable Values)
Call External Functions
Predefined Mathematical Functions
A c c e s s t o D at a Re c o r d s
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
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 / 25
A c c e s s t o Da t a Re c o r d s – Ex a m p l e
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
A c c e s s t o R e fe r e n c e D a t a New Feature
Reference Characteristics in Operands
Business Scenario – We are calculating the revenue from the planned quantities and the prices. Revenue and quantity are stored in 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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 27
A c c e s s t o R e fe r e n c e D a t a New Feature
Input Help for Operands with Reference Fields You can pick additional reference characteristics
Result of operand in editor: { SEMPS_003, Apple Juice | Z_PRODLIN = Juice }
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 28
Variables
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 / 29
Loops
General Looping
Variable number of loops – DO... EXIT… ENDDO
Predefined number of loops – DO n TIMES... ENDDO
Looping over Certain Values
Plan data values (only existing records) – FOREACH
... ENDFOR
Reference data values – FOREACH IN REFDATA... ENDFOR
Selection criteria (filter) – FOREACH IN SELECTION... ENDFOR
BI Variable – FOREACH IN VARIABLE... ENDFOR
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 30
New Feature
L oo p s – Ex a m p l e
Example
Fields to be changed – Key Figure, 0FISCYEAR
Formula DA T A y e a r T Y PE 0 F I S CY EA R. F ORE A CH y e a r . { 0 A MOUNT , y e a r } = { 0 A MOUNT , 2 0 0 7 } * 1 . 0 5 . 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 { 0 A MOUNT , 2 0 0 8 } = { 0 A MOUNT , 2 0 0 7 } * 1 . 0 5 . – Second loop: YEAR is replaced with 2009 and system calculates { 0 A MOUNT , 2 0 0 9 } = { 0 A MOUNT , 2 0 0 7 } * 1 . 0 5 .
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 31
Co n d i t i o n a l B r a nc h i n g
Program Flow Based on Conditions
Single condition – IF… ENDIF.
Single condition and others – IF… ELSE… ENDIF.
Multiple conditions – IF… ELSEIF… ELSE… ENDIF.
Example
Fields to be changed – Key Figure, 0FISCYEAR
Formula I F { 0 A MOUNT , 2 0 0 7 } > 1 0 0 0 . { 0 A MOUNT , 2 0 0 8 } = { 0 A MOUNT , 2 0 0 7 } * 1 . 0 5 . ELSE. { 0 A MOUNT , 2 0 0 8 } = { 0 A MOUNT , 2 0 0 7 } * 1 . 1 0 . E NDI F .
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 32
Pr o g r a m E l e m e n t 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 / 33
N e w P re d e f i n e d Fu n c t i o n s i n Fo r m u l a s 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
Ca l l i n g A B A P Fu n c t i o n M o d u l e s New Feature
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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 35
Planning Function Types Designing Planning Functions Configuring Formulas Performance Tuning of Formulas
H o w t o Op t i m i z e Fo r m u l a s ( 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 / 37
Re a l -w o r l d E x a m p l e Fi e l d s t o b e ch an ge d:
{ K e y f i g ur e , Co s t
E l e me n t ,
Ve r s i o n,
P l a n n i n g I t e m,
I n f o Pr o v i d er
P a r a me t e r g r o u p :
* C a s h Di s c o u n t = ( B a s e Re v e n u e - P r i c e Ad j u s t me n t )
* 2%
DATA C TYPE 0COSTELMNT. D A T A V T Y P E 0 V E R S I ON . D A T A P T Y P E Z P L A N I T E M. F OR EA CH C , V , P . { 0 A MOUNT , 0 0 0 0 4 1 5 0 0 1 , V , CA SHDI S C, P A0 0 0 0 0 4 } = (
{ 0 A MOUNT , 0 0 0 0 4 0 0 0 0 1 , V , CUS T S AL E S, P A0 0 0 0 0 4 }
-
{ 0 A MOUNT , 0 0 0 0 4 1 0 0 0 1 , V , P RI CA DJ D I S , P A0 0 0 0 0 4 }
+
{ 0 A MOUNT , 0 0 0 0 4 0 5 0 0 2 , V , P RI CA DJ B KT , P A0 0 0 0 0 4 } ) ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 38
* 0 . 02.
}
Op t i m i z at i o n 1 : " F i e l d s t o b e c h a n g e d "
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
Op t i m i za t i o n 1 : Ex a m p l e Op t i mi z a t i o n 1 :
" F i e l d s t o b e c ha ng ed " t h at
a r e n ot
c h an ge d
Re mo v e f r o m " F i e l d s t o b e c h a n g e d " :
K e y f i g u r e = 0 A MOU NT
Re mo v e f r o m " F i e l d s t o b e c h a n g e d " :
Ve r s i o n = V
Re mo v e f r o m " F i e l d s t o b e c h a n g e d " :
I n f o Pr o v i d e r
= ' PA0 0 0 0 0 4 '
Fi e l d s t o b e ch an ge d: { Co s t E l e me n t ,
Pl a n n i n g I t e m }
P a r a me t e r g r o u p : * C a s h Di s c o u n t = ( B a s e Re v e n u e - P r i c e Ad j u s t me n t ) DATA C TYPE 0COSTELMNT. D A T A P T Y P E Z P L A N I T E M. F O RE A CH C , P . { 0 0 0 0 4 1 5 0 0 1 , CA SHDI S C} = ( { 0 0 0 0 4 0 0 0 0 1 , CUS TS A L E S}
-
{ 0 0 0 0 4 1 0 0 0 1 , P RI CA DJ D I S } + { 0 0 0 0 4 0 5 0 0 2 , P RI CA DJ B KT } )
* 0. 02.
ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 40
* 2%
Op t i m i z at i o n 2 : " F o r m u l a s e l e c t i o n "
Determine the selections i.e. the characteristic combinations that are changed by the formula and compare it against the filter. 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 / 41
Op t i m i za t i o n 2 : Ex a m p l e Op t i mi z a t i o n 2 A : filter
" F o r mu l a s e l e c t i o n s ( e x c l .
Re s t r i c t l e v e l / f i l t e r
t o f o r mu l a s e l e c t i o n :
r e f e r e n ce da t a ) " t h at
a r e di f f e r e nt
t h an
Ke y f i g u r e
L e v el / Fi l t e r : = 0 A MOU NT ,
Z P RI C E AD J ,
Z U NC OL L A R
Level contains more key figures than necessary
F o r mu l a : = 0AMOUNT
Re s t r i c t l e v e l / f i l t e r
t o f o r mu l a s e l e c t i o n :
Co s t E l e me n t
L e v el / Fi l t e r : No r e s t r i c t i o n
Level is not restricted on Cost Element but formula changes only one Cost Element
F o r mu l a : = ' 0 0 00 4 1 50 0 1 '
Op t i mi z a t i o n 2 B : filter
" F o r mu l a s e l e c t i o n s ( i n c l .
Op t i mi z a t i o n wo r k s s a me wa y a s 2 A b u t
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 42
r e f e r e n ce d at a ) " t h at
a r e d i f f e r e nt
t r i e s t o c o mb i n e t wo d a t a b a s e s e l e c t i o n s .
t h an
Op t i m i z at i o n 3 : " C on d i t i o n s "
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 / 43
Op t i m i z at i o n 4 : " Fo r m u l a o p e r a n d s "
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 / 44
Op t i m i za t i o n 4 : Ex a m p l e Fi e l d s t o b e c ha ng ed : { Ma t e r i a l ,
P a r a me t e r
Pl a nn i n g I t e m }
g r o u p ( B E F ORE ) :
D A T A M T Y P E 0 M A T E RI A L .
If there are 1,000 materials, then TOTALSALES has to be read and updated 1,000 times
{ M, T OT A L SA L E S} = 0 . FOREACH M. { M, T OT A L S AL E S} = { M, T OT A L SA L E S} + { M, CUS T SA L ES } . ENDFOR.
P a r a me t e r g r o u p ( A F T E R) : D A T A M T Y P E 0 M A T E RI A L . DATA TOTAL TYPE F. TOTAL = 0. FOREACH M. T OT A L = T O T AL + { M, CUS T S AL E S } . ENDFOR. { M, T OT A L SA L E S} = T O TA L .
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 45
There's only one update of TOTALSALES independent of the number of materials
Op t i m i z at i o n 5 : " Op e r a n d s i n F o r e a c h L o o p s "
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 / 46
Op t i m i za t i o n 5 : Ex a m p l e Fi e l d s t o b e c ha ng ed : { Co s t E l e me n t ,
P a r a me t e r
Pl a n n i n g I t e m }
g r o u p ( B E F ORE ) :
* C a s h Di s c o u n t = ( B a s e Re v e n u e - P r i c e Ad j u s t me n t ) DATA C TYPE 0COSTELMNT.
* 2%
CASHDISC is updated inside the loop although it does not depend on C or P.
D A T A P T Y P E Z P L A N I T E M. F O RE A CH C , P . { 0 0 0 0 4 1 5 0 0 1 , CA SHDI S C} = ( { 0 0 0 0 4 0 0 0 0 1 , CUS TS A L E S}
-
{ 0 0 0 0 4 1 0 0 0 1 , P RI CA DJ D I S } + { 0 0 0 0 4 0 5 0 0 2 , P RI CA DJ B KT } )
* 0. 02.
The other operands are read inside the loop although they don't depend on C or P.
ENDFOR.
P a r a me t e r g r o u p ( A F T E R) : { 0 0 0 0 4 1 5 0 0 1 , CA S HDI S C} = ( { 0 0 0 0 4 0 0 0 0 1 , CUS T SA L E S }
-
{ 0 0 0 0 4 1 0 0 0 1 , P RI CA DJ DI S } + { 0 0 0 0 4 0 5 0 0 2 , P RI CA DJ B K T } )
* 0. 02.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 47
Ultimately the complete Foreach loop can be removed.
Op t i m i za t i o n 6 : " Fo r m u l a s o n M u l t i Pr o v i d e r 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 / 48
Op t i m i z at i o n 7 : " N e s t e d L o o p s " Use nested FOREACH statements only if necessary. Use F ORE A CH V A R1 , V A R2 , . . . , Example:
V A Rn wherever it is possible.
Records 0PRODUCT
0FISCYEAR
0AMOUNT
0001
2010
10
0002
2011
20
F ORE ACH p r o d u c t . F ORE A CH y e a r . F ORE A CH p r o d u c t ,
. . .
year .
ENDFOR.
ENDFOR. ENDFOR. 0PRODUCT
0FISCYEAR
0AMOUNT
0001
2010
10
0001
2011
0
0002
2010
0
0002
2011
20
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 49
0PRODUCT
0FISCYEAR
0AMOUNT
0001
2010
10
0002
2011
20
Op t i m i za t i o n 8 : " I f S t a t e m e n t 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 only 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 / 50
T i p 9 : " N a m i n g Co n v e n t i o n s "
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 / 51
T i p 9 : Ex a m p l e Fi e l d s t o b e c ha ng ed : { K e y f i g u r e n a me , P o s t i n g p e r i o d , * Po s t i n g p e r i o d a nd t o t a l
Ve r s i o n }
a mo u n t
D AT A CH A_ 0 F I S CP E R3 T Y P E 0 F I S CP E R3 . DATA KYF_ TOTAL
TYPE F.
* Pl a nn i n g v er s i o n ( v i a va r i a bl e ) D A T A V A R _ Z P L N V ER * Ac t u al
T Y P E 0 V E R S I O N.
pe r i od ( a t t r i but e of
D AT A A T R _ Z A C T PE R * Ge t a c t u a l
T Y P E 0 F I S CP E R3 .
p er i o d f r o m p l a n v e r s i o n ( v i a v ar i a bl e )
V AR_ Z P L NV ER = V ARV ( ' Z P L NV ER' A T R_ Z A C T PE R = A T RV ( ' Z A CT P E R' , * Ge t
t ot al
p l a n ver s i on)
) . V A R_ Z P L N V ER ) .
t o b e di s t r i b u t e d g r e at e r t h an a c t u al
per i od
KYF_TOTAL = 0. F O RE A CH CH A _ 0 F I S C P ER 3 . I F CH A_ 0 F I S CP E R3 > A T R_ Z A CT P E R. K YF _ T O T A L = K YF _ T O T AL + { 0 A MOUNT , CHA _ 0 F I S CP ER 3 , V AR _ Z P L NV ER} . E NDI F . ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 52
T i p 1 0 : " R ef e r e n c e D a t 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 / 53
T i p 1 0 : Ex a m p l e Fi e l d s t o b e c ha ng ed : { Co mp a n y ,
Ve r s i o n }
* Co mp a n y DATA CHA_0COMPANY TYPE 0COMPANY. * So ur c e ve r s i o n ( a t t r i b ut e of
c o mp a n y )
Business Case: Copy data into a target version and each company potentially has a different source version.
D A T A AT R _ S V E R S I O N T Y P E S V E RS I ON . * Ta r g et
v e r s i o n ( v ar i a bl e )
D A T A V A R _ T V E R S I O N T Y P E 0 V E R S I ON .
* Ge t t a r g e t
v er s i o n f r o m v ar i a bl e
V AR_ T V ERS I ON = V ARV ( ' T V ER SI ON'
).
* Co py d at a f r o m s o u r c e t o t a r g e t v e r s i o n
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!
FOREACH CHA_0COMPANY. A T R_ S V E RS I ON = A T RV ( ' S V ERS I ON' ,
CHA _ 0 C OMP A NY ) .
{ C HA _ 0 C OMP A NY , V A R_ T V E RS I ON } = { C HA _ 0 C OMP A NY , A T R _ S V ER SI ON } . ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 54
T i p 1 1 : " En d l e s s L o o p s "
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 / 55
Tip 12: "Performanc e Analysis"
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 / 56
Key Learnings
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 / 57
Co n t a c t I n f o r m a t i o n
Marc
. Bernar
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 [email protected]
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 58