Requesting the sort or merge
To read records from an input file (files for MERGE
)
without preliminary processing, use SORT . . . USING
or MERGE
. . . USING
and the name of the input file (files) that you
declared in a SELECT
clause.
About this task
To transfer
sorted or merged records from the sort or merge program to another
file without any further processing, use SORT . . . GIVING
or MERGE
. . . GIVING
and the name of the output file that you declared
in a SELECT
clause. For example:
SORT Sort-Work-1
ON ASCENDING KEY Sort-Key-1
USING Input-File
GIVING Output-File.
For SORT . . . USING
or MERGE
. . . USING
, the compiler generates an input procedure to
open the file (files), read the records, release the records to the
sort or merge program, and close the file (files). The file (files)
must not be open when the SORT
or MERGE
statement
begins execution. For SORT . . . GIVING
or MERGE
. . . GIVING
, the compiler generates an output procedure
to open the file, return the records, write the records, and close
the file. The file must not be open when the SORT
or MERGE
statement
begins execution.
The USING
or GIVING
files
in a SORT
or MERGE
statement can
be sequential files residing in the z/OS® UNIX file system.
Example: describing sort and input files for SORT
You can also use the FASTSRT
compiler
option to let IBM® DFSORT, or
an equivalent product, perform sort input and output instead of the
Enterprise COBOL compiler (along with Language Environment® run time).
Using FASTSRT
improves the performance of most sort
operations. For details, see FASTSRT.
If you want an input
procedure to be performed on the sort records before they are sorted,
use SORT . . . INPUT PROCEDURE
. If you want an output
procedure to be performed on the sorted records, use SORT
. . . OUTPUT PROCEDURE
. For example:
SORT Sort-Work-1
ON ASCENDING KEY Sort-Key-1
INPUT PROCEDURE EditInputRecords
OUTPUT PROCEDURE FormatData.
Example: sorting with input and output procedures
Restriction: You
cannot use an input procedure with the MERGE
statement.
The source of input to the merge operation must be a collection of
already sorted files. However, if you want an output procedure to
be performed on the merged records, use MERGE . . . OUTPUT
PROCEDURE
. For example:
MERGE Merge-Work
ON ASCENDING KEY Merge-Key
USING Input-File-1 Input-File-2 Input-File-3
OUTPUT PROCEDURE ProcessOutput.
In the FILE SECTION
, you must define Merge-Work in
an SD
entry, and the input files in FD
entries.
SORT statement (Enterprise COBOL for z/OS Language Reference)
MERGE statement (Enterprise COBOL for z/OS Language Reference)