Sorting of Tables

Format 2 of the SORT statement (table sort) is supported. Most of the details are given in the section The SORT Statement. Additional details are contained in this section.

General Format


Syntax for General Format for Sorting of Tables

Syntax Rules

  1. For data-name-3, the same rules apply as for data-name-2.
  2. If the USING phrase is used, data-name-2 and data-name-3 must be described as alphanumeric data items.

General Rules

  1. Data-name-3, if specified, is the table to be sorted; otherwise, the table specified by data-name-2 is sorted.
  2. By specifying USING data-name-3, a second table is used for sort processing. In this case, the elements of the table specified by data-name-3 are transferred to the table specified by data-name-2 and then sorted in the table specified by data-name-2. The individual table elements are transferred in accordance with the rules for the MOVE statement:
    • If the "sending" element is shorter than the "receiving" element, it is padded with blanks;
    • if it is longer, it is truncated.
  3. Transfer of the data-name-3 table elements to the data-name-2 table ends with the last table element of data-name-3 or on reaching the number of table elements for data-name-2. This means that if the data-name-3 table contains more elements than the data-name-2 table, the excess elements are not transferred. If it contains fewer elements, the excess elements of the data-name-2 table are retained unchanged.
  4. Sort processing does not change the contents of the data-name-3 table.