Formula Contexts

Formulas run within an application-specific execution context, which determines the context variables available to the formula. Context values act as SQL bind values when the formula fetches database item values from the database. Formulas can also pass context values into formula function calls.

Here are some examples of the execution contexts:

  • EFFECTIVE_DATE : The date on which the formula becomes effective.

  • PAYROLL_ID: The payroll run for which the formula is processed.

  • PERSON_ID: The person for whom the formula is processed.

Context Value Setting

The application code that's calling a formula usually sets all the context values. For some complex applications, such as the payroll run, the code sets only the contexts necessary to meet general processing requirements.

Here's how formulas for payroll work:

  • A payroll run sets contexts for the legislative data group, date earned, the payroll being processed, the payroll relationship, payroll actions, and the person being processed.

  • Additional, country-specific contexts are also available. For example, the jurisdiction area and tax code context values are country-specific.

Formula Context-Handling Statements

If you use a variable in a context-handling statement, the formula searches the list of contexts. The variable must appear in the contexts list; otherwise the formula returns an error. The data type is stored along with the context list entry.

This table describes the formula context-handling statements.

Statement

Purpose of the Statement

Example

CHANGE_CONTEXTS(assignment [,...])

Changes context values within the context changing block. Inside this block, the formula function calls, the database items, and the called formulas use the new context values. Outside the block, the formula uses the original values.

You can nest context changing blocks to apply context changes in stages.

/*
 * Nested Context changes: DBI1 depends upon SOURCE_ID and SOURCE_TEXT. */
CHANGE_CONTEXTS(SOURCE_TEXT = 'A')
(
  /* SOURCE_TEXT = 'A' */
  X = DBI1
 
  /* Nesting used to change Contexts in stages. */
  CHANGE_CONTEXT(SOURCE_ID = 2)
  (
    /* SOURCE_TEXT = 'A',
SOURCE_ID  = 2 */
    Y = DBI1
    
    /* Overriding a Context change. */
    CHANGE_CONTEXTS(SOURCE_TEXT = 'B',SOURCE_ID = 3)
    (
      /* SOURCE_TEXT = 'B', SOURCE_ID  = 3 */
      Z = DBI1
       )
)

CONTEXT_IS_SET(context)

Tests whether or not a context value is set.

This code tests whether or not the AREA3 context is set.

IF CONTEXT_IS_SET(AREA3) THEN

GET_CONTEXT(context, default value)

Returns a context's value if the context is set, otherwise it returns the default value specified in its second argument.

/* AREA1 is a context of type TEXT. */
AREA1_VALUE = GET_CONTEXT(AREA1,' ')