0% found this document useful (0 votes)
192 views4 pages

Cobol Sort Verb

The SORT verb in COBOL allows programmers to sort one or more input files by specified keys into a single sorted output file. It calls an external SYNCSORT program to perform the sorting. Programmers can provide input and output procedures to manipulate records before and after sorting, and special registers track the sort status and control message output.

Uploaded by

Santhosh Acharya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
192 views4 pages

Cobol Sort Verb

The SORT verb in COBOL allows programmers to sort one or more input files by specified keys into a single sorted output file. It calls an external SYNCSORT program to perform the sorting. Programmers can provide input and output procedures to manipulate records before and after sorting, and special registers track the sort status and control message output.

Uploaded by

Santhosh Acharya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

COBOL SORT verb

The SORT verb takes one or more files of input records and
sorts them in ascending or descending order by one or more
programmer specified keys.

The result is a single sorted file.

Format: SORT sd-file-name


ON ASCENDING/DESCENDING KEY sd-key-name

|USING input-file-name |
|INPUT PROCEDURE IS routine-name|

|GIVING sorted-file-name |
|OUTPUT PROCEDURE IS routine-name|.

sd-file-name a temporary sort work file


SD in the DATA DIVISION
SELECT statement in the
ENVIRONMENT DIVISION
MUST be CLOSED when the sort is
called

sd-key-name key field from the SD record


description

USING input-file-name this is the file that


will be sorted
FD in the DATA DIVISION
SELECT stmt in the
ENVIRONMENT DIVISION
MUST be CLOSED when the
sort is called

INPUT PROCEDURE IS routine-name

- routine-name is a programmer coded routine


that will
select which records are to be used in the
sort

- input procedure pseudocode:

OPEN input-file-name

READ the first record

While there are input records


Modify the current record
MOVE record to sd-file-record
RELEASE sd-file-record
READ next record
Endwhile

CLOSE input-file-name

- To release a record to the sort:

RELEASE sd-file-record [FROM ws-area].

this is equivalent to a WRITE in COBOL


except that its
performed on an SD file and is used ONLY in
an input
procedure

GIVING sorted-file-name this is the resulting


sorted file
FD in the DATA DIVISION
SELECT stmt in the
ENVIRONMENT DIVISION
MUST be CLOSED when the
sort is called

OUTPUT PROCEDURE IS routine-name


- routine-name is a programmer coded routine
that will
manipulate the records AFTER they are sorted

- output procedure pseudocode:

OPEN sorted-file-name

RETURN the first sd-file-record

While there are input records


Modify the sorted record
MOVE sd-file-record to sorted-file-record
WRITE sorted-file-record
RETURN the next sd-file-record
Endwhile

CLOSE sorted-file-name

- To return a record:

RETURN sd-file-name [INTO ws-area]


[AT END do something]
[NOT AT END do something else]
END-RETURN.

this is equivalent to a READ in COBOL except


that it is
performed on an SD file and is used ONLY in
an output
procedure

The COBOL SORT verb calls SYNCSORT to do its work.

There are some "special" registers that are set by the SORT
verb and can be set or tested by a programmer.

SORT-RETURN after a SORT this will contain a


return code that
can be tested
0 success
16 failure

if a programmer moves a non-zero value


to this
register, the sort will stop on the
next RETURN
or RELEASE

SORT-FILE-SIZE equivalent to SYNCSORTs FILSZ

SORT-MESSAGE can use this one to specify an 8 byte


ddname for
SYNCSORT to write its messages to

In COBOL: MOVE 'SORTOUT' TO SORT-


MESSAGE.

In JCL: //SYSOUT DD SYSOUT=*


//SORTOUT DD SYSOUT=*

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy