Array Subscripting [ COMMUNICATOR 3000 XL, XL Release 1.1 (Core Software Release A.10.00) ] MPE/iX Communicators
COMMUNICATOR 3000 XL, XL Release 1.1 (Core Software Release A.10.00)
Array Subscripting
Provides Transact programmers with the ability to manipulate single-
dimensional arrays within the context of certain verbs.
Syntax
...(array-item[subscript])...
where "subscript" is of the form:
((index)|constant)
Parameters
array-item The name of a parent or child item. This can be either
a compound item or a child of a compound item. This is
a required parameter.
index A data item, or an arithmetic expression which indicates
the occurrence of the array item to be referenced.
Indices cannot be less than 1. An index value of 1
references the first occurrence of the array. Data
items which are used as indices should be enclosed in
parentheses within the subscript parentheses.
As only one array subscript is permitted for each
referenced array item, the subscript always applies to
the highest level compound item of which the array item
is a child even though the array item itself is a
compound item (refer to Example 10).
This is an optional parameter. If no subscript is
specified, the item is treated as a compound item is
currently treated.
constant A numeric constant which indicates the occurrence of the
array item to be referenced. Indices cannot be less
than 1. An index value of 1 references the first
occurrence of the array. The subscript always applies
to the highest level compound item of which the array
item is a child.
This is an optional parameter. If no subscript is
specified, the item is treated as a compound item is
currently treated.
Discussion
Array subscripting provides Transact programmers with the ability to
manipulate single-dimensional arrays by allowing them to subscript array
items. The ability to subscript compound items is allowed, in most
contexts, for all Transact verbs. Subscripting is not allowed when any
of the Transact registers are manipulated or updated (i.e. list, update,
match, key, argument, and input registers), and for items included in the
"LIST=" option of any Transact input/output verb (i.e. DELETE, FILE,
FIND, GET, PUT, REPLACE, and UPDATE). The Transact compiler will generate
an error if subscripted array items are used with any of these verbs.
In addition, Transact generates the following run time errors when arrays
are improperly used:
CANNOT SUBSCRIPT AN ITEM NOT DEFINED AS AN ARRAY
ARRAY SUBSCRIPT IS OUT OF RANGE
CAUTION: As array subscripting is an alternative to using LET OFFSET, it
is not advisable to combine the use of the LET OFFSET verb with a
subscripted item. Doing this may cause the program to update the data
register in areas outside the limits of the item referenced and could
lead to unpredictable results.
Subscripted items will only be allowed in the following contexts:
CALL
For the data item holding the name of the called system.
For the data item holding the password.
For the data item holding the open mode.
For the data item on the DATA= option.
DATA
For all data items in the case where DATA has no modifier.
For all data items in the case of DATA(SET).
DELETE
For the data item on the RECNO= option.
DISPLAY
For all the data items to be displayed.
DISPLAY(TABLE)
For all data items to be displayed.
FILE(CONTROL)
For the data items on the PARM= option.
FIND
For the data item on the RECNO= option.
FORMAT
For all the data items to be displayed by this FORMAT.
GET
For the data item on the RECNO= option.
GET(FORM)
For the data item holding the name of the form used.
For the data item on the FKEY= option.
For the data item holding the name of the highlighted field.
For the data item holding the message for the window.
IF
For all the data items used as part of the condition.
LET
For all the data items used as part of the expression (not permitted
with LET OFFSET).
LOGTRAN
For the data item holding the log message.
MOVE
For all data items used as source or target fields.
OUTPUT
For the data item on the RECNO= option.
PROC
For all the data item used in the parameter list.
PUT
For the data item on the RECNO= option.
PUT(FORM)
For the data item holding the name of the form used.
For the data item on the FKEY= option.
For the data item holding the name of the highlighted field.
For the data item holding the message for the window.
REPEAT
For all the data items used as part of the condition.
REPLACE
For the data item on the RECNO= option.
SET(FORM)
For the data item holding the name of the form used.
For the data item on the FKEY= option.
For the data item holding the name of the highlighted field.
For the data item holding the message for the window.
SET(LANGUAGE)
For the data item holding the language.
SET(OPTION)
For the data item on the FORMSTORE= option.
For the data item on the VPLS= option.
UPDATE(FORM)
For the data item holding the name of the form used.
For the data item on the FKEY= option.
For the data item holding the name of the highlighted field.
For the data item holding the message for the window.
WHILE
For all the data items used as part of the condition.
Example
Given the following array definitions,
DEFINE(ITEM) QUANTITY 50 I(4):
array
ON-HAND-ARRAY X(200):
ON-HAND 50 I(9)=ON-HAND-ARRAY(1):
array
CUST-INDX X(4):
QUAN-INDX I(4,,4):
CUST-ARRAY 50 X(59):
array
NAME X(20)=ADDRESS(1):
STREET X(20)=ADDRESS(21):
CITY X(12)=ADDRESS(41):
STATE X(2)=ADDRESS(53):
ZIP X(5)=ADDRESS(55):
PARENT-ARRAY 10 X(54):
CHILD-NAME 5 X(10)=PARENT-ARRAY(1):
CHILD-AGE 5 I(8)=PARENT-ARRAY(51):
CHILD-SEX 5 X(2)=PARENT-ARRAY(53);
LIST QUANTITY: ON-HAND-ARRAY: CUST-INDX: CUST-ARRAY:
QUAN-INDX: PARENT-ARRAY;
The following are examples of correct array manipulation:
1) MOVE (NAME(1)) = "JOHNNY B. GOODE";
first array item
2) LET (CUST-INDX) = 27;
MOVE (NAME((CUST-INDX))) = (NAME);
move the first array item to twenty-seventh array item
3) DISPLAY NAME(8): ADDRESS(8): CITY(8): STATE(8);
4) DATA ON-HAND((QUAN-INDX));
5) DATA(SET) ON-HAND(3);
6) LET (QUANTITY) = (ON-HAND(9)) - (QUANTITY(9));
7) IF (NAME((CUST-INDX))) = "PAUL B. CREDITRISK" THEN...;
8) WHILE (QUANTITY((QUAN-INDX))) < 0 DO
LET (QUANTITY((QUAN-INDX))) = (QUANTITY((QUAN-INDX))) * -1;
LET (QUAN-INDX) = (QUAN-INDX) + 1;
DOEND;
9) REPEAT LET(ON-HAND(3)) = (ON-HAND(3)) + 1
UNTIL (ON-HAND(3)) > 0;
10) MOVE (CHILD-NAME(4)) = "DANIEL";
moves string to the compound item, CHILD-NAME, within the fourth
occurrence of PARENT-ARRAY
MPE/iX Communicators