END READ


The END READ statement indicates the end of a BEG READ “Read Next Record” loop.

    ••••• END READ ••• ••••••••••••••••••••••
    (1)            (2) (3)

(1) T/F execution conditions

(2) Application ID

(3) File name (or field name for RDBMS)

Using the Statement

When using this statement in conjunction with an RDBMS table, you can specify a field name instead of a file name to limit the volume of data being passed between APPX and the RDBMS. See the Partial-Record I/O section in Chapter 4-3: Specifying Statements for more information.

The END READ statement acts as a GOTO and a placeholder; the END READ “goes to” the statement after the corresponding BEG READ. The END READ statement is also used by the BEG READ statement as a placeholder, to know where to continue execution when the loop is finished.

Restrictions

The application ID and file name must match those specified in a previous BEG READ statement.

The END READ statement cannot be used with one-record files.

Execution Errors

A non-recoverable file processing error occurs if an END READ statement executes without, or before, the corresponding BEG READ statement. A non-recoverable error also occurs if, once loop termination has taken place, the END READ is re-executed without or before another corresponding BEG READ statement. All loops are considered terminated when an event point ends.

Related Statements

BEG AT, BEG READ, END AT, READNEXT

Example

The following example demonstrates a common use of the END READ statement where a range is specified:

          BEG AT   TAR TRANFILE IN TAR CUSTOMER ID
          END AT   TAR TRANFILE IN TAR CUSTOMER ID

          BEG READ TAR TRANFILE               HOLD 0 KEY IS  TRANFILE KEY

          *
          *        (process each TRANFILE record for specified customer)
          *

          END READ TAR TRANFILE

In this example, the system reads the TRANFILE file, beginning with the first record where the TRANFILE CUSTOMER ID is equal to or greater than the first one found in the TRANFILE (TRANFILE CUSTOMER ID must be the first part of TRANFILE KEY). The BEG READ “Read Next Record” loop terminates when the key in TRANFILE exceeds the one specified in the END AT statement. If no BEG AT is present, the read begins with the first record in the file.