Formula Statements
You use formula statements to provide instructions that you want your formula to carry out. When working with statements, it's important to have knowledge of the different statement types, the required order, and how to group statements.
Statement Types
Here are the statements that you can use in your formulas to provide instructions.
Statement |
Statement Form |
Description and Example |
---|---|---|
|
|
Provides a different name for a database item or global value. Sometimes the database item names that the application provides are too long to use in a formula. Use the ALIAS statement to shorten the name of a database item. Once the ALIAS is created, use it instead of the database item name. Using an alias is more efficient than assigning the database item to a local variable with a short name.
|
|
variable = expression array[index] = expression |
Assigns an expression value to a variable or an array variable at an index position. A formula evaluates the expression on the right-hand side of the statement. It places its result in the variable you name on the left-hand side. The left side of an assignment statement must always be a local variable because a formula can only change the value of local variables. Within a "CHANGE_CONTEXTS" statement, assign values only to contexts. Outside a "CHANGE_CONTEXTS" statement, assign values only to input, output, and local variables.
|
|
(context1 = expression1 [,context2 = expression2 ] |
Changes one or more contexts within a formula. Within
the "CHANGE_CONTEXTS" statement, use
|
|
|
The DEFAULT FOR statement provides a value that the formula uses for a formula input or database item in these situations:
The DEFAULT_DATA_VALUE FOR statement provides a value for an array database item where individual data values are NULL. Some database items are defined to require a default value because they could return no data or NULL values from the database.
|
|
|
Immediately exits from the enclosing
|
|
|
Calls a formula from another formula. For example, formulas can call a small formula that performs a common calculation. You can use this approach to avoid writing long formulas.
|
|
|
Executes one or more statements if a condition is
true. Use the
|
|
|
Lists the input variables for the formula. There's
only one
|
|
|
Causes a formula to stop executing immediately. For
its value to be returned to the caller, you must enter a formula output
variable in the You can enter multiple return statements in a formula.
|
|
|
Executes a number of statements as long as one condition is true. If the
|
|
|
Stores reference data, which you can set, fetch, or delete.
|
Ordering Statements
Place the statements in this order in the formulas:
-
ALIAS statements, if any
-
DEFAULT statements, if any
-
INPUT statements, if any
-
Other statements
Grouping Statements
If you want to group more than one statement under IF/THEN statements, ELSE clauses, WHILE loops, or CHANGE_CONTEXTS, enclose the group of statements within brackets. In the absence of brackets, the preceding statement applies only to the first statement.
Here's an example of how you can group statements:
I = A.FIRST
WHILE (A.EXISTS(I)) LOOP
(
A[I] = I
I = A.NEXT(I,-1)
)
Here's an example of how you should not group statements::
I = A.FIRST
WHILE (A.EXISTS(I)) LOOP
A[I] = I
I = A.NEXT(I,-1) /* This is not executed as part of the loop. */