The RETURN statement transfers records from the final phase of a sorting or merging operation to an OUTPUT PROCEDURE.
The RETURN statement can be used only within the range of an OUTPUT PROCEDURE associated with a SORT or MERGE statement.
Format: RETURN statement >>-RETURN--file-name-1--+--------+--+--------------------+------> '-RECORD-' '-INTO--identifier-1-' >--+-------------------------------------+----------------------> '-+----+--END--imperative-statement-1-' '-AT-' >--+------------------------------------------+-----------------> '-NOT--+----+--END--imperative-statement-2-' '-AT-' >--+------------+---------------------------------------------->< '-END-RETURN-'
Within an OUTPUT PROCEDURE, at least one RETURN statement must be specified.
When the RETURN statement is executed, the next record from file-name-1 is made available for processing by the OUTPUT PROCEDURE.
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. If any data items lie beyond the length of the current record, their contents are undefined.
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 following rules apply:
identifier-1 must be a valid receiving field for the selected sending record description entry in accordance with the rules of the MOVE statement.
The record areas associated with file-name-1 and identifier-1 must not be the same storage area.
The imperative-statement specified on the AT END phrase executes 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, 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 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.
This explicit scope terminator serves to delimit the scope of the RETURN statement. END-RETURN permits a conditional RETURN statement to be nested in another conditional statement. END-RETURN can also be used with an imperative RETURN statement.
For more information, see Delimited scope statements.