• Aucun résultat trouvé

Teleprocessing is d1SCUSSed in chapter 12

Dans le document OS PL/I (Page 134-139)

-Record-Oriented Transmission.-) These blocks allow the data set to be transmitted

Chapter

10:

Input and output

121

and processed in portions rather than being transmitted in its entirety before any processing is carried out. For processing purposes, each block may consist of logical subdivisions called records, each of which contains one or more data items. A block can comprise part of a record, a single record, or several records. (Sometimes a block is called a physical record, because i t is the unit of data that is physically transmitted to and from a volume, and its logical subdivisions are called logical records.)

When a block contains two or more records, the records are said to be blocked.

Blocked records permit more compact and efficient use of auxiliary storage. The use of blocked records can also improve the throughput of a program where a large

number of short records are to be processed, by reducing the number of physical input/output operations.

In data sets with VSAM organization, the data items are arranged in control

intervals, which are in turn arranged in control areas. For processing purposes, the data items within a control interval are arranged in logical records. A control interval may contain one or more logical records, and a logical record may span two or more control intervals. Further

information on the structure of VSAM data sets is given in the Programmer's Guide for the relevant compiler.

Most data processing applications are concerned with logical records rather than Iblocks or control intervals. Therefore,

the input and output statements of PL/I generally refer to logical records; this allows the programmer to concentrate on the data to be processed, without being

directly concerned about its physical organization in external storage.

INFORMATION INTERCHANGE CODES

In system/360 and System/310, the standard code used to represent data, both in main storage and on auxiliary storage, is EBCDIC

(extended binary-coded-decimal interchange code). In general, PL/I programs compiled by the optimizing or checkout compiler use EBCDIC to record all character data. The operating system does, however, support the use of an alternative code, namely ASCII

(American Standard code for Information Interchange), to represent data on

auxiliary storage, and such data sets may be read or created using PL/I. The support is limited to data sets held on magnetic tape.

122 OS PL/I CKT AND OPT LRM PART I

Translation between the two codes is performed by the operating system. Apart from the options specified in the

ENVIRONMENT attribute, the same PL/I

program may be used to handle an ASCII data set as would be used for a standard EBCDIC data set. On output, translation from EBCDIC to ASCII is performed immediately before data is written from a buffer to external storage. On input, translation is

pe~formed from ASCII to EBCDIC as soon as a buffer is filled with data.

In PL/I, only CHARACTER data may be written onto an ASCII data set. Each character in the ASCII code is represented by a seven-bit pattern and there are 128 such patterns. In EBCDIC, each character has an eight-bit pattern, and there are 256 possibilities. The ASCII set includes a substitute character (the SUB control character) that is used to represent EBCDIC characters having no valid ASCII code. (In the American National Standards Institute table, this is the character having the column 1, row 10 position.) Upon reading this data, the character would be

translated to the EBCDIC SUB character, which has the bit pattern 00111111.

Files

To allow a source program to deal primarily with the logical aspects of data rather than with its physical organization in a data set, PL/I employs a symbolic

representation of a data set called a file.

This symbolic representation determines how input and output statements access and process the associated data set. Unlike a data set, however, a file has significance only within the source program and does not exist as a physical entity external to the program.

PL/I requires that an identifier which represents

a

file be declared with the FILE attribute. Such an identifier may either be a file constant or a file variable. A file variable is a data item to which a file constant can be assigned. After assignment, a reference to the file variable has the same significance as a reference to the assigned file constant.

Each data set processed by a PL/I program must be associated with a file constant identifier.

File constants: The individual

characteristics of eacb file are described with keywords called file description attributes. The following lists show the attributes that apply to each type of data transmission:

stream-oriented Transmission FILE

STREAM INPUT OUTPUT PRINT ENVIRONMENT

Record-Oriented Transmission FILE

RECORD INPUT OUTPUT UPDATE SEQUENTIAL DIRECT TRANSIENT BUFFERED UNBUFFERED BACKWARDS KEYED EXCLUSIVE ENVIRONMENT

File variables: A file variable is an identifier that has the attributes FILE and VARIABLE; i t cannot have any of the file description attributes (except FILE). File variables can be collected into arrays or structures. Note that the VARIABLE

attribute can be implied by, for example, the dimension attribute.

File expressions.: A file expression can be a reference to a file constant, a file variable, or a function reference which returns a value with the FILE attribute.

A detailed description of each of these attributes appears in section I,

·At~ributes.· The discussions below give a brief description of each of the file description attributes and show how these attributes are declared for a file.

FILE ATTRIBUTE

The FILE attribute indicates that the

