The RETURN statement retrieves records from sort or merge operations.
RETURN file-name RECORD [ INTO dest-record ]
AT END statement-1
[ NOT AT END statement-2 ]
[ END-RETURN ]
- file-name is the name of a sort file described by an SD entry in the Data Division.
- dest-record is a data item.
- statement-1 and statement-2 are imperative statements.
- 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.
- The record area associated with file-name and dest-record may not have overlapping storage.
- 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.
- Any area in the record area associated with file-name that is beyond the end of the returned record is left unchanged.
- 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
- When no more records are available from the SORT or MERGE operation, statement-1 is executed. Otherwise, statement-2, if specified, is executed.
- The RETURN statement does not update the FILE STATUS variable associated with file-name.
- 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.