IntroductionMTB StatementsFile SystemCompilerApplicationsReference GuideIndex

Pseudocode for sort/merge

Here are the steps to follow to perform a sort/merge of more than 64K bytes of data.

  1. Use the DSTAT function on configured gateway devices (G00, G01, etc.) to determine an available sort gateway. The DSTAT function returns information about each Comet device, including gateways. For an available sort gateway, DSTAT returns the first 3 bytes as blank spaces (indicating that there is no current owner of the gateway), followed by a "2" (indicating that the device is a type-2 gateway).

  2. Open the gateway device and assign it to a specific logical unit number in your program. If your program receives an exception 31, another user has opened the gateway you were trying to open. Return to step 1 and determine another available gateway.

  3. Send the following control code to the gateway lun:

              FILE (lun) CTL="@02xxxx@"
    

    This control sets the record length for the sort records, where xxxx is the number of bytes in hex. The maximum value is 0400 hex (1,024 decimal).

  4. Create two Comet sequential work files with the same record size as the records to be sorted.

  5. Open the sequential work files.

  6. Send one of the following controls to the gateway lun:

    FILE (lun) CTL="@04xxyy@" to specify ascending sort/merge, or
    FILE (lun) CTL="@05xxyy@" to specify descending sort/merge

    where xx and yy are the logical unit numbers in hex of two open Comet sequential work files.

  7. Write records to the gateway lun. The records will "pass through" the sort area and be written to the disk. If the disk becomes full, your program will receive an exception.

  8. After all records have been written, send the following control code to the gateway to begin the sort/merge operation:

              FILE (lun) CTL="@06@"
    

    Control will not be returned to your program until the sort is complete.

  9. After the records have been sorted, you program may read them from the gateway in the same fashion it would read records from a sequential file (i.e., sequential reads, one read per record, until an exception 2 is encountered).

  10. Optionally, your program may re-read the records from the gateway. To reset the read pointer to the first record in the sort area, use the following control:

              FILE (lun) CTL="@03@"
    

    Subsequent reads from the sort area will proceed from the first record.

  11. When the sort operation is complete, one of the work files will contain the sorted records and the other will be empty (the result of successive merges between the two files). Your program is responsible for erasing or renaming these work files as appropriate.


Sort Gateway