HP OpenVMS Systems Documentation

Content starts here

HP COBOL
DBMS Database Programming Manual


Previous Contents Index

4.1.1 Compiler-Directing Statements and Sentences

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:

  • At the end of a sentence: the separator period. It terminates the scope of all previously unterminated statements.
  • In a statement containing another statement: the next phrase of the containing statement after the contained statement terminates the scope of all unterminated contained statements. Examples are ELSE and WHEN.

4.3 Scope of Names

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:

  • Data-name
  • Keeplist-name
  • Realm-name
  • Record-name
  • Set-name

4.4 Database Key Identifiers

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.


General Rules

Format 1

  1. Record-name references a database record in the subschema.
  2. Set-name references a database set in the subschema.
  3. Realm-name references a subschema realm.
  4. Use this format to select a record whose database key value is in a currency indicator.
  5. The referenced currency indicator is the currency indicator for the record, set, or realm you specify in record-name, set-name, or realm-name.
  6. If you do not specify the WITHIN phrase, the referenced currency indicator is the currency indicator of the current record of the run unit.
  7. An exception condition occurs if the referenced currency indicator is null:
    1. Run-unit currency indicator (DB-CONDITION is set to DBM$_CRUN_NULL).
    2. Record type currency indicator (DB-CONDITION is set to DBM$_CRTYP_NULL).
    3. Set type currency indicator (DB-CONDITION is set to DBM$_CSTYP_NULL).
    4. Realm currency indicator (DB-CONDITION is set to DBM$_CRELM_NULL).

    See the USE statement for information on USE FOR DB-EXCEPTION.
  8. Other exception conditions occur if the referenced currency indicator points to a vacant position in the database collection:
    1. Run-unit currency indicator (DB-CONDITION is set to DBM$_CRUN_POS).
    2. Set type currency indicator (DB-CONDITION is set to DBM$_CSTYP_POS).
    3. Realm currency indicator (DB-CONDITION is set to DBM$_CRELM_POS).

    See the USE statement for information on USE FOR DB-EXCEPTION.

Format 2

  1. Integer-exp is an arithmetic expression or integer. It refers to a position in keeplist-name. Integer-exp cannot be zero.
  2. Keeplist-name is a keeplist defined in the Subschema Section.
  3. Use this format to select a record whose database key value is in a keeplist. Because a keeplist can contain more than one entry, you must specify which keeplist entry you want.
  4. Integer-exp can be either an integer or an arithmetic expression. Both result in a longword integer value.
  5. Using the FIRST clause is equivalent to OFFSET plus 1. It references the first database key value in the keeplist.
  6. Using the LAST clause is equivalent to OFFSET minus 1. It references the last database key value in the keeplist.
  7. The value of integer-exp points to an entry in keeplist-name. The entry whose ordinal position in the keeplist is equal to the value of integer-exp is called the referenced keeplist entry.
    1. If integer-exp is positive, the ordinal position is relative to the first entry in the keeplist.
    2. If integer-exp is negative, the ordinal position is relative to the last entry in the keeplist.
  8. An exception condition occurs if:
    1. Integer-exp is zero. DB-CONDITION is set to DBM$_BADZERO.
    2. The absolute value of integer-exp is greater than the number of database key values in the keeplist. DB-CONDITION is set to DBM$_END.
    3. The identified keeplist is empty. DB-CONDITION is set to DBM$_END.

    See the USE statement for information on the USE FOR DB-EXCEPTION statement.

4.5 Database Conditions

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:

  1. Places the record name of database-record in the special register DB-CURRENT-RECORD-NAME.
  2. Places the UID (User ID number) of the database record in DB-CURRENT-RECORD-ID.
  3. Invokes an applicable USE FOR DB-EXCEPTION Declaratives procedure, if any; otherwise, the DBCS abnormally terminates the run unit (see the USE statement). Under these circumstances, the result of the test is false.


Previous Next Contents Index