Derived Fields

A derived field is a conceptual field that uses the values of existing fields. It does not retain any values itself and is not physically stored in the database.

You can define five types of derived fields: string fields, group fields, condition fields, compute fields, and array value fields. You can identify derived field types in a file by observing the text in the sixth column of the list of fields on the File Definition form of the Database Definition tool.

You can also define derived fields when you paint a program (that is, define the layout of a form). To save time, add a derived field to the database definition if it will be used in more than one report or program.

Note: A derived field cannot be the target of a rule that alters the value of a field. For example, you cannot use an Assign rule to define the value of a derived field; because the field is only conceptual, it does not retain any values.

String Fields and Group Fields

A string field connects fields and values together, and allows the creation of a string that combines portions (partial or complete) of multiple fields. A string field can include the current date or current time. If a field used in a string field has leading or trailing spaces or zeros, they are removed.

In the following example, the string field definition uses three fields from the Employee file: First Name, Middle Init, and Last Name. A program using this definition retrieves these fields individually to make up the employee name. If the First Name field has the value John, the Middle Init field has the value K, and the Last Name field has the value Doe, the output would be "JohnKDoe" because a string field removes all spaces and zeros.

In the following example, the string field definition strings the three name fields together with a space between each of them, making the output "John K Doe."

You can use group fields in order to link multiple whole fields that participate together as a single compound key—for example: accounting unit, account, and sub account. No general formatting is supported.

A group field does not remove leading or trailing spaces or zeros. Also, group fields cannot include values, current date, or current time.

For the procedure for defining a string field or a group field, see Defining a String Field or a Group Field.

Condition Fields

A condition field consists of conditional statements (If and Else) followed by fields, values, or another conditional statement.

The following conditional field statement indicates that if the employee has an hourly salary class, the program accesses the field Pay Rate; otherwise, the program accesses the field Pay Div 2080.

For the procedure for defining a condition field, see Defining a Condition Field.

Compute Fields

A compute field calculates a value using existing fields and values. You can use only numeric, signed, and date fields to compute values. You can also use another compute field as long as it does not refer to the compute field you are defining (doing so would create a recursive definition).

The following compute statement computes the hourly pay rate for a salaried employee. It is equal to the pay rate divided by 2080.

Computing with date fields works in the following manner:

Compute format Result Type
Date1 – Date2 Number of days Signed
Date1 ± (Number) Date2 Identical to Date1

For the procedure for defining a compute field, see Defining a Compute Field.

Array Value Fields

An array value field can access a specific value in an array, or sum the values in an array.

An array is an easy way to keep track of a list of data. For example, a file stores a company's monthly balances. Because there are 12 months, you can store each monthly balance in a separate field, as follows:

You can also store the balances in an array field that has 12 values (occurrences), one for each month.

A subscript lets you reference each value in the array. For example, the first month's balance is subscript 1 of the Balances field, the second month's balance is subscript 2 of the Balances field, and so on.

The following array value field, Mth 3 Balance, accesses a specific value (subscript 3) in the Balances array.

You can also use a variable value, stored in a field, to access a specific array value. In the following example, the Cur Balance array value field accesses the monthly balance for the current period. The Company file stores the current period in the Cur Period field. If the value in the Cur Period field is 5, the fifth value of the Balances field is the Cur Balance.

You can also define an array value field that adds one or more values in an array. In the following example, Scnd Qtr Sales sums the fourth, fifth, and sixth values in the Monthly Sales array field.

For the procedure for defining an array value field, see Defining an Array Value Field.