Both the operating system and the PL/I language include features that facilitate the formatting of printed output. The operating system allows you to use the first byte of each record for a print control character. The control characters, which are not printed, cause the printer to skip to a new line or page. (Tables of print control characters are given in Figure 29 and Table 17.)
In a PL/I program, the use of a PRINT file provides a convenient means of controlling the layout of printed output from stream-oriented data transmission. The compiler 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.
PRINT files opened with FB or VB will cause the UNDEFINEDFILE condition to be raised. PRINT files should be opened with the "A" option; i.e., FBA or VBA.
The compiler 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.
A PRINT file uses only the following five print control characters:
The compiler handles the PAGE, SKIP, and LINE options or format items by padding the remainder of the current record with blanks and inserting the appropriate control character in the next record. If SKIP or LINE specifies more than a 3-line space, the compiler inserts sufficient blank records with appropriate control characters to accomplish the required spacing. In the absence of a print control option or format item, when a record is full the compiler inserts a blank character (single line space) in the first byte of the next record.
If a PRINT file is being transmitted to a terminal, the PAGE, SKIP, and LINE options will 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 either by specifying a record length in your PL/I program (ENVIRONMENT attribute) or in a DD statement, or by giving a line size in an OPEN statement (LINESIZE option). The record length must include the extra byte for the print control character, that is, it must be 1 byte larger than the length of the printed line (5 bytes larger for V-format records). The value you specify in the LINESIZE option refers to the number of characters in the printed line; the compiler adds the print control character.
The blocking of records has no effect on the appearance of the output produced by a PRINT file, but it does result in more efficient use of auxiliary storage when the file is associated with a data set on a direct access device. If you use the LINESIZE option, ensure that your line size is compatible with your block size. For F-format records, block size must be an exact multiple of (line size+1); for V-format records, block size must be at least 9 bytes greater than line size.
Although you can vary the line size for a PRINT file during execution by closing the file and opening it again with a new line size, you must do so with caution if you are using the PRINT file to create a data set on a direct access device. You cannot change the record format that is established for the data set when the file is first opened. If the line size you specify in an OPEN statement conflicts with the record format already established, the UNDEFINEDFILE condition is raised. To prevent this, either specify V-format records with a block size at least 9 bytes greater than the maximum line size you intend to use, or ensure that the first OPEN statement specifies the maximum line size. (Output destined for the printer can be stored temporarily on a direct access device, unless you specify a printer by using UNIT=, even if you intend it to be fed directly to the printer.)
Since PRINT files have a default line size of 120 characters, you need not give any record format information for them. In the absence of other information, the compiler assumes V-format records. The complete default information is:
Figure 27 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'.
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 DD statement defining the data set created by this program includes no record-format information. The compiler infers the following from the file declaration and the line size specified in the statement that opens the file TABLE:
The program in Figure 31 uses record-oriented data transmission to print the table created by the program in Figure 27.
%PROCESS INT F(I) AG A(F) OP STG NEST X(F) SOURCE ;
%PROCESS LIST;
SINE: PROC OPTIONS(MAIN);
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;
ON ERROR
BEGIN;
ON ERROR SYSTEM;
DISPLAY ('ONCODE = '|| ONCODE);
END;
ON ENDPAGE(TABLE)
BEGIN;
DCL I;
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);
IF PGNO ¬= 0 THEN
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(93);
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);
END SINE;Data-directed and list-directed output to a PRINT file are aligned on preset tabulator positions. See Figure 14 and Figure 28 for examples of declaring a tab table. The definitions of the fields in the table are as follows:
You can override the default PL/I tab settings for your program by causing the linkage editor to resolve an external reference to PLITABS. To cause the reference to be resolved, supply a table with the name PLITABS, in the format described above.
To supply this tab table, include a PL/I structure in your source program with the name PLITABS, which you must declare to be STATIC EXTERNAL in your MAIN procedure or in a program linked with your MAIN procedure. An example of the PL/I structure is shown in Figure 28. This example creates three tab settings, in positions 30, 60, and 90, and uses the defaults for page size and line size. Note that TAB1 identifies the position of the second item printed on a line; the first item on a line always starts at the left margin. The first item in the structure is the offset to the NO_OF_TABS field; FILL1, FILL2, and FILL3 can be omitted by adjusting the offset value by –6.
DCL 1 PLITABS STATIC EXT,
2 (OFFSET INIT(14),
PAGESIZE INIT(60),
LINESIZE INIT(120),
PAGELENGTH INIT(0),
FILL1 INIT(0),
FILL2 INIT(0),
FILL3 INIT(0),
NO_OF_TABS INIT(3),
TAB1 INIT(30),
TAB2 INIT(60),
TAB3 INIT(90)) FIXED BIN(15,0);