HP OpenVMS Systems Documentation
The DBA divides the database into areas so you can reference the
database in sections instead of an entire unit. Areas are physical
divisions of the database
that are defined in the schema and are used to dump selectively,
verify, or recover sections of the database; improve I/O; group
logically related record types; and provide protection restrictions.
Areas are stored as separate files and can be on separate volumes.
A realm is a group of one or more areas. Realms are logical divisions of the database. A realm is the object of the DML READY statement. Figure 5-27 shows the relationship between the schema, areas, subschema, and realms. Even though realms can contain data from more than one area, the type of data they contain is dependent on the subschema. It acts as a filter, allowing access to only specific data items.
Entire realms, as well as individual database records, are locked by the DBCS as they are retrieved by the run unit, and the degree of locking depends on the specific DML command used. For more information, see Section 6.1.
Figure 5-27 Database Relationships
The term run unit and program are not the same. A run unit is an
executable image that may access a database, while a program can be
used in two or more run units. For example, program SHOW-EMPLOYEE can
be run simultaneously by a payroll department employee to obtain
employee data, and by an accountant to obtain job cost data. Each
person controls his or her own run unit.
5.13 Currency Indicators
When you access database records, the database control system (DBCS) uses pointers called currency indicators to keep track of record storage and retrieval. HP COBOL uses currency indicators to remember records and their positions in the database. Currency indicators can be changed by DML statement execution. Thus, they assist in defining the environment of a DML statement and are updated as a result of executing DML statements.
All the currency indicators in a run unit are null prior to execution of the first DML statement. The null value indicates there is neither a current record nor a current position. Execution of certain DML statements can change the value of currency indicators. However, currency indicators do not change if statement execution fails.
The DBCS also uses currency indicators as place markers to control its sequence of access to the database. For example, if VENDOR is the name of the vendor records in Figure 5-2, then the current of VENDOR is normally the vendor record most recently accessed. Likewise, in the set VENDOR_SUPPLY, the current of VENDOR_SUPPLY is normally the most recently accessed record of that set. Note that current of set could be either a member or owner record because both record types are part of the VENDOR_SUPPLY set.
Failure to establish correct currency can produce incorrect or
unpredictable results. For example, you might unknowingly modify or
delete the wrong record. The following sections describe how the DBCS
sets currency indicators and how to use currency status in a DML
5.13.1 Current of Realm
Each realm currency indicator can be null or it can identify:
000100 PROCEDURE DIVISION. 000110 . 000120 . 000130 . 000500 FIND FIRST PART WITHIN BUY. 000510 FIND FIRST PART WITHIN MAKE. 000520 FIND NEXT PART WITHIN BUY. 000600 FIND NEXT SUPPLY WITHIN PART_INFO. 000610 . 000620 . 000630 .
For example, if LABEL and CASSETTE are in the BUY realm, while TAPE is
in the MAKE realm, statement 000500 sets the first occurrence of PART
record in realm BUY (LABEL) as current of realm BUY. Statement 000510
sets the first occurrence of PART record in realm MAKE (TAPE) as
current of realm MAKE. Notice that current of realm BUY is still the
record occurrence accessed in statement 000500. Statement 000520
changes the current of realm BUY to the next occurrence PART record in
realm BUY (CASSETTE). Current of realm MAKE remains the record accessed
in statement 000510. Because the SUPPLY record type is located in the
MARKET realm, statement 000600 sets the current of MARKET realm to the
first SUPPLY record in the current PART_INFO set.
5.13.2 Current of Set Type
Each set type currency indicator can be null or it can identify:
If the ordering criterion for a set type is NEXT or PRIOR, the set type's currency indicator specifies the insertion point for member records. Therefore, if the currency indicator points to an empty position, a member record can be inserted in the specified position. If the currency indicator points to a record and NEXT is specified, a member record can be inserted after the current record for the set type. If the currency indicator points to a record and PRIOR is specified, a member record can be inserted before the current record for the set type.
The DBCS updates current of set type only when you reference a record that participates either as an owner or member in a set type occurrence. For example:
000100 PROCEDURE DIVISION. . . . 000500 FIND FIRST PART. 000510 FIND FIRST SUPPLY WITHIN PART_INFO. 000520 FIND OWNER WITHIN VENDOR_SUPPLY. 000600 . . .
Statement 000500 sets the first occurrence of PART (LABEL) as current
of set types PART_USES, PART_USED_ON, and PART_INFO. This is because
PART records participate in three sets (see Figure 5-2). Because
LABEL is current of PART_INFO, statement 000510 sets the first
occurrence of SUPPLY (4-DAYS) owned by LABEL as current of set type
PART_INFO. Because SUPPLY also participates in the VENDOR_SUPPLY set,
this statement also sets the current occurrence of SUPPLY as current of
set type VENDOR_SUPPLY. Statement 000520 sets the VENDOR owner record
occurrence (SOUND-OFF CO.), which owns the current SUPPLY record, as
current of set type VENDOR_SUPPLY.
5.13.3 Current of Record Type
Each record type currency indicator can be null or it can identify:
Record type currency indicators do not identify a record type's relationship with other record types.
A record identified by a record type currency indicator is called current of record type. The DBCS updates the current of record type only when you reference a different record occurrence of the record type. References to other record types do not affect this currency. For example:
000100 PROCEDURE DIVISION . . . 000500 FIND LAST PART. 000510 FIND FIRST SUPPLY WITHIN PART_INFO. 000520 FIND NEXT WITHIN PART_INFO. 000530 FIND FIRST VENDOR. . . .
Statement 000500 sets the last occurrence of PART (TAPE) as current of record type PART. Statement 000510 sets the SUPPLY record occurrence (2-DAYS) as current of record type SUPPLY. Statement 000520 updates current of record type for SUPPLY to record occurrence (1-WEEK). Statement 000530 sets VENDOR record occurrence (MUSICO INC.) as current of record type VENDOR.