Sort and merge process
During the sorting of a file, all of the records in the file are ordered according to the contents of one or more fields (keys) in each record. You can sort the records in either ascending or descending order of each key.
If there are multiple keys, the records are first sorted according to the content of the first (or primary) key, then according to the content of the second key, and so on.
To sort a file, use the format 1 SORT
statement.
During the merging of two or more files (which must already be sorted), the records are combined and ordered according to the contents of one or more keys in each record. You can order the records in either ascending or descending order of each key. As with sorting, the records are first ordered according to the content of the primary key, then according to the content of the second key, and so on.
Use MERGE
. . . USING
to name the files that you
want to combine into one sequenced file. The merge operation compares
keys in the records of the input files, and passes the sequenced records
one by one to the RETURN
statement of an output procedure
or to the file that you name in the GIVING
phrase.
SORT statement (Enterprise COBOL for z/OS® Language Reference)
MERGE statement (Enterprise COBOL for z/OS Language Reference)