The RETURN Statement

The RETURN statement obtains either sorted records from the final phase of a SORT operation or merged records during a MERGE operation.

General Format


RETURN

Syntax Rules

  1. File-name must be described by a sort-merge file description entry in the Data Division.
  2. A RETURN statement can only be used within the range of an output procedure associated with a SORT or MERGE statement for file-name.
  3. 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 storage area.
  4. OSVSVSC2MF Identifier-1 can be a floating-point item.

General Rules

  1. 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.
  2. 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

    ANS85 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.

  3. ANS85 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.
  4. ANS85 The END-RETURN phrase delimits the scope of the RETURN statement.
  5. 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 desc