Derived Fields
A derived field is a simple field or table field column whose value is derived from the value of one or more fields or columns on the same form or a constant. The value is determined by a formula that is specified when the form is defined in VIFRED. (See the appropriate section of this guide for information about defining a derived field.)
The derivation formulas for simple fields can use constant values, values in other simple fields, or aggregate values of non-hidden table field columns. The formulas for table field columns can use constant values or values in non-hidden columns in the same table field row.
A field or column that is directly referenced in another field's derivation formula is said to be a direct source field for that field. For example, if field A is dependent on the values in fields B and C, then fields B and C are source fields for field A. A source field can itself be a derived field. For example, if field C is itself dependent on fields F and G, then fields F and G are the direct source fields of field C and indirect source fields of field A.
You can nest field dependencies to any level. However, you cannot define circular dependencies. That is, you cannot derive field A from field B, which depends on field C, if field C is derived from field A. Circular dependencies generate an error, either when the form is saved or when the form is specified with the addform or forminit statement in an application. When this error occurs, the form is not displayed.
Values in derived fields are valid only when the values in all source fields, direct and indirect, are valid, with one exception. The exception occurs in the context of table field aggregates. Invalid values in a table field column are ignored during aggregate processing, which means that an aggregate value of a table field column is never invalid. (See the appropriate section of this guide for a complete description of how aggregates are used in derivation formulas.)
Because source fields must be valid, the FRS calculates derived values after the source fields are validated. If the user enters data into the source fields, the validations occur according to the tables shown in
How Field Validation Works. If user-entered data is not valid, then no derivation calculations are performed and derived fields are blanked out. When the program enters data into the source fields, the validation occurs immediately after data entry.
The FRS also calculates derived field values, if possible, whenever a user creates a new row by scrolling the cursor past the end of the data set or whenever an insertrow or loadtable creates a new row. Any derived value in an UNDEFINED table field row is displayed if it can be calculated. However, a derived simple field or table field column is not displayed if the form or table field, respectively, is in query mode.
Whenever you or the program attempts to retrieve a derived value, through a getform, getrow, unloadtable, or finalize statement, the FRS checks the validity of all source fields of the derived value. If a source field has been changed, it is validated and the derived value is recalculated. If the source field fails the validation check, then the derived value is marked invalid and it is not placed into the designated variable.
The FRS marks derived values invalid and clears the field whenever:
• A source field contains an invalid value.
• A source field is cleared.
• An exception, such as math underflow or overflow or value truncation or rounding, occurs during a derivation calculation.
Some environments do not signal floating division by zero as an exception.
• A form is displayed in query mode.
• A source table field is in query mode.
• A table field containing a column that is a derived field is in query mode.
Even if the derived field (column) is derived from constants, it is still cleared if its parent table field is in query mode.
• The form's mode is changed to query mode.
• An explicit validation of a derived field fails.
An explicit validation fails if any of the source fields fails its validation.
Because values in derived fields are determined by a predefined formula, it is not possible for either the program or the user to access these fields to change or edit their values. Because you cannot move the cursor into a derived field, you cannot define a field activation on a derived field. If you try to do so, you receive a runtime error.
Last modified date: 08/14/2024