associated identifier is a file constant or variable. For example, the identifier MASTER is declared to be a file constant in the following statement:

DECLARE MASTER FILE;

In the following statement, the

identifier ACCOUNT is declared to be a file variable, and ACCT1, ACCT2, ••• are

declared to be file constants; the file constants may subsequently be assigned to the file variable.

DECLARE ACCOUNT FILE VARIABLE,

~\.

ACCTl FILE, ACCT2 FILE,

The following example shows how the VARIABLE attribute may be implied.

DECLARE PAYREC(10) FILE;

PAYREC(I), where I has a value from 1 to 10, has the attribute FILE by explicit declaration and the attribute VARIABLE by implication of the dimension attribute (10) in the DECLARE statement.

The attributes associated with a file constant fall into two categories:

alternative attributes and additive attributes. An alternative attribute is one that is chosen from a group of

attributes. If no explicit or implicit declaration is given for one of the alternative attributes in a group and i f one of the alternatives is required, a default attribute is assumed.

An additive attribute is one that must be stated explicitly or is implied by another explicitly stated attribute. The additive attribute KEYED is implied by the DIRECT attribute. The additive attribute PRINT can be implied by the standard output file name SYSPRINT. An additive attribute can never be implied by default.

~ With the exception of the INTERNAL and EXTERNAL scope attributes, all the alternative and additive attributes imply the FILE attribute. Therefore, the FILE attribute need not be specified for a file that has at least one of the alternative or additive attributes already specified explicitly.

ALTERNATIVE ATTRIBUTES

PL/I provides five groups of alternative file attributes. Each group (except scope, which is discussed in section I,

"Attributes") is discussed individually.

Following is a list of the groups.

Chapter 10: Input and Output 123

Group Alternative Default

~ Attributes Attribute

Osage STREAM

I

RECORD STREAM Function INPUT

I

OUTPUT

I

UPDATE INPUT Access SEQUENTIAL

I

DIRECT I SEQUENTIAL

TRANSIENT

Buffering BUFFERED

I

UNBUFFERED BUFFERED (for SEQUENTIAL and

TRANSIENT files);

UNBUFFERED (for DIRECT files) Scope EXTERNAL

I

INTERNAL EXTERNAL The scope attributes are discussed in detail in section I, "Attributes."

STREAM and RECORD Attributes

