[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
The Database Query utility (DBQ) commands and generic DML statements are the tools you use to debug and test your HP 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 an HP 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 HP COBOL User Manual). However, neither method gives you information on currency indicators and the effects DML statements have on them.
Another method of debugging HP 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 HP 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 HP COBOL DML statements explained in Chapter 4. However, not all HP 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 HP 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 HP 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. |
Previous | Next | Contents | Index |