Sorting and Merging Files

Arranging records in a particular sequence is a common requirement in data processing. Such record sequencing can be accomplished using sort or merge operations.
  • The sort operation accepts unsequenced input and produces output in a specified sequence.
  • The merge operation compares two or more sequenced files and combines them in sequential order.
To sort or merge files, you need to do the following:
  1. Describe the input and output files, if any, for sorting or merging.
    • This is accomplished by selecting the files in the FILE-CONTROL paragraph of the INPUT-OUTPUT SECTION and by describing the file using FD (File Description) entries in the FILE SECTION of the DATA DIVISION.
  2. Describe the sort files and merge files.
    • This is accomplished by selecting the sort or merge files in the FILE-CONTROL paragraph of the INPUT-OUTPUT SECTION and by describing the file using SD (Sort Description) entries in the FILE SECTION of the DATA DIVISION.
  3. Specify the sort or merge operation.
    • This is accomplished by performing the SORT or MERGE statements in the PROCEDURE DIVISION.