• Aucun résultat trouvé

I (character-string-

Dans le document OS PL/I (Page 194-197)

I

SEQUENTIAL INPUT

I

ILOCATE variable FILE(file-expr) I SET (pointer-variable)

I KEYFROM(expression);

I

I

READ

I I I

READ

I I I

READ

FILE (file-expr) INTO(variable): I KEY (expression) or

I

(character-string-I

variable)

FILE(file-expr) SET(pointer-variable);IKEY(expression) or I (character-string-I variable)

FILE (file-expr) IGNORE(expression): I

KEYTO

KEYTO

SEQUENTIAL UPDATEIREAD FILE(file-expr) INTO(variable);

I

KEY (expression) or KEYTO

(character-string-variable)

KEY(expression) or KEYTO

(character-string-variable)

DIRECT INPUT

I

IREAD FILE(file-expr) SET(pointer-variable):

I I

IREAD FILE(file-expr) IGNORE(expression):

I

IREWRITE FILE(file-expr):

I

IDELETE FILE(file-expr):

IREAD FILE(file-expr) INTO(variable) I KEY(expression):

FROM (variable) KEY(expression)

I EVENT (event-variable)

I

I DIRECT

I

UPDATE IREAD FILE(file-expr) INTO (variable) I KEY(expression)i

I EVENT (event-variable)

I I I I I I I I

I

IREWRITE FILE(file-expr) FROM(variable)

I

KEY(expression);

I

IWRITE FILE(file-expr) FROM(variable) I KEYFROM(expression)i

I

I

IEVENT(event-variable)

I I

IEVENT(event-variable)

I

I IDELETE FILE(file-expr) KEY(expression):

I

I EVENT (event-variable)

L---J

Figure 12.9 (Part 1 of 2). Statements and options permitted for creating and accessing INDEXED data sets

the use of either option is shown in figure 12.10.

Programs written for the PL/I F Compiler which use records with embedded keys can be compiled without alteration to the

ENVIRONMENT attribute for the inclusion of the KEYLOC option, if the original RKP subparameter is specified when the recompiled program is executed.

The use of embedded keys avoids the need for the KEYTO option during sequential input, but the KEYFROM option is still required for output. (However, the data specified by the KEYFROM option may be the embedded key portion of the record variable itself.) In a data set with unblocked records, a separate recorded key precedes

each record, even when there is already an embedded key. If the records are blocked, the key of only the last record in each block is recorded separately in front of the block.

During the execution of a WRITE

statement that adds a record to a data set with embedded keys, the value of the

expression in the KEYFROM option is assigned to the embedded key position in the record variable. Note that a record variable can be declared as a structure with an embedded key declared as a

structure member, but that such an embedded key must not be declared as a VARYING

string.

For a LOCATE statement, the KEYFROM

Chapter 12: Record-oriented Transmission 181

r---

DIRECT UPDATE EXCLUSIVE

READ FILE(file-expr) INTO (variable) KEY(expression);

REWRITE FILE(file-expr) FROM (variable) KEY(expression):

WRITE FILE(file-expr) FROM (variable) KEYFROM(expression);

DELETE FILE(file-expr) KEY(expression):

UNLOCK FILE(file-expr) KEY(expression);

---,

EVENT (event-variable) and/or NOLOCK

EVENT (event-variable) EVENT (event-variable) EVENT(event-variable)

~The complete file declaration would include the attributes FILE, RECORD, and ENVIRONMENT: if any of the options KEY, KEYFROM, and KEYTO is used, i t must also include the attribute KEYED.

2The statement: READ FILE (file-expression); is equivalent to the statement:

READ FILE (file-expression) IGNORE (1):

Notes: The attribute UNBUFFERED is ignored and BUFFERED is assumed for INDEXED SEQUENTIAL and SEQUENTIAL files.

Use of the DELETE statement is invalid if OPTCD=L (DCB subparameter) was not specified when the data set was created or if the RKP subparameter is zero for FB records, or four for V and VB records.

L---J

Figure 12.9 (part 2 of 2). Statements and options permitted for creating and accessing INDEXED data sets

r---1

I I I

Data Set

I I

1---KEYLOC

I

RKP

I

Record Variable

I

Unblocked

I

Blocked

(n)

I I I

records

I

records

---n>l

I

RKP equivalent = Key Key

I

Key

I

n-1+C~

I

---n=l

I

No equivalent Key Key2

I

Key

n=O or not specified

I

RKP=C~

I

No key

I

No key

I

Key3

1---1 I I I

I

RKP>C1

I

Key

I

Key

I

Key

1 C = number of control bytes, if any: C=O for fixed-length records C=4 for variable-length records

2 In this instance the key is not recognized by data management.

3 Each logical record in the block has a key.

L---J

Figure 12.10. Effect of KEYLOC and RKP values on establishing embedded keys in record variables or data sets

182 OS PL/I CKT AND OPT LRM PART I

string is assigned to the embedded key when the next operation on the file is

encountered.

DUMMY RECORDS

Records within an INDEXED data set are either actual records containing valid data or dummy records. A dummy record is

identified by the constant (8)'1'B in its first byte. Dummy records can be inserted by the programmer, or can be created by deleting records. They can be replaced by valid data records having the same keys as the dummy records. The sUbparameter

OPTCD=L must be included in the DD

statement that defines the data set when i t is created, so that dummy records are

recognized and not retrieved by READ statements.

CREATING A DATA SET

When an INDEXED data set is being created, the associated file must be opened for SEQUENTIAL OUTPUT, and the records must be presented in the order of ascending key values. (If ther~ is an error in the key sequence, the KEY condition will be

raised.) A DIRECT file cannot be used for the creation of an INDEXED data set.

Once an INDEXED data set has been created, the file that accesses i t can be opened for SEQUENTIAL INPUT or UPDATE, or for DIRECT INPUT or UPDATE. In the case of F-format records, i t can also be opened for OUTPUT to add records at the end of the data set. The keys for these records must have higher values than the existing keys for that data set and must be in ascending order. The storage allocated for a data set can be increased when i t is required for output.

SEQUENTIAL ACCESS

A SEQUENTIAL file that is used to access an INDEXED data set may be opened with either the INPUT or the UPDATE attribute. The data transmission statements need not

include source keys, nor need the file have the KEYED attribute. Sequential access is in order of ascending recorded-key values;

records are retrieved in this order, and not necessarily in the order in which they were added to the data set. Dummy records are not retrieved if the DO statement that defined the data set included the

subparameter OPTCD=L.

Except that the EVENT option cannot be used, rules governing the relationship between the READ and REWRITE statements for a SEQUENTIAL UPDATE file that accesses an INDEXED data set are identical to those for a CONSECUTIVE data set (described above).

Embedded keys in a record to be updated must not be altered. The modified record must always overwrite the updated record in the data set.

Additionally, records can be effectively deleted from the data set; a DELETE

statement marks a record as a dummy by putting (8)'1'B in the first byte. The DELETE statement should not be used to process a data set with F-format blocked records and either KEYLOC=l or RKP=O, or V-or VB-fV-ormat recV-ords and either KEYLOC=l V-or RKP=4. (The code (8) 'l'B would overwrite the first byte of the recorded key.) Note that the EVENT option is not supported for SEQUENTIAL access of INDEXED data sets.

During sequential access of an INDEXED data set, i t is possible to read a

particular record by supplying a source key in the KEY option of a READ. statement, and to continue sequential reading from that pOint in the data set. (The associated file must have the KEYED attribute.) Thus, a READ statement that includes the KEY option will cause the record, whose key is supplied, to be read; a subsequent READ statement without the KEY option will cause the record with the next higher recorded key to be read (even if the keyed record has not been found).

The effect of supplying a source key that is shorter than the recorded keys in the data set differs according to whether or not the GENKEY option is specified in the ENVIRONMENT attribute. In the absence of the GENKEY option, the source key is padded on the right with blanks to the length specified in the KEYLENGTB option of the ENVIRONMENT attribute, and the record with this padded key is read (if such a record exists). If the GENKEY option is specified, the source key is interpreted as a generic key, and the first record with a key in the class identified by this generic key is read. (Refer to -Key

Classification,- above.)

DIRECT ACCESS

A DIRECT file that is used to access an INDEXED data set may be opened with either the INPUT or the UPDATE attribute. All data transmission statements must include

Chapter 12: Record-oriented Transmission 183

source keys; the DIRECT attribute implies

Dans le document OS PL/I (Page 194-197)