Use SORT...GIVING if you want to transfer the sorted records directly from the sort file into another file without any further processing. With SORT...GIVING file-name, the ILE COBOL compiler generates an output procedure to open the file, return the records, write the records, and close the file. At the time the SORT statement is performed, the file named with the GIVING phrase must not be open.
If you want to select, edit, or otherwise modify the sorted records before writing them from the sort work file into another file, use the OUTPUT PROCEDURE phrase of the SORT statement.
In the output procedure, you must use the RETURN statement to make each sorted record available to the output procedure. Your output procedure may then contain any statements necessary to process the records that are made available, one at a time, by the RETURN statement.
You can use RETURN INTO, instead of RETURN, to return and process records into Working-Storage or to an output area. You may also use the AT END phrase with the RETURN statement. The imperative statements on the AT END phrase are performed after all the records have been returned from the sort file.
Each output procedure must include at least one RETURN or RETURN INTO statement. Also, each output procedure must be represented as either a section or a paragraph.
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.