COBOL Manual for TNS and TNS/R Programs
Procedure Division Verbs
HP COBOL Manual for TNS and TNS/R Programs—522555-006
9-235
SORT
•
Output Phase of Execution
°
GIVING phrase
If the GIVING phrase appears, the output phrase transfers all records in the
sd-name file to each output file outfile. Each output file must be in the
closed state, but not in the locked state, when the output phase begins
executing. First, the output phrase implicitly opens each output file in the output
mode. The output phase then executes implicit return operations to retrieve the
records from the sort file and implicit WRITE statements write operations to
release them to each of the output files. Finally, the output phase implicitly
closes each of the output files.
The open and close operations are equivalent to OPEN OUTPUT and CLOSE
statements having no 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 output files or accesses the record area associated with any output file.
When more than one instance of outfile is specified, each operation is
performed on each file in the order that they appear in the GIVING phrase.
That is, the output files are opened in order, each retrieved record is written to
each file in order, and then the files are closed in order.
If an output file is a relative file, the relative key data item is set to the value 1
for the first record returned, 2 for the second, and so forth. After the SORT
statement finishes executing, the content of the relative key data item indicates
the last record returned to the file.
If an output file has fixed-length records, each record retrieved from the sort file
containing fewer character positions than the fixed size specified for the output
file is extended on the right with as many space characters as needed before it
is written to the output file.
The first attempt to write beyond the defined boundaries of an output file
causes a boundary violation condition. This in turn causes the execution of the
applicable USE procedure, if one exists. If the logic of the non-CRE
environment permits continued execution of the run unit, control then returns to
the output phase. In this case no additional implicit write operations are
executed for that file; however, the logic of the output phase closes it as
described earlier.
The sort operation automatically closes the sort file after the end of the output
phase. Then the SORT statement terminates execution.