Compaq COBOL AAQ2G1FTK User Manual

Page 99

Advertising
background image

Handling Numeric Data

2.5 Evaluating Numeric Items

contains an invalid sign value, the NUMERIC class test rejects the item, and
program control takes the false path of the IF statement.

The ALPHABETIC class test check is not valid for an operand described as
numeric.

2.5.4 Success/Failure Tests

The success/failure condition tests the return status codes of COBOL and non-
COBOL procedures for success or failure conditions. You test status-code-id as
follows:

status-code-id IS



SUCCESS
FAILURE



You can use the SET statement to initialize or alter the status of status-code-id
(which must be a word or longword COMP integer represented by PIC 9(1 to 9)
COMP or PIC S9(1 to 9) COMP), as follows:

SET status-code-id TO



SUCCESS
FAILURE



The SET statement is typically in the called program, but the calling program
may also SET the status of status-code-id. The SUCCESS class condition is true
if status-code-id has been set to SUCCESS, otherwise it is false. The FAILURE
class condition is true if status-code-id has been set to FAILURE, otherwise it is
false. The results are unspecified if status-code is not set.

Example 2–1 shows the significant COBOL code relevant to a success/failure test.

Example 2–1 Success/Failure Test

. . .

PROGRAM-ID.

MAIN-PROG.

. . .

O1

RETURN-STATUS

PIC S9(9) COMP.

. . .

CALL "PROG-1" GIVING RETURN-STATUS.
IF RETURN-STATUS IS FAILURE PERFORM FAILURE-ROUTINE.

. . .

PROGRAM-ID. PROG-1.

. . .

.

WORKING-STORAGE SECTION.
01

RETURN-STATUS

PIC S9(9) COMP.

PROCEDURE DIVISION GIVING RETURN-STATUS.

. . .

IF NUM-1 = NUM-2

SET RETURN-STATUS TO SUCCESS

ELSE

SET RETURN-STATUS TO FAILURE.

. . .

EXIT PROGRAM.

END PROGRAM PROG-1.
END PROGRAM MAIN-PROG.

Handling Numeric Data 2–5

Advertising