Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Files for the sort program

The following files are required for a sort operation:

Sort file

Data records are sorted in this file (work area). Its name is declared, for example, via the clause

SELECT sort-file ASSIGN TO "SORTWK"

In addition, the file must be described in the sort file description entry (SD) of the Data Division. The file is accessed with the statement

SORT sort-file ...

Without the user having to issue a SET-FILE-LINK command, this file will be cataloged under the name SORTWORK.tsn.yymmdd.hhmmss (where tsn = task sequence number, yy = year, mm = month, dd = day, hhmmss = time in six digits). The link name is SORTWK. After a normal termination of the sort operation the file is deleted.
By default, the size of the sort file when created without the SET-FILE-LINK command is 24 * 16 = 384 PAM pages (this value can be modified by supplying values to special registers for SORT). Accordingly, the primary allocation is 384 PAM pages; the secondary allocation is 1/4 of this, i.e. 96 PAM pages.

Using the command

/MODIFY-FILE-ATTRIBUTES filename,-
/      SUPPORT=PUBLIC-DISK(SPACE=RELATIVE(PRIMARY-ALLOCATION=.., -
/                   SECONDARY-ALLOCATION=..)) 

the user can define the sort file size independently (see “Sort” manual [6]). This is recommended for large files. After normal termination of the sort operation this file will be closed, but not deleted.

Special registers for SORT (see “COBOL2000 Reference Manual” [1]):

The programmer can load the following special registers for SORT before the sort operation:

  • SORT-FILE-SIZE: This register is loaded with the total number of records.

  • SORT-MODE-SIZE: This register is loaded with the average record size.

The SORT utility routine uses these two registers to calculate the file size. This implies that the programmer can indirectly affect the SPACE operand.

  • SORT-CORE-SIZE: This register is loaded with the desired size of the internal work areas, expressed in bytes.
    These entries can be used to influence program execution.
    If they are omitted, 24 * 4096 bytes (i.e. 24 4-Kb pages) is assumed by default. For further information see “Sort” manual [6] on sort run optimization.

After SORT, RELEASE and before RETURN statements, the programmer may interrogate the SORT special register SORT-RETURN:

“0” indicates that sorting was successful,

“1” that sorting was errored.

This interrogation is recommended because the program is not terminated in the event of an errored sort operation.

If an invalid value is loaded into a SORT special register, error message COB9134 is issued (see chapter "Messages of the COBOL2000 system").

Input file(s)

If no input procedure has been defined, COBOL2000 generates an OPEN INPUT and a READ...AT END for the specified file. Each input file must be defined in the COBOL program.

The link names SORTIN and SORTINnn (01 <= nn <= 99) must not be used within a sort program.

Output file

If no output procedure has been defined, COBOL2000 generates an OPEN OUTPUT and a WRITE for the specified file. The output file must be defined in the COBOL program.

The link name SORTOUT must not be used within a sort program.

SORT parameter files

SORT permits predefined values to be specified and modified for some parameters (see MODIFY-SORT-DEFAULTS statement in the “Sort” manual [6]).

Most of these values have no effect on SORT statements in COBOL programs. Consequently such parameter files are analyzed only in the first SORT statement in a COBOL runtime unit. Subsequent changes have no effect for the rest of the program run. This speeds up COBOL programs, which dynamically execute a large number of SORT statements with few records that need to be sorted.