Previous | Contents | Index |
A record selection expression is used to select a record in the database. It can be used in a FETCH or FIND statement. The record thus selected becomes the current record of the run unit upon which subsequent statements may operate when accessing the database.
Refer also to the Oracle CODASYL DBMS Programming Guide and the Oracle CODASYL DBMS Programming Reference Manual for additional information.
Format 1---Database Key Identifier Access
This format selects a record by a database key value held by the Database Control System (DBCS) in a currency indicator or a keeplist entry.
database-key-identifier
identifies a record according to the rules of database key identifiers. (See Section 4.4, Database Key Identifiers for more information.)
For example:
FIND CURRENT WITHIN PART-REC |
This format selects the record that owns a set.
set-name
is a subschema set name. The DBCS uses the currency indicator for set-name to choose the owner record of that set occurrence. A database exception condition occurs if set-name is a singular set (DB-CONDITION is set to DBM$_SINGTYP) or if the currency indicator for the set type is null (DB-CONDITION is set to DBM$_CSTYP_NULL).
This format selects the record that is referred to by the database key contained in the special register DB-KEY.
Format 4---Record Position Access
This format selects a record by its position within a collection of records and optionally by its record type and contents.
int-exp
is an integer or arithmetic expression resulting in a longword integer value. It cannot be zero. It may be an embedded literal or an integer data-name.realm-name
is a subschema realm name.record-name
is a subschema record name.set-name
is a subschema set name.rec-key
is a key data item within the subschema record occurrence. The same rec-key can appear only once in a given USING phrase.bool-expression
is a conditional expression that involves data items of the object record. It is used to specify additional requirements of a qualifying record.bool-alternate
is one or more sub-expressions (simple-bool-relation). Pairs of sub-expressions are joined by the logical operator AND.simple-bool-relation
is a simple-condition (bool-condit), an expression, or the negation of either.bool-condition
is a relation involving two operands joined by a relational operator.Relational operators can be one of the following:
[NOT] EQUAL (=) TO
[NOT] LESS (<) THAN
[NOT] GREATER (>) THAN
GREATER THAN OR EQUAL (>=) TO
LESS THAN OR EQUAL (<=) TO
[NOT] CONTAIN
[NOT] CONTAINS
[NOT] MATCH
[NOT] MATCHESThe relational operator CONTAINS is used to check that a given data item in the record contains the specified string anywhere within it. At least one of the operands must be the identifier of a nondatabase item or a nonnumeric literal; the other operand must be an elementary item in the record being found or fetched.
The relational operator MATCHES checks that a given item in the records matches the specified pattern string. At least one of the operands must be the identifier of a nondatabase item or a nonnumeric literal; the other must be an elementary item in the record being found or fetched.
The pattern string is formed from any character string; however, two characters, the percent sign (%) and the asterisk (*), have special meanings. If the percent sign (%) occurs in the pattern string, it will match the current single character in the item being matched. If the asterisk (*) occurs in the pattern string, it will match any number of characters starting at the current character in the item being matched. For example:
FIND ALL KEEP-1 WHERE PARTDESC MATCHES '*DISK*' FIND ALL KEEP-1 WHERE PARTDESC MATCHES '*F%%'To match either the percent sign (%) or asterisk (*) in the pattern string, precede it with the caret (that is, to match percent sign (%) use caret and percent (^%), and to match asterisk (*) use caret and asterisk (^*)).
The reserved word WITHIN with set-name or realm-name is called the collection clause. Use the collection clause to restrict a search to a specific collection of records in the database. If you do not use the collection clause, the DBCS searches through all the records in the database to which you have access.
The collection clause specifies the object collection. The following rules govern its use:
Use record-name to restrict the search to records of a particular type. If you do not use record-name, the DBCS searches each record type in the subschema. You can further restrict the search to records with specific data item values. You do this by specifying the qualification clause. The qualification clause is either the reserved word USING followed by one or more rec-keys, or the reserved word WHERE followed by a Boolean expression. When USING is specified, the DBCS searches for only those database records whose key data items equal the corresponding data items in your user work area. When WHERE is specified, the DBCS searches for database records of the object record type whose item values cause the Boolean expression to evaluate to true.
The qualification clause optionally specifies the following additional rules for determining the object record type, the qualifying record, and the key data item:
The reserved words FIRST, LAST, NEXT, PRIOR, ANY, DUPLICATE, and RELATIVE make up the position clause. The position clause selects a specific qualifying record in the object collection. The position clause rules follow:
The record selection expression causes a database exception condition to occur if:
See Section 4.8.3, Exception Conditions and the USE Statement statement for an explanation of DBM$_symbolic
constants.
4.7 Set Membership Options and DML Verbs
The Compaq COBOL data manipulation language (DML) verbs CONNECT, DISCONNECT, ERASE, MODIFY, RECONNECT, and STORE can affect a record's set membership. The effects of these verbs depend on the INSERTION and RETENTION clauses declared for the record's membership in each set in the schema.
The member's INSERTION clause determines whether the record is automatically inserted into a set when it is stored:
The member's RETENTION clause determines whether the record can be removed from a set with the verbs ERASE, DISCONNECT, and RECONNECT. If the RETENTION IS FIXED clause is used, you cannot remove the record from a set occurrence at all unless you erase the record at the same time. If the RETENTION IS MANDATORY clause is used, you cannot use DISCONNECT to remove the record from a set occurrence; you can use RECONNECT to move it from one occurrence of the set type to another. If the RETENTION IS OPTIONAL clause is used, you can use either DISCONNECT or RECONNECT to remove the record from a set occurrence.
The ERASE statement always removes the erased record from all sets of which it is a member. ERASE also affects sets owned by that record. If you use the ERASE ALL option, all members of sets owned by an erased record are erased in a recursive process. If you use ERASE without the ALL option, the effect on each set member depends on the member's RETENTION clause: FIXED members are erased; OPTIONAL members are not erased (but are removed from the set, since the set is about to vanish). If any members have a RETENTION MANDATORY clause, an exception occurs because they can exist in the database without being members of this set occurrence. However, the Database Control System does not know into which set occurrence the members should be inserted.
The MODIFY statement may reposition a record within the same set occurrence if its sort key for that set is one of the data items being modified.
See the Oracle CODASYL DBMS DML documentation that summarizes the effects of
the various verbs on the record directly modified and on any members
(ERASE only).
4.8 Programming for Database Exceptions and Error Handling
Your program must contain logic to accommodate exceptions and errors.
The items of syntax in Compaq COBOL that are used for this purpose are
ON ERROR, AT END, and USE.
4.8.1 Database On Error Condition
The database on error exception condition occurs when the DBCS encounters a database exception condition for any data manipulation language (DML) statement.
The ON ERROR phrase in a DML statement allows the selection of an imperative statement sequence when any database exception condition occurs.
The NOT ON ERROR phrase allows execution of an imperative statement when a database exception condition does not occur.
Stment is an imperative statement.
When a database exception condition occurs and the statement contains an ON ERROR phrase:
When a database exception condition occurs and the statement does not contain an ON ERROR phrase:
When a database exception condition does not occur:
Use the ON ERROR phrase to transfer execution control to the associated statements' error handling routine, where your program can supply useful and effective debugging information. (See Section 4.8.3 for examples and Glossary of Oracle DBMS-Related Terms for more information on Oracle CODASYL DBMS Database Special Registers.) The ON ERROR phrase can be part of every DML statement. It allows you to plan the graceful termination of a program that would otherwise terminate abnormally. (In a FETCH or FIND statement, you cannot specify both the ON ERROR and AT END phrases in the same statement.) For example:
PROCEDURE DIVISION. . . . RECONNECT PARTS_RECORD WITHIN ALL ON ERROR DISPLAY "Exception on RECONNECT" PERFORM PROCESS-EXCEPTION. . . . PROCESS-EXCEPTION. DISPLAY "Database Exception Condition Report". DISPLAY " ". DISPLAY "DB-CONDITION = ", DB-CONDITION WITH CONVERSION. DISPLAY "DB-CURRENT-RECORD-NAME = ", DB-CURRENT-RECORD-NAME. DISPLAY "DB-CURRENT-RECORD-ID = ", DB-CURRENT-RECORD-ID WITH CONVERSION. DISPLAY " ". CALL "DBM$SIGNAL". STOP RUN. |
An at end condition occurs when a program detects the end of a file. The at end condition may occur as a result of a FETCH or FIND statement execution in your database program. You use the AT END phrase to specify the action your program is to take when an at end condition occurs.
The NOT AT END phrase specifes the action your program takes if an AT END does not occur.
Use the AT END phrase of the FETCH and FIND statements to handle the end of a collection of records condition. Your program will terminate if: (1) an at end condition occurs, (2) the program does not include the AT END phrase, and (3) there is no applicable USE statement.
When an at end condition occurs and the statement contains an AT END phrase:
When an at end condition occurs and the statement does not contain an AT END phrase:
When an at end condition (or any other error condition) does not occur:
Planning for exception conditions is an effective way to increase program and programmer productivity. A program with USE statements is more flexible than a program without them. They minimize operator intervention and often reduce or eliminate the time you need to debug and rerun the program.
The USE statement traps unsuccessful run-time Oracle CODASYL DBMS exception conditions that cause the execution of a Declaratives procedure. A Declaratives procedure can:
Two sets of USE statements follow:
USE [ GLOBAL ] FOR DB-EXCEPTION. |
Example 4-1 A Single USE Statement |
---|
PROCEDURE DIVISION. DECLARATIVES. 200-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION. DB-ERROR-ROUTINE. DISPLAY "Database Exception Condition Report". DISPLAY "-------------------------------------------". DISPLAY "DB-CONDITION = ", DB-CONDITION WITH CONVERSION. DISPLAY "DB-CUR-REC-NAME = ", DB-CURRENT-RECORD-NAME. DISPLAY "DB-CURRENT-RECORD-ID = ", DB-CURRENT-RECORD-ID WITH CONVERSION. DISPLAY "DB-CUR-REC-ID = ", DB-CRID. DISPLAY " ". CALL "DBM$SIGNAL". END DECLARATIVES. |
maximum
USE [GLOBAL] FOR DB-EXCEPTION ON DBM$_exception-condition [, DBM$_exception-condition]... |
A Format 1 database declarative executes whenever a database
exception condition occurs and the corresponding
DBM$_exception-condition is explicitly stated in the USE statement.
USE [ GLOBAL ] FOR DB-EXCEPTION ON OTHER. |
A Format 2 declarative executes whenever a database exception
condition occurs and the corresponding DBM$_exception-condition is not
explicitly stated in any Format 1 USE statement.
Example 4-2 Multiple USE Statements |
---|
PROCEDURE DIVISION. DECLARATIVES. 200-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION ON DBM$_CRELM_NULL, DBM$_CRTYPE_NULL. 200-DATABASE. PERFORM 300-REPORT-DATABASE-EXCEPTIONS. IF DB-CONDITION = ..... GO TO ... IF DB-CONDITION = ..... GO TO ... STOP RUN. 225-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION ON DBM$_DUPNOTALL. 225-DATABASE. PERFORM 300-REPORT-DATABASE-EXCEPTIONS. GO TO ... 250-DATABASE-EXCEPTIONS SECTION. USE FOR DB-EXCEPTION ON OTHER. 250-DATABASE. PERFORM 300-REPORT-DATABASE-EXCEPTIONS. EVALUATE DB-CONDITION WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN ..... GO TO ... WHEN OTHER PERFORM... . STOP RUN. 300-REPORT-DATABASE-EXCEPTIONS. DISPLAY "Database Exception Condition Report". DISPLAY " ". DISPLAY "DB-CONDITION = ", DB-CONDITION WITH CONVERSION. DISPLAY "DB-CUR-REC-NAME = ", DB-CURRENT-RECORD-NAME. DISPLAY "DB-CURRENT-RECORD-ID = ", DB-CURRENT-RECORD-ID DISPLAY " ". CALL "DBM$SIGNAL". |
Previous | Next | Contents | Index |