Professional Documents
Culture Documents
SAP IP Tips and Tricks Implementing IP
SAP IP Tips and Tricks Implementing IP
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 / Marc F. Bernard / 2
Learning Objectives 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 formulas
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 3
Planning Function Types Designing Planning Functions Configuring Formulas Performance Tuning of Formulas
BEx Analyzer
MS Excel Add-in
Caching services
Master Data
Formulas
Quantity times Price Calculation Scheme for Contribution Margin Calculate Revenue depending on number of workdays in company calendar
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 7
Formulas (FOX) 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
Formulas (FOX)
Complexity, Functionality
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 9
When to Use Formulas (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
When to Use Customer Planning Function 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)
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
How to Design a Planning Function 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
Aggregation Level
We use an InfoProvider with 0PRODUCT and 0FISCYEAR as characteristics and 0AMOUNT as key figure.
0PRODUCT 0001 0002 0FISCYEAR 2007 2007 0AMOUNT 100 200
Before
After
Field(s) to be changed
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 14
Planning Functions Subsets 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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 15
Number of calls/records 4 calls, one record per call 2 calls, records (1+2) and (3+4) 2 calls, records (1+3) and (2+4) 1 call, all records
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 16
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
How to Test Planning Functions 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
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
5. Select which fields should be changed (mandatory) and which fields should be used for conditions (optional)
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 21
7. For each condition, enter the formula (FOX) in the editor Various forms of input help and documentation of program elements are available
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 22
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 23
Formula Elements
String Operations
Formulas (FOX)
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
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
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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 28
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 29
BI Variable
FOREACH <Variable> IN VARIABLE... ENDFOR
New Feature
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 30
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
Multiple conditions
IF ELSEIF ELSE ENDIF.
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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 33
String Operations
Get part of a value
SUBSTR
Concatenate values
CONCAT
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
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
How to Optimize Formulas (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
Real-world Example
Fields to be changed:
Parameter group:
* Cash Discount = (Base Revenue - Price Adjustment) * 2% DATA C TYPE 0COSTELMNT. DATA V TYPE 0VERSION. DATA P TYPE ZPLANITEM. FOREACH C,V,P. {0AMOUNT,0000415001,V,CASHDISC,PA000004} = ( {0AMOUNT,0000400001,V,CUSTSALES,PA000004} -
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
Optimization 1: "Fields to be changed" that are not changed
Remove from "Fields to be changed": Key figure = 0AMOUNT Remove from "Fields to be changed": Version = V Remove from "Fields to be changed": InfoProvider = 'PA000004'
Parameter group: * Cash Discount = (Base Revenue - Price Adjustment) * 2% DATA C TYPE 0COSTELMNT. DATA P TYPE ZPLANITEM. FOREACH C,P. {0000415001,CASHDISC} = ( {0000400001,CUSTSALES} -
Optimization 2: "Formula selection" 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
Optimization 2: Example
Optimization 2 A: "Formula selections (excl. reference data)" that are different than filter
Restrict level/filter to formula selection: Key figure Level/Filter: = 0AMOUNT, ZPRICEADJ, ZUNCOLLAR Formula: = 0AMOUNT
Restrict level/filter to formula selection: Cost Element Level/Filter: No restriction Formula: = '0000415001'
Level is not restricted on Cost Element but formula changes only one Cost Element
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: 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
Optimization 4: "Formula operands" 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
Optimization 4: Example
Fields to be changed: { Material, Planning Item }
Parameter group (BEFORE): DATA M TYPE 0MATERIAL. {M,TOTALSALES} = 0. FOREACH M. {M,TOTALSALES} = {M,TOTALSALES} + {M,CUSTSALES}. ENDFOR.
If there are 1,000 materials, then TOTALSALES has to be read and updated 1,000 times
Parameter group (AFTER): DATA M TYPE 0MATERIAL. DATA TOTAL TYPE F. TOTAL = 0. FOREACH M. TOTAL = TOTAL + {M,CUSTSALES}. 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" 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
Optimization 5: Example
Fields to be changed: { Cost Element, Planning Item }
Parameter group (BEFORE): * Cash Discount = (Base Revenue - Price Adjustment) * 2% DATA C TYPE 0COSTELMNT. DATA P TYPE ZPLANITEM. FOREACH C,P. {0000415001,CASHDISC} = ( {0000400001,CUSTSALES} -
The other operands are read inside the loop although they don't depend on C or P.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 47
Optimization 6: "Formulas on MultiProviders" 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
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 49
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 50
Tip 9: "Naming Conventions" 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.
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 } * Posting period and total amount DATA CHA_0FISCPER3 TYPE 0FISCPER3. DATA KYF_TOTAL TYPE F.
* Get actual period from plan version (via variable) VAR_ZPLNVER = VARV( 'ZPLNVER' ). ATR_ZACTPER = ATRV( 'ZACTPER', VAR_ZPLNVER ). * Get total to be distributed greater than actual period KYF_TOTAL = 0. FOREACH CHA_0FISCPER3. IF CHA_0FISCPER3 > ATR_ZACTPER. KYF_TOTAL = KYF_TOTAL + {0AMOUNT,CHA_0FISCPER3,VAR_ZPLNVER}. ENDIF. ENDFOR.
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 52
Tip 10: "Reference Data" 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
* Company DATA CHA_0COMPANY TYPE 0COMPANY. * Source version (attribute of company) DATA ATR_SVERSION TYPE SVERSION. * Target version (variable) DATA VAR_TVERSION TYPE 0VERSION.
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 / 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. 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: "Performance Analysis" Always do a performance analysis before you start optimizing.
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
Contact Information
Marc F. Bernard
Chief SAP NetWeaver Specialist SAP NetWeaver RIG
SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 58
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