Compaq COBOL AAQ2G1FTK User Manual

Page 84

Advertising
background image

Developing Compaq COBOL Programs
1.4 Program Run Messages

If, during execution, the program increments A-COUNTER by a value other
than 1 (2 or 1.5, for example), A-COUNTER may never equal 10, causing a
loop in ABC-ROUTINE. You can prevent this type of error by changing the
statement to something like this:

* This is a test for inequality
PERFORM ABC-ROUTINE UNTIL A-COUNTER > 9

Testing two floating point numbers (for example, COMP-1 and COMP-2 fields)
for equality. The calculations of your program might never produce exact
numerical equality between two floating point values.

Two negative test conditions combined with an OR. The object of the following
statement is to execute GO TO 200-PRINT-REPORT when TEST-FIELD
contains other than an A or B. However, the GO TO always executes because
no matter what TEST-FIELD contains, one of the conditions is always true.

IF TEST-FIELD NOT = "A" OR NOT = "B"

GO TO 200-PRINT-REPORT.
.
.
.

The following statement does not contain the logic error:

IF TEST-FIELD NOT = "A" AND NOT = "B"

GO TO 200-PRINT-REPORT.
.
.
.

1.4.3 Run-Time Input/Output Errors

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. (See the Compaq 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.

.
.
.

1–54 Developing Compaq COBOL Programs

Advertising