In contrast to arrays and lists, which combine a number of values of the same type under a single variable name, a STRUCTURE-type variable permits several elements of any type to be combined, where each element is identified by its own name. The element names are appended to the name of the structure variable, separated from it by a period; this enables elements to be addressed individually:
/DECL-VAR SALES(TYPE=*STRUCTURE) /SALES.HEAD = 'H. Haegar' /SALES.NO-EMPLOYEES = 17 /SALES.TURNOVER = 99000
The structure elements may again be arrays, lists or structures:
/DECL-ELEM SALES.PERSONEL(TYPE=*STRUCTURE),MULT-ELEM=*LIST /SALES.PERSONEL#1.NAME = 'S. Lucky' /SALES.PERSONEL#1.PERS-ID = 13 /SALES.PERSONEL#2.NAME = 'D. Harry' /SALES.PERSONEL#2.PERS-ID = 17
The example below illustrates how a list of structures can be used as a simple database. To create elements and assign values, a special form of the SET-VARIABLE command is used; it expects a string in the format of an SDF command substructure from which it generates individual value assignments. The entries in the “database” are processed sequentially by means of FOR loops, presenting the various possible inputs to the user who will then select the desired entry.
/DECL-VAR JOB-START(TYPE=*STRUCT),MULT-ELEM=*LIST /DECL-VAR JOB(TYPE=STRUCT) / /&* Set up list of job definitions /JOB-START=*STR-TO-VAR('PAR(NAME=CTL,CPU=60,FILE=E.CONTROL)'), - / WRITE-MODE=*EXTEND /JOB-START=*STR-TO-VAR('PAR(NAME=DB,CPU=999,FILE=$AV.DB-START)'), - / WRITE-MODE=*EXTEND /"... any number of job definitions as required ..." / /&* Show all defined jobs /TEXT = ' Selection:' /FOR JOB=*LIST(JOB-START) / TEXT = TEXT // ' ' // JOB.NAME /END-FOR /WRITE-TEXT '&TEXT' / /&* Selection by the user /READ-VAR JNAM,PROMPT=' Which job would you like?' / /&* Search list for appropriate job and start /FOR JOB=*LIST(JOB-START) / IF (UPPER-CASE(JNAM) == UPPER-CASE(JOB.NAME)) / ENTER-JOB &(JOB.FILE),CPU-LIMIT=&(JOB.CPU) / END-IF /END-FOR
Structures for which any number of elements may be created (and deleted) during the procedure run are referred to as “dynamic structures”. On the other hand, the complete layout of a structure, including the names and types of all its elements, can be defined at the time of variable declaration. The following commands create a layout under the name DEPARTMENT which is used exclusively for the declaration of a variable (as “static structure”):
/BEGIN-STRUCTURE DEPARTMENT / DECLARE-ELEMENT HEAD(TYPE=*STRING) / DECLARE-ELEMENT NO-EMPL(TYPE=*INTEGER) / DECLARE-ELEMENT TURNOVER(TYPE=*INTEGER) /END-STRUCTURE DEPARTMENT /DECL-VAR MEDICAL(TYPE=*STRUCT(DEFINITION=DEPARTMENT)) /MEDICAL.HEAD = 'Dr. Zook' /MEDICAL.NO-EMPL = 2; MEDICAL.TURNOVER = 99001
SET-VARIABLE can be used to assign a complete structure to another; the WRITE-MODE operand then serves to determine whether elements of the destination structure that are not addressed are to be retained. If the destination structure is a static structure, those elements of the source structure not present in the destination variable will be ignored during assignment.
Some system commands can optionally reroute their output to structure variables. The SHOW-FILE-ATTRIBUTES command, for instance, can output a structure whose elements contain all catalog information for a file. This information can then be processed in an
S procedure with direct access to the structure elements (see section “Structured output inS variables” for further details).