Examples of Calling a Formula from a Formula
Use these examples to understand how to call a formula from another formula using these methods:
-
A series of separate calls
-
A single self-contained call
The examples include two versions of a wage formula, and a table comparing the two methods using a few use cases.
The first two examples show different versions of the wage formula. These points apply to both examples:
-
The formula calls RATE_FORMULA to get a value for HOURLY_RATE.
-
The RATE_FORMULA enters text to call UNIT.
-
The formula call sets to enter the UNIT to 'Hourly'.
-
The RATE_FORMULA returns the rate in the output variable called RATE.
-
The GET_OUTPUT call returns 0.00 if the RATE_FORMULA doesn't return RATE.
Wage Formula Using Separate Calls
This example shows how to call a formula using separate calls.
SET_INPUT('UNIT', 'Hourly')
EXECUTE('RATE_FORMULA')
HOURLY_RATE = GET_OUTPUT('RATE',0.0)
WAGE = HOURS_WORKED * HOURLY_RATE
RETURN WAGE
Wage Formula Using a Self-Contained Call
This example shows how to call a formula using a self-contained call.
CALL_FORMULA
('RATE_FORMULA','Hourly' > 'UNIT'
/* SET_INPUT('UNIT', 'Hourly') */
,HOURLY_RATE < 'RATE' DEFAULT 0.0
/* HOURLY_RATE = GET_OUTPUT('RATE',0.0) */
)
WAGE = HOURS_WORKED * HOURLY_RATE
RETURN RATE
Sample Expressions to Compare Methods
Here's what you can do using sample expressions in the two methods:
-
Call a formula
-
Set inputs and context values
-
Unset context values
-
Get output values into a variable or array variable
-
Provide a default output value
SET_INPUT or > statements have no effect if the calling formula has no formula input or context of the same name.
This table shows a few use cases that compare the two methods using sample expressions.
Use Case |
Using Separate Calls |
Using a Self-Contained Call |
---|---|---|
Execute a formula where the formula |
|
Use within a
|
Set an input value in the called formula where you round off EXTRA_HOURS to 2 decimal places and set the input OVERTIME in the called formula. |
|
Use within a
|
Leave a formula input value unset inside the called
formula, where |
A SET_INPUTS statement isn't required, but you can this:
|
A SET statement isn't required, but you can use this:
|
Inherit a context value from the called formula. For example, both the calling formula and the called formula support the AREA1 context. The called formula inherits the AREA1 context value from the calling formula. |
No statements are required to do this. |
No statements are required to do this. |
Set a context value inside a called formula, where the called formula supports the AREA1 context and you must set AREA1 to 'London' in the called formula. |
|
|
Call a formula with an unset context value, where the called formula supports the AREA1 context and AREA1 has to be unset in the called formula. |
|
|
Get a formula output from the called formula. Get BONUS_RATE output value into the RATE variable using the default value 0.0 if the BONUS_RATE output doesn't exist or wasn't set. |
|
|
Get a formula output from a called formula into an array Get the BONUS_RATE output value into the RATES array variable at index position 'BONUS'. Use the default value 0.0 if the BONUS_RATE output doesn't exist or wasn't set. |
|
|