Creating and accessing consecutive data sets are illustrated in the program in Figure 14. The program merges the contents of two PL/I files INPUT1 and INPUT2, and writes them onto a new PL/I file, OUT. INPUT1 and INPUT2 are associated with the disk files EVENS.INP and ODDS.INP, respectively, and contain 6-byte records arranged in ASCII collating sequence.
/********************************************************************/
/* */
/* DESCRIPTION */
/* Merge 2 data sets creating a CONSECUTIVE data set. */
/* */
/* USAGE */
/* The following commands are required to establish */
/* the environment variables to run this program: */
/* */
/* SET DD:OUT=CON4.DAT */
/* SET DD:INPUT1=EVENS.INP */
/* SET DD:INPUT2=ODDS.INP */
/* */
/* */
/********************************************************************/
MERGE: proc options(main);
put skip list('START CON4 TEST');
dcl Input1 file record sequential input env(recsize(6));
dcl Input2 file record sequential input env(recsize(6));
dcl Out file record sequential env(recsize(15));
dcl Sysprint file print; /* normal print file */
dcl Input1_Eof bit(1) init('0'b); /* eof flag for Input1 */
dcl Input2_Eof bit(1) init('0'b); /* eof flag for Input2 */
dcl Out_Eof bit(1) init('0'b); /* eof flag for Out */
dcl True bit(1) init('1'b); /* constant True */
dcl False bit(1) init('0'b); /* constant False */
dcl Item1 char(6) based(a); /* item from Input1 */
dcl Item2 char(6) based(b); /* item from Input2 */
dcl A pointer; /* pointer var */
dcl B pointer; /* pointer var */
on endfile(Input1) Input1_Eof = True;
on endfile(Input2) Input2_Eof = True;
on endfile(Out) Out_Eof = True;
open file(Input1),
file(Input2),
file(Out) output;
read file(Input1) set(A); /* priming read */
read file(Input2) set(B);
do while ((Input1_Eof = False) & (Input2_Eof = False));
if Item1 > Item2 then
do;
write file(Out) from(Item2);
put file(Sysprint) skip edit('1>2', Item1, Item2)
(a(5),a,a);
read file(Input2) set(B);
end;
else
do;
write file(Out) from(Item1);
put file(Sysprint) skip edit('1<2', Item1, Item2)
(a(5),a,a);
read file(Input1) set(A);
end;
end;
do while (Input1_Eof = False); /* Input2 is exhausted */
write file(Out) from(Item1);
put file(Sysprint) skip edit('1', Item1) (a(2),a);
read file(Input1) set(A);
end;
do while (Input2_Eof = False); /* Input1 is exhausted */
write file(Out) from(Item2);
put file(Sysprint) skip edit('2', Item2) (a(2),a);
read file(Input2) set(B);
end;
close file(Input1), file(Input2), file(Out);
put file(Sysprint) page;
open file(Out) sequential input;
read file(Out) into(Item1); /* display Out file */
do while (Out_Eof = False);
put file(Sysprint) skip edit(Item1) (a);
read file(Out) into(Item1);
end;
close file(Out);
put skip list('END CON4 TEST');
end MERGE;
Here is a sample of evens.inp: BBBBBB DDDDDD FFFFFF HHHHHH JJJJJJ Here is a sample of odds.inp: AAAAAA CCCCCC EEEEEE GGGGGG IIIIII KKKKKK
The program in Figure 15 uses record-oriented data transmission to write the table created by the program in Figure 10 to a file called out.txt.
/********************************************************************/ /* */ /* DESCRIPTION */ /* Write a SEQUENTIAL data set created by the SINE program to a */ /* file. */ /* */ /* USAGE */ /* The following commands are required to establish */ /* the environment variables to run this program: */ /* */ /* SET DD:TABLE=MYTAB.DAT */ /* SET DD:PRINTER=PRN */ /* */ /********************************************************************/ PRT: proc options(main); put skip list('START CON5 TEST'); dcl Table file record input sequential; dcl Output file record output seql env(recsize(200)); dcl Line char(102) var; dcl Table_Eof bit(1) init('0'b); /* Eof flag for Table */ dcl True bit(1) init('1'b); /* constant True */ dcl False bit(1) init('0'b); /* constant False */ on endfile(Table) Table_Eof = True; open file(Table), file(Output); read file(Table) into(Line); /* priming read */ do while (Table_Eof = False); if Line='' then /* insert blank lines */ Line= ' '; write file(Output) from(Line); read file(Table) into(Line); end; close file(Table), file(Output); put skip list('END CON5 TEST'); end PRT;