Previous | Contents | Index |
When you create a Compaq COBOL DML program, you must include the
SUB-SCHEMA SECTION entry as the first section in the
Data Division. The SUB-SCHEMA SECTION is followed by a DB statement and
any LD statements. The Procedure Division contains all occurrences of
the DML verbs.
1.4 Compiling a Compaq COBOL DML Program
Your database administrator (DBA) creates schema and subschema definitions in Oracle CDD/Repository. These record definitions are defined in DMU format and are intended to serve all OpenVMS languages that might access them. In this format, the record definitions are not compatible with COBOL record definitions. Therefore, when the Compaq COBOL compiler retrieves the subschema definition from Oracle CDD/Repository, it translates the file into an internal form acceptable to the Compaq COBOL compiler.
If the translation results in compiler errors, they will probably be fatal.
You should alert your DBA to any errors resulting from a DB statement.
You can define the logical name CDD$DEFAULT as the starting schema node in Oracle CDD/Repository. There is only one logical name translation in the DB statement for schema-name. If you do not define it, CDD$TOP is the default.
You must recompile a Compaq COBOL DML program each time the subschema referenced by a DB statement is created. At compile time, the date and time of subschema creation (date and time stamps) are included with the translated subschema record definitions. If you do not recompile, your program will receive a fatal error at run time. |
A separately compiled Compaq COBOL database program must include the
SUB-SCHEMA SECTION header and only one DB statement. The compiler
copies and translates the record, set, and realm definitions in the
subschema named by the DB statement into compatible Compaq COBOL
record definitions. You will not see any database record definitions
listed immediately following the DB statement. The translated record,
set, and realm definitions are only in the compiler's subschema map
listing. To list these definitions in your program listing, use the
/MAP compiler command line qualifier.
1.4.2 Using the /MAP Compiler Qualifier
Use the /MAP compiler qualifier to generate a subschema map containing a translated subschema listing. Section 7.3 contains two subschema map listings on Alpha and two on VAX and explains how to read them. The following example compiles DBPROG and creates a listing that includes a subschema map:
$ COBOL/LIST/MAP DBPROG |
Compaq COBOL DML programs must be linked with the shareable Oracle CODASYL DBMS Library (SYS$LIBRARY:DBMDML/OPT). This library was created as part of the Oracle CODASYL DBMS installation procedure. Therefore, to link a Compaq COBOL DML object program named DMLPROG.OBJ with the shareable Oracle CODASYL DBMS Library, you use this DCL command:
$ LINK DMLPROG,SYS$LIBRARY:DBMDML/OPT |
You use the DCL command RUN to execute your Compaq COBOL DML program. At run time, the Database Control System (DBCS) fills a variety of roles in Compaq COBOL. Its major functions are to monitor database usage, act as an intermediary between Compaq COBOL and the OpenVMS operating system, and manipulate database records on behalf of user programs. Upon execution of the first DML statement, the DBCS implicitly executes a BIND statement that links the run unit to the database. If the BIND statement is unsuccessful, a database exception occurs.
The DBCS also enforces the subschema view of the database. For example, a database schema record may contain 20 data items. However, a subschema record may only define 10 of those data items. If a FETCH statement references this record, the DBCS only retrieves those defined 10 data items and makes them available to the COBOL program in the user work area (UWA). The other 10 items are not available to the COBOL program. Figure 1-2 illustrates the run-time relationships between an application program requesting subschema data (a FETCH statement, for example), the DBCS, and the data the subschema describes.
Figure 1-2 Database and Application Program Relationship
In your database programming project you will need familiarity with:
A user-defined word is a COBOL word that you must supply to satisfy the format of a clause or statement. This word consists of characters selected from the set A to Z, 0 to 9, the currency sign ($), underline (_), and hyphen (-). Throughout this manual, and except where specific rules apply, the hyphen (-) and the underline (_) are treated as the same character in a user-defined word. The underline (_), however, can begin or end a user-defined word, and the hyphen (-) cannot. By convention, names containing a currency sign ($) are reserved for Compaq.
Within a given source program, but excluding any contained program, each database-related user-defined word belongs to one of the following disjoint sets:
Keeplist-names
Realm-names
Schema-names
Set-names
Sub-schema-names
Record-names
Data-item-names
Each user-defined database-related word in a program can belong to only one of these sets. User-defined words in each set must be unique, except as described in the rules for uniqueness of reference. (Refer to the section on Uniqueness of Reference in the Procedure Division chapter of the Compaq COBOL Reference Manual. The same chapter defines user-defined names.)
Table 2-1 provides brief descriptions of the COBOL database-related user-defined words.
User-Defined Word Set | Purpose |
---|---|
Keeplist-name | Names a list of database keys used by the run unit to lock records for later use. |
Realm-name | Names a database realm. (See the READY statement in the Procedure Division chapter.) |
Schema-name | Names a database schema. (See the DB statement in the Data Division chapter.) |
Set-name | Identifies a database set type. |
Sub-schema-name | Names a database subschema. (See the DB statement in the Data Division chapter.) |
Record-name | Names a database record type. |
Data-item-name | Names a data-item that is defined for a record type. |
A reserved word can be used only as specified in the general formats.
It cannot be a user-defined word. (See the appendix that lists Reserved
Words.) Among the COBOL reserved words are required words,
optional words, and special-purpose words. One of the
special-purpose words, DB-CONDITION, is of special interest to the
database programmer.
2.2.1 DB-CONDITION
The reserved word DB-CONDITION names a database exception condition register. It is a longword COMP item represented by PIC S9(9) USAGE IS COMP. The execution of every COBOL data manipulation language (DML) statement causes the Database Control System (DBCS) to place a status code value in this register indicating either a successful condition or an exception condition.
Before the program executes the first DML statement, the value of DB-CONDITION is initialized to DBM$_NOT_BOUND. For an explanation of this and other Oracle CODASYL DBMS status codes, refer to the Oracle CODASYL DBMS documentation set.
If a DML statement causes an exception condition, the return status
code in DB-CONDITION equals the condition value. If the execution of a
DML statement does not result in a database exception condition,
DB-CONDITION contains a successful return status. Procedure Division
statements can access the values in this register; however, only the
DBCS can change the value.
2.2.2 DB-CURRENT-RECORD-NAME
This reserved word names a database register. It consists of 31 alphanumeric characters represented by PIC X(31) USAGE IS DISPLAY. The execution of COBOL data manipulation language (DML) statements that alter currency indicators causes the Database Control System (DBCS) to place a value in this register.
If the currency indicator for the run unit is not null, the register
contains the name of the record type of the current record of the run
unit. If the currency indicator for the run unit is null, the register
contains spaces. Procedure Division statements can access the values in
this register; however, only the DBCS can change the value.
2.2.3 DB-CURRENT-RECORD-ID
The reserved word DB-CURRENT-RECORD-ID names a database register. It consists of a word COMP item represented by PIC S9(4) USAGE IS COMP. The execution of COBOL data manipulation language (DML) statements that alter currency indicators causes the Database Control System (DBCS) to place a value in this register.
If the currency indicator for the run unit is not null, the register
contains the subschema User ID number (UID) of the record type of the
current record of the run unit. If the currency indicator for the run
unit is null, the register contains zero. Procedure Division statements
can access the values in this register; however, only the DBCS can
change the value.
2.2.4 DB-KEY
The reserved word DB-KEY names a database register. It consists of a quadword COMP item represented by PIC S9(18) USAGE IS COMP. The execution of the COBOL data manipulation language (DML) statements FETCH, FIND, and STORE causes the Database Control System (DBCS) to place a value in this register.
The DB-KEY special register contains three values. To access the individual values, move the DB-KEY register to a record as follows:
01 DATABASE-KEY 02 LINE-NUMBER PIC 9(4) USAGE IS COMP. 02 PAGE-NUMBER PIC 9(9) USAGE IS COMP. 02 AREA-NUMBER PIC 9(4) USAGE IS COMP. |
The reserved word DB-UWA names a database register. It consists of 108 alphanumeric characters represented by PIC X(108) USAGE IS DISPLAY. The Database Control System (DBCS) makes data items available to your program through the DB-UWA record delivery area. The DB-UWA register can be used with callable DBQ routines. Procedure Division statements can access the values in this register; however, only the DBCS can change the value. For more information, refer to the the discussion of the DBO/WORK_AREA command in the Oracle CODASYL DBMS documentation set.
The logical and physical concepts that apply to the Data Division in any COBOL program also apply to your database programs. The Compaq COBOL Reference Manual presents the general formats for Data Division entries and clauses, describes their basic elements, and lists rules of use. Information of special interest to the database programmer will be found here.
The Data Division defines the data processed by your COBOL program in both physical and logical terms. It also specifies whether the data is contained in files, a database, or Oracle CDD/Repository, or is developed only for local use in your program.
The Subschema Section specifies data contained in a database or Oracle CDD/Repository. The Working-Storage and Linkage Sections contain data description entries, which describe characteristics of data developed for use in your program.
3.1 DATA DIVISION General Format and Rules
Function
The Data Division describes data the program creates, receives as input, manipulates, and produces as output.
SUB-SCHEMA SECTION.
FILE SECTION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
REPORT SECTION.
SCREEN SECTION. (Alpha)
The last five COBOL sections are described and discussed in the Compaq COBOL Reference Manual chapter on Data Division.
Refer to the Compaq COBOL Reference Manual for:
The Subschema entry allows a program to access a subschema in Oracle CDD/Repository under the schema name.
sub-schema-name
references a subschema name in Oracle CDD/Repository under the schema name. See Technical Notes for more information.schema-name
references a schema name in Oracle CDD/Repository. See Technical Notes for more information.database-name
represents a complete or partial file specification defining the database occurrence. A database occurrence is a root file. At run time, database-name points the Database Control System (DBCS) to the root file. See Technical Notes for more information.stream-name
represents the name of the stream. See Technical Notes for more information.
DDL | COBOL |
---|---|
SIGNED BYTE | (a) |
UNSIGNED BYTE | (a) |
SIGNED WORD | S9(4) COMP |
UNSIGNED WORD | (b) |
SIGNED LONGWORD | S9(9) COMP |
UNSIGNED LONGWORD | (b) |
SIGNED QUADWORD | S9(18) COMP |
UNSIGNED QUADWORD | (b) |
SIGNED OCTAWORD | (a) |
UNSIGNED OCTAWORD | (a) |
FLOATING | COMP-1 |
FLOATING COMPLEX | (a) |
D_FLOATING | COMP-2 |
D_FLOATING COMPLEX | (a) |
G_FLOATING | COMP-2 (/FLOAT=G on Alpha) |
G_FLOATING COMPLEX | (a) |
H_FLOATING | (a) |
H_FLOATING COMPLEX | (a) |
CHARACTER l | X(l) |
UNSIGNED NUMERIC l s | 9(m)V9(n) |
LEFT SEPARATE NUMERIC l s | S9(m)V9(n) LEADING SEPARATE |
LEFT OVERPUNCHED NUMERIC l s | S9(m)V9(n) LEADING |
RIGHT SEPARATE NUMERIC l s | S9(m)V9(n) TRAILING SEPARATE |
RIGHT OVERPUNCHED NUMERIC l s | S9(m)V9(n) TRAILING |
ZONED NUMERIC l s | (a) |
PACKED DECIMAL l s | S9(m)V9(n) COMP-3 |
l---The total number of digits for the item.
s---The decimal offset to 1.
( a ) ---COBOL has no equivalent for this data type. A fatal diagnostic is issued for such an item, which is part of a subschema record description. The compiler treats this item as if it had been specified as an alphanumeric data item that occupies the same number of bytes.
( b ) ---COBOL has no exact equivalent for this data type. A warning diagnostic is issued for such an item, which is part of a subschema record description. The compiler treats this item as if it had been specified as the equivalent unsigned COMP item.
$ DBO/REPORT |
$ DBO/EXTRACT- $_ schema-name/SUB-SCHEMAS=sub-schema-name/OUTPUT=filename - $_ /OPTION=FULL $ PRINT filename |
$ DBO/DUMP database-name/SUB-SCHEMAS=sub-schema-name/OUTPUT=filename $ PRINT filename |
Previous | Next | Contents | Index |