Supported RPG Features

FROMFILE(file) loads an array from a table file at program initialization. The table file must be declared with an F-spec using designation T (table):

     FARRTBL    IT   F   10        DISK
     D Arr             S             10A   DIM(3) FROMFILE(ARRTBL)

On JVM, FROMFILE reads from the named JDBC table at program startup (each record's first field provides one array element).

The table file must be declared on an F-spec - naming an undeclared file is rejected with TRN3028. The declaration is what makes the program a database program, so without it there is no connection to read the array through.

A pre-runtime array is fixed-format only: FROMFILE and TOFILE on a free-form DCL-S are rejected with TRN3026. Declare the array on a D-spec instead - a /COPY member holding the D-spec works from an otherwise free-form program.

TOFILE(file) writes the array back to its file when the program ends with *INLR on. The array's current elements replace the file's records (one record per element, in array order); a program that loads with FROMFILE(t) TOFILE(t), mutates the array, and ends with LR therefore leaves the file holding the mutated values on the next run. Like the load, the write-back is fixed-format only. Ending the program with LR off (an RT return that keeps the program activated) does not write back - the array persists in memory for the next call instead, matching IBM i.

Because the RPG cycle opens the FROMFILE table implicitly during initialization, a failed load - the table is missing, or the connection cannot open it - raises file status 01216 ("error on an implicit OPEN") and halts the program. The program never runs against a silently-empty array. A MONITOR/ON-ERROR block or the (E) extender at program start can trap it.

The record count is checked against the array's DIM(n). A table holding more records than the array can hold is a load-time failure: it raises file status 01051 ("excess entries in array/table file") and halts before the program body runs.

The array is never silently truncated. A table holding fewer records than DIM(n) is not an error - the array takes every record and leaves the surplus elements at their default (blanks for character, zero for numeric), as on IBM i.