Calling DFSORT from a PL/I program

When calling DFSORT, a PL/I program must pass a SORT control statement, a RECORD control statement, and the amount of main storage to be available to DFSORT. On the RECORD control statement, you specify the record type and length for the input data set. Following the RECORD control statement, you specify the main storage value for DFSORT either as MAX, or as a value in bytes. (DFSORT performs best when MAX is specified as the main storage value.)

You can also specify DFSORT control statements in a SORTCNTL or DFSPARM data set.

This JCL is for the program shown in Figure 1. A SORTCNTL data set is used to specify an INCLUDE control statement that selects only the English department books.

//EXAMP    JOB  A492,PROGRAMMER
//BOOKS    EXEC PGM=PLIPGM
//STEPLIB  DD   DSN=USER.PGMLIB,DISP=SHR
//SYSOUT   DD   SYSOUT=A
//SORTIN   DD   DSN=A123456.SORT.SAMPIN,DISP=SHR
//SORTOUT  DD   DSN=A123456.SORT.SAMPOUT,DISP=OLD
//SORTCNTL DD *
   INCLUDE COND=(110,5,CH,EQ,C'ENGL')
/*
//SYSPRINT DD   SYSOUT=A

The sample PL/I program shown in Figure 1 calls DFSORT to sort the bookstore file by title. It specifies appropriate SORT and RECORD control statements, and a DFSORT main storage value of MAX.

Figure 1. Sample PL/I Program with SORT Commands
PLIPGM:  PROC OPTIONS(MAIN);

           DCL 1 MASTER_RECORD,
               5 TITLE_IN    CHAR(75),
               5 AUTH_LN_IN  CHAR(20),
               .
               .
               .
               5 PRICE_IN    BIN FIXED(31);

           DCL RETURN_CODE FIXED BIN(31,0);
           DCL MAXSTOR FIXED BIN(31,0);
             UNSPEC(MAXSTOR)='00000000'B||UNSPEC('MAX');
           .
           .
           .
           CALL PLISRTA (' SORT FIELDS=(1,75,CH,A) ',
                       ' RECORD TYPE=F,LENGTH=(173) ',
                       MAXSTOR,
                       RETURN_CODE);
           IF RETURN_CODE ¬= 0 THEN DO;
                PUT SKIP EDIT ('SORT FAILED')(A);
                CALL PLIRETC(RETURN_CODE);
           END;
           .
           .
           .
           CALL OUTPUT;
           .
           .
           .
           OUTPUT: PROCEDURE;
           .
           .
           .
           . Print a report from the sorted master file (SORTOUT)
           .
           .
           .
           END;
END PLIPGM;
Sumary
This chapter covered methods of calling DFSORT from COBOL, and PL/I.