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
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
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
. . .
CALL "PROG-1" GIVING RETURN-STATUS.
IF RETURN-STATUS IS FAILURE PERFORM FAILURE-ROUTINE.
. . .
PROGRAM-ID. PROG-1.
. . . .
WORKING-STORAGE SECTION.
01 RETURN-STATUS
PROCEDURE DIVISION GIVING RETURN-STATUS.
. . .
IF NUM-1 = NUM-2
ELSE
. . .
EXIT PROGRAM.
END PROGRAM PROG-1.
END PROGRAM MAIN-PROG.
SUCCESS
FAILURE
SUCCESS
FAILURE
PIC S9(9) COMP.
PIC S9(9) COMP.
SET RETURN-STATUS TO SUCCESS
SET RETURN-STATUS TO FAILURE.
Handling Numeric Data
2.5 Evaluating Numeric Items
Handling Numeric Data 2–5
Need help?
Do you have a question about the COBOL AAQ2G1FTK and is the answer not in the manual?
Questions and answers