The RETURN statement obtains either sorted records from the final phase of a SORT operation or merged records during a MERGE
- File-name must be described by a sort-merge file description entry in the Data Division.
- A RETURN statement can only be used within the range of an output procedure associated with a SORT or MERGE statement for
- The INTO phrase must not be used when the input file contains logical records of various sizes as indicated by their record
descriptions. The storage area associated with identifier and the record area associated with file-name must not be the same
- Identifier-1 can be a floating-point item.
- When the logical records of a file are described with more than one record description, these records automatically share
the same storage area; this is equivalent to an implicit redefinition of the area. The contents of any data items which lie
beyond the range of the current data record are undefined at the completion of the execution of the RETURN statement.
- The execution of the RETURN statement causes the next existing record in the file referenced by file-name, as determined by
the keys listed in the SORT or MERGE statement, to be made available in the record area associated with file-name. If no next
logical record exists in the file referenced by file-name, the AT END condition exists and control is transferred to imperative-statement-1
of the AT END phrase. Execution continues according to the rules for each statement specified in imperative-statement-1. If
a procedure branching or conditional statement which causes explicit transfer of control is executed, control is transferred
according to the rules for that statement. Otherwise, upon completion of the execution of imperative-statement-1, control
is transferred to the end of the RETURN statement
and the NOT AT END phrase if specified is ignored.
When the AT END condition occurs, execution of the RETURN statement is unsuccessful and the contents of the record area associated
with file-name are undefined. After the execution of imperative-statement-1 in the AT END phrase, no RETURN statement can
be executed as part of the current output procedure.
- If an AT END condition does not occur during the execution of a RETURN statement, then after the record is made available
and after executing any implicit move resulting from the presence of an INTO phrase, control is transferred to imperative-statement-2,
if specified. Otherwise, control is transferred to the end of the RETURN statement.
- The END-RETURN phrase delimits the scope of the RETURN statement.
- The INTO phrase can be specified in a RETURN statement if one of the following conditions apply:
- If only one record description is subordinate to the sort-merge file description entry:
- If all record-names associated with file-name and the data item referenced by identifier describe groups item or elementary
- The result of the execution of a RETURN statement with the INTO phrase is equivalent to the application of the following rules
in the order specified:
- The same RETURN statement without the INTO phrase is executed.
- The current record is moved from the record area to the area specified by identifier according to the rules for the MOVE statement
without the CORRESPONDING phrase. The size of the current record is determined by rules specified for the RECORD clause. If
the file description entry contains a RECORD IS VARYING clause, the implied move is a group move. The implied MOVE statement
does not occur if the execution of the RETURN statement was unsuccessful. Any subscripting associated with identifier-1 is
evaluated after the record has been read and immediately before it is moved to the data item. The record is available in both
the record area and the data item referenced by identifier-1.