HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
Hewlett-Packard recommends using terminal format, an HP optional format, when you create source files from interactive terminals. The compiler accepts terminal format as the default reference format.
Terminal format eliminates the line number and identification fields of ANSI format and allows horizontal tab characters and short lines. Terminal format saves disk space and decreases compile time. It is easier to edit source code written in terminal format.
The following table shows the structure and content of a terminal reference source line: To select ANSI format, specify the -ansi flag (on Tru64 UNIX systems) or the /ANSI_FORMAT qualifier (on OpenVMS systems) at compile time. You can choose this format if your COBOL program is written for a compiler that uses ANSI format.
For ANSI format, the compiler expects 80-character program lines. The following table shows the structure and content of an ANSI reference source line:
Character Positions | Contents |
---|---|
1 to 6 | Optional sequence numbers |
7 | Indicators |
8 to 11 | Area A |
12 to 72 | Area B |
73 to 80 | Optional Area |
For more information about the two reference formats, refer to the
HP COBOL Reference Manual.
1.3.3.2 Converting Between Reference Formats
The REFORMAT utility allows you to convert a terminal format program to
ANSI format and vice versa. You can also use REFORMAT to match the
formats of HP COBOL source files and library files when their
formats are not the same. See Chapter 14 for a description of the
REFORMAT utility.
1.4 Program Run Messages
Incorrect or undesirable program results are usually caused by data
errors or program logic errors. You can resolve most of these errors by
desk-checking your program and by using a debugger.
1.4.1 Data Errors
Faulty or incorrectly defined data often produce incorrect results. Data errors can sometimes be attributed to one or more of the following actions:
77 COUNTER PIC S9. . . . PROCEDURE DIVISION. . . . LOOP. ADD 1 TO COUNTER IF COUNTER < 10 GO TO LOOP. |
01 PAY-RECORD. 03 P-NUMBER PIC X(5). 03 P-WEEKLY-AMT PIC S9(5)V99 COMP-3. 03 P-MONTHLY-AMT PIC S9(5)V99 COMP-3. 03 P-YEARLY-AMT PIC S9(5)V99 COMP-3. . . . |
In the following example, a program references the file incorrectly. The field described as P-YEARLY-AMT actually contains P-MONTHLY-AMT data, and vice versa.
01 PAY-RECORD. 03 P-NUMBER PIC X(5). 03 P-WEEKLY-AMT PIC S9(5)V99 COMP-3. 03 P-YEARLY-AMT PIC S9(5)V99 COMP-3. 03 P-MONTHLY-AMT PIC S9(5)V99 COMP-3. . . . PROCEDURE DIVISION. ADD-TOTALS. ADD P-MONTHLY-AMT TO TOTAL-MONTHLY-AMT. . . . |
You can minimize record field position errors by writing your file and record descriptions in a library file and then using the COPY statement in your programs. On OpenVMS systems, you can also use the COPY FROM DICTIONARY statement.
Choosing your test data carefully can minimize faulty data problems. For instance, rather than using actual or ideal data, use test files that include data extremes.
Determining when a program produces incorrect results can often help
your debugging effort. You can do this by maintaining audit counts
(such as total master in = nnn, total transactions in = nnn, total
deletions = nnn, total master out = nnn) and displaying the audit
counts when the program ends. Using conditional compilation lines (see
Section 1.2.2.7) in your program can also help
you to debug it.
1.4.2 Program Logic Errors
When checking your program for logic errors, first examine your program for some of the more obvious bugs, such as the following:
050-DO-WEEKLY-TOTALS. IF W-CODE = "W" PERFORM 100-WEEKLY-SUMMARY ADD WEEKLY-AMT TO WEEKLY-TOTALS. GO TO 000-READ-A-MASTER. WRITE NEW-MASTER-REC. |
* This is a test for equality PERFORM ABC-ROUTINE UNTIL A-COUNTER = 10. |
* This is a test for inequality PERFORM ABC-ROUTINE UNTIL A-COUNTER > 9 |
IF TEST-FIELD NOT = "A" OR NOT = "B" GO TO 200-PRINT-REPORT. . . . |
IF TEST-FIELD NOT = "A" AND NOT = "B" GO TO 200-PRINT-REPORT. . . . |
An input/output error is a condition that causes an I/O statement to fail. These I/O errors are detected at run time by the I/O system. Each time an I/O operation occurs, the I/O system generates a two-character file status value. One way to determine the nature of an I/O error is to check a file's I/O status by using file status data items. (Refer to the HP COBOL Reference Manual for a list of file status values.) See Chapter 7, Handling Input/Output Exception Conditions for additional information about I/O exception condition handling.
Checking a file's I/O status within a Declarative USE procedure or in an INVALID KEY imperative condition can help you determine the nature of an I/O error. For example:
FD INDEXED-MASTER ACCESS MODE IS DYNAMIC FILE STATUS IS MASTER-STATUS RECORD KEY IN IND-KEY. . . . WORKING-STORAGE SECTION. 01 MASTER-STATUS PIC XX VALUE SPACES. . . . PROCEDURE DIVISION. . . . 050-READ-MASTER. READ INDEXED-MASTER INVALID KEY PERFORM 100-CHECK-STATUS GO TO 200-INVALID-READ. . . . 100-CHECK-STATUS. IF MASTER-STATUS = "23" DISPLAY "RECORD NOT IN FILE". IF MASTER-STATUS = "24" DISPLAY "BOUNDARY VIOLATION OR RELATIVE RECORD NUMBER TOO LARGE". . . . |
If your program contains a Declarative USE procedure for a file and an I/O operation for that file fails, the I/O system performs the USE procedure, but does not display an error message.
A Declarative USE procedure can sometimes avoid program termination. For example, File Status 91 indicates that the file is locked by another program; rather than terminate your program, you can perform other procedures and then try reopening the file. If program continuation is not desirable, the Declarative USE procedure can perform housekeeping functions, such as saving data or displaying program-generated diagnostic messages.
Previous | Next | Contents | Index |