直接データ・セットにアクセスするために使用する DIRECT ファイルは、OUTPUT 属性、INPUT 属性、または UPDATE 属性を持つことができます。KEYED SEQUENTIAL ファイルを使用する場合とまったく同様に、レコードの読み取り、書き込 み、再書き込み、または削除が可能です。
図 23 は、直接データ・セットの更新の例を示しています。DIRECT UPDATE ファイルが使用され、キーによって新しいレコードが書き込まれます。ワークステーション VSAM では空のレコードは使用できないため、レコードが空かどうかを検査する必要はありません。
プログラムの後半では、更新済みファイルが印刷されます。ここでも、REGIONAL(1) にあるような空のレコードの検査は必要ありません。
/********************************************************************/
/* */
/* */
/* DESCRIPTION */
/* Update an ISAM direct data set by key. */
/* */
/* */
/* USAGE */
/* The following commands are required to establish */
/* the environment variables to run this program. */
/* */
/* SET DD:SYSIN=ISAM5.INP,RECSIZE(80) */
/* SET DD:NOS=ISAM4.OUT,AMTHD(ISAM),APPEND(Y) */
/* */
/* Note: This sample program is using the direct ISAM data set */
/* ISAM4.OUT created by the previous sample program CREATD. */
/* */
/********************************************************************/
UPDATD: proc options(main);
dcl Nos file record keyed
env(organization(relative));
dcl Sysin file input record;
dcl Sysin_Eof bit (1) init('0'b);
dcl Nos_Eof bit (1) init('0'b);
dcl 1 In_Area,
2 Name char(20),
2 (CNewNo,COldNo) char( 2),
2 In_Area_1 char( 1),
2 Code char( 1);
dcl IoField char(20);
dcl NewNo fixed(15);
dcl OldNo fixed(15);
dcl oncode builtin;
on endfile (Sysin) sysin_Eof = '1'b;
open file (Nos) direct update;
/* trap errors */
on key(Nos)
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;
/* update the direct data set */
read file(Sysin) into(In_Area);
do while(¬Sysin_Eof);
if CNewNo¬=' ' then
NewNo = CNewNo;
else
NewNo = 0;
if COldNo¬=' ' then
OldNo = COldNo;
else
OldNo = 0;
select(Code);
when ('A') write file(Nos) keyfrom(NewNo) from(Name);
when ('C')
do;
delete file(Nos) key(OldNo);
write file(Nos) keyfrom(NewNo) from(Name);
end;
when('D') delete file(Nos) key(OldNo);
otherwise put file(sysprint) skip list ('Invalid code:',Name);
end;
read file(Sysin) into(In_Area);
end;
close file(Sysin),file(Nos);
/* open and print updated file */
open file(Nos) sequential input;
on endfile (Nos) Nos_Eof = '1'b;
read file(Nos) into(IoField) keyto(CNewNo);
do while(¬Nos_Eof);
put file (sysprint) skip
edit (CNewNo,IoField)(a(5),a);
read file(Nos) into(IoField) keyto(CNewNo);
end;
close file(Nos);
end UPDATD;
An input file for this program might look like this:
NEWMAN,M.W. 5640 C
GOODFELLOW,D.T. 89 A
MILES,R. 23 D
HARVEY,C.D.W. 29 A
BARTLETT,S.G. 13 A
CORY,G. 36 D
READ,K.M. 01 A
PITT,W.H. 55 X
ROLF,D.F. 14 D
ELLIOTT,D. 4285 C
HASTINGS,G.M. 31 D
BRAMLEY,O.H. 4928 C