RETURN Statement

The RETURN statement retrieves records from sort or merge operations.

General Format

RETURN file-name RECORD [ INTO dest-record ]

      AT END statement-1

    [ NOT AT END statement-2 ]

    [ END-RETURN ]

Syntax Rules

  1. file-name is the name of a sort file described by an SD entry in the Data Division.
  2. dest-record is a data item.
  3. statement-1 and statement-2 are imperative statements.
  4. A RETURN statement may appear only in an output procedure associated with a SORT or MERGE statement. A RETURN statement may not be placed in Declaratives.
  5. The record area associated with file-name and dest-record may not have overlapping storage.

General Rules

  1. The RETURN statement returns the next record from the output phase of a SORT or MERGE statement and places this record in the record area associated with file-name. The RETURN statement may be executed only while the program is executing an output procedure of a SORT or MERGE statement.
  2. Any area in the record area associated with file-name that is beyond the end of the returned record is left unchanged.
  3. If the INTO phrase is specified, the record area associated with file-name is moved to dest-record according to the rules of the MOVE statement. This move occurs after the record is retrieved, but only if the statement is successful.
  4. When no more records are available from the SORT or MERGE operation, statement-1 is executed. Otherwise, statement-2, if specified, is executed.
  5. The RETURN statement does not update the FILE STATUS variable associated with file-name.
  6. If a RETURN statement is executed in a wrong context, the runtime displays the error Illegal RETURN. This error belongs to the class of intermediate runtime errors that, upon occurrence, call installed error procedures. See CBL_ERROR_PROC in Appendix I. Library Routines for more information.