Overview of Calling a Formula from a Formula
A formula can call another formula. This enables some modularity in formula organization. You specify the called formula name and any formula input or output names as TEXT values. The names are case-independent.
You can call a formula in any of these ways:
-
Using a single call
-
Using separate calls
As you write your formula, consider these points:
-
Validation of the Called Formula
-
Passing Contexts
-
Call a Formula using any of these methods:
-
Using Separate Calls
-
Using a Single Self-Contained Call
-
-
Use Cases to Compare Methods
Validation of the Called Formula
When a formula runs, it validates whether the called
formula can be run, and whether the specified input and output data
types are correct. You can use the IS_EXECUTABLE
call to determine whether an executable formula with a specified
name exists. You must compile the formula to make it available for
the specified legislative data group. Also, the formula must be valid
on the effective date on which the calling formula runs. In addition,
the payroll code imposes extra restrictions based on formula type
combinations.
Passing Contexts
Context values are inherited from the calling formula. You can also set or unset the context values explicitly in the nested formula call.
Alternative Methods to Call a Formula
You can call a formula fro within another formula in any of these ways:
-
Using a series of separate calls
-
Using a single self-contained call
Using Separate Calls
You can use three separate calls:
-
Set the Inputs
Use the
SET_INPUT
call for each formula input and context that you need to explicitly set for the formula call. You don't need to specify all formula inputs and contexts. To explicitly unset a context value, use theSET_INPUT
call without passing the optional value parameter. Any extra inputs specified inSET_INPUT
calls are ignored. -
Call the Formula
Use the
EXECUTE
call to call a formula. -
Get the Formula Outputs
Use one or more
GET_OUTPUT
calls to fetch outputs from the last formula call.
When the formula runs, it returns an execution error in these scenarios:
-
The called formula isn't executable.
-
The called formula is already running.
-
The data type of an input variable (specified using SET_INPUT) or an output variable (specified using GET_OUTPUT) doesn't match its actual data type within the called formula.
This table summarizes the methods for calling a formula using separate calls.
Method |
Use To |
---|---|
|
Sets the value of an input or a context to the value specified in the value parameter. The value parameter is optional. If you specify the value parameter, the input is set to this value. If you don't specify the value parameter, the input or context is passed as unset to the formula. The data type of the value is the expected data type for the input. If you use a context in a SET_INPUT call, its value will be set to the value in the calling formula. |
|
Executes the called |
|
Gets the value of the output parameter after calling a formula. If there is no formula output called 'output' or it's not set, the formula returns the value specified in the default value parameter. The data type of default value is the expected data type for the output. |
Formula inputs that are set using SET_INPUT
persist as long as no EXECUTE
or GET_OUTPUT
calls are made. Output
values from a called formula persist as long as no SET_INPUT
or new EXECUTE
calls
are made. When the calling formula exits, the process removes any
saved input or output values.
Using a Single Self-Contained Call
Here's what a single self-contained call does:
-
Clears the input values at the start to not use prior
SET_INPUT
call values. -
Discards the outputs at the end so that the subsequent
GET_OUTPUT
calls only return the default values.
Here's how you can use the CALL_FORMULA
method:
CALL_FORMULA(formula, [set statement, get statement])
A SET
statement is
a SET_INPUT
call. A GET
statement assigns the result of a GET_OUTPUT
call to a variable in the calling formula. The
calls execute in this order:
-
SET_INPUT calls
-
EXECUTE call
-
GET_OUTPUT assignments
The compiler generates code to execute in this order, even if SET and GET statements are interspersed.