Script Logic
Script logic is a feature that allows you to create files called logic scripts containing instructions for performing calculations on planning and consolidation data
Features
You can perform logic calculations on base level members only. In addition, logic is specific to each model.
Business Planning and Consolidation provides a library of MDX formulas, and the EnvironmentShell sample environment contains a number of logic functions.
Logic keywords are not case-sensitive. However, all environment, model, dimension, and member names in K2 are case-sensitive.
You have the following two files for each piece of script logic you create:
-
An .LGF file, which is an ASCII file you create and edit when setting up logic calculations. You access the .LGF file through the logic editor.
-
An .LGX file, which is the compiled logic file created by the system when you validate and save your logic. This is an executable version of the .LGF file that is not stored in Business Planning and Consolidation.
Default logic is a special logic statement that is executed on every writeback to a model. All logic in Default.LGF is run after data sends. Data is first committed to the model and then, Default.LGF is run on model data. Having all of your logic in the Default.LGF logic file might become unmanageable. Therefore you can create other logic files, such as FXTrans.LGF for foreign currency translation and ICElim.LGF for intercompany eliminations. Your default logic can contain an INCLUDE statement to execute specific logic in real-time, such as currency translation if desired, rather than having to run a separate batch process.
You access logic files from the Script Logic subdirectory within the hierarchy of a model.
Logic Library
Business Planning and Consolidation has a library of standard logic functions available for your use. The file has the extension .LGF, which can be called at validation by using the INCLUDE function in your logic file. The logic module scans the library file for the appropriate formulas to use based on the information in the .LGF file.
The following are examples of logic delivered with Business Planning and Consolidation:
-
Allocation.lgf: runs an allocation
-
Calcaccount.lgf: used to prepare Cash Flow; runs an Account Calculation business rule
-
Consolidation.lgf: used to run a Legal Consolidation business rule
-
Copy_Opening.lgf: used to run a Balance Carry Forward business rule
-
FX_Trans.lgf: used to run currency conversion
-
ICBooking.lgf: used for running Intercompany reconciliation and difference posting
-
ICData.lgf: used to run Intercompany reconciliation
-
ICElim.lgf: used to run Intercompany reconciliation
-
System_Constants.lgf: stores constant values for use within script logic. See the System Constants File section that follows for more information.
-
System_Library.lgf: includes basic examples of a set of keywords
-
Validation.lgf: used for running a Validation rule
System Constants File
The system constants file is the logic file that maps your dimension names for a model to the standard Business Planning and Consolidation logic. By updating the dimension constants file with your dimensions, you avoid having to change or rewrite any of the standard functions that are included with Business Planning and Consolidation.
The system constants file is located in the \\root\Webfolders\ <Environment>\systemlibrary\logic library folder. You can edit this file using download and upload functions from transaction UJFS in the ABAP interface.
Running Script Logic
Script logic can be automatically invoked each time the system sends data to the database. Instructions in the default logic file are executed immediately after data is sent and you can see the results immediately. Script 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, you may decide to wait until all data has been entered in the local currency before generating the translated amounts in reporting currencies.
Activities
From the Planning and Consolidation Administration screen, you can view all logic scripts for a model by choosing Logic Scripts under the Rules section. After that select a model and choose Open. All logic scripts that have been set up for that model display.
You can create a new logic script for the selected model by choosing New, then assigning a name to the logic script. You can type directly into the logic editor. You can also insert Business Planning and Consolidation keywords, MDX keywords, dimension names, and member names from the dropdown lists, replacing variables in the keywords as appropriate. To add a keyword from the dropdown lists to a line in a script, you can double-click on a keyword, you can select a keyword and then select Insert Keyword, and you can drag and drop a keyword from the dropdown list into a line in the logic editor.
You can comment out and uncomment blocks of script logic, as well as individual lines, in the logic editor.
When you create new logic script and edit an existing script, you can validate its syntax. Any problems with the logic display in the lower portion of the logic editor with line numbers to make locating and resolving the problems easier.
You can copy an existing logic script by selecting a file, then providing a name for the new script, and modifying it as you need.
You can use the following color coding in the logic editor to assist in writing and troubleshooting logic scripts:
-
Keywords display in blue
-
Constant values display in green
-
Comments display in grey
-
Incorrect syntax, such as parenthesis errors, misspelled keywords and dimension names, and unrecognized words, displays in red
You can easily resolve errors in script logic using the error lines in the lower portion of the logic editor window. Errors in a script appear by line number.
More Information
For more detailed documentation of script logic and examples, see the Enterprise
Performance Management (EPM) How-to Guides section of the SAP SDN
at: http://wiki.sdn.sap.com/wiki/display/BPX/Enterprise+Performance+Management+%28EPM%29+How-to+Guides
.