Summary -

In this topic, we described about the Sorting and Merging with detailed example.

SORT or MERGE statements used to arrange records in a sequence. SORT and MERGE statements can use in the same COBOL program. 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 below steps that generally sort or merge are follows -

  • Specify the sort or merge file to be used for sorting or merging.
  • Specify the input to be sorted or merged. If the records require to process before sorting, code an input procedure.
  • Specify the output from sorting or merging. If the records require to process after sorting or merging, code an output procedure.
  • Request the sort or merge.
  • Determine whether the sort or merge operation was successful.

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.The records 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. The records can add, delete or change records after they are merged.