The STREAM and RECORD attributes describe the type of data transmission (stream-oriented or record-(stream-oriented) to be used in input and output operations for the file.

The STREAM attribute causes a file to be treated as a continuous stream of data items recorded only in character form.

The RECORD attribute causes a file to be treated as a sequence of records, each record consisting of one or more data items recorded in any internal form.

DECLARE MASTER FILE RECORD, DETAIL FILE STREAM;

INPUT, OUTPUT, and UPDATE Attributes

The function attributes determine the direction of data transmission permitted for a file. The INPUT attribute applies to files that are to be read only. The OUTPUT attribute applies to files that are to create or, in some cases, extend data sets.

The UPDATE attribute (which applies only to RECORD files) describes a file that is to be used for both input and output; i t allows records to be inserted into an

existing data set and other records already in that data set to be altered.

124 OS PL/I CKT AND OPT LRM PART I

SEQUENTIAL, DIRECT and TRANSIENT Attributes

The access attributes apply only to a file with the RECORD attribute, and describe how the records in the file are to be accessed.

The SEQUENTIAL attribute specifies that records in the data set are to be accessed in physical sequence or in key sequence I order. For certain data set organizations, la file with the SEQUENTIAL attribute can lalso be used for random access or for a Imixture of random and sequential access.

lIn this case, the file must have the ladditive attribute KEYED.

The DIRECT attribute specifies that records in a data set may be accessed in any order. The location of the record in the data set is determined by a character-string "key": therefore, the DIRECT

attribute implies the KEYED attribute. The associated data set must be in a direct-access volume.

The TRANSIENT attribute applies to files used for teleprocessing applications. A TRANSIENT file is associated with a data set which consists of a queue of messages.

The message queue data set contains

messages originating from and destined for remote terminals while in transit between a message control program and the PL/I

message processing program. The action of reading a record removes that record from the data set. Access is sequential, but the file must have the KEYED attribute since a key is used to identity the terminal concerned; a buffer is always used, and so the file must also have the BUFFERED attribute. Teleprocessing is discussed in chapter 12, "Record-Oriented Transmission."

BUFFERED and UNBUFFERED Attributes

The buffering attributes apply only to RECORD files. The BUFFERED attribute indicates that records transmitted to and from a file must pass through an

intermediate internal-storage area. If BUFFERED is specified, data transmission is, in most cases, overlapped automatically with processing.

The UNBUFFERED attribute indicates that a record in a data set need not pass

through a buffer but may be transmitted directly to and from the main storage associated with a variable. A file with the UNBUFFERED attribute must not be blocked. When UNBUFFERED is specified, data transmission is not overlapped

automatically with processing; the p,rogrammer must use the EVENT option to achieve such overlapping.

The UNBUFFERED attribute is assumed for DIRECT files unless BUFFERED is specified explicitly. The UNBUFFERED attribute is not allowed for TRANSIENT files.

Note: Specification of UNBUFFERED does not preclude the use of buffers. In nearly all cases, "hidden buffers" are required.

These cases are listed in the discussion of the BUFFERED and UNBUFFERED attributes in section I, "Attributes."

ADDITIVE ATTRIBUTES

The additive attributes are:

PRINT BACKWARDS KEYED EXCLUSIVE

ENVIRONMENT (option-list)

PRINT Attribute

The PRINT attribute applies only to files with the STREAM and OUTPUT attributes. It indicates that the file is eventually to be printed, that is, the data associated with the file is to appear on printed pages, although i t may first be written on some other medium. The PRINT attribute causes the initial byte of each record of the associated data set to be reserved for a printer control character.

BACKWARDS Attribute

The BACKWARDS attribute applies only to SEQUENTIAL RECORD INPUT files and only to data sets on magnetic tape. I t indicates that a file is to be accessed in reverse order, beginning with the last record and proceeding through the file until the first record is accessed.

KEYED Attribute

The KEYED attribute applies only to files

with the RECORD attribute. It indicates that records in the file can be accessed using one of the key options (KEY, KEYTO, or KEYFROM) of data transmission statements or of the DELETE statement. Note that the KEYED attribute does not necessarily

indicate that the actual keys exist on, or are to be written in, or are to be read from the data set: consequently, i t need not be specified unless one of the key options is to be used. The nature and use of keys is discussed in detail in chapter 12, "Record-Oriented Transmission."

EXCLUSIVE Attribute

When access to a record is restricted to one task, the record is said to be locked by that task. The EXCLUSIVE attribute, which can be specified for DIRECT UPDATE files only, provides a temporary locking mechanism to prevent one task from

interfering with an operation by another task. I t can be suppressed by the NOLOCK option on the READ statement. Figure 10.1 shows the effects of various operations on an EXCLUSIVE file.

The EXCLUSIVE attribute will also lock a record on a data set that is shared between two PLiI jobs in a multi-programming

environment. The effect is as for sharing between two tasks.

I The EXCLUSIVE attribute, the UNLOCK I statement, and the NOLOCK option of the IREAD statement have no effect for a file lassociated with a VSAM data set.

ENVIRONMENT Attribute

The ENVIRONMENT attribute provides information that allows the compiler to determine the method of accessing the data associated with a file. It specifies the phySical organization of the data set that will be associated with the file, and indicates how the data set is to be handled.

The general format of the ENVIRONMENT attribute is

ENVIRONMENT (option-list)

The ENVIRONMENT attribute can be given in a file declaration or as an option of the CLOSE statement. When ENVIRONMENT is specified in a CLOSE statement, the only option allowed is LEAVE or REREAD.

The options appropriate to the two types of

Chapter 10: Input and output 125

r---,

Attempted

I

current state of Addressed Record

1---Operation I Unlocked I Locked by this task

I

Locked by another task

~---

---READ NOLOCK Proceed Proceed Wait for unlock

READ 11. Lock record Proceed Wait for unlock

12.

Proceed

DELETE/REWRITE 11. Lock record 11. Proceed Wait for unlock

12.

Proceed

12.

Unlock1 record

13.

Unlock1 record I

UNLOCK No effect Unlock record No effect

CLOSE FILE IRaise ERROR if there are records locked by another task. Otherwise, lunlock all records locked in this task, and proceed with closing.

Terminate Task IUnlock all records locked by task. Close file, i f opened in this taskl

---1

1The unlocking occurs at the end of the operation, on completion of anyon-units

I

entered because of the operation (that is, at the corresponding WAIT statement when I the EVENT option has been specified). If the EVENT option has been specified with a I READ statement, the operation is not completed until the corresponding WAIT statement I is reached; in the meantime, no attempt to delete or rewrite the record should be

I

made.

I

L---J

Figure 10.1. Effect of operations on EXCLUSIVE files

data transmission are described in chapter 11, ·Stream-Oriented Transmission,· and chapter 12, wRecord-Oriented Transmission,·

both in Part I.

Dans le document OS PL/I (Page 134-139)