COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-233
SORT
•
Sort Output Procedures
The OUTPUT PROCEDURE phrase defines a sort output procedure that extends
from outproc-1 to outproc-2, each of which must identify a Procedure
Division section or paragraph. If THROUGH or THRU is omitted, the compiler
assumes an outproc-2 that specifies the same section or paragraph as
outproc-1.
•
Execution Phases
The execution of the SORT statement consists of three phases:
°
The input phase transfers records to the sort file sd-name, either from one or
more infile files specified in a USING phrase or from a sort input procedure
specified in an INPUT PROCEDURE phrase.
°
The sort phase reorders these records according to the sort keys and the
applicable collating sequence.
°
The output phase either transfers the sorted records to a set of one or more
files specified by outfile in the GIVING phrase or returns them to the sort
output procedure specified in an OUTPUT PROCEDURE phrase.
•
Input Phase of Execution
°
USING phrase
If the USING phrase appears, the input phase transfers all of the records in
each input file infile to the sort file sd-name. When the SORT statement
begins executing, each input file must be either closed but not locked, or open
but not in conflict with a following open for protected input (that is, the same file
connector cannot be open).
For each input file, the input phase implicitly opens it in the input mode,
executes implicit “READ infile NEXT AT END …” statements to retrieve the
records and implicit release operations to release them to the sort file, then it
implicitly closes the input file. The open and close operations are equivalent to
OPEN INPUT and CLOSE statements without any optional phrases.
All of these implicit functions are performed such that any associated
declarative procedures are executed; however, the execution of a declarative
procedure must not cause the execution of any statement that manipulates any
of the input files or accesses the record area associated with any input file.