Compaq COBOL AAQ2G1FTK User Manual

Page 267

Advertising
background image

Sharing Files and Locking Records

8.3 Ensuring Successful File Sharing

You can obtain the values that apply to file-sharing exceptions (or to successful
file-sharing operations) by using the VALUE IS EXTERNAL clause, as shown in
Example 8–3:

Example 8–3 Program Segment for RMS-STS Values (OpenVMS)

WORKING-STORAGE SECTION.

01 RMS-SUC

PIC S9(9) COMP

VALUE IS EXTERNAL RMS$_SUC.

01 RMS-FLK

PIC S9(9) COMP

VALUE IS EXTERNAL RMS$_FLK.

.
.
.

PROCEDURE DIVISION.
DECLARATIVES.
FILE-1-ERR SECTION.

USE AFTER STANDARD EXCEPTION PROCEDURE ON FILE-1.

FILE-1-USE.

EVALUATE RMS-STS OF FILE-1

WHEN RMS-SUC

DISPLAY "successful operation"

WHEN RMS-FLK

DISPLAY "file is locked - access denied".

.
.
.

Specifying the OPEN EXTEND Statement in a File-Sharing Environment

If you specify an OPEN EXTEND in a file-sharing environment, be aware that
the EXTEND results differ depending upon what file organization you use.

OPEN EXTEND with a Shared Sequential File

In a shared sequential file

environment, when two concurrent access streams open the file in EXTEND
mode, and both streams issue a write to the end of the file (EOF), the additional
data will come from both streams, and the data will be inserted into the file in
the order in which it was written to the file.

OPEN EXTEND with a Shared Relative File

You must use the sequential access

mode when you open a relative file in extend mode. Sequential access mode
for a relative file indicates that the record order is by ascending relative record
number.

In sequential access mode for a relative file, the RELATIVE KEY clause of the
WRITE statement is not used on record insertion; instead, the RELATIVE KEY
clause acts as a receiving field. Consequently, after the completion of a write by
the first access stream, the relative key field is set to the actual relative record
number.

Figure 8–3 illustrates why this condition occurs.

As the file operations begin, both access streams point to the end of file by setting
record 4 as the highest relative record number in the file. When access stream 1
writes to the file, record 5 is created as the next ascending relative record number
and 5 is returned as the RELATIVE KEY number.

Sharing Files and Locking Records 8–15

Advertising