1.

How is sorting achieved in the COBOL program?

Answer»

It is done by using the SORT command whose syntax goes as follows:

SORT file_1 ON ASCENDING/DESCENDING KEY key…USING file_2GIVING file_3.

where

  • file_1 - sort workfile that needs to be described by using SD entry in FILE SECTION.
  • file_2 - INPUT file for SORT that needs to be described using FD entry in FILE SECTION and using a SELECT clause in FILE CONTROL.
  • file_3 - output file from SORT and again needs to be described using FD entry in FILE SECTION and SELECT clause in FILE CONTROL section.

All THREE files are not supposed to be opened explicitly.

Note:

  • USING clause can be replaced by INPUT PROCEDURE IS para_1 THRU para_2. While using INPUT PROCEDURE, we need to REMEMBER that the section will be executed before sort and the records need to be released to the work file from the RESULT of the input procedure.
  • GIVING clause can be replaced by OUTPUT PROCEDURE IS para_1 THRU para_2. While using OUTPUT PROCEDURE, we need to note that the procedure will be executed once all records were sorted and the records from the sort work file should be populated one record at a time to the output procedure.


Discussion

No Comment Found