When a direct data set is being loaded, you must open the associated file for OUTPUT. Use either a DIRECT or a SEQUENTIAL file.
For a DIRECT OUTPUT file, each record is placed in the position specified by the relative record number (or key) in the KEYFROM option of the WRITE statement (see Using keys for workstation VSAM data sets).
For a SEQUENTIAL OUTPUT file, use WRITE statements with or without the KEYFROM option. If you specify the KEYFROM option, the record is placed in the specified slot; if you omit it, the record is placed in the slot following the current position. There is no requirement for the records to be presented in ascending relative record number order. If you omit the KEYFROM option, you can obtain the relative record number of the written record by using the KEYTO option.
If you want to load a direct data set sequentially, without use of the KEYFROM or KEYTO options, you are not required to use the KEYED attribute.
It is an error to attempt to load a record into a position that already contains a record. If you use the KEYFROM option, the KEY condition is raised; if you omit it, the ERROR condition is raised.
Figure 23 is an example of a program that defines and loads a workstation VSAM direct data set. In the PL/I program, the data set is loaded with a DIRECT OUTPUT file and a WRITE...FROM...KEYFROM statement is used. You can also use this program to process a DDM or SFS file by modifying the AMTHD specification.
If the data were in order and the keys in sequence, it would be possible to use a SEQUENTIAL file and write into the data set from the start. The records would then be placed in the next available slot and given the appropriate number. The number of the key for each record could be returned using the KEYTO option.
/**********************************************************************/
/* DESCRIPTION */
/* Load an ISAM direct data set. */
/* */
/* USAGE */
/* The following commands are required to establish */
/* the environment variables to run this program: */
/* */
/* SET DD:SYSIN=ISAM4.INP,RECSIZE(80) */
/* SET DD:NOS=ISAM4.OUT,AMTHD(ISAM),RECCOUNT(100) */
/*********************************************************************/
CREATD: proc options(main);
put skip list('ISAM4 TEST START');
dcl Nos file record output direct keyed
env(organization(relative) recsize(20) );
dcl Sysin file input record;
dcl 1 In_Area,
2 Name char(20),
2 Number char( 2);
dcl Sysin_Eof bit (1) init('0'b);
dcl Ntemp fixed(15);
on endfile (Sysin) Sysin_Eof = '1'b;
open file(Nos);
read file(Sysin) into(In_Area);
do while(¬Sysin_Eof);
Ntemp = Number;
write file(Nos) from(Name) keyfrom(Ntemp);
put file(sysprint) skip edit (In_Area) (a);
read file(Sysin) into(In_Area);
end;
close file(Nos);
put skip list('ISAM4 TEST END');
end CREATD;
This could be the input file for this program: ACTION,G. 12 BAKER,R. 13 BRAMLEY,O.H. 28 CHEESNAME,L. 11 CORY,G. 36 ELLIOTT,D. 85 FIGGINS,E.S. 43 HARVEY,C.D.W. 25 HASTINGS,G.M. 31 KENDALL,J.G. 24 LANCASTER,W.R. 64 MILES,R. 23 NEWMAN,M.W. 40 PITT,W.H. 55 ROLF,D.E. 14 SHEERS,C.D. 21 SURCLIFFE,M. 42 TAYLOR,G.C. 47 WILTON,L.W. 44 WINSTONE,E.M. 37