How Formulas Determine Variable Data Types

Variables can be of these data types: numeric, text or date. The data type determines the type of information the variable holds.

You don't have to specify the variable type. Formulas determine the type based on how you use the variable. For example, if you set a variable to 'J. Smith', the formula interprets it as a text variable.

Caution: Inconsistent or incorrect use of variables, such as trying to add a number to a text string, causes formula compilation errors.

Determine Variable Data Types

Formulas process the rules that determine the variable data type in the order listed:

  1. The variable can be an input you name in the input statement. For example:

    INPUTS ARE SALARY_AMOUNT,
    START_DATE (DATE),
    FREQUENCY (TEXT)

    If you don't specify the variable data type in the statement, the formula assumes it's a number.

    You can use the DEFAULT_FOR statement to determine the variable data type:

    DEFAULT FOR B IS 0 /* B is a NUMBER variable. */

    For an array database item, the DEFAULT FOR statement determines the index type and value type:

    DEFAULT FOR A IS EMPTY_NUMBER_NUMBER /* A is a NUMBER_NUMBER array variable. */

    You can use the DEFAULT_DATA_VALUE FOR statement to determine the variable data type:

    DEFAULT_DATA_VALUE FOR A IS 0 /* A could be a NUMBER_NUMBER or NUMBER_TEXT variable. */
  2. The formula searches the list of database items. If the variable is in the list, the data type is known.

  3. If the variable appears in a context handling statement, then the formula searches the list of contexts. If the variable is in the list, then the formula knows the data type, otherwise it returns an error.

  4. If the variable isn't a database item or a context, then the formula treats it as a local variable and determines the data type based on how you use the variable. For example:

    A = 'abc' /* A is a TEXT variable. */