• Aucun résultat trouvé

RELATIVE FILE ORGANIZATION

Dans le document TRAX COBOL User's Guide (Page 175-181)

OUTPUT-MASTER,

CHAPTER 6 FILE HANDLING

6.2 RELATIVE FILE ORGANIZATION

Relative file organization arranges the records of the file into numbered record positions. It assigns each record position a number that identifies that position relative to the beginning of the file (the first record position in the file has record number 1, the second has record number 2, etc.).

1 2 3 4 5 6 7 8 9 10 Record positions in a Relative File

When a program executes a random DELETE, REWRITE, READ or WRITE operation on a relative file, the value in the relative key is used to select records from these numbered record positions in the same way that a subscript selects an item in a table.

Thus, while sequential and relative files both arrange their record positions in a serial order, COBOL statements can address the record positions of a relative file by their position numbers, and successive accesses do not have to proceed through the file in a prescribed, serial, order.

Another significant feature of relative file organization is that each record position does not have to contain a valid record. Although each position actually occupies one record space, a byte preceding the record on the storage medium indicates whether or not that space contains a valid record. Thus, a file may have fewer records than it has record positions, and the indicated empty record positions may be anywhere in the file.

The numerical order of the record positions remains the same during all operations on a relative file; however, the accessing statements can move a record from one position to another, delete a record from a position, or insert new records into empty positions.

6.2.1 Record Size

A relative file may contain either fixed-length or variable-length records. (Fixed-length records have one or more record descriptions that describe the same size record. Variable-length records have more than one record description that describe seve~al different sized records.) However, the COBOL compiler allocates a record area on the I/O device, equal to the largest record described plus one. This extra byte is an existence byte. It indicates whether the record area contains a valid record. For variable length records in a relative file, the software adds a two byte count field. On a write operation the actual record is written out to the I/O device not the maximum length record. The length of this record is placed in the two byte count field. On a read operation this two byte count field is used to determine the length of the record to be read in.

6.2.2 RECORD CONTAINS Clause

The RECORD CONTAINS clause, when specified without the "integer-l TO"

option, is for documentation purposes only. The compiler determines record size from the data descriptions. When the "integer-l TO"

option is specified, i t forces the compiler to generate a variable length record file, even if the data descriptions describe fixed length records.

Conversely, if the data descriptions for a sequential file describe variable-length records, the software sets up variable sized records automatically and ignores this clause.

Even though the software ignores the values in the "integer-l TO •.. "

FILE HANDLING 6.2.3 SAME RECORD AREA Clause

The SAME RECORD AREA clause is identical for all file organizations.

See Section 6.1.3.

6.2.4 Record Blocking

The size of a file is expressed as an inte~ral number of blocks. Virtual blocks are physical storage structures.

each virtual block within a file is a unit of data whose size on the physical medium on which the file resides.

virtual That is, depends Relative files may reside only on disk. The size of virtual blocks within files on disk devices is always 512 bytes.

Relative files use a logical storage structure known as a logical block or bucket. A bucket consists of from 1 to 32 virtual blocks.

This distinction should be made clear. A virtual block is a physical entity which is fixed in size and cannot be changed. A bucket, however, is a logical entity. Its size is directly under your control. Records may span virtual block boundaries. They may never span bucket boundaries.

Increasing the bucket size increases the speed of sequential processing of a file because fewer I/O operations are needed to access the smaller number of buckets in the file. On the other hand, a larger bucket size means that more memory space is taken up by the I/O buffers. Increasing the bucket size may not increase the speed of random processing of a relative file.

There are three ways that the bucket size may be specified in a COBOL program; by default, by using the construct BLOCK CONTAINS integer RECORDS, or by using the construct BLOCK CONTAINS integer CHARACTERS.

The default is to make the bucket size as small as possible, to minlmlze the memory buffer space required. By using the BLOCK CONTAINS integer (RECORDS of integer CHARACTERS) clause, you can

increase the memory buffer space required. Increasing the buffer space allows for faster I/O by decreasing the number of operations required to access a file. The following paragraphs further define the three blocking methods:

Default

The default philosophy is to make the bucket size as small as possible to minlmlze the memory buffer space required. The algorithms for calculating the bucket size follow:

Bnum= «1+Rlen}/5l2}+1 Fixed length record Bnum= {{3+Rmax}/512}+1 Variable length record Where:

Bnum Rlen Rmax

is the number of virtual blocks per bucket, ranging from 1 to 9.

is the fixed record length {in bytes}.

is the maximum record length (in bytes) record length is variable.

if the

The number 1 is for the existence byte. The number 3 is for the existence byte plus 2 bytes for the record length.

Table 6-4 gives the bucket size for possible record lengths.

Table 6-4

Bucket Sizes for possible Record Lengths

Bnum Rlen Rmax

1 1-511 1-509

