Loading a Run-Time Array by Reading Several Records from A File

If the data for the array is not available in a single record from the database file, the array must be loaded by reading more than one record from the database file. Each record may provide the data for one or more elements of the array. The ILE RPG program processes one record at a time. Therefore, the entire array is not processed until all the records containing the array information are read and the information is moved into the array elements. It may be necessary to suppress calculation and output operations until the entire array is read into the program.

For example, assume that each record from file ARRFILE2 contains the information for one array element in positions 1-12. You can code the Input specification for the array element with a variable index. Your program would set the index before the record was read as shown in Figure 71.

Figure 71. Loading an array from a file, one element per record
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++ 
DARRX             S             12A   DIM(6)
DN                S              5P 0 INZ(1)
IFilename++SqNORiPos1+NCCPos2+NCCPos3+NCC................................
I........................Fmt+SPFrom+To+++DcField+++++++++L1M1FrPlMnZr....
IARRFILE2  AA  01
I                                  1   12  ARRX(N)
CL0N01Factor1+++++++Opcode&ExtFactor2;+++++++Result++++++++Len++D+HiLoEq
C                   IF        N = %ELEM(ARR)
 * The array has been loaded
 ..... process the array
 * Set the index to 1 to prepare for the next complete array
C                   EVAL      N = 1
C                   ELSE
 * Increment the index so the next input operation will fill
 * the next array element
C                   EVAL      N = N + 1
C                   ENDIF


[ Top of Page | Previous Page | Next Page | Contents | Index ]