Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Arrays and lists

&pagelevel(4)&pagelevel

In addition to the simple variables which can contain precisely one value of type STRING, INTEGER or BOOLEAN, there also exist variables which can contain numerous values of the same type. Arrays are one example: they offer a (predefinable) number of locations that can optionally be addressed via an index value:

/DECLARE-VARIABLE COST(TYPE=*INTEGER), -
/                 MULTIPLE-ELEMENTS = *ARRAY(1990,2099)
/COST#1996 = 8000 "cents per hour"
/YEAR = 1996
/WHILE (YEAR < 2005)    "loop over 10 years"
/  NEW-COST = (COST#YEAR * 105 + 50) / 100    "+ 5% per year"
/  YEAR = YEAR + 1
/  COST#YEAR = NEW-COST
/END-WHILE

The index value, specified as a number or the name of a simple integer variable, is linked to the variable name via the character #. Any number of array elements can be created, addressed and deleted independently of each other as long as they are taken from the valid index range as defined at variable declaration (see also the FREE-VARIABLE command).

Lists, on the other hand, always consist of a sequence of values that are consecutively numbered, starting with 1. Values can be added only at the end or the beginning of the list; in the latter case, the indexes of all existing values are automatically incremented by 1. Since the sequence of list elements without gaps is always ensured, lists are especially suitable for processing in loops (FOR command). In addition, the commands READ-VARIABLE and SHOW-VARIABLE support record-by-record transfer of file contents to and from lists. The sample procedure below writes the records of a file in reverse order to an output file, making use of two list variables:

/DECL-PARAM (FROM,TO)
/DECL-VAR (IN,OUT),MULT-ELEM=*LIST
/READ-VAR *LIST(IN),STR-QUOTES=*NO,INPUT=&FROM
/FOR LINE=*LIST(IN)
/  OUT = LINE, WRITE-MODE=*PREFIX
/END-FOR
/SHOW-VAR OUT,PREFIX=*NO,OUTPUT=&TO    "###"

The predefined array SYSSWITCH is a special case. Its 32 BOOLEAN-type elements (SYSSWITCH#0 through SYSSWITCH#31) are internally mapped to the job switches of the current job, enabling these to be set and queried directly:

/SW4-BEFORE = SYSSWITCH#4      "###"
/SYSSWITCH#4 = TRUE
/START-EXECUTABLE-PROGRAM $EDT
@...
@HALT
/SYSSWITCH#4 = SW4-BEFORE