Show TOC

Syntax documentation*FUNCTION / *ENDFUNCTION Locate this document in the navigation structure

A user-defined function is the name of a placeholder that a user can insert in formulas in place of a corresponding MDX statement or part of one. This can greatly improve the readability of a logic statement.

The definitions of the logic functions can be inserted anywhere in a logic file or in an included file. Their syntax is the following:

For single line functions

*FUNCTION {functionname}({Param1}[,{Param2}…]) = {Function Text}

For multi-line functions

*FUNCTION {functionname}({Param1}[,{Param2}…])

{Function text}

{Function text}

*ENDFUNCTION

An unlimited number of functions can be defined within a script logic file.

An unlimited number of parameters can be passed to a function to dynamically modify the corresponding MDX string.

Functions currently cannot be nested, meaning a function cannot contain another function.

The position of the functions in the logic file is irrelevant, unless the same function is redefined, in which case the new definition of the function applies only from the point of the redefinition.

The values of the passed parameters are replaced in the function text without any validation, even if they are embedded in longer words, like in the following example:

Use caution when defining the names of the parameters, to avoid the risk of conflicts with MDX reserved words and with the text surrounding them in logic. The best practice is to always surround the name of the parameters with a delimiter, as in the following example:

Example Example

*FUNCTION Price(%COST%,%HOUR%)

%COST%/%HOUR%

*ENDFUNCTION[#CE0661000] = Price([CE0004000],[CE0652000])

End of the example.

The example calculates the Price. You do not have to check the denominator for Zero to avoid divide-by-zero error. The Script Logic engine automatically replaces the divide by zero error with zero.

You can also use *FUNCTION to substitute members or dimensions to make scripts more readable.

*FUNCTION PERSONAL_COST = CE0004000

*FUNCTION LAB_HOUR = CE0652000

*FUNCTION PER_PRICE = CE0661000

*FUNCTION ACCOUNT = P_ACCT

Price(%COST%,%HOUR%)

%COST%/%HOUR%

*ENDFUNCTION

[ACCOUNT].[#PER_PRICE] = Price([ACCOUNT].[PERSONAL_COST],[ACCOUNT].[LAB_HOUR])

The following characters, plus the blank character, are invalid in logic functions names:

+ - / * ^ % > < = ( ) [ ] { } , . ; ' : & \ | # ~ "

Any software coding and/or code lines / strings ("Code") included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended to better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or by its gross negligence.