Rational Developer for System z
PL/I for Windows, Version 8.0, プログラミング・ガイド

連続データ・セットの例

連続データ・セットを作成し、それにアクセスする方法 については、図 14 のプログラムに示されています。このプログラムでは、INPUT1 および INPUT2 という 2 つの PL/I ファイルの内容をマージし、OUT という新規 PL/I ファイルに書き込んでいます。INPUT1 および INPUT2 は、それぞれディスク・ファイル EVENS.INP および ODDS.INP に関連付けられており、ASCII 照合シーケンスに配置された 6 バイトのレコードを格納しています。

図 14. 連続データ・セットのマージ、ソート、作成と連続データ・セットへのアクセス
 /********************************************************************/
 /*                                                                  */
 /*  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

図 15 のプログラムは、レコード単位データ伝送を 使って、図 10 のプログラムが作成するテーブルを 印刷します。

図 15. レコード単位データ伝送の印刷
 /********************************************************************/
 /*                                                                  */
 /*  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)