Rational Developer for System z
PL/I for Windows, Version 7.6, Programming Guide

Choosing the type of sort

To make the best use of the sort program, you should understand how it works. In your PL/I program you specify a sort by using a CALL statement to the built-in subroutine PLISRTx. Each specifies a different source for the unsorted data and destination for the data when it has been sorted.

For example, a call to PLISRTA specifies that the unsorted data (the input to sort) is on a data set, and that the sorted data (the output from sort) is to be placed on another data set. The CALL PLISRTx statement must contain an argument list giving the sort program information about the data set to be sorted, the fields on which it is to be sorted, the name of a variable into which sort places a return code indicating the success or failure of the sort, and the name of any output or input handling procedure that can be used.

The sort interface routine builds an argument list for the sort from the information supplied by the PLISRTx argument list and depends on your choice of A, B, C, or D for x. Control is then transferred to the sort program. If you have specified an output- or input-handling routine, it is called by the sort program as many times as is necessary to handle each of the unsorted or sorted records.

The sort operation ends in one of two ways:

  1. Communicating success or failure by sending a return code of 0 or 16 to the PL/I calling procedure.
  2. Raising an error condition when certain errors are detected and the return code is undefined.

Figure 33 is a simplified flowchart showing the sort operation.

Figure 33. Flow of control for the sort program
                                      .--------------.
                                      |              |
                                      | CALL PLISRTx |
                                      |              |
                                      '--.--.--.--.--'
                                         |  |  |  |
            .----------------------------'  |  |  '----------------------------.
            |                     .---------'  '---------.                     |
            V                     V                      V                     V
         PLISRTA               PLISRTB                PLISRTC               PLISRTD
            |                     |                      |                     |
            V                     V                      V                     V
.-----------'---------------------'----------------------'---------------------'-----------.
|                                       SORT PROGRAM                                       |
'-----------.---------------------.----------------------.---------------------.-----------'
|           V                     V                      V                     V           |
| .---------'--------.  .---------'---------.  .---------'--------.  .---------'---------. |
| | Get records from |  | Call PL/I sub-    |  | Get records from |  | Call PL/I sub-    | |
| | data set until   |  | routine receiving |  | data set until   |  | routine receiving | |
| | end of file      |  | one record on     |  | end of file      |  | one record on     | |
| |                  |  | each call (E15)   |  |                  |  | each call (E15)   | |
| '---------.--------'  '---------.---------'  '---------.--------'  '---------.---------' |
|           |                     |                      |                     |           |
|           |                     '---------.  .---------'                     |           |
|           '----------------------------.  |  |  .----------------------------'           |
|                                        |  |  |  |                                        |
|                                        V  V  V  V                                        |
|                                     .--'--'--'--'--.                                     |
|                                     |              |                                     |
|                                     | Sort records |                                     |
|                                     |              |                                     |
|                                     '--.--.--.--.--'                                     |
|                                        |  |  |  |                                        |
|           .----------------------------'  |  |  '----------------------------.           |
|           |                     .---------'  '---------.                     |           |
|           |                     |                      |                     |           |
|           V                     V                      V                     V           |
| .---------'--------.  .---------'---------.  .---------'--------.  .---------'---------. |
| | Place sorted     |  | Place sorted      |  | Call PL/I sub-   |  | Call PL/I sub-    | |
| | records on       |  | records on        |  | routine passing  |  | routine passing   | |
| | data set         |  | data set          |  | one record on    |  | one record on     | |
| |                  |  |                   |  | each call (E35)  |  | each call (E35)   | |
| '---------.--------'  '---------.---------'  '---------.--------'  '---------.---------' |
|           |                     |                      |                     |           |
|           |                     '---------.  .---------'                     |           |
|           '----------------------------.  |  |  .----------------------------'           |
|                                        |  |  |  |                                        |
|                                        V  V  V  V                                        |
|                                 .------'--'--'--'------.                                 |
|                                 | Set up return code   |                                 |
|                                 | to indicate success  |                                 |
|                                 | or failure of sort   |                                 |
|                                 '----------.-----------'                                 |
|                                            |                                             |
'--------------------------------------------+---------------------------------------------'
                                             |
                                             V
                                    .--------'---------.
                                    | Return to caller |
                                    |   of PLISRTx     |
                                    '------------------'

Within the sort program itself, the flow of control between the sort program and output- and input-handling routines is controlled by return codes. The sort program calls these routines at the appropriate point in its processing. (Within the sort program, these routines are known as user exits. The routine that passes input to be sorted is the E15 sort user exit. The routine that processes sorted output is the E35 sort user exit.) From the routines, the sort program expects a return code indicating either that it should call the routine again, or that it should continue with the next stage of processing.

The remainder of this chapter gives detailed information on how to use sort from PL/I. First the required PL/I statements are described, followed by the data set requirements. The chapter finishes with a series of examples showing the use of the four built-in subroutines.


Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)