Summary -

In this topic, we described about the below sections -

The RETURN statement transfers records from the final phase of a sorting or merging operation to an OUTPUT PROCEDURE.

The RETURN statement used only within the range of an OUTPUT PROCEDURE associated with a SORT or MERGE statement. At least one RETURN statement must be specified within an OUTPUT PROCEDURE.

Syntax -


When the RETURN statement is executed, the next record from file-name-1 is made available for processing by the OUTPUT PROCEDURE.

file-name-1 -

Must be a sort or merge file name specified in a data division SD entry. If more than one record description is associated with file-name-1, those records automatically share the same storage; that is, the area is implicitly redefined. After RETURN statement execution, only the contents of the current record are available.

INTO phrase -

Specifies the valid receiving area to receive the file-name-1 record.

When there is only one record description associated with file-name-1, the result of the execution of a RETURN statement with the INTO phrase is equivalent to the same RETURN statement without the INTO phrase.

When the data item referenced by identifier-1 describe an elementary alphanumeric item or an alphanumeric group item, the current record is moved from the record area to the area specified by identifier-1 according to the rules for the MOVE statement.

When there are multiple record descriptions associated with file-name-1 and they do not all describe an alphanumeric group item or elementary alphanumeric item, the below rules apply -

  • If the file referenced by file-name-1 contains variable-length records, a group move takes place.
  • If the file referenced by file-name-1 contains fixed-length records, a move takes place according to the rules for a MOVE statement using.

identifier-1 must be a valid receiving field. The record areas and identifier-1 must not be the same storage area.

AT END phrase -

The AT END phrase executes imperative-statement after all records have been returned from file-name-1. No more RETURN statements 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, control is transferred to the imperative statement specified by the NOT AT END phrase.

If an at-end condition does occur, control is transferred to the end of the RETURN statement.

END-RETURN phrase -

The END-RETURN used to end the scope of the RETURN statement. END-RETURN is not required when RETURN statement ended with period.

END-RETURN can also be used with an imperative RETURN statement. END-RETURN permits conditional RETURN to be nested in another conditional statement.