04 - Logics Scripts
04 - Logics Scripts
0 NW SPBO Training
Logic Scripts
Calculations in BPC
Logic allows you to define formulas that perform calculations on SAP Business Planning and Consolidation members and data. You can have three different type of calculations:
Front-End Worksheet logic (Excel & VBA) On-the-Fly
Each type has advantages and disadvantages. You typically use some combination of all four types to achieve the desired results.
Logics
Cons
Static - the formulas are only available in the worksheet in which they are written, and need to be rewritten for each worksheet. Cannot be applied as a process - worksheet formulas cannot be executed via the Data Manager (i.e. the calculations are not performed until the sheet is opened and the data refreshed). Not stored - results are not stored in the database. Risk of incompatibilities between different version of MS Excel Usage of VBA can cause performance issues in Citrix environments Usage of VBA can increase maintenance work on reports / input schedules
Tip
Make sure the dimension and dimension member case are correct!
In the event of a formula collision between the above members, the Account3 formula should take precedence over the Product3 formula because solve_order = 5 has higher priority than solve_order = 100.
24 + 26 = 50 but 250 / 10 <> 50 Incorrect result because account ratio is calculated prior to and over-ridden by the product addition formula. 250 / 10 = 25 but 24 + 26 <> 25 Correct result because account ratio is calculated after the product addition formula.
Options tab
The following SAP Business Planning and Consolidation 5.x standard functions are not included in SAP Business Planning and Consolidation 7.0, version for SAP NetWeaver:
Profitability Ratios Return on Assets, Return on Equity, Return on Common Equity, Cost of Goods Sold to Sales, Net Profit Margin, Gross Profit Margin, SG&A to Sales Ratio. Efficiency Analysis Ratios Asset Turnover Ratio, A/R Turnover Ratio, Average Collection Period, A/P Turnover Ratio, Inventory Turnover Ratio, Average Age of Inventory, Sales to Total Assets Ratio, Days in Receivables, Days in Payables, Days in Inventory. Capital Structure Analysis Ratios Debt Ratio, Debt to Equity Ratio, Interest Coverage Ratio, Debt Coverage Ratio. Capital Market Analysis Ratios Earnings per Share, Price Earnings Ratio, Book Value per Share, Market to Book Ratio, Dividend Yield, Dividend Payout.
Cons
Lack of flexibility - dimension logic applies to all levels in the dimension and in all applications using the dimension. If you want to apply a formula only to base level members or want a formula to be used in only one application you should use advanced logic. Creates load on the server.
Results are written directly to the application as base data, and are aggregated up the dimensional hierarchy as they are, without being recalculated at upper levels.
All dimension logic formulas are applied to these results. This process allows you to perform such calculations as units times price because the formulas are applied only to those members specified in the logic file.
Source Data
Calculations
Calculation Output
Destination Data
=
Delta Application
In the MDX mode, the execution scope represents the data region where calculations result should be posted. In the SQL mode, the execution scope represents the data region where the source data are.
*XDIM_ADDMEMBERSET
Add members to the scope of that dimension
*XDIM_FILTER
Filters the members of the scope of that dimension
*XDIM_MAXMEMBERS
Specifies the maximum number of members that should be included in one query (per dimension)
*SELECT
Assigns a list of members to a memory variable
Variant on XDIM_MEMBERSET *XDIM_MEMBERSET {Dimension name} = BAS{Members Set} *XDIM_MEMBERSET {Dimension name} = DEP{Members Set} *XDIM_MEMBERSET {Dimension name} = ALL{Members Set} Example: *XDIM_MEMBERSET TIME = BAS(2007.TOTAL) Selects all base level members of the 2007.TOTAL parent node
Adds to Member Selection *XDIM_ADDMEMBERSET {dimension} = {members set} Example: User sends data only on Entity1 and the default logic contains: *XDIM_ADDMEMBERSET ENTITY=Entity2 Logic will be executed for Entity1 AND Entity2.
Syntax
*XDIM_FILTER {Dimension name} = {Members Set}
Example
If the scope is France, Italy, USA, the instruction:
*XDIM_FILTER ENTITY= [ENTITY].Properties(EUROPE)=Y would limit the scope to the European Entities : France and Italy
Above instruction, if entities to process exceed the limit of 50 members, the logic will break the query into multiple queries of no more than 50 entities each.
PREFORMANCE RELATED
Script Logic
Calculations - *REC
The *REC instruction is used to generate a new database. The *REC statement has two type of parameters:
Calculation on the current value of the record (Using the keywords EXPRESSION and FACTOR Overwriting the members where the records should be generated (you usually do not want to overwrite your source record with the result, but write that result back to another member) Example: The following syntax multiplies the value of the record by 2 and writes-it back to the category budget
*REC(FACTOR=2,CATEGORY=BUDGET)
The *REC statement can only be used within an *WHEN / *ENDWHEN structure
Script Logic
Example
*REC(FACTOR=1/2) Current value is multiplied by 0.5 *REC(EXPRESSION=%VALUE% + 500) Adds 500 to the existing value
Script Logic
A *When / *Endwhen structure can contain several *IS statements and one *ELSE statement The *When keyword can use any property of a dimension, for example Entity.Currency. The *IS keword can then filter on the values of that property
Script Logic
Calculations - *WHEN / *ENDWHEN Example This example copies the values of the account sales from the category Actual to Budget and multiply the values by 2
*WHEN Category *IS Actual *WHEN Account *IS Sales *REC(FACTOR = 2, Category=Budget) *ENDWHEN *ENDWHEN
Script Logic
Script Logic
Calculations - *LOOKUP
*LOOKUP/*ENDLOOKUP
*Lookup/*EndLookup - This set of instructions can be used in conjunction with a WHEN/ENDWHEN structure to retrieve (lookup) some other values that may be needed either in the calculation of the new value or to define some criteria to be evaluated. A relationship is defined between the current record being processed and the record to lookup Can be used in Factor\Expression or *WHEN Can lookup values in current application or different application in the same application set
Syntax
*LOOKUP {App} *DIM [{Lookup ID}:] {Dimension Name}=Value | {Calling Dimension Name} [. {Property}] [*DIM.] *ENDLOOKUP
*Where:
{App} is the name of the application from which the amounts are searched {DimensionName} is a dimension in the lookup app {CallingDimensionName} is a dimension in the current application {LookupID} is an optional identifier of the looked-up amount. This is only required when multiple values must be retrieved.
The desination application needs to have the same structure than the source application, the keywords *Skip_dim, *Add_dim and *Rename_dim are not supported
The behavior of the XDIM_MAXMEMBERS option for SQL logic is that the process will commit the generated result as they are generated by each single query. When XDIM_MAXMEMBERS is used in MDX type logics, the logic query is broken in as many queries as required. However all resulting records are committed to the database in one lump at the end of the loop of queries.
It may be preferable to perform a commit to the database after each individual query. This can be accomplished inserting the instruction:
*COMMIT_MAXMEMBERS
Advanced logic can be run from Data Manager for batch processing of formulas.
Using Data Manager to execute Logic module formulas is useful for calculations that do not need to be executed immediately. For example, an administrator may decide to wait until all the data has been entered in the local currency before generating the translated amounts in the reporting currencies.
Usage: *RUNALLOCATION *FACTOR={expression} *DIM {dim name} WHAT={set}; WHERE={set}; *DIM *ENDALLOCATION [USING ={set};] [TOTAL={set}]
Description Within SAP Business Planning and Consolidation 5.x, this was run as a stored procedure. Within SAP Business Planning and Consolidation 7.0, version for SAP NetWeaver, this is natively a Script Logic Keyword. An allocation method to allocate a value to a number of target member using reference values or percentage Rather than writing custom script logic, the allocation engine was designed to simplify allocations and is a best practice methodology. The allocation engine is referenced in a script logic package, but uses a table based approach.
SAP 2008 / Page 54
WHAT=NON_INTERCO; WHERE=<<<;
Badi
Agenda
1.
Call Custom Logic Where am I .main views in BPC NW Custom Logic Overview Create Custom Logic for Input Schedule Create Custom Logic for Data Package Debugging Custom Logic
Data Modeling Maintain Master Data Data Modeling Script Logic Maintain Master Data User Management Script Logic User Management
Reporting Input Scheduling Reporting Data Mangement Input Scheduling Data Mangement
Administration
- Process Chain (RSPC) - BPC: File Service User Interface (UJFS)
Development
- Dev. Workbench (SE80) - BADI (SE19) - SAP Table (SE16) - Programms (SE38)
Authorization
User Maintanance (SU01), Role Maintanance (PFCG), Management of Analysis Authorizations (RSECADMIN)
To create a new function, create a Business Add-in (BADI) Implementation of UJ_CUSTOM_LOGIC (SE18). If the BADI has a filter, then in script logic the customer need to provide the a filter value. Note: To pass parameters to the BADI, you can use Data Manager prompts and read the values of these parameters within your call custom logic code.
For instructions about implementing an SAP Business Add-In, see the ABAP online help at:
http://help.sap.com/saphelp_nw70/helpdata/en/32/a83942424dac04e10000000a1550b0/cont ent.htm. For instructions on how to pass parameters to Custom Logic BADI using START_BADI https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/20f4252d-98ca-2b10-e689f85085ae2d12
You can use Custom Logic in two different ways, find below a short summary:
Decision Points: Custom Logic in Input Schedule Data Selection Modeling Debugging Input Schedule and Default Logic BADI, Scipt, Input Schedule External Breakpoint, Maintain Debugging User Custom Logic in Data Package Query and Scipt Logic BADI, Process Chain, Script, Data Package External Breakpoint, Maintain Debugging User, Save SYNCHRONOUS.run File
Script Logic
BADI BADI
BW BW Developer Developer
Script Logic
Data Package
2. Create Process Chain 2. Create Process Chain
2. A) Create Start Process 2. A) Create Start Process 2. B) BPC Modify Dynamically 2. B) BPC Modify Dynamically
BADI BADI
BW BW Developer Developer
Process Chain Process Chain BW BW Process Chain Process Chain Admin Admin Workbench Workbench
2. C) BPC Run Logic 2. C) BPC Run Logic 2. D) or Process 2. D) or Process 2. E) BPC Clear BPC Tables 2. E) BPC Clear BPC Tables
Customizing via Customizing via Drag & Drop Drag & Drop
4. Create Data Management 4. Create Data Management Package Package 5. Call Data Package 5. Call Data Package
1.
2. 3.
Set External Debug User in your Coding Only for Data Package: Create File SYNCHRONOUS.run with Content Y (direct under C:\ on you Client PC)
Lessons learned
Lessons Learned
Script Logic has still a few functional gaps with the Microsoft Release, but is catching up quickly (lots of features were delivered in SP01 and SP02) Performance of Dimension Member Formulas (MDX) is rather poor, should be avoided whenever possible Limit the number of *COMMIT Limit the scope of your calculations Limit the content of your Default logic file
Thank you!
Weitergabe und Vervielfltigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrckliche schriftliche Genehmigung durch SAP AG nicht gestattet. In dieser Publikation enthaltene Informationen knnen ohne vorherige Ankndigung gendert werden. Einige von der SAP AG und deren Vertriebspartnern vertriebene Softwareprodukte knnen Softwarekomponenten umfassen, die Eigentum anderer Softwarehersteller sind. SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, SAP Business ByDesign, ByDesign, PartnerEdge und andere in diesem Dokument erwhnte SAP-Produkte und Services sowie die dazugehrigen Logos sind Marken oder eingetragene Marken der SAP AG in Deutschland und in mehreren anderen Lndern weltweit. Alle anderen in diesem Dokument erwhnten Namen von Produkten und Services sowie die damit verbundenen Firmenlogos sind Marken der jeweiligen Unternehmen. Die Angaben im Text sind unverbindlich und dienen lediglich zu Informationszwecken. Produkte knnen lnderspezifische Unterschiede aufweisen. Die in diesem Dokument enthaltenen Informationen sind Eigentum von SAP. Dieses Dokument ist eine Vorabversion und unterliegt nicht Ihrer Lizenzvereinbarung oder einer anderen Vereinbarung mit SAP. Dieses Dokument enthlt nur vorgesehene Strategien, Entwicklungen und Funktionen des SAP-Produkts und ist fr SAP nicht bindend, einen bestimmten Geschftsweg, eine Produktstrategie bzw. -entwicklung einzuschlagen. SAP bernimmt keine Verantwortung fr Fehler oder Auslassungen in diesen Materialien. SAP garantiert nicht die Richtigkeit oder Vollstndigkeit der Informationen, Texte, Grafiken, Links oder anderer in diesen Materialien enthaltenen Elemente. Diese Publikation wird ohne jegliche Gewhr, weder ausdrcklich noch stillschweigend, bereitgestellt. Dies gilt u. a., aber nicht ausschlielich, hinsichtlich der Gewhrleistung der Marktgngigkeit und der Eignung fr einen bestimmten Zweck sowie fr die Gewhrleistung der Nichtverletzung geltenden Rechts. SAP bernimmt keine Haftung fr Schden jeglicher Art, einschlielich und ohne Einschrnkung fr direkte, spezielle, indirekte oder Folgeschden im Zusammenhang mit der Verwendung dieser Unterlagen. Diese Einschrnkung gilt nicht bei Vorsatz oder grober Fahrlssigkeit. Die gesetzliche Haftung bei Personenschden oder die Produkthaftung bleibt unberhrt. Die Informationen, auf die Sie mglicherweise ber die in diesem Material enthaltenen Hotlinks zugreifen, unterliegen nicht dem Einfluss von SAP, und SAP untersttzt nicht die Nutzung von Internetseiten Dritter durch Sie und gibt keinerlei Gewhrleistungen oder Zusagen ber Internetseiten Dritter ab. Alle Rechte vorbehalten.
SAP 2008 / Page 69