Programming Languages COBOL Subjective
Mar 15, 2013

Explain sorting techniques in COBOL program? Provide the sort file definition, the sort statement, its syntax and meaning

Detailed Explanation

COBOL supports 2 sorting techniques.

1. Ascending order of sorting is done by using ASCENDING KEY clause
2. Descending order of sorting is done by using DESCENDING KEY clause

A sort file definition is:
SORT SORT-EMPLOYEE ON ASCENDING KEY EMP-ID USING SOURCE-EMPLOYEE GIVING TARGET-EMPLOYEE

The sort file is defined by using
- SORT verb
- ON order of sorting,
- specifying key field
- USING source file
- GIVING target file

The SORT-EMPLOYEE file is the “work-file” that is the interface between source file and target file. SORT-EMPLOYEE is not the actual file, but it is declarative file that communicates to the compiler as an external file.

ON ASCENDING KEY EMP-ID – indicates the order of sorting is ascending and the key field is EMP-ID
SOURCE-EMPLOYEE is the source file that is to be sorted
TARGET-FILE is the resultant file that will have sorted records of source file

Discussion (0)

No comments yet. Be the first to share your thoughts!

Share Your Thoughts
Feedback