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

Embed Size (px)

DESCRIPTION

TIPS

Citation preview

  • Marc F. BernardChief SAP NetWeaver SpecialistSAP NetWeaver RIG

    2007-05-30

    Tips and Tricks forImplementing andOptimizing Formulas inSAP NetWeaver BIIntegrated Planning

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 2

    Prerequisites

    Required Knowledge:

    ? General understanding of BI Integrated Planning inSAP NetWeaver 7.0

    Recommended Knowledge:

    ? Some experience with implementing formulas in BI IntegratedPlanning or BW-BPS

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 3

    Learning Objectives

    ? Learn about planning functions in BI Integrated Planning and howto 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

  • Configuring Formulas

    Performance Tuning of Formulas

    Planning Function Types

    Designing Planning Functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 5

    Enterprise Reporting, Query and Analysis

    Business Planning & Analytical Services

    Enterprise Data Warehousing

    Planning Functions &Sequences Distribute Formulas (FOX) Copy Revaluate Repost Forecast Custom defined

    Planning Modeler

    Architected Data MartsOperationalData Store Data Warehouse Layer

    MasterData

    BEx Query Designer

    BEx Web

    Web Analyzer Web Application Designer

    BEx Analyzer

    Analytical Engine

    Caching services Plan data cache

    OLAP services Drill Down Currencies/Units Calculations/Formulas Exceptions/Conditions Variables Hierarchies Aggregation Sort

    Planning specificservices Enqueue Validations Data slices Characteristic relations

    Pattern

    Information Broadcasting

    Enterprise Portal

    Report DesignerMS Excel

    Add-in

    Focus for this webinar

    SAP NetWeaver BI Architecture for Business Planning

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 6

    Various Business Requirements and Their Solutions

    Copy data fromactual version to

    plan version

    Increase the plannedrevenue by 10%

    Distributeplanned revenue

    to differentproducts

    Quantity timesPrice

    Delete the datain one plan

    version

    Convert from Euro toUSD

    Calculation Scheme forContribution Margin

    Calculate Revenuedepending on number of

    workdays in companycalendar

    Formulas

    Customer definedType of Planning

    Function

    Predefined Types ofPlanning Functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 7

    Predefined Planning Function Types

    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 beforeyou 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 inorder to generate plan data. Formula functions enable you to useextended mathematical functions to calculate plan data.

    In addition to different calculation functions, which you can use forvalue assignment in formulas, there is also the possibility to modelcomplex flow structures with the formula language FOX (FOrmulaeXtensions).

    Formulas (FOX)

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 9

    Complexity vs. Functionality

    PredefinedFunction Types Formulas (FOX)

    CustomerDefined

    FunctionTypes

    Complexity, Functionality

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 10

    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 functiontype but several planning functions/sequence are needed

    ? The customizing of a standard planning function type gets tocomplicated

    Performance

    ? Many times it is faster to have one formula doing the job than anumber of planning functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 11

    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 orformula 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 Planning Functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 13

    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 haveto 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 usedfor calculation by the planning function. These are the fields tobe 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

    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.

    20020070002

    10020070001

    0AMOUNT0FISCYEAR0PRODUCT

    20020080002

    20020070002

    10020080001

    10020070001

    0AMOUNT0FISCYEAR0PRODUCT

    Field(s) to be changed

    Before

    After

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 15

    Planning Functions Subsets

    To make it easier to configure planning functions, the systemspackages 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

    Planning Functions Subsets: Example

    Sample data

    records:

    20020080002

    20020070002

    10020080001

    10020070001

    0AMOUNT0FISCYEAR0PRODUCT

    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/recordsFields 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 Selection (based on Filter)

    Execute Function

    Build Subsets from Selected Data

    Add Subsets for Reference Data

    FOREACH Subset.

    ENDFOR.

    Phase 1

    Phase 2

    Flowchart for Planning Functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 18

    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 (freecharacteristics). As a result, the query output looks like the datarecords that are processed by the formula.

    ? Execute the planning function using the trace ("execute withtrace")

    ? In formulas you can send messages with the relevant values tothe message log of the planning function

  • Configuring Formulas

    Performance Tuning of Formulas

    Planning Function Types

    Designing Planning Functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 20

    Configuring Formulas 1/3

    3. Select the type Formula, enter technical name anddescription, and pick the aggregation level

    4. Choose Transfer

    1. Start the Planning Model and go to the Planning Function tab2. Choose Create

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 21

    Configuring Formulas 2/3

    5. Select which fields shouldbe changed (mandatory) andwhich fields should be usedfor conditions (optional)

    6. Enter the conditions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 22

    Configuring Formulas 3/3

    Control display showingwhich fields can be changedin the formula.

    Various forms of input help anddocumentation of programelements are available

    {SEMPS_003, Mango Juice} = {SEMPS_003, Apple Juice} + {SEMPS_003,Orange Juice}.

    7. For each condition, enterthe formula (FOX) in theeditor

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 23

    Formula Syntax

    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

    Formula Elements

    Formulas(FOX)

    Access Data RecordsCalculations Information

    Retrieval (e.g.Variable Values)

    Foreach and DoLoops

    ConditionalBranching Programming

    Variables

    PredefinedMathematicalFunctions

    StringOperations Call External

    Functions

    FOX = Formula Extensions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 25

    Access to Data Records

    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 forentering 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

    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 / 27

    Access to Reference Data

    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 pricescome 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

    Access to Reference Data

    Input Help for Operands with Reference Fields

    You can pick additionalreference characteristics

    { SEMPS_003, Apple Juice | Z_PRODLIN = Juice }

    ?

    ? ?Result of operand in editor:

    New Feature

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 29

    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 forvariable 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... 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

    New Feature

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 31

    Loops Example

    Example? Fields to be changed

    Key Figure, 0FISCYEAR

    ? FormulaDATA 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 / 32

    Conditional Branching

    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

    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 / 33

    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 / 34

    New Predefined Functions in Formulas

    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

    Calling ABAP Function Modules

    You can call selected ABAP function moduleswithin 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 touse the construct MESSAGE...RAISING

    New Feature

  • Configuring Formulas

    Performance Tuning of Formulas

    Planning Function Types

    Designing Planning Functions

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 37

    How to Optimize Formulas (FOX)

    The idea is to reduce the complexity of the formula, withoutchanging the result of the calculation.

    Less lines of FOX leads to less ABAP coding that the system has toprocess and therefore faster execution times.

    There are two main targets for optimization:1. Formula Operands2. Foreach Loops

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 38

    Real-world Example

    Fields to be changed:

    { Key figure, Cost Element, Version, Planning Item, InfoProvider }

    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} -

    {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 / 39

    Optimization 1: "Fields to be changed"

    Find all characteristics that are restricted to only one value in theformula. This means that the characteristic is NOT being changedand 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

    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'

    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 / 41

    Optimization 2: "Formula selection"

    Determine the selections i.e. the characteristic combinations thatare 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 readonly 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

    Optimization 2: Example

    Optimization 2 A: "Formula selections (excl. reference data)" that are different thanfilter

    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'

    Optimization 2 B: "Formula selections (incl. reference data)" that are different thanfilter

    Optimization works same way as 2A but tries to combine two database selections.

    Level contains more keyfigures than necessary

    Level is not restricted on CostElement but formula changes

    only one Cost Element

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 43

    Optimization 3: "Conditions"

    Optimization 3 A:

    If the condition is equal to the filter restriction, then the conditioncan be removed.

    Optimization 3 B:

    If there's only one condition it can be merged with the filterselection.

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 44

    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 severaltimes. Instead, the operands should be stored temporarily usinglocal 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

    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.

    Parameter group (AFTER):

    DATA M TYPE 0MATERIAL.

    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 beread and updated 1,000 times

    There's only one update ofTOTALSALES independent of

    the number of materials

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 46

    Optimization 5: "Operands in Foreach Loops"

    If an operand is used in an foreach loop but does not depend on anyforeach variable, then the operand is being processed too often andtherefore should be moved before (reference data) or after (resultdata) 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

    Optimization 5: ExampleFields 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} -

    {0000410001,PRICADJDIS} +

    {0000405002,PRICADJBKT} ) * 0.02.

    ENDFOR.

    Parameter group (AFTER):

    {0000415001,CASHDISC} =

    ( {0000400001,CUSTSALES} -

    {0000410001,PRICADJDIS} +

    {0000405002,PRICADJBKT} ) * 0.02.

    CASHDISC is updated insidethe loop although it does not

    depend on C or P.

    The other operands are readinside the loop although they

    don't depend on C or P.

    Ultimately the completeForeach loop can be

    removed.

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 48

    Optimization 6: "Formulas on MultiProviders"

    If the formulas is using data of only one InfoProvider but is definedon a MultiProvider, then the complete formula should be moved tothe single base InfoProvider.

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 49

    Optimization 7: "Nested 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

    200002

    100001

    0AMOUNT0PRODUCT

    2011

    2010

    2011

    2010

    0FISCYEAR

    20

    0

    0

    10

    0AMOUNT

    0002

    0002

    0001

    0001

    0PRODUCT

    FOREACH product.

    FOREACH year.

    ...

    ENDFOR.

    ENDFOR.

    FOREACH product, year.

    ENDFOR.

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 50

    Optimization 8: "If Statements"

    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 / 51

    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.

    Add comments to the formula.

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 52

    Tip 9: ExampleFields to be changed:

    { Key figure name, Posting period, Version }

    * Posting period and total amount

    DATA CHA_0FISCPER3 TYPE 0FISCPER3.

    DATA KYF_TOTAL TYPE F.

    * Planning version (via variable)

    DATA VAR_ZPLNVER TYPE 0VERSION.

    * Actual period (attribute of plan version)

    DATA ATR_ZACTPER TYPE 0FISCPER3.

    * 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 / 53

    Tip 10: "Reference Data"

    If you set a local variable for a characteristic using TMVL, ATRV, orATRVT and use this variable in a reference data operand (right sideof formula), then the system ignores any restrictions for thischaracteristic when reading the reference data from the database.

    This can lead to performance problems. Check the BI statistics forlong 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

    Tip 10: ExampleFields to be changed:

    { Company, Version }

    * Company

    DATA CHA_0COMPANY TYPE 0COMPANY.

    * Source version (attribute of company)

    DATA ATR_SVERSION TYPE SVERSION.

    * Target version (variable)

    DATA VAR_TVERSION TYPE 0VERSION.

    * Get target version from variable

    VAR_TVERSION = VARV( 'TVERSION' ).

    * Copy data from source to target version

    FOREACH CHA_0COMPANY.

    ATR_SVERSION = ATRV( 'SVERSION', CHA_0COMPANY ).

    {CHA_0COMPANY,VAR_TVERSION} = {CHA_0COMPANY,ATR_SVERSION} .

    ENDFOR.

    Business Case: Copy datainto a target version and each

    company potentially has adifferent 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 knowwhich ones would be required!

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 55

    Tip 11: "Endless Loops"

    Save the formula before testing! Otherwise you loose your work ifthe program goes into an endless loop and you have to stop theprogram.

    To stop a modus after having programmed an "endless loop" (forexample a do loop without exit statement) go to transaction SM50and choose Program/Mode? Program? Cancel.

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 56

    Tip 12: "Performance Analysis"

    Always do a performance analysis before you start optimizing.

    Use various statistics to determine the cause of performanceissues:? 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, whichcan 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 Learnings

    ? Follow the steps on "how to design a planning function"

    ? Use subsets to your advantage

    ? Remember the tips for implementing and optimizing FOXformulas

    ? 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

    Marc F. BernardChief SAP NetWeaver SpecialistSAP NetWeaver RIG

    SAP Labs, LLC20 Perimeter Summit BoulevardAtlanta, GA 30319

    T 1.404.943.2725F 1.404.943.4290E [email protected]

    Contact Information

  • ? SAP AG 2007, Tips and Tricks for Formulas in BI-IP / Marc F. Bernard / 59

    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 bechanged 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 aretrademarks 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 registeredtrademarks 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 priorwritten 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 thisdocument 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 itemscontained 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. Thislimitation 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 inthese materials and does not endorse your use of third-party Web pages nor provide any warranty whatsoever relating to third-party Web pages.