COBOL SORT
The COBOL SORT statement, which sorts records inside a program, with the site's sort product doing the sorting.
Also written SORT statement, SD, sort description, RELEASE, INPUT PROCEDURE, OUTPUT PROCEDURE
COBOL can sort records itself with the SORT statement. The file to be sorted is described with an SD, a sort description, instead of an FD. SORT SORT-WORK ON ASCENDING KEY SW-ACCT-NO USING IN-FILE GIVING OUT-FILE reads IN-FILE, sorts it by account number and writes the result to OUT-FILE.
The program can also take part in the sort. With INPUT PROCEDURE, a paragraph reads and checks records and hands the ones to sort over with RELEASE. With OUTPUT PROCEDURE, a paragraph receives the sorted records one by one with RETURN and processes them, for example to print a report with totals. That avoids writing intermediate files.
On z/OS, the sorting itself is done by the site's sort product, such as DFSORT, so it is fast, and the job needs the DD statements that the sort product uses, such as SORTWKnn work files at some sites.
For a plain sort of a whole file, many teams prefer a separate DFSORT step, which is simpler to change. COBOL SORT is useful when a program selects or processes records as part of sorting them.
Where can I learn this hands-on?
Right here, at ZedBank. You take a junior job at a simulated bank and learn each part of the work by doing it, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- DFSORTThe standard sort utility, used far beyond sorting to select, merge, reformat and summarise records at speed.
- File descriptionThe FD entry in a COBOL program that describes a file's records, connecting the program to data supplied by the JCL.
- READ and WRITEThe COBOL statements that open, read, write, update and close files.
- PERFORMThe COBOL statement that runs a paragraph and returns, and the way loops are written.
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.