Rational Developer for System z
COBOL for Windows, Version 7.5, Programming Guide


Sorting and merging files

You can arrange records in a particular sequence by using a SORT or MERGE statement. You can mix SORT and MERGE statements in the same COBOL program.

SORT statement
Accepts input (from a file or an internal procedure) that is not in sequence, and produces output (to a file or an internal procedure) in a requested sequence. You can add, delete, or change records before or after they are sorted.
MERGE statement
Compares records from two or more sequenced files and combines them in order. You can add, delete, or change records after they are merged.

A program can contain any number of sort and merge operations. They can be the same operation performed many times or different operations. However, one operation must finish before another begins.

The steps you take to sort or merge are generally as follows:

  1. Describe the sort or merge file to be used for sorting or merging.
  2. Describe the input to be sorted or merged. If you want to process the records before you sort them, code an input procedure.
  3. Describe the output from sorting or merging. If you want to process the records after you sort or merge them, code an output procedure.
  4. Request the sort or merge.
  5. Determine whether the sort or merge operation was successful.

related concepts
Sort and merge process

related tasks
Describing the sort or merge file
Describing the input to sorting or merging
Describing the output from sorting or merging
Requesting the sort or merge
Determining whether the sort or merge was successful
Stopping a sort or merge operation prematurely

related references
SORT statement (COBOL for Windows Language Reference)
MERGE statement (COBOL for Windows Language Reference)


Terms of use | Feedback

Copyright IBM Corporation 1996, 2008.
This information center is powered by Eclipse technology. (http://www.eclipse.org)