[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
The success/failure condition tests the return status codes of COBOL and non-COBOL procedures for success or failure conditions.
status-code-id
must be a COMP integer represented by PIC 9(1 to 9) COMP or PIC S9(1 to 9) COMP.
You can use the SET statement to initialize or alter the status of status-code-id.
The SUCCESS class condition is true if you specify status-code-id IS SUCCESS and status-code-id is in a SUCCESS state. Otherwise, the SUCCESS class condition is false.
The FAILURE class condition is true if you specify status-code-id IS FAILURE and status-code-id is in a FAILURE state. Otherwise, the FAILURE class condition is false.
status-code-id is in the SUCCESS state when the low-order bit of status-code-id is 1. It is in the FAILURE state when its low-order bit is 0.
WORKING-STORAGE SECTION. 01 RMS-EOF PIC S9(9) COMP VALUE EXTERNAL RMS$_EOF. 01 RETURN-STATUS PIC S9(9) COMP. PROCEDURE DIVISION. A000-BEGIN. . . . CALL "LIB$GET_SCREEN" USING BY DESCRIPTOR INPUT-TEXT, PROMPT, BY REFERENCE OUT-LEN, GIVING RETURN-STATUS. IF RETURN-STATUS = RMS-EOF PERFORM CTRL-Z-TRAP-ROUTINE. IF RETURN-STATUS IS FAILURE PERFORM FAILURE-ROUTINE. . . . <> |
IDENTIFICATION DIVISION. PROGRAM-ID. MAIN-PROGRAM. DATA DIVISION. WORKING-STORAGE SECTION. 01 RETURN-STATUS PIC S9(9) COMP. PROCEDURE DIVISION. . . . CALL "SUB" GIVING RETURN-STATUS. IF RETURN-STATUS IS FAILURE PERFORM FAILURE-ROUTINE. . . . IDENTIFICATION DIVISION. PROGRAM-ID. SUB. . . . WORKING-STORAGE SECTION. 01 RETURN-STATUS PIC S9(9) COMP. PROCEDURE DIVISION GIVING RETURN-STATUS. . . . IF A = B SET RETURN-STATUS TO SUCCESS ELSE SET RETURN-STATUS TO FAILURE. . . . EXIT PROGRAM. END PROGRAM SUB. END PROGRAM MAIN-PROGRAM. |
You form complex conditions by combining or negating other conditions. The conditions being combined or negated can be either simple or complex.
The logical operators AND and OR combine conditions. The logical operator NOT negates conditions. A space must precede and follow each logical operator in your program.
The truth value of a complex condition depends upon the following:
Table 6-4 shows the effect of each logical operator in complex conditions.
Logical Operator |
Meaning and Effect |
---|---|
AND | Logical conjunction. The truth value is true if both connected conditions are true. It is false if one or both connected conditions are false. |
OR | Logical inclusive OR. The truth value is true if one or both connected conditions are true. It is false if both conditions are false. |
NOT | Logical negation or reversal of truth value. The truth value is true if the original condition is false. It is false if the original condition is true. |
The logical operator NOT negates a simple condition. The truth value of a negated simple condition is the opposite of the simple condition's truth value. Thus, the truth value of a negated simple condition is true only if the simple condition's truth value is false. It is false only if the simple condition's truth value is true.
The format for a negated simple condition is as follows:
Combined and Negated Combined Conditions
A combined condition results from connecting conditions with one of the logical operators AND or OR.
The general format is as follows:
In the general format, condition can be one of the following:
You can use matched pairs of parentheses in a combined condition. You do not need to write parentheses if the condition combines two or more conditions with the same logical operator (either AND or OR). In this case, the parentheses have no effect on the condition's evaluation. However, you might have to use parentheses if you use a mixture of AND, OR, and NOT logical operators. In this case, the parentheses can affect the condition's evaluation.
When the relevant parentheses are missing from a complex condition, the evaluation order of the logical operators determines the conditions to which the specified logical operators apply and implies the equivalent parentheses. The evaluation order is NOT, AND, OR. Thus, specifying:
a OR NOT b AND c |
implies and is equivalent to specifying:
a OR ((NOT b) AND c) |
(See also Section 6.5.9.)
Table 6-5 shows the permissible combinations of conditions, logical operators, and parentheses.
In a Conditional Expression | In a Left-to-Right Element Sequence | |||
---|---|---|---|---|
Element | Can Element Be First? |
Can Element Be Last? |
Element, When Not First, Can Immediately Follow | Element, When Not Last, Can Immediately Precede |
simple-
condition |
Yes | Yes | OR, NOT, AND, ( | OR, AND, ) |
OR or AND | No | No | simple-condition, ) | simple-condition, NOT, ( |
NOT | Yes | No | OR, AND, ( | simple-condition, ( |
( | Yes | No | OR, NOT, AND, ( | simple-condition, NOT, ( |
) | No | Yes | simple-condition, ) | OR, AND, ) |
For example, Table 6-5 shows whether or not the following element pairs can occur in your program:
Element Pair |
Permitted? |
---|---|
OR NOT | Yes |
NOT OR | No |
NOT ( | Yes |
NOT NOT | No |
Previous | Next | Contents | Index |