Throughout this section we shall assume the field in the table below is defined:
| Field | Type | Value |
|---|---|---|
| SALES_CODE | I2*5 | 23 43 7 19 2 |
In a formula you can reference individual occurrences from a
field or expression using the subscript operator [] like this:
SALES_CODE[5]. It is also sometimes
possible to refer to a subrange of occurences of a field using this
operator as well using the following syntax:
SALES_CODE[2..3]
Most operators and functions in the formula processor work
with multi-occurs expressions. This allows calculations which might
require a for or while loop in other languages to be
expressed in a single expression. For example
SALES_CODE+1 adds 1 to each occurrence of SALES_CODE,
while SALES_CODE*SALES_CODE multiplies corresponding
occurences of SALES_CODE together. See Expressions with Multi-ccurs
Operands for details.
There are also a number of functions are intended specifically
for multi-occurs fields, for example the MINIMUM function returns
the minimum of a set of values expressed as a multi-occurs field.
Thus MIN(SALES_CODE) returns the value 2. The SUM
function returns the sum of the occurrences. SUM(SALES_CODE
> 7) returns 3.
You can construct a new multi-occurs expresion by combining
expressions with the concatenation operator |. For example
the SALES_CODE value could be assigned using this expression:
23 | 43 | 7 | 19 |2. The | operator can be used
with any type of field except character fields. Character fields
are concatenated as strings using the concat operator, but you can also initialise a
multi-occurs field directly as explained in Constants.
You can easily assign a formula to a fixed range of occurrences in a multi-occurs field, by selecting the low and high occurs values appropriately in the field details.
One weakness of the DP4 formula processor is that is not possible to assign a value to the nth occurrence of a field, or a variable subrange of occurrences. This is because in field processing you always have to specify a fixed range of occurences to process. There is a work-around for this problem, which is explained in Assigning to a Variable Occurrence.