Memory-Only Mode

If no sort work files are specified on tapes, and the disk size is specifically set to 0, a memory-only sort operation is performed. Failure to set the disk size to 0 results in the default value for disk being used, and a disk-only sort operation occurs.

Memory-only sorts attempt to read user input directly into memory. If the utility fills sort memory—as specified by the MEMORYSIZE parameter before it reads the last user input record, SORT terminates with SORT ERROR #3.

To avoid running out of memory, use the SORTLIMITS option when you execute your program. If you use input procedures, the program must pass the number of records to SORT in the RECORDSIZE parameter so that the SORT utility can calculate the memory requirements.

If the SORTLIMITS option is set, the SORT Utility will determine whether the requested memory size is adequate, based on the record size and number of records as specified in the RECORDSIZE parameter, prior to performing the actual sort operation. If it determines that the memory size requested is inadequate, it will request permission to allocate more memory.

If a COBOL85 program performs a SORT that uses an input procedure, it is not possible to determine the actual number of input records before the sort operation is performed. If the SORTLIMITS option is used in this situation, the number of records passed in the RECORDSIZE parameter will be calculated based on the record size and requested memory size. If the requested memory size is greater than zero and less than 1524 words, an estimate of 2000 records will be provided, and the requested memory size adjusted accordingly.

In this situation, it is important that the memory size provided in the program reasonably indicates the actual number of records to be sorted. An estimate that is much too large may cause unnecessary memory expansion requests. An estimate that is too small may cause SORT to run out of memory.

Memory-only sorting is of particular value when the number of records to be sorted is small. To determine whether or not you have an optimum number of records to sort, use the following formula as a guide:

  • Multiply the number of records to be sorted by the size of the records measured in words.

  • The product of this result must be less than the memory size specification.