Previous | Contents | Index |
The Database Query utility (DBQ) commands and generic DML statements are the tools you use to debug and test your Compaq COBOL program's DML statements. For example, you can use DBQ commands to display currency indicators, test program loops, or check your program's execution efficiency.
It is important to eliminate any logic errors prior to running a Compaq COBOL DML program against a live database, because poorly written or incorrect logic can corrupt a database. You can resolve some logic errors by desk-checking a program. Desk-checking involves reviewing the logical ordering and proper use of DML statements; for example, to check for executing a FIND when you intend to execute a FETCH, or executing a CONNECT instead of a RECONNECT. You can also use a debugger (refer to the debugging information in the Compaq COBOL User Manual). However, neither method gives you information on currency indicators and the effects DML statements have on them.
Another method of debugging Compaq COBOL DML programs is to test DML statements using the DBQ utility. DBQ is an online interactive utility that uses a split screen to show the results of each execution of a DML statement. It is also an effective database programming learning tool. For a complete description of the DBQ utility, refer to the Oracle CODASYL DBMS documentation on data manipulation and programming.
We recommend that you use all of these tools to design, test, and debug
your Compaq COBOL DML programs.
7.1 DBQ Commands and DML Statements
The DBQ utility provides both generic DML statements and DBQ-specific commands. Generic DML statements are similar to the Compaq COBOL DML statements explained in Chapter 4. However, not all Compaq COBOL DML syntax is applicable to the DBQ utility. These statements and entries do not apply:
DB PARTSS3 WITHIN PARTS FOR NEW. |
dbq>BIND PARTSS3 FOR NEW |
For a complete discussion of generic DML, refer to the Oracle CODASYL DBMS
documentation on data manipulation and programming.
7.2 Sample Debugging and Testing Session
This section shows how to use the DBQ utility for debugging and testing Compaq COBOL DML programs. Because the split screen limits the number of lines that can be displayed at one time, the split screen figures show the Bachman diagram only. Corresponding DBQ prompts, entries, and messages follow each Bachman diagram and are shown in their entirety.
The session tests and finds a logic error in the DML program statements in Example 7-1. The sample COBOL DML program is intended to:
Remember, the database key values displayed on your screen may be different from those in the examples.
If you are currently accessing PARTSS3 with the DBQ utility and have made any changes to the database, use the ROLLBACK statement to cancel your changes. Otherwise, you might change the results of the debugging session. |
Example 7-1 Sample Compaq COBOL DML Program Statements |
---|
DATA DIVISION. DB PARTSS3 WITHIN PARTS FOR NEW. . . . PROCEDURE DIVISION. 000-BEGIN. READY PROTECTED UPDATE. . . . MOVE "AZ177311" TO PART_ID. FETCH FIRST PART USING PART_ID. MOVE "N" TO END-OF-COLLECTION. PERFORM A100-LOOP THROUGH A100-LOOP-EXIT UNTIL END-OF-COLLECTION = "Y". . . . STOP RUN. A100-LOOP. FETCH NEXT WITHIN PART_SUPPLY AT END MOVE "Y" TO END-OF-COLLECTION GO TO A100-LOOP-EXIT. IF SUP_RATING = "0" MOVE "5" TO SUP_RATING MODIFY SUP_RATING MOVE 1 TO MODIFY-COUNT FETCH OWNER WITHIN VENDOR_SUPPLY PERFORM PRINT-VENDOR. IF MODIFY-COUNT = 1 MOVE "X" TO PART_STATUS MODIFY PART_STATUS. A100-LOOP-EXIT. EXIT. |
The following DBQ session tests and debugs the sample DML program statements in Example 7-1:
$ DBQ dbq> BIND PARTSS3 FOR NEW dbq> READY PROTECTED UPDATE dbq> SET CURSIG dbq> FETCH FIRST PART USING PART_ID |
DBQ prompts you for a PART_ID value:
PART_ID [CHARACTER(8)] =AZ177311 |
Entering AZ177311 as the PART_ID value causes the Bachman diagram in Figure 7-1 to appear on your screen.
Figure 7-1 Split Screen After FETCH FIRST PART USING PART_ID
The next DML statement in Figure 7-2 is FETCH NEXT WITHIN PART_SUPPLY. Although this statement is in a performed loop, you can still test its logic by executing a series of FETCH NEXT WITHIN PART_SUPPLY until you find a SUP_RATING equal to 0.
dbq> FETCH NEXT WITHIN PART_SUPPLY |
Figure 7-2 Split Screen After FETCH NEXT WITHIN PART_SUPPLY
Because SUPPLY participates in two sets, the Bachman diagram in Figure 7-2 shows the set relationships for SUPPLY. Notice the SUPPLY record has a SUP_RATING equal to 0. Therefore, you can test the next DML statement.
dbq> MODIFY SUP_RATING SUP_RATING [CHARACTER(1)]= 5 |
Notice how the MODIFY statement causes DBQ to issue a prompt, as shown in the preceding statement. When you MODIFY or STORE a record, DBQ prompts you for data entry by displaying the data name and its attributes. After entering the new SUP_RATING, use the RETURN key to execute the MODIFY statement.
Because this MODIFY statement does not change currency, the Bachman diagram in Figure 7_3 is the same as the one in Figure 7-2. Also, DBQ does not display currency update messages.
Figure 7-3 Split Screen After MODIFY SUP_RATING
The next statement to test is the FETCH for SUPPLY record's owner in the VENDOR_SUPPLY set.
dbq> FETCH OWNER WITHIN VENDOR_SUPPLY |
Figure 7-4 Split Screen After FETCH OWNER WITHIN VENDOR_SUPPLY
Assuming the data item MODIFY-COUNT has a value 1, you can test the last (MODIFY PART) DML statement.
dbq> MODIFY PART_STATUS PART_STATUS [CHARACTER(1)]= X dbq> DBM-F-WRONGRTYP, Specified record type not current record type |
DBQ generates an error message indicating the MODIFY statement did not execute because the current of run unit is not a PART record. Comparing the shading and intensities of the Bachman diagram in Figure 7-4 with the legend shows the current record is a VENDOR record. Therefore, the diagram indicates that a MODIFY to the PART record will not work even before you attempt the MODIFY statement.
To correct the logic error, PART must be the current record type prior to execution of the MODIFY PART_STATUS statement. One way to correct the logic error is to execute a FETCH CURRENT PART statement before the MODIFY PART_STATUS statement. Example 7-2 shows a corrected version of the sample COBOL DML program statements in Example 7-1.
Example 7-2 Sample DML Program Statements |
---|
DATA DIVISION. DB PARTSS3 WITHIN PARTS FOR NEW. . . . PROCEDURE DIVISION. 000-BEGIN. READY PROTECTED UPDATE. . . . MOVE "AZ177311" TO PART_ID. FETCH FIRST PART USING PART_ID. MOVE "N" TO END-OF-COLLECTION. PERFORM A100-LOOP THROUGH A100-LOOP-EXIT UNTIL END-OF-COLLECTION = "Y". . . . STOP RUN. A100-LOOP. FETCH NEXT WITHIN PART_SUPPLY AT END MOVE "Y" TO END-OF-COLLECTION GO TO A100-LOOP-EXIT. IF SUP_RATING = "0" MOVE "5" TO SUP_RATING MODIFY SUP_RATING MOVE 1 TO MODIFY-COUNT FETCH OWNER WITHIN VENDOR_SUPPLY PERFORM PRINT-VENDOR. IF MODIFY-COUNT = 1 MOVE "X" TO PART_STATUS FETCH CURRENT PART RETAINING PART_SUPPLY MODIFY PART_STATUS. A100-LOOP-EXIT. EXIT. |
The FETCH CURRENT PART statement uses the RETAINING clause to keep the current SUPPLY record as current of PART_SUPPLY.
Continue testing, starting with the new FETCH statement.
dbq> FETCH CURRENT PART RETAINING PART_SUPPLY |
Figure 7-5 shows that executing FETCH CURRENT PART RETAINING PART_SUPPLY makes PART the current record type, while the RETAINING clause keeps SUPPLY current of PART_SUPPLY set. Retaining the current supply record as current of PART_SUPPLY means the next execution of FETCH NEXT WITHIN PART_SUPPLY uses the current SUPPLY record's currency to locate the next SUPPLY record. If you executed a FETCH CURRENT PART without the RETAINING clause, a FETCH NEXT WITHIN PART_SUPPLY would use PART's currency and FETCH the first SUPPLY record belonging to PART.
Figure 7-5 Split Screen After FETCH CURRENT PART RETAINING PART_SUPPLY
Now you can retest the MODIFY PART_STATUS.
dbq> MODIFY PART_STATUS PART_STATUS [CHARACTER(1)]= X dbq> |
The DBQ prompt indicates the MODIFY was successful.
With the logic error found and fixed, you can test to see if the next execution of the FETCH NEXT WITHIN PART_SUPPLY fetches the next SUPPLY record belonging to the first PART record.
dbq> FETCH NEXT WITHIN PART_SUPPLY |
The database keys displayed by the currency update messages in Figure 7_6 and Figure 7-7 are the same, thereby showing the A100-LOOP paragraph will fetch the next SUPPLY record owned by the first PART record.
Notice the data items also have the same value. Comparing data item contents instead of database key values is not a good practice because duplicate records may be allowed. For example, a PART may have two or more SUPPLY records containing the same data. Also, each SUPPLY record could point to a different owner in the VENDOR_SUPPLY set type.
Figure 7-6 Split Screen After FETCH NEXT WITHIN PART_SUPPLY
To show that the record is indeed the second SUPPLY record belonging to the first PART record, execute the following statement:
dbq> FETCH 2 WITHIN PART_SUPPLY |
Figure 7-7 Split Screen After FETCH 2 WITHIN PART_SUPPLY
Listings are different on OpenVMS Alpha and OpenVMS VAX systems. This
section shows two listings on Alpha and two on VAX.
7.3.1 Listings on Alpha
This section shows two compiler listing examples on OpenVMS Alpha.
PARTSS1 Program Map Listing (Alpha)
PARTSS1-PROGRAM in Example 7-3 includes the Oracle CODASYL DBMS data-names of the PARTSS1 subschema. The complete subschema can be obtained from the Oracle CDD/Repository DICTIONARY utility, using the following commands (refer to the Oracle CDD/Repository documentation):
$ DICTIONARY OPERATOR CDO> SET OUTPUT filename.extension CDO> SHO GENERIC CDD$DATABASE/FULL database-name |
(The logical CDD$DEFAULT must have been previously defined.)
Example 7-3 PARTSS1-PROGRAM Compiler Listing (Alpha) |
---|
PARTSS1-PROGRAM Source Listing 18-JUN-2001 08:20:37 Compaq COBOL V2.7 Page 1 0 Source Listing 18-JUN-2001 08:17:19 DEVICE:[COBOL.EXAMPLES]PARTSS1.COB;1 1 IDENTIFICATION DIVISION. 2 PROGRAM-ID. PARTSS1-PROGRAM. 3 4 DATA DIVISION. 5 SUB-SCHEMA SECTION. 6 DB PARTSS5 WITHIN PARTS FOR "DBM$IVP_OUTPUT:DBMPARTS". 7 8 PROCEDURE DIVISION. 9 END PROGRAM PARTSS1-PROGRAM. PARTSS1-PROGRAM Source Listing 18-JUN-2001 08:20:37 Compaq COBOL V2.7 Page 2 0 Program Section Summary 18-JUN-2001 08:17:19 DEVICE:[COBOL.EXAMPLES]PARTSS1.COB;1 PROGRAM SECTION INDEX Index Name Bytes Alignment Attributes ----- ---------------- ---------- --------- ------------------------------------------------------------- 11 DBM$UWA_B 576 OCTA 4 PIC OVR REL GBL SHR NOEXE RD WRT NOVEC 12 DBM$SSC_B 48 OCTA 4 PIC CON REL GBL NOSHR NOEXE RD NOWRT NOVEC DIAGNOSTICS SUMMARY Informationals 1 (suppressed) ---------------------- Total 1 PARTSS1_PROGRAM\PARTSS1_PROGRAM Source Listing 18-JUN-2001 08:20:37 Compaq COBOL V2.7 Page 3 0 Data Names in Alphabetic Order 18-JUN-2001 08:17:19 DEVICE:[COBOL.EXAMPLES]PARTSS1.COB;1 Line Level Name Location Size Bytes Usage Category Subs Attribute ----- ----- ------------- ------------- ---------- ---------- -------- -------- ---- --------- 6 01 CATEGORY 11 000000C8 23 23 DISPLAY Group Glo 6 02 CLASS_CODE 11 000000C8 2 2 DISPLAY AN Glo 6 02 CLASS_DESC 11 000000CA 20 20 DISPLAY AN Glo 6 02 CLASS_STATUS 11 000000DE 1 1 DISPLAY AN Glo 6 02 COMP_MEASURE 11 000000F0 1 1 DISPLAY AN Glo 6 02 COMP_OWNER_PART 11 000000E8 8 8 DISPLAY AN Glo 6 02 COMP_QUANTITY 11 000000F1 5 3 COMP-3 N Glo 6 02 COMP_SUB_PART 11 000000E0 8 8 DISPLAY AN Glo 6 01 COMPONENT 11 000000E0 20 20 DISPLAY Group Glo 6 01 DB-CONDITION 11 0000003C 9 4 COMP N Glo 6 01 DB-CURRENT-RECORD-ID 11 00000000 4 2 COMP N Glo 6 01 DB-CURRENT-RECORD-NAME 11 00000019 31 31 DISPLAY AN Glo 6 01 DB-KEY 11 0000007A 18 8 COMP N Glo 6 01 DB-UWA 11 00000000 108 108 DISPLAY AN Glo 6 02 EMP_FIRST_NAME 11 0000010F 10 10 DISPLAY AN Glo 6 02 EMP_ID 11 000000F8 5 3 COMP-3 N Glo 6 02 EMP_LAST_NAME 11 000000FB 20 20 DISPLAY AN Glo 6 02 EMP_LOC 11 00000120 5 5 DISPLAY AN Glo 6 02 EMP_PHONE 11 00000119 7 7 DISPLAY AN Glo 6 01 EMPLOYEE 11 000000F8 45 45 DISPLAY Group Glo 6 02 GROUP_NAME 11 00000128 20 20 DISPLAY AN Glo 6 01 PART 11 00000140 71 71 DISPLAY Group Glo 6 02 PART_COST 11 00000180 9 5 COMP-3 N Glo 6 02 PART_DESC 11 00000148 50 50 DISPLAY AN Glo 6 02 PART_ID 11 00000140 8 8 DISPLAY AN Glo 6 02 PART_PRICE 11 0000017B 9 5 COMP-3 N Glo 6 02 PART_STATUS 11 0000017A 1 1 DISPLAY AN Glo 6 02 PART_SUPPORT 11 00000185 2 2 DISPLAY AN Glo 6 01 PR_QUOTE 11 00000188 26 26 DISPLAY Group Glo 6 02 QUOTE_DATE 11 0000018F 6 6 DISPLAY AN Glo 6 02 QUOTE_ID 11 00000188 7 7 DISPLAY AN Glo 6 02 QUOTE_MIN_ORDER 11 00000195 5 3 COMP-3 N Glo 6 02 QUOTE_QTY_PRICE 11 0000019D 9 5 COMP-3 N Glo 6 02 QUOTE_UNIT_PRIC 11 00000198 9 5 COMP-3 N Glo 6 02 SUP_LAG_TIME 11 000001AD 10 10 DISPLAY AN Glo 6 02 SUP_RATING 11 000001A8 1 1 DISPLAY AN Glo 6 02 SUP_TYPE 11 000001A9 4 4 DISPLAY AN Glo 6 01 SUPPLY 11 000001A8 15 15 DISPLAY Group Glo 6 02 VEND_ADDRESS 11 00000206 15 15 DISPLAY AN 1 Glo 6 02 VEND_CONTACT 11 000001E8 30 30 DISPLAY AN Glo 6 02 VEND_ID 11 000001B8 8 8 DISPLAY AN Glo 6 02 VEND_NAME 11 000001C0 40 40 DISPLAY AN Glo 6 02 VEND_PHONE 11 00000233 10 10 DISPLAY AN Glo 6 01 VENDOR 11 000001B8 133 133 DISPLAY Group Glo 6 01 WK_GROUP 11 00000128 20 20 DISPLAY Group Glo PARTSS1_PROGRAM\PARTSS1_PROGRAM Source Listing 18-JUN-2001 08:20:37 Compaq COBOL Page 4 0 Procedure Names in Alpha Order 18-JUN-2001 08:17:19 DEVICE:[COBOL.EXAMPLES]PARTSS1.COB;1 Line Name Location Type ----- ------------------------------- ------------- ----------------------------------------------------- 2 PARTSS1-PROGRAM ** Program PARTSS1_PROGRAM\PARTSS1_PROGRAM Source Listing 18-JUN-2001 08:20:37 Compaq COBOL V Page 5 0 Compilation Summary 18-JUN-2001 08:17:19 DEVICE:[COBOL.EXAMPLES]PARTSS1.COB;1 COMMAND QUALIFIERS COBOL /NOALIGNMENT /GRANULARITY = QUAD /NOANALYSIS_DATA /NOINCLUDE /NOANSI_FORMAT /LIST /ARCHITECTURE = GENERIC /NOMACHINE_CODE /ARITHMETIC = NATIVE /MAP = ALPHABETICAL /NOAUDIT /MATH_INTERMEDIATE = FLOAT /CHECK = (NOPERFORM, NOBOUNDS, NODECIMAL, NODUPLICATE_KEYS) /NATIONALITY = US /NOCONDITIONALS /NOOBJECT /NOCONVERT = LEADING_BLANKS /OPTIMIZE = (LEVEL=4,TUNE=GENERIC) /NOCOPY_LIST /RESERVED_WORDS = (XOPEN, NOFOREIGN_EXTENSIONS, NO200X) /NOCROSS_REFERENCE /NOSEPARATE_COMPILATION /DEBUG = (NOSYMBOLS, TRACEBACK) /NOSEQUENCE_CHECK /NODEPENDENCY_DATA /STANDARD = (NOXOPEN, NOSYNTAX, NOV3, 85, NOMIA) /NODIAGNOSTICS /NOTIE /NODISPLAY_FORMATTED /NOTRUNCATE /NOFIPS /VFC /NOFLAGGER /WARNINGS = (NOINFORMATION, OTHER) /FLOAT = D_FLOAT COMPILATION STATISTICS CPU time: 1.59 seconds Elapsed time: 7.59 seconds Pagefaults: 1014 I/O Count: 343 Source lines: 9 339 lines per CPU minute. |
PARTSS3 Program Map Listing (Alpha)
PARTSS3-PROGRAM in Example 7-4 includes the Oracle CODASYL DBMS data-names of the PARTSS3 subschema.
Example 7-4 PARTSS3-PROGRAM Compiler Listing (Alpha) |
---|
PARTSS3-PROGRAM Source Listing 18-JUN-2001 08:33:40 Compaq COBOL V2.7 Page 1 0 Source Listing 18-JUN-2001 08:30:39 DEVICE:[COBOL.EXAMPLES]PARTSSE.COB;1 1 IDENTIFICATION DIVISION. 2 PROGRAM-ID. PARTSS3-PROGRAM. 3 4 DATA DIVISION. 5 SUB-SCHEMA SECTION. 6 DB PARTSS3 WITHIN PARTS FOR "DBM$IVP_OUTPUT:DBMPARTS". 7 8 PROCEDURE DIVISION. 9 END PROGRAM PARTSS3-PROGRAM. PARTSS3-PROGRAM Source Listing 18-JUN-2001 08:33:40 Compaq COBOL V2.7 Page 2 0 Program Section Summary 18-JUN-2001 08:30:39 DEVICE:[COBOL.EXAMPLES]PARTSSE.COB;1 PROGRAM SECTION INDEX Index Name Bytes Alignment Attributes ----- ----------- ---------- --------- ------------------------------------------------------------- 11 DBM$UWA_B 376 OCTA 4 PIC OVR REL GBL SHR NOEXE RD WRT NOVEC 12 DBM$SSC_B 48 OCTA 4 PIC CON REL GBL NOSHR NOEXE RD NOWRT NOVEC DIAGNOSTICS SUMMARY Informationals 1 (suppressed) ---------------------- Total 1 PARTSS3_PROGRAM\PARTSS3_PROGRAM Source Listing 18-JUN-2001 08:33:40 Compaq COBOL V2.7 Page 3 0 Data Names in Alphabetic Order 18-JUN-2001 08:30:39 DEVICE:[COBOL.EXAMPLES]PARTSSE.COB;1 Line Level Name Location Size Bytes Usage Category Subs Attribute ----- ----- -------------- ------------- ---------- ---------- -------- -------- ---- --------- 6 01 DB-CONDITION 11 0000003C 9 4 COMP N Glo 6 01 DB-CURRENT-RECORD-ID 11 00000000 4 2 COMP N Glo 6 01 DB-CURRENT-RECORD-NAME 11 00000019 31 31 DISPLAY AN Glo 6 01 DB-KEY 11 0000007A 18 8 COMP N Glo 6 01 DB-UWA 11 00000000 108 108 DISPLAY AN Glo 6 01 PART 11 000000A0 61 61 DISPLAY Group Glo 6 02 PART_DESC 11 000000A8 50 50 DISPLAY AN Glo 6 02 PART_ID 11 000000A0 8 8 DISPLAY AN Glo 6 02 PART_STATUS 11 000000DA 1 1 DISPLAY AN Glo 6 02 PART_SUPPORT 11 000000DB 2 2 DISPLAY AN Glo 6 02 SUP_LAG_TIME 11 000000E5 10 10 DISPLAY AN Glo 6 02 SUP_RATING 11 000000E0 1 1 DISPLAY AN Glo 6 02 SUP_TYPE 11 000000E1 4 4 DISPLAY AN Glo 6 01 SUPPLY 11 000000E0 15 15 DISPLAY Group Glo 6 02 VEND_ADDRESS 11 0000013E 15 15 DISPLAY AN 1 Glo 6 02 VEND_CONTACT 11 00000120 30 30 DISPLAY AN Glo 6 02 VEND_ID 11 000000F0 8 8 DISPLAY AN Glo 6 02 VEND_NAME 11 000000F8 40 40 DISPLAY AN Glo 6 02 VEND_PHONE 11 0000016B 10 10 DISPLAY N Glo 6 01 VENDOR 11 000000F0 133 133 DISPLAY Group Glo PARTSS3_PROGRAM\PARTSS3_PROGRAM Source Listing 18-JUN-2001 08:33:40 Compaq COBOL V2.7 Page 4 0 Procedure Names in Alpha Order 18-JUN-2001 08:30:39 DEVICE:[COBOL.EXAMPLES]PARTSSE.COB;1 Line Name Location Type ----- ---------- ------------- ------------------------------------------------------------------------- 2 PARTSS3-PROGRAM ** Program PARTSS3_PROGRAM\PARTSS3_PROGRAM Source Listing 18-JUN-2001 08:33:40 Compaq COBOL V2.7 Page 5 0 Compilation Summary 18-JUN-2001 08:30:39 DEVICE:[COBOL.EXAMPLES]PARTSSE.COB;1 COMMAND QUALIFIERS COBOL /NOALIGNMENT /GRANULARITY = QUAD /NOANALYSIS_DATA /NOINCLUDE /NOANSI_FORMAT /LIST /ARCHITECTURE = GENERIC /NOMACHINE_CODE /ARITHMETIC = NATIVE /MAP = ALPHABETICAL /NOAUDIT /MATH_INTERMEDIATE = FLOAT /CHECK = (NOPERFORM, NOBOUNDS, NODECIMAL, NODUPLICATE_KEYS) /NATIONALITY = US /NOCONDITIONALS /NOOBJECT /NOCONVERT = LEADING_BLANKS /OPTIMIZE = (LEVEL=4,TUNE=GENERIC) /NOCOPY_LIST /RESERVED_WORDS = (XOPEN, NOFOREIGN_EXTENSIONS, NO200X) /NOCROSS_REFERENCE /NOSEPARATE_COMPILATION /DEBUG = (NOSYMBOLS, TRACEBACK) /NOSEQUENCE_CHECK /NODEPENDENCY_DATA /STANDARD = (NOXOPEN, NOSYNTAX, NOV3, 85, NOMIA) /NODIAGNOSTICS /NOTIE /NODISPLAY_FORMATTED /NOTRUNCATE /NOFIPS /VFC /NOFLAGGER /WARNINGS = (NOINFORMATION, OTHER) /FLOAT = D_FLOAT COMPILATION STATISTICS CPU time: 1.59 seconds Elapsed time: 7.63 seconds Pagefaults: 1053 I/O Count: 340 Source lines: 9 339 lines per CPU minute. <> |
Previous | Next | Contents | Index |