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

Examples of consecutive data sets

Creating and accessing consecutive data sets are illustrated in the program in Figure 14. The program merges the contents of two PL/I files INPUT1 and INPUT2, and writes them onto a new PL/I file, OUT. INPUT1 and INPUT2 are associated with the disk files EVENS.INP and ODDS.INP, respectively, and contain 6-byte records arranged in ASCII collating sequence.

Figure 14. Merge Sort--Creating and accessing a consecutive data set
 /********************************************************************/
 /*                                                                  */
 /*  DESCRIPTION                                                     */
 /*    Merge 2 data sets creating a CONSECUTIVE data set.            */
 /*                                                                  */
 /*  USAGE                                                           */
 /*    The following commands are required to establish              */
 /*    the environment variables to run this program:                */
 /*                                                                  */
 /*      SET DD:OUT=CON4.DAT                                         */
 /*      SET DD:INPUT1=EVENS.INP                                     */
 /*      SET DD:INPUT2=ODDS.INP                                      */
 /*                                                                  */
 /********************************************************************/

  MERGE: proc options(main);

    dcl Input1 file record sequential input env(recsize(6));
    dcl Input2 file record sequential input env(recsize(6));
    dcl Out    file record sequential env(recsize(15));
    dcl Sysprint    file print;              /* normal print file    */

    dcl Input1_Eof  bit(1) init('0'b);       /* eof flag for Input1  */
    dcl Input2_Eof  bit(1) init('0'b);       /* eof flag for Input2  */
    dcl Out_Eof     bit(1) init('0'b);       /* eof flag for Out     */
    dcl True        bit(1) init('1'b);       /* constant True        */
    dcl False       bit(1) init('0'b);       /* constant False       */

    dcl Item1       char(6) based(a);        /* item from Input1     */
    dcl Item2       char(6) based(b);        /* item from Input2     */
    dcl A           pointer;                 /* pointer var          */
    dcl B           pointer;                 /* pointer var          */

    on endfile(Input1) Input1_Eof = True;
    on endfile(Input2) Input2_Eof = True;
    on endfile(Out)    Out_Eof    = True;

    open file(Input1),
         file(Input2),
         file(Out) output;

    read file(Input1) set(A);                /* priming read         */
    read file(Input2) set(B);
    do while ((Input1_Eof = False) & (Input2_Eof = False));
      if Item1 > Item2 then
        do;
          write file(Out) from(Item2);
          put file(Sysprint) skip edit('1>2', Item1, Item2)
              (a(5),a,a);
          read file(Input2) set(B);
        end;
      else
        do;
          write file(Out) from(Item1);
          put file(Sysprint) skip edit('1<2', Item1, Item2)
              (a(5),a,a);
          read file(Input1) set(A);
        end;
    end;

    do while (Input1_Eof = False);           /* Input2 is exhausted  */
      write file(Out) from(Item1);
      put file(Sysprint) skip edit('1', Item1) (a(2),a);
      read file(Input1) set(A);
    end;

    do while (Input2_Eof = False);           /* Input1 is exhausted  */
      write file(Out) from(Item2);
      put file(Sysprint) skip edit('2', Item2) (a(2),a);
      read file(Input2) set(B);
    end;

    close file(Input1), file(Input2), file(Out);
    put file(Sysprint) page;
    open file(Out) sequential input;

    read file(Out) into(Item1);              /* display Out file     */
    do while (Out_Eof = False);
      put file(Sysprint) skip edit(Item1) (a);
      read file(Out) into(Item1);
    end;
    close file(Out);

  end MERGE;
Here is a sample of EVENS.INP:

BBBBBB
DDDDDD
FFFFFF
HHHHHH
JJJJJJ

Here is a sample of ODDS.INP:

AAAAAA
CCCCCC
EEEEEE
GGGGGG
IIIIII
KKKKKK

The program in Figure 15 uses record-oriented data transmission to print the table created by the program in Figure 10.

Figure 15. Printing record-oriented data transmission
 /********************************************************************/
 /*                                                                  */
 /*  DESCRIPTION                                                     */
 /*    Print a SEQUENTIAL data set created by the SINE program.      */
 /*                                                                  */
 /*  USAGE                                                           */
 /*    The following commands are required to establish              */
 /*    the environment variables to run this program:                */
 /*                                                                  */
 /*      SET DD:TABLE=MYTAB.DAT                                      */
 /*      SET DD:PRINTER=PRN                                          */
 /*                                                                  */
 /********************************************************************/

 PRT: proc options(main);

   dcl Table       file record input sequential;
   dcl Printer     file record output seql
                        env(recsize(200) ctlasa);
   dcl Line        char(102) var;

   dcl Table_Eof   bit(1) init('0'b);       /* Eof flag for Table   */
   dcl True        bit(1) init('1'b);       /* constant True        */
   dcl False       bit(1) init('0'b);       /* constant False       */


   on endfile(Table) Table_Eof = True;

   open file(Table),
        file(Printer);

   read file(Table) into(Line);             /* priming read         */

   do while (Table_Eof = False);
     if Line='' then                        /* insert blank lines   */
        Line= ' ';
     write file(Printer) from(Line);
     read file(Table) into(Line);
   end;

   close file(Table),
         file(Printer);
 end PRT;

Terms of use | Feedback

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