Previous | Contents | Index |
Refer to the Oracle CODASYL DBMS documentation set for more information.
DB DEFAULT_SUB-SCHEMA WITHIN PARTS. |
DB PARTSS1 WITHIN PARTS FOR "DB1:[COBOL88]NEW.ROO". |
DB DEFAULT_SUB-SCHEMA WITHIN PARTS THRU "STREAM1". |
The Keeplist Description entry names a keeplist.
keeplist-name
is a user-defined name.integer
is a positive integer.
The following example defines three keeplists to navigate through the PARTSS1 subschema: KEEP-COMPONENT, K-EMPLOYEE, and KL-ID:
DB PARTSS1 WITHIN PARTS. LD KEEP-COMPONENT. LD K-EMPLOYEE. LD KL-ID. |
The Procedure Division of your COBOL database programs may contain declarative and nondeclarative procedures. These may include:
There are four types of COBOL statements:
Table 4-1 shows the three types of COBOL statements (conditional, imperative, delimited-scope) that are considered particularly relevant to database programming.
Type | Verb |
---|---|
Conditional |
COMMIT ([NOT] ON ERROR)
CONNECT ([NOT] ON ERROR) DISCONNECT ([NOT] ON ERROR) ERASE ([NOT] ON ERROR) FETCH ([NOT] AT END or [NOT] ON ERROR) FIND ([NOT] AT END or [NOT] ON ERROR) FREE ([NOT] ON ERROR) GET ([NOT] ON ERROR) KEEP ([NOT] ON ERROR) MODIFY ([NOT] ON ERROR) READY ([NOT] ON ERROR) RECONNECT ([NOT] ON ERROR) ROLLBACK ([NOT] ON ERROR) STORE ([NOT] ON ERROR) |
Imperative |
COMMIT (1)
CONNECT (1) DISCONNECT (1) ERASE (1) FETCH (2) FIND (2) FREE (1) GET (1) KEEP (1) MODIFY (1) READY (1) RECONNECT (1) ROLLBACK (1) STORE (1) |
Delimited-Scope |
COMMIT (END-COMMIT)
CONNECT (END-CONNECT) DISCONNECT (END-DISCONNECT) ERASE (END-ERASE) FETCH (END-FETCH) FIND (END-FIND) FREE (END-FREE) GET (END-GET) KEEP (END-KEEP) MODIFY (END-MODIFY) READY (END-READY) RECONNECT (END-RECONNECT) ROLLBACK (END-ROLLBACK) STORE (END-STORE) |
( 1 ) Without the optional [NOT ] ON ERROR phrase
( 2 ) Without the optional [NOT ] AT END or [NOT ] ON ERROR phrase
Like statements, COBOL sentences also can be compiler-directing, imperative, or conditional. Sentence type depends upon the types of clauses the statement contains. Table 4-2 summarizes the contents of the three types of COBOL sentences. The remaining text in this section discusses each type of statement and sentence in greater detail.
Type | Contents of Sentence |
---|---|
Imperative | One or more consecutive imperative statements ending with a period |
Conditional | One or more conditional statements, optionally preceded by an imperative statement, terminated by the separator period |
Compiler-Directing | Only one compiler-directing statement ending with a period |
A compiler-directing statement causes the compiler to take an action during compilation. The verbs COPY, REPLACE, RECORD, or USE define a compiler-directing statement. When it is part of a sentence that contains more than one statement, the COPY, REPLACE, RECORD, or USE statement must be the last statement in the sentence.
A compiler-directing sentence is one COPY, REPLACE, RECORD, or USE
statement that ends with a period.
4.1.2 Imperative and Conditional Statements and Sentences
An imperative statement specifies an unconditional action for the program. It must contain a verb and the verb's operands, and cannot contain any conditional phrases. For example, the following statement is imperative:
READY UPDATE. |
However, the following statement is not imperative because it contains the phrase ON ERROR, which makes the program's action conditional:
STORE PART-REC ON ERROR PERFORM BAD-STORE. |
A delimited-scope statement is a special category of imperative statement used in structured programming. A delimited-scope statement is any statement that includes its explicit scope terminator. For more information, see the section on Explicit and Implicit Attributes.
In the Procedure Division rules, an imperative statement can be a sequence of consecutive imperative statements. The sequence must end with: (1) a separator period or (2) any phrase associated with a statement that contains the imperative statement. For example, the following sentence contains a sequence of two imperative statements following the AT END phrase.
FIND NEXT PART-REC AT END PERFORM NO-MORE-RECS DISPLAY "No more records." END-FIND. |
An imperative sentence contains only imperative statements and ends
with a
separator period.
4.2 Explicit and Implicit Scope Terminators
Scope terminators delimit the scope of some Procedure Division statements.
Explicit scope terminators for database programs are as follows:
END-COMMIT | END-FIND | END-READY |
END-CONNECT | END-FREE | END-RECONNECT |
END-DISCONNECT | END-GET | END-ROLLBACK |
END-ERASE | END-KEEP | END-STORE |
END-FETCH | END-MODIFY |
Implicit scope terminators are as follows:
A contained COBOL program can refer to a user-defined word in its containing program if the user-defined word has the global attribute. (See the section on User-Defined Words.) Some user-defined words always have the global attribute, some never have the attribute (that is, they are local), and some may or may not, depending on the use of the GLOBAL clause. The following rules explain how to use different kinds of user-defined words and what kinds of local and global name scoping to expect.
User-defined words in the Subschema Section are always global. The program defining this section and in any program it contains can reference these user-defined words:
Database key identifiers are indicated by the reserved words CURRENT, OFFSET, FIRST, and LAST as shown in the two formats below. FETCH and FIND may use database key identifiers to access database data records. Conditional clauses may also use them.
Database conditions allow alternate paths of control depending on the truth value of a test involving conditions specific to the database environment. The database conditions are the tenancy, member, and database key conditions.
Database exception conditions can occur during evaluation of these conditions. If a database exception condition occurs during the execution of a database condition, the Database Control System (DBCS) places a database exception condition code in the special register DB-CONDITION. This code identifies the condition. The DBCS also does the following:
These conditions determine whether a record in the database is an owner, or member, or a tenant in one or more sets.
set-name
is a subschema set name.
The result of the test is true if the current record of the run unit is as follows:
Otherwise, the result of the test is false. For example:
IF PART_USES OWNER PERFORM 100-PART-OWNER. IF PART_USED_ON MEMBER ... IF RESPONSIBLE_FOR TENANT ... |
If NOT is used, the result of the test is reversed.
Omitting set-name allows all subschema set types in which the record participates to be considered in determining the truth value of the condition.
If the run-unit currency indicator is null, a database exception
condition occurs and DB-CONDITION is set to DBM$_CRUN_NULL. If the
run-unit currency indicator only specifies a position, a database
exception condition occurs and DB-CONDITION is set to DBM$_CRUN_POS.
See Section 4.8.3, Exception Conditions and the USE Statement for information on USE FOR DB-EXCEPTION.
4.5.2 Empty Condition
The empty condition determines whether member records are present in one or more sets. Only member record types defined in the Subschema Section are considered in determining the truth value of the condition.
set-name
is a subschema set name.
If set-name is specified, the object set is the current set of that set type. If the object set has no member records, the result of the test is true. If the object set has member records, the result of the test is false.
If set-name is not specified, the object sets, if any, are owned by the current record of the run unit whose set type is defined in the Subschema Section. If each object set has no member records, the result of the test is true. If any object set has member records, the result of the test is false. For example:
IF PART_USES EMPTY ... IF EMPTY ... |
If NOT is used, the result of the test is reversed.
A database exception condition occurs if either:
See Section 4.8.3, Exception Conditions and the USE Statement for information on USE FOR DB-EXCEPTION.
4.5.3 Database Key Condition
The database key condition determines whether: (1) two database key values identify the same database record, (2) a database key value is null, or (3) a database key value is identical to any database key value in a keeplist.
database-key
references a currency indicator (see section on Database Key Identifiers) or a keeplist entry in the Subschema Section.
The result of the test is true if:
IF CURRENT WITHIN ALL_PARTS IS ALSO CURRENT ... |
IF CURRENT IS NULL NEXT SENTENCE ELSE KEEP USING KEEP-LIST-A. |
IF CURRENT IS WITHIN KEEP-LIST-A PERFORM 200-ITS-IN-THE-LIST. |
Otherwise, the result of the test is false.
If NOT is used, the result of the test is reversed.
A database exception condition occurs if:
Parentheses can specify the evaluation order in complex conditions. Conditions in parentheses are evaluated first. In nested parentheses, evaluation starts with the innermost set of parentheses. It proceeds to the outermost set.
Conditions are evaluated in a hierarchical order when there are no parentheses in a complex condition. This same order applies when all sets of parentheses are at the same level (none are nested). The hierarchy is shown in the following list:
In the absence of parentheses, the order of evaluation of consecutive operations at the same hierarchical level is from left to right.
Previous | Next | Contents | Index |