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

DIRECT ファイルを用いたワークステーション VSAM キー順データ・セットへのアクセス

ワークステーション VSAM キー順データ・セットにアクセスするのに 使用する DIRECT ファイルをオープンするには、INPUT 属性、OUTPUT 属性 または UPDATE 属性を指定します。

DIRECT OUTPUT ファイルを使ってデータ・セットに レコードを追加するときに、そのデータ・セット にすでにあるレコードと同じキーをもつレコードを挿入しようとすると、KEY 条件が生じます。

DIRECT INPUT ファイルまたは DIRECT UPDATE ファイルを 使用すれば、KEYED SEQUENTIAL ファイルの場合と同様に、レコードの読み取り、書き込み、再書き込み、または削除が行えます。

図 21 に、キー順データ・セットを更新するために使用可能なメソッドの 1 つを示します。

図 21. ワークステーション VSAM キー順データ・セットの更新
 /********************************************************************/
 /*                                                                  */
 /*                                                                  */
 /*  DESCRIPTION                                                     */
 /*    Update an ISAM keyed data set by key.                         */
 /*                                                                  */
 /*                                                                  */
 /*  USAGE                                                           */
 /*    The following commands are required to establish              */
 /*    the environment variables to run this program:                */
 /*                                                                  */
 /*      SET DD:DIREC=ISAM2.OUT,AMTHD(ISAM)                          */
 /*      SET DD:SYSIN=ISAM3.INP,RECSIZE(80)                          */
 /*                                                                  */
 /*    Note: This program is using ISAM2.OUT file created by the     */
 /*          previous sample program NAMELD.                         */
 /*                                                                  */
 /********************************************************************/

  DIRUPDT: proc options(main);

   dcl Direc file record keyed update
       env(organization(indexed)
           recsize(23)
           keyloc(1)
           keylength(20)
          );

   dcl 1 IoArea,
         5 NewArea,
           10 Name char(20),
           10 Number char(3),
         5 Code char(1);

   dcl oncode builtin;
   dcl Eof bit(1) init('0'b);

   on endfile(sysin) Eof = '1'b;

   on key(Direc)
   begin;
      if oncode=51 then put file(sysprint) skip edit
         ('Not found: ',Name)(a(15),a);
      if oncode=52 then put file(sysprint) skip edit
         ('Duplicate: ',Name)(a(15),a);
   end;

   open file(Direc) direct update;
   get file(sysin) edit (Name,Number,Code) (a(20),a(3),a(1));
   do while (¬Eof);
      put file(sysprint) skip edit (' ',Name,'#',Number,' ',Code)
          (a(1),a(20),a(1),a(3),a(1),a(1));
      select (Code);
             when('A') write file(Direc) from(NewArea) keyfrom(Name);
             when('C') rewrite file(Direc) from(NewArea) key(Name);
             when('D') delete file(Direc) key(Name);
             otherwise put file(sysprint) skip edit
                ('Invalid code: ',Name) (a(15),a);
       end;
       get file(sysin) edit (Name,Number,Code) (a(20),a(3),a(1));
   end;

   close file(Direc);
   put file(sysprint) page;

   /* Display the updated file                          */

   open file(Direc) sequential input;

   Eof = '0'b;
   on endfile(Direc) Eof = '1'b;

   read file(Direc) into(NewArea);
   do while(¬Eof);
      put file(sysprint) skip edit(Name,Number)(a,a);
      read file(Direc) into(NewArea);
   end;
   close file(Direc);
 end DIRUPDT;

An input file for this program might look like this one:

NEWMAN,M.W.         516C
GOODFELLOW,D.T.     889A
MILES,R.               D
HARVEY,C.D.W.       209A
BARTLETT,S.G.       183A
CORY,G.                D
READ,K.M.           001A
PITT,W.H.              X
ROLF,D.E.              D
ELLIOTT,D.          291C
HASTINGS,G.M.          D
BRAMLEY,O.H.        439C

DIRECT 更新ファイルが使用され、ファイル SYSIN 内の レコードに渡されたコードにしたがって、データが変更されます。

A
新しいレコードの追加
C
既存名の番号の変更
D
レコードの削除

名前、番号、およびコードが読み取られ、そのコードの値に従って処理されます。KEY ON ユニットを使用して、誤ったキーに対する処置がとられます。更新が終了すると、ファイル DIREC はクローズされてから、属性 SEQUENTIAL INPUT でもう一度オープンされます。次に、このファイルは順次読み取られ、印刷されます。


Terms of use | Feedback

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