HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

8.2 Choosing a File Sharing and Record Locking Standard (Alpha, I64)

On Alpha and I64 systems, HP COBOL offers two methods of controlling potential conflicts of multi-user file access between simultaneously running processes:

  • HP standard, which is compatible with the behavior of HP COBOL for OpenVMS VAX1
  • X/Open standard (Alpha, I64), which conforms to the X/Open CAE Specification: COBOL Language and which offers X/Open portability

Both effectively control potential conflicts of file access between simultaneously running COBOL processes. Both offer locking for all file types: sequential, relative, and indexed.

Note

If you choose X/Open standard file sharing and record locking for a file connector, you must not use HP standard syntax anywhere in your program for the same file connector. The two are mutually exclusive.

The HP COBOL compiler determines whether to apply X/Open standard behavior or HP standard behavior for any file connector on the basis of the syntax used for that file connector. The following syntax identifies X/Open standard:

LOCK MODE (SELECT statement)
WITH LOCK (OPEN statement)
WITH [NO] LOCK (READ statement)
UNLOCK RECORDS

The following syntax identifies Hewlett-Packard standard:

APPLY LOCK-HOLDING (Environment Division)
ALLOWING1
REGARDLESS1 (Procedure Division)
UNLOCK ALL

For any given file connector, any subsequent I-O locking syntax in your program must be consistent: X/Open standard and HP standard file sharing/record locking (implicit or explicit) cannot be mixed for the same file connector.

If a program includes any ambiguous semantics for I-O verbs (that is, no locking syntax for verbs for which the two standards provide different default behavior) and the previous code does not use HP or X/Open standard-specific syntax for that file connector, the compiler determines which standard to use by applying the specification (or default) from your compile command line, as follows:

  • The -std [no]xopen flag on the cobol command for the Tru64 UNIX operating system
  • The /STANDARD=[NO]XOPEN qualifier on the COBOL command for the OpenVMS Alpha and OpenVMS I64 operating systems

If you do not specify the flag or qualifier, the default is noxopen (HP standard) file sharing and record locking.

If you want X/Open file sharing and record locking and have not used the LOCK MODE clause, therefore, you should specify /STANDARD=XOPEN or -std xopen to ensure X/Open standard behavior in instances of conflicting default semantics. Note, however, that the qualifier/flag comes into effect only when the explicit syntax has not determined the usage. <>

Note

1 Some exceptions exist on Tru64 UNIX. Refer to the HP COBOL Reference Manual for details.

8.3 Ensuring Successful File Sharing

Successful file sharing requires that you:

  • Provide disk residency for the file.
  • Use the operating system file protection facility, namely the contents of /etc/groups (on Tru64 UNIX systems) or the UIC (on OpenVMS systems).
  • Determine the intended access mode to the file (HP COBOL open modes).
  • Indicate the file access allowed by other streams, using X/Open standard (on Alpha and I64 only) or HP standard syntax to specify file sharing.

The remainder of this section describes these requirements in more detail.

8.3.1 Providing Disk Residency

Only files that reside on a disk can be shared. In HP COBOL you can share sequential, relative, and indexed files.

8.3.2 Using File Protection

By applying the appropriate file permissions at the operating system level, the owner of a file determines how other users can access the file. An owner can permit different types of file access for different users or groups.

Note

The following OpenVMS operating system file protection access types are not a part of HP COBOL syntax.

The four types of file access are as follows:

  • READ---Permits the reading of the records in the file.
  • WRITE---Permits updating or extending the records in the file.
  • EXECUTE---Applies to on-disk volume protection and image execution and is therefore not applicable to an HP COBOL program except through system service routines.
  • DELETE---Permits deletion of the file and is therefore not applicable to an HP COBOL program (since HP COBOL has no delete file facility) except through system service routines.

In the OpenVMS file protection facility, four different categories of users exist with respect to data structures and devices. A file owner determines which of the following user categories can share the file:

  • SYSTEM---Users of the system whose group numbers are in the range 0 to the value of the MAXSYSGROUP parameter or who have certain I/O-related privileges
  • OWNER---Users of the system whose UIC group and member numbers are identical to the UIC of the file owner
  • GROUP---Users of the system whose group number is identical to the group number of the file owner
  • WORLD---All other users of the system who are not included in the previous categories

The OpenVMS operating system applies a default protection to each newly created file unless the owner specifically requests modified protection.

For more information on file protection, refer to the OpenVMS User's Manual. <>

Note

The following Tru64 UNIX operating system file access types are not a part of HP COBOL syntax.

On Tru64 UNIX systems, the three types of file access are as follows:

  • Read---Permits the reading of the records in the file.
  • Write---Permits updating or extending the records in the file.
  • Execute---Applies to image execution and is therefore not applicable to an HP COBOL program.

There are three categories of users:

  • User---Owner of the file
  • Group---Users in the same group as the owner
  • Others---All other users

HP COBOL determines the access permission for newly created files in the following manner:

  1. The default access permissions are granted:
    • User and Group are granted read and write access.
    • Others are granted read access.
  2. Then the file mode creation mask of the process creating the file is taken into account.

Additional information on file permission can be found in the Tru64 UNIX man pages for chmod, ls, open, and umask . <>

8.3.3 Determining the Intended Access Mode to a File

Once you establish disk residency and permission for a file, you can consider how the stream intends to access the file. You specify this intention by using the HP COBOL open and access modes.

The HP COBOL open modes are INPUT, OUTPUT, EXTEND, and I-O. The HP COBOL access modes are SEQUENTIAL, RANDOM, and DYNAMIC. The combination of open and access modes determines the operations intended on the file.

You must validate your HP COBOL intention against the file protection assigned by the file owner. For example, to use an OPEN INPUT clause requires that the file owner has granted read access privileges to the file. To use an OPEN OUTPUT or EXTEND clause requires write access privileges to the file. To use an OPEN I-O clause requires both read and write access privileges.

The following chart shows the relationship between open and access modes and intended HP COBOL operations. The word ANY indicates that all three access methods result in the same intentions.

Open Mode Access Mode Intended COBOL Operations
INPUT ANY READ, START
OUTPUT ANY WRITE
I-O SEQUENTIAL READ, START, REWRITE, DELETE
  RANDOM/DYNAMIC READ, START, REWRITE, DELETE, WRITE
EXTEND SEQUENTIAL WRITE

Note

If the file protection does not permit the intended operations, file access is not granted, even if open and access modes are compatible.

File protection and open mode access apply to both the unshared and shared (multiple access stream) file environments. A file protection and intent check is made when the first access stream opens a file (in the unshared file environment), and again when the second and subsequent access streams open the file (in the shared file environment).


Previous Next Contents Index