When a keyed data set is being loaded, you must open the associated file for KEYED SEQUENTIAL OUTPUT. You must present the records in ascending key order, and you must use the KEYFROM option.
If a keyed data set already contains some records, and you open the associated file with the SEQUENTIAL and OUTPUT attributes, you can add records at the end of the data set only. Again, you must present the records in ascending key order, and you must use the KEYFROM option. In addition, the first record you present must have a key greater than the highest key present on the data set.
Figure 21 is an example of a program that loads a workstation VSAM keyed data set. Within the PL/I program, a KEYED SEQUENTIAL OUTPUT file is used with a WRITE...FROM...KEYFROM statement. The data is presented in ascending key order. A keyed data set must be loaded in this manner. You can also use this program to process a DDM or SFS file by modifying the AMTHD specification.
/********************************************************************/ /* */ /* DESCRIPTION */ /* Load an ISAM keyed data set. */ /* */ /* */ /* 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=ISAM2.INP,RECSIZE(80) */ /* */ /********************************************************************/ NAMELD: proc options(main); put skip list('START ISAM2 TEST'); dcl Direc file record keyed sequential output env(organization(indexed) recsize(23) keyloc(1) keylength(20) ); dcl Eof bit(1) init('0'b); dcl 1 IoArea, 5 Name char(20), 5 Number char(3); on endfile(sysin) Eof = '1'b; open file(Direc); get file(sysin) edit(Name,Number) (a(20),a(3)); do while (¬Eof); write file(Direc) from(IoArea) keyfrom(Name); get file(sysin) edit(Name,Number) (a(20),a(3)); end; close file(Direc); put skip list('END ISAM2 TEST'); end NAMELD;
The input file for this program could be: ACTION,G. 162 BAKER,R. 152 BRAMLEY,O.H. 248 CHEESMAN,D. 141 CORY,G. 336 ELLIOTT,D. 875 FIGGINS,S. 413 HARVEY,C.D.W. 205 HASTINGS,G.M. 391 KENDALL,J.G. 294 LANCASTER,W.R. 624 MILES,R. 233 NEWMAN,M.W. 450 PITT,W.H. 515 ROLF,D.E. 114 SHEERS,C.D. 241 SURCLIFFE,M. 472 TAYLOR,G.C. 407 WONG, X-G. 509 WILTON,L.W. 404 WINSTONE,E.M. 307 VISWANATHAN, I. 411