...
- The simplest case is shown above i.e. the Array is created explicitly using the [value1, value2,..] syntax.
- An Array of Integers between the values n and m can be created using the expression [n..m] e.g. [51..100] creates an Array of 50 elements [51, 52, ... 100].
- Arrays can also be created by Array Handling Functions functions e.g. split() which turns a String into an Array.
- Finally an Array can be generated by referring to an Attribute on a Pipe when that Pipe contains several rows. In this case the Array has an entry for each row in the Pipe and the value of each entry is value of the specified Attribute. For example:
Expression | Result |
---|---|
$amounts = invoice.value, $numInvoices = countElements($amounts), $maxValue = max(invoice.value), $average1 = $maxValue / $numInvoices , $average2 = average(invoice.value) | invoice is the name of a pipe which looks up all invoices for a customer (in fact it produces a Record Set which is discussed below. invoice.value creates an Array of all the value Attributes in invoice. E.g. if the customer had 3 invoices of value 100, 150 and 125, then invoice.value would be the Array [100, 150, 125]. countElements(), max() and average() show examples of the arrays being used. Note that $average1 and $average2 will contain the same result. |
The majority of Arrays that you are likely to use will contain values of one type e.g. all Numbers however Arrays can contain values of different types:
...
Expression | Result |
---|---|
$day = $weekDays[3] | Sets $day to "Wednesday" |
$i = 3, $day = $weekDays[$i+2] | Sets $day to "Friday" |
$day = getElement($weekDays,4) | Sets $day to "Thursday" |
$day = $weekDays.3 | Sets $day to "Wednesday" |
$day = $weekDays[9] | Sets $day to _NULL since there is no element at position 9 |
$weekDays = _NULL, $day = $weekDays.3 | Sets $day to _NULL since there is no element at position 3 (in fact there are no elements at all) |
$weekDays = [], $day = getElement($weekDays,3) | Sets $day to _NULL since there is no element at position 3 (in fact there are no elements at all) |
...
Expression | Result |
---|---|
$accountNum = account.accountNum | account.accountNum returns the value of the Attribute accountNum within the Record Set account. Because the Pipe just returns a single value, $accountNum is a single value (not an Array). |
$invoiceNumbers = invoices.number | invoices.number returns an Array of the Attribute number within the Record Set invoices. |
$firstInvoiceNumber = invoices.number[1] | This gets the first invoice number. |
$firstInvoice = invoices[1], $firstInvoiceNumber = $firstInvoice.number | This also gets the first invoice number. Note that the Record Set invoices[1] has been assigned into a $-Variable. |
$attr = "number", $invoiceNumbers = invoices.$attr | This also creates an Array of the invoice numbers. Note that the $-Variable $attr has been set to the name of the Attribute which is then used to decide which Attribute to read from invoices. |
...