A DIRECT file used to access a direct data set can have the OUTPUT, INPUT, or UPDATE attribute. You can read, write, rewrite, or delete records exactly as though you were using a KEYED SEQUENTIAL file.
Figure 24 shows a direct data set being updated. A DIRECT UPDATE file is used and new records are written by key. You do not need to check for the records being empty, because the empty records are not available under workstation VSAM. You can also use this program to process a DDM or SFS file by modifying the AMTHD specification.
In the second half of the program, the updated file is printed. Again, you do not need to check for the empty records as there is in 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); put skip list('ISAM5 TEST START'); 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);
put skip list('ISAM5 TEST END');
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
WONG,X-G. 20 C
PITT,W.H. 55 X
ROLF,D.F. 14 D
ELLIOTT,D. 4285 C
HASTINGS,G.M. 31 D
BRAMLEY,O.H. 4928 C
VISWANATHAN, I. 4115 D