IntroductionMTB StatementsFile SystemCompilerApplicationsReference GuideIndex

Pseudocode for in-memory sort

Here are the steps to follow to perform an in-memory sort of up to 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. Write records to the gateway lun. If the sort area becomes full (exceeds 64K bytes), your program will receive an exception 2.

  5. After all records have been written to the gateway, send one of the following controls to the gateway:

    FILE (lun) CTL="@00@" to begin an ascending sort, or
    FILE (lun) CTL="@01@" to begin a descending sort

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

  6. 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).

  7. Optionally, your program may re-read the records from the gateway, or sort them in a different order (descending, for example). 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.


Sort Gateway