2 512-1023 510-1021

3 1024-1535 1022-1533

4 1536-2047 1534-2045

5 2048-2559 2046-2557

6 2560-3071 255&-3069

7 3072-35H3 3070-3581

8 3584-4095 3582-4093

9 4094-4095

BLOCK CONTAINS Rnum RECORDS

If the BLOCK CONTAINS Rnum RECORDS clause is used, where Rnum is an integer, then the following algorithms are used to calculate the bucket size.

Bnum= (((Rlen+l)*Rnum)/512)+1 Fixed length record or

Bnum= (((Rmax+3)*Rnum)/512)+1 Variable length record Where:

Bnum Rlen Rmax Rnum

is the number of virtual blocks per bucket, ranging from 1 to 32.

is the fixed record length (in bytes).

is the maximum record length (in bytes) if the record length is variable.

is the number of records per bucket as given in the BLOCK CONTAINS clause.

BLOCK CONTAINS Cnum CHARACTERS

If the BLOCK CONTAINS Cnum CHARACTERS clause is used, where Cnum is an integer, then Cnum is subject to the following constraints.

(1) Cnum Rlen+l for fixed length records or

Cnum Rmax+3 for variable length records (2) Cnum mod 512 0

FILE HANDLING

Based on CNUM, the bucket size is calculated as follows:

Bnum=Cnum/5l2 where:

Cnum is the number of characters per bucket as given in the BLOCK CONTAINS clause.

Rlen Rmax

is the fixed record length (in bytes).

is the maximum record length (in bytes) record length is variable.

if the Bnum is the number of virtual blocks per bucket,

ranging from 1 to 32.

Violation of constraint (1) causes a warning error and the default method is used to calculate the bucket size. Constraint (2) means that Cnum should be a multiple of 512. If not, a warning error is given and Cnum is increased to the next even multiple of 512.

The bucket size must be the same when the file is created and each time the file is accessed. Therefore, the BLOCK CONTAINS clause must never change for a particular file.

Note: The previous discussion has used the following format:

[BLOCK CONTAINS integer {

RECORDS }]

CHARACTERS If the following format is used:

[BLOCK CONTAINS[integer-l TO]integer-2 {

RECORDS }]

CHARACTERS

the compiler ignores integer-I, and integer-2 is used as the integer.

6.2.5 Buffering

When the system performs a sequential or random input operation, it reads a bucket from the medium into the buffer, and moves a record from the buffer to the current record area. Any subsequent sequential read operations move a record from the buffer to the current record area. When it has exhausted the buffer (has read an entire bucket), the system reads another bucket into the buffer.

When performing a random read operation, the appropriate bucket is read into a file's buffer. The record is thp.n moved from the buffer to the current record area.

When performing a sequential output operation, each write operation moves a record from the file's current record area into the file's buffer. Each subsequent sequential write operation moves a record from the current record area into the buffer. The system writes the bucket to the medium when it has filled the buffer.

When performing a random output operation, the appropriate bucket is read and the record is moved from the file's current record area into the appropriate position in the file's buffer. The system writes the bucket back out to the medium before reading any additional blocks.

The following subsections discuss the size of the buffers, the number of buffers, and the sharing of buffers.

6.2.5.1 Buffer Size - Buffer size depends on the size of the largest record in the file and on the blocking factor. For relative files, buffer size must be some multiple of 256 words (512 bytes).

6.2.5.2 I/O Buffer Areas - The RESERVE clause in the Environment Division specifies the number of I/O buffer areas to be allocated for each file where an area represents the space for one bucket. A minimum of one and a maximum of two I/O areas are permitted for relative files. One is the default. It is recommended that this clause not be used, because two I/O areas do not increase the speed of access and take up additional space.

6.2.5.3 Buffer Space - To calculate the total amount of buffer space in bytes required for each Relative file, the following algorithm may be used:

Buffer space

=

record size + bucket size + 266

In addition, there are 76 bytes of buffer space that are shared among all files.

6.2.5.4 Sharing Buffer Space Among Files - The SAME AREA clause provides a simple method of sharing buffer space among several files.

This clause is identical for all file organizations. See Section 6.1.6.4.

6.2.6 Relative I/O Statements

The COBOL I/O statements, CLOSE, DELETE, OPEN, READ, WRITE, REWRITE, and START can refer to relative files.

A COBOL program may open a relative file in one of three modes, INPUT, OUTPUT, or I-a, and access an open relative file in one of three ways, sequentially, randomly, or dynamically. In INPUT mode, tecords may be read from the file; in OUTPUT mode, the file is created and records may be written to the file; in I-a mode, records may be read from the file, updated on the file, deleted from the file, or written to the file. The following table shows which statements and access methods apply to the three different OPEN modes of relative files.

FILE ACCESS

Dans le document TRAX COBOL User's Guide (Page 175-181)