In a PL/I program, using a PRINT file provides a convenient means of controlling the layout of printed output from stream-oriented data transmission. PL/I automatically inserts print control characters in response to the PAGE, SKIP, and LINE options and format items.
You can apply the PRINT attribute to any STREAM OUTPUT file, even if you do not intend to print the associated data set directly. When a PRINT file is associated with a direct-access data set, the print control characters have no effect on the layout of the data set, but appear as part of the data in the records.
PL/I reserves the first byte of each record transmitted by a PRINT file for an American National Standard print control character, and inserts the appropriate characters automatically (see Printer-destined files).
PL/I handles the PAGE, SKIP, and LINE options or format items by inserting the appropriate control character in the records. If the SKIP or the LINE option specifies more than a 3-line space, PL/I inserts sufficient blank records with appropriate control characters to accomplish the required spacing.
If a PRINT file is being transmitted to a terminal device, the PAGE, SKIP, and LINE options never cause more than 3 lines to be skipped, unless formatted output is specified.
You can limit the length of the printed line produced by a PRINT file by either:
RECSIZE must include the extra byte for the print control character; it must be 1 byte larger than the length of the printed line. LINESIZE refers to the number of characters in the printed line; PL/I adds the print control character.
Do not vary the line size for a file during execution by closing the file and opening it again with a new line size.
Since PRINT files have a default line size of 120 characters, you need not give any record length information for them.
Figure 10 illustrates the use of a PRINT file and the printing options of stream-oriented data transmission statements to format a table and write it onto a direct-access device for printing on a later occasion. The table comprises the natural sines of the angles from 0° to 359° 54' in steps of 6'.
/********************************************************************/
/* */
/* DESCRIPTION */
/* Create a SEQUENTIAL data set. */
/* */
/* USAGE */
/* The following command is required to establish */
/* the environment variable to run this program: */
/* */
/* SET DD:TABLE=MYTAB.DAT,ASA(Y) */
/* */
/********************************************************************/
SINE: proc options(main);
put skip list('START CON3 TEST');
/* Build a table of SINE values. */
dcl Table file stream output print;
dcl Deg fixed dec(5,1) init(0); /* init(0) for endpage */
dcl Min fixed dec(3,1);
dcl PgNo fixed dec(2) init(0);
dcl Oncode builtin;
dcl I fixed dec(2);
on error
begin;
on error system;
display ('oncode = '|| Oncode);
end;
on endpage(Table)
begin;
if PgNo ¬= 0 then
put file(Table) edit ('page',PgNo)
(line(55),col(80),a,f(3));
if Deg ¬= 360 then
do;
put file(Table) page edit ('Natural Sines') (a);
put file(Table) edit ((I do I = 0 to 54 by 6))
(skip(3),10 f(9));
PgNo = PgNo + 1;
end;
else
put file(Table) page;
end;
open file(Table) pagesize(52) linesize(102);
signal endpage(Table);
put file(Table) edit
((Deg,(sind(Deg+Min) do Min = 0 to .9 by .1) do Deg = 0 to 359))
(skip(2), 5 (col(1), f(3), 10 f(9,4) ));
put file(Table) skip(52);
put skip list('END CON3 TEST');
end SINE;The statements in the ENDPAGE ON-unit insert a page number at the bottom of each page, and set up the headings for the following page.
The program in Figure 15 uses record-oriented data transmission to print the table created by the program in Figure 10.