RETURN Statement
The RETURN statement transfers records from the final phase of a sort or merge 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.
RETURN Statement - Format >>-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.
The record areas associated with file-name-1 and identifier-1 must not be the same storage area.
- file-name-1
- Must be described in a Data Division SD entry.
If more than one record description is associated with file-name-1, these 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.
- INTO identifier-1
- The
RETURN INTO statement is equivalent to the statements:
RETURN file-name-1 MOVE record-name TO identifier-1IBM ExtensionIBM Extension Identifier-1 can be a DBCS, floating-point, or date-time data item. End of IBM Extension
End of IBM ExtensionMoving takes place 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. However, the implied MOVE does not occur when the RETURN statement is unsuccessful.
Any subscripting, indexing, or reference modification associated with identifier-1 is evaluated after the record has been returned and immediately before it is moved to identifier-1.
The INTO phrase may be specified in a RETURN statement if one or both of the following are true:- If only one record description is subordinate to the sort-merge file description entry, and/or
- If all record-names associated with file-name-1 and the data item referenced by identifier-1 describe a group item or an elementary alphanumeric item.
