Vous êtes sur la page 1sur 3

Data type: Structure

A compound data type represented by the number 9. A structure is a group of


named elements of (possibly) differing data types accessed by an index (element)
number. Structures are delimited with both curly braces and square brackets
({[ ]}). Note the following examples:

• {[1,"a",true]}

• {[true,‘10/16/90 00:00’,false]}

• {[1,1,"b",0]}

You can use either of the following syntaxes to extract an element from a structure:

• $structure[index of field]

• index of field in $structure

For example, to extract the value of the part number (672) in the part.no field
within the structure $order.line1 with the value of [{672,10,"ball.bearings"]} with
the field names part.no, quantity and description, use either of the following
syntaxes:

• $order.line1[1]

• 1 in $order.line1

In addition, elements of structures may be extracted using their element number.


For example, the 1 in $order.line1 is the same as part.no in $order.line1.

Field names are contained in the database dictionary and can only be used when
associated with a file variable. The following table shows commands that work and
commands that do not work.

These commands work because they are associated with a file variable.
$x=part,
part.no in $file

These commands do not work because they are not associated with a file
variable.
$y=part in $file
$x=part.no in $y
Data type: Array
A compound data type represented by the number 8. An array is a method used to
store a list of items. It is a list of elements of the same data type accessed by an
index (element) number. The term array is synonymous with the terms list, vector,
and sequence. Elements in arrays can be of any data types (including arrays or
structures). A fully qualified array name (array field in $file) can be used in place of
an array variable. The number of items in an array can vary and does not have to
be allocated in advance. Arrays are delimited by curly braces ({ }). The following
table shows examples.

Descript
ion Literal examples

Numeric {1,2,3}

Charact {"a","b","c","f","e","h"}
er

Boolean {true, true, unknown}

Time {‘12/7/42 00:00,’ ‘1/3/62 00:00’}

Nested {{1,2},{3,4}}

Structur {{[1,"a"]}{[2,"b"]}}
es {{[1,"a",true]},{[2,"b",false]},
{[3,"c",unknown]}}

Empty {}

You can use either of the following equivalent syntaxes to access an element in an
array:

• $array[element_number]

• element_number in $array

For example, to extract the value of the first customer number (2753) in the array
$customer with value {2753, 2842, 2963}, use any of the following equivalent
syntaxes:

• 1 in $customer
• $customer[1]

If the accessed array element does not exist, the element is created and set to
NULL. This effectively extends the array. To insert a value into an array use the
insert RAD function. To delete an element from an array use the delete RAD
function.

Note: Always denull arrays before assigning them to a record or adding them to the
database.

Vous aimerez peut-être aussi