• Aucun résultat trouvé

NAME CHAR(19), NUM CHARCl),

Dans le document OS PL/I Optimizing Compiler: (Page 167-171)

CHAPTER 5. DEFINING DATA SETS FOR STREAM FILES

3 NAME CHAR(19), NUM CHARCl),

3 SERNO CHAR(7), 3 PROF CHARCl8), 2 VREC CHARC3S), IN CHAR(80) DEF REC;

ON ENDFILECWORK) GO TO FINISH;

OPEN FILECWORK);

MORE: GET FILECWORK) EDITCIN,VREC)CAC4S),AC7*NUM»;

PUT FILECSYSPRINT) SKIP EDITCIN)CA);

GO TO MORE;

FINISH: CLOSE FILECWORK);

END PEOPLE;

/* //GO.WORK DD DSN=HPU8.PEOPLE,DISP=(OLD,DELETE)

Figure 51. Accessing a Data Set with Stream-Oriented Data Transmission

When using stream-oriented data transmission to access a data set you do not need to know the record format of the data set

(except when you must specify a block size); each GET statement transfers a discrete number of characters or graphics to your program from the data stream.

If you do give record-format information, it must be compatible with the actual structure of the data set. For example, if a data set is created with F-format records, a record size of 600 bytes, and a block size of 3600 bytes, you can access the

records as if they are U-format with a maximum block size of 3600 bytes; but if you specify a block size of 3500 bytes, your data will be truncated.

142 OS PL/I Optimizing Compiler: Programmer's Guide

EXAMPLE

PRINT FILES

The program in Figure 51 on page 142 reads the data set created by the program in Figure 48 on page 139 and uses the file

SYSPRINT to list the data it contains. (For details on SYPRINT, see "SYSIN and SYSPRINT Filesn on page 147.) Each set of data is read, by the GET statement, into two variables: FREC, which always contains 45 characters; and VREC, which always contains 35 characters. At each execution of the GET statement, VREC consists of the number of characters generated by the expression 7*NUM, together with sufficient blanks to bring the total number of characters to 35. The DISP parameter of the DD statement could read simply DISP=OLD; if DELETE is omitted, an existing data set will not be deleted.

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 62 on page 163 and Figure 63 on page 164. 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 magnetic-tape or 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.

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:

Character Action

b (blank) Space I line before printing

o

Space 2 lines before printing Space 3 lines before printing + No space before printing 1 Start new page

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 (see the CMS User's Guide or TSO User's Guide).

RECORD FORMAT

EXAMPLE

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 I 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 th~ file is associated with a data set on a magnetic-tape or dirsct-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 magnetic-tape or

direct-access device; you cannot change the record format

established for the data set when the file is first opened. If the line size specified in an OPEN statement conflicts with the record format already established~ the UNDEFINEDFILE condition will be 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 may 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:

BLKSIZE=129 LRECL=125 RECFM=VBA

Figure 52 on page 145 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 00 to 3590 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:

Record format =

V (the default for a PRINT file).

144 as PL/I Optimizing Compiler: Programmer's Guide

Record size =

98 (line size + 1 byte for print control character + 4 bytes for record control field).

Block size =

102 (record length + 4 bytes for block control field).

The program in Figure 67 on page 166 uses record-oriented data transmission to print the table created by the program in Figure 52.

//OPT715 JOB

//STEP1 EXEC PlIXClG //PlI.SYSIN DD *

SINE: PROC OPTIONS(MAIN)i

/*

DCl TABLE FILE STREAM OUTPUT PRINT,

DEG FIXED DEC(5,1) INIT(O), /* INITCO) FOR TEST IN ENDPAGE */

MIN FIXED DEC(3,l), /* INCREMENTS TO 1.0 IN DO-lOOP*/

PGNO FIXED DEC(2) INITCO);

ON ENDPAGE(TABlE) BEGIN;

DCl Ii

IF PGNO -= 0 THEN /* ! FOOTING */

PUT FIlE(TABlE) EDIT

C'PAGE',PGNO) ClINE(55),COl(80),A,F(3»i IF DEG ~= 360 THEN /* ! HEADING */

DO; PUT FIlE(TABLE) PAGE EDIT ('NATURAL SINES') (A)i

IF PGNO -= 0 THEN /* ! HEADING CONTINUED */

PUT FILE(TABLE) EDIT

(I (CONT"D)') (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;

ENDi

OPEN FILECTABLE) PAGESIZE(52) lINESIZE(93);

SIGNAL ENDPAGE(TABLE); /* HEADING - FIRST PAGE */

PUT FILE(TABLE) EDIT

CCDEG,CSIND(DEG+MIN) DO MIN = 0 TO .9 BY .1) DO DEG = 0 TO 359») (SKIPC2), 5 (COL(I), F(3), 10 F(9,4)

»;

PUT FILE(TABLE) SKIP(52)i

END SINE;

/* FORCE LAST PAGE FOOTING

(SIGNAL ENDPAGE CANNOT BE USED, WHEN PRINTING FOOTING PAST PAGESIZE-SEE ENDPAGE COND.) */

//GO.TABlE DD DSN=HPU8.SINES,DISP=(NEW,CATlG,DElETE), // UNIT=SYSDA,SPACE=(TRK,(l,l»,VOl=SER=nnnnnn Figure 52. Creating a Data Set Using a PRINT File

Dans le document OS PL/I Optimizing Compiler: (Page 167-171)