Developing Compaq COBOL Programs
1.4 Program Run Messages
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 Alpha 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.3.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:
•
Hidden periods. Periods inadvertently placed in a statement usually produce
unexpected results. For example:
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.
The period at the end of ADD WEEKLY-AMT TO WEEKLY-TOTALS
terminates the scope of the IF statement and changes the logic of
the program. Including the extra period before the GO TO statement
transforms GO TO 000-READ-A-MASTER from a conditional statement to
an unconditional statement. Because the GO TO statement is not within the
scope of the IF statement, it will always be executed. In addition, the WRITE
statement following the GO TO will never be executed.
•
Tests for equality, which can cause an infinite loop if the procedure is to be
executed until the test condition is met, for example:
* This is a test for equality
PERFORM ABC-ROUTINE UNTIL A-COUNTER = 10.
Developing Compaq COBOL Programs 1–53
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......