Module lessons (1/2)
Batch sorting with SORT and MERGE
Define temporary files SD (Sort Description), sort by ASCENDING/DESCENDING keys with SORT USING/GIVING, and merge sorted streams via MERGE.
What you'll learn in this lesson
- Declare a temporary working file with
SD(Sort Description) inFILE SECTION. - Sort sequential archives on one or more keys with
SORT ... ON ASCENDING/DESCENDING KEY ... USING ... GIVING .... - Merge multiple already sorted files into a single output with
MERGE ... USING ... GIVING .... - Understand when to replace
USING/GIVINGwithINPUT PROCEDUREandOUTPUT PROCEDUREfor streaming filtering or aggregation.
Overview
In financial batches, sorting millions of transactions by account and date before reconciliation is a daily operation. COBOL integrates the SORT and MERGE verbs directly into the syntax of the language.
A work file used for sorting does not have a permanent path: in ENVIRONMENT DIVISION you associate it with a work file and in FILE SECTION you define it with SD instead of FD:
Sections covered in this lesson
- 11. The temporary descriptor
SD(Sort Description) - 22. Multi-key sorting with
SORT ... USING ... GIVING - 33. Quick Merge with
MERGE - 44. Streaming filtering with
INPUT/OUTPUT PROCEDURE - 5Try it yourself
Unlock "Batch sorting with SORT and MERGE" and the full Course COBOL curriculum
Define temporary files SD (Sort Description), sort by ASCENDING/DESCENDING keys with SORT USING/GIVING, and merge sorted streams via MERGE.
Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Course COBOL plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.