26 Develop Custom-Defined Calculation Functions
To enhance the calculation functions available for Essbase block storage cubes, you can use Java to develop your own custom-defined functions (CDFs). After you write the functions, install the Java class and then register the functions, either globally with the Essbase Server, or locally to an application.
You can use your custom-defined functions in Essbase calculation scripts.
Essbase does not provide tools for creating Java classes and archives; you must have a supported version of the JDK.
For examples of custom-defined functions, see Java Code Examples.
Custom defined functions are available only for block storage cubes (not relevant to aggregate storage cubes).
To create a custom-defined function, use the following workflow.
-
Review the requirements for custom-defined functions: Requirements for Validity of Custom-Defined Functions
-
Write a public Java class that contains at least one public, static method to be used as a custom-defined function: Create and Compile a Java Class for Custom Defined Functions
-
Install the Java class: Installing Java Classes on Essbase Server
-
Register the custom-defined function as a local or global function: Register Custom-Defined Functions
Requirements for Validity of Custom-Defined Functions
You design your Essbase custom-defined functions as methods in a Java class. For global functions, write methods in one class. For application functions, use separate classes and jar files per application. Test functions locally to one application before registering them globally. Note the supported data types, variables, and naming conventions.
You can create multiple methods in a class for use as a custom-defined function. Typically, Oracle recommends that you create the methods that you plan to use across all applications on an Essbase Server as custom-defined functions in a single class. If, however, you plan to add custom-defined functions that will be used in selective applications on the Essbase Server, create these custom-defined functions in a separate class and add them to Essbase Server in a separate .jar
file.
When creating multiple Java classes that contain methods for use as custom-defined functions, verify that each class name is unique. Duplicate class names cause methods in the duplicate class not to be recognized, and you cannot register those methods as custom-defined functions.
Using test programs in Java, test the Java classes and methods. When you are satisfied with the output of the methods, install them on Essbase Server and register them in a single test application. Do not register functions globally for testing; doing so makes updating them more difficult if you encounter problems.
Methods in custom-defined functions can have any combination of the following supported data types as input parameters:
-
boolean
-
byte
-
char
-
com.hyperion.essbase.calculator.CalcBoolean
-
float, double
-
java.lang.String
-
short, int, long
-
arrays of any of these types
CalcBoolean is an Essbase-specific data type that can include three values—TRUE, FALSE, and #MISSING. For information about the other listed data types, see the JDK documentation.
The method return data type can be void or any of the preceding data types. Returned data types are converted to Essbase-specific data types. Strings are mapped to a string type. Boolean values are mapped to the CalcBoolean data type. All other values are mapped to a double type.
Note:
Essbase does not support double variables returned with infinite or Not-a-Number values. If these values are returned from a Java program, they may not be recorded or displayed correctly in Essbase. Double variables should be checked for infinite or Not-a-Number values and set to finite values before being returned to Essbase. See the entry for the class Double in the JDK documentation.
For creating, deleting, and managing custom-defined functions, Essbase requires these security permissions:
-
Local, application-wide, custom-defined functions: Application Manager or higher
-
Global, server-wide, custom-defined functions: System Administrator
When you register a custom-defined function in Essbase, you give the function a name, which is used in calculation scripts and formulas and is distinct from the Java class and method name used by the function.
Follow these requirements for naming custom-defined functions:
-
Start the name with the @ symbol. The rest of a function name can contain letters, numbers, and the following symbols: @, #, $, and _. Function names cannot contain spaces.
For example: @MYFUNCTION
-
Start the names of custom-defined functions that are called only by custom-defined macros with “@_”, to distinguish them from general-use functions and macros.
For example: @_MYFUNCTION
-
Custom-defined functions must have unique names. Function names must be different from each other, from the names of custom-defined macros, and from the names of existing calculation functions.
-
If an Essbase application contains a local function that has the same name as a global function, the local function is used for calculation.
Create and Compile a Java Class for Custom Defined Functions
To create and compile a Java class for Essbase custom defined functions (CDFs), write the class using a text editor or IDE (integrated development environment), and compile it using the javac
tool.
Here is a sample workflow for creating a Java class for a CDF:
Install Java Classes on Essbase Server
To install the Java classes for your custom defined calculation functions (CDFs) onto the Essbase Server, compile them, copy the jar file to a global or application level udf
directory as specified in these instructions, and restart the application or server.
Java classes must be compiled in a JAR file, using the JDK jar
tool.
To create a .jar
file and install it on an Essbase Server:
Register Custom-Defined Functions
Use MaxL to register your custom defined functions (CDFs) with Essbase. The registration task comes after you have written the CDFs within Java classes, compiled the classes, and installed the jar files.
After you have compiled the Java classes for CDFs into .jar
files and installed the .jar
files on Essbase Server, you must register the functions before you can use them in calculation scripts and formulas. See Requirements for Validity of Custom-Defined Functions.
When you register a global CDF, all Essbase applications on the Essbase Server can use it. Test the functions in a single application (and register them only in that application) before making them global.
Use the same process for updating the catalog of functions as for updating the catalog of macros. See Refresh the Catalog of Custom-Defined Macros.
Caution:
Do not register global functions for testing; doing so makes changing them more difficult if you encounter problems.
To register a CDF, use the create function MaxL statement.
To register a CDF with local scope, include the application name as a prefix. For example, the following MaxL statement registers the function @JSUM in the CalcFunc class as a local function for use within the Sample application:
create function Sample.'@JSUM'
as 'CalcFunc.sum'
spec '@JSUM(memberRange)'
comment 'adds list of input members';
To register a CDF with global scope, do not include the application name as a prefix. For example, the following MaxL statement registers the function @JSUM in the CalcFunc class as a global function for use in any application on Essbase Server:
create function '@JSUM'
as 'CalcFunc.sum'
spec '@JSUM(memberRange)'
comment 'adds list of input members';
Note:
Specifying input parameters for the Java method is optional. If you do not specify input parameters, Essbase reads them from the method definition in the Java code. If, however, you are registering multiple CDFs with the same method name but with different parameter sets, you must register each version of the function separately, specifying the parameters for each version of the function.
Implement Registered Custom-Defined Functions
You can use registered custom-defined functions (CDFs) in calculation scripts and formulas, the same way you use native Essbase calculation functions.
To use a registered CDF:
Update Custom-Defined Functions
To update an Essbase custom defined function (CDF), determine if it is local or global in scope, shut down the impacted application(s), replace the .jar
file that contains the code for the function, and re-register the function.
The procedure for updating CDFs depends on these conditions:
-
Whether the function is registered locally or globally.
-
Whether the signature of the CDF—class name, method name, or input parameters—has been changed in the Java code.
Typically, to update a CDF, you must replace the .jar
file that contains the code for the function, and then re-register it. If, however, the signature of the CDF has not changed, and it has only one set of input parameters (it is not an overloaded method), you can replace the .jar
file that contains the function.
Note:
Only administrators should update global CDFs.
To update a CDF:
View Custom-Defined Functions
View a custom-defined function (CDF) in Essbase to determine whether it has been registered successfully and whether it is local or global in scope. CDFs are not displayed until they have been created and registered.
To view a CDF:
Use the display function MaxL statement.
For example, use the following MaxL statement to view the CDFs in the Sample application and any registered global functions:
display function Sample;
The display function statement lists global functions without an application name to indicate that they are global. If the application contains a function with the same name as a global function, only the local function is listed.
Remove Custom-Defined Functions
To remove/unregister Essbase custom defined functions (CDFs), first be sure that they are not in use. Then, shut down the application(s) in which the CDFs are defined, remove the CDFs by issuing the MaxL drop function statement, and restart the affected application(s).
The following permissions are required to remove a CDF:
-
Local: At least Application Manager permission for the application
-
Global: System Administrator permission
Before removing CDFs, you should verify that no calculation scripts or formulas are using them. Global CDFs can be used in calculation scripts and formulas across Essbase Server, so you must verify that no calculation scripts or formulas on Essbase Server are using a global CDF before removing it.
Caution:
Remove global CDFs only when users are not accessing Essbase cubes, and calculation routines are not being performed.
To remove a CDF:
Copy Custom-Defined Functions
You can copy custom-defined functions (CDFs) to any Essbase Server and application to which you have appropriate access.
To copy a CDF, use the create or replace function as MaxL statement.