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

Calling PLISRTB

Figure 39. PLISRTB--Sorting from input-handling routine to output data set
/*******************************************************************/
/*                                                                 */
/*  DESCRIPTION                                                    */
/*    Sorting from an input-handling routine to an output data set */
/*                                                                 */
/*  Use the following statements:                                  */
/*                                                                 */
/*    set dd:sysin=ex107.dat,type(crlf),lrecl(80)                  */
/*    set dd:sortout=ex107.out,type(crlf),lrecl(80)                */
/*                                                                 */
/*******************************************************************/
 ex107:  proc options(main);

     dcl Return_code fixed bin(31,0);

     call plisrtb (' SORT FIELDS=(7,74,CH,A) ',
                  ' RECORD TYPE=F,LENGTH=(80) ',
                  0,
                  Return_code,
                  e15x);
     select(Return_code);
       when(0)  put skip edit
           ('Sort complete return_code 0') (a);
       when(16) put skip edit
           ('Sort failed, return_code 16') (a);
       other   put skip edit
           ('Invalid return_code = ',Return_code)(a,f(2));
     end /* Select */;
         /* Set pl/i return code to reflect success of sort    */
     call pliretc(Return_code);

 e15x:   /* Input-handling routine gets records from the input
            stream and puts them before they are sorted        */
     proc returns (char(80));
          dcl sysin file stream input,
              Infield char(80);

          on endfile(sysin) begin;
             put skip(3) edit ('End of sort program input')(a);
             call pliretc(8);  /* Signal that last record has
                                  already been sent to sort    */
             goto ende15;
             end;

           get file (sysin) edit (infield) (l);
           put skip edit (infield)(a(80)); /*  Print input     */
           call pliretc(12);  /* Request sort to include current
                                 record and return for more    */
          return(Infield);
    ende15:
          end e15x;
 end ex107;

Content of EX107.DAT to be used with Figure 39

003329HOOKER S.W. RIVERDALE, SATCHWELL LANE, BACONSFIELD
002886BOOKER R.R. ROTORUA, LINKEDGE LANE, TOBLEY
003077ROOKER & SON, LITTLETON NURSERIES, SHOLTSPAR
059334HOOK E.H. 109 ELMTREE ROAD, GANNET PARK, NORTHAMPTON
073872HOME TAVERN, WESTLEIGH
000931FOREST, IVER, BUCKS
Rational Developer for System z
PL/I for Windows, Version 8.0, Programming Guide