An array is a structure that stores sets of data within a function. The contents of an array are available only as long as the function is active. The structure has a defined layout and each entry (element) of the structure has the same layout. Define this layout with any set of fields from the model, such as attribute, code, and function fields.
Use arrays to:
-
Improve performance where a function requires repeated access and use of a finite number of entries, such as table lookups.
-
Move between a field and a data structure.
-
Sequence a finite set of data by a set of unrelated key fields.
-
Programmers (*PGMR) and designers (*DSNR) can define arrays.
Arrays can be used only by the *CVTVAR built-in function and the following four standard data function types:
-
Create Object (CRTOBJ) to add an element
-
Change Object (CHGOBJ) to change an element
-
Delete Object (DLTOBJ) to delete an element
-
Retrieve Object (RTVOBJ) to read an element or set of elements
Structuring Field Data Using Arrays
Since a single-element array is equivalent to a data structure, you can use the *CVTVAR built-in function and the ELM context to apply a data structure to a field.
This gives you a simple way to decompose a field into a structure and to (re)compose a set of fields into a single field in a single operation.
Passing Parameters
You can also use arrays to define a set of fields that are then used as a parameter entry to any function. This process allows you to define a large number of parameters of any field type to a function without creating a structure file (a *DSNR function).
Storing Data Between Calls
For programs that do not close down, arrays are initialized on the first call to the program. Subsequent calls do not clear the array.
The first call loads the array and subsequent calls retrieve that data. In addition, you can define an array to store and restore any fields in the program between calls.
The PGM context variable Initial Call can be used to distinguish between first and subsequent calls. This variable is always set to *YES if the program closes down.
Defining an Array
At the Edit Database Relations panel, type *a or *ARRAY in the positioner field on the top line of the panel and press Enter.
Take Z to see all arrays.
Take Z on any array, it will show all fields.
Take F7, we can see the array key fields