[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
When both operands are numeric, their algebraic values are compared. The program performs the necessary conversion if the data descriptions of the operands specify different USAGE. When you use operands that are literals or arithmetic expressions, their length (in terms of the number of digits represented) is not significant.
Unsigned numeric operands are assumed to be positive for comparison.
A zero value is always treated the same way, whether or not the operand
contains a sign.
6.5.1.2 Comparison of Nonnumeric Operands
When one (or both) of the operands is nonnumeric, each operand is considered a string of alphanumeric characters. Therefore, the operands are compared according to the program's collating sequence. (See the Section 4.1.2 paragraph in Chapter 4.)
If one of the operands is numeric, it must be either an integer literal or a data item described as an integer. The data item must be implicitly or explicitly described with USAGE DISPLAY. The treatment of the numeric data item is further affected by the following:
The two operands are compared character by character, beginning at the left end of each string. When the operation finds an unequal character pair, it uses that pair to evaluate the comparison. The greater operand is the one that contains the character with the higher collating sequence position. If the operands are of unequal size, the shorter operand is treated as if it were extended on the right with spaces to make it the same size as the other. Therefore, ABCD is greater than ABC (unless the program's collating sequence dictates otherwise).
Comparisons of Index-Names or Index Data Items
A program can compare the following:
The class condition tests whether the contents of an operand are numeric or alphabetic. It also determines if an alphabetic operand contains only uppercase characters, only lowercase characters, or if an operand is in conformance with class-name. The general format is as follows:
The identifier must reference a data item whose usage is explicitly or implicitly DISPLAY or COMP-3. If the identifier is a function-identifier, it must reference an alphanumeric function.
The following rules apply to the NUMERIC test:
The following rules apply to the ALPHABETIC test:
The ALPHABETIC-LOWERCASE test is true when the operand contains only the characters a to z, and the space; otherwise, it is false.
The ALPHABETIC-UPPERCASE test is true when the operand contains only the characters A to Z, and the space; otherwise, it is false.
The class-name test is true when the operand consists entirely of the characters listed in the definition of class-name in the SPECIAL-NAMES paragraph. The class-name test must not be used with an item whose data description describes the item as numeric.
NOT and the key word following it are treated as a unit. For example,
NOT NUMERIC is a test for determining that the operand is nonnumeric.
6.5.3 Condition-Name Condition
The condition-name condition determines if a data item contains a value assigned to one of that item's condition-names. The term conditional variable refers to the data item. condition-name refers to a level 88 entry associated with that item.
The general format for this condition is:
The condition is true if one of the values corresponding to condition-name equals the value of the associated conditional variable. The data description for a variable can associate condition-name with one or more ranges of values. In this case, the condition tests to determine if the value of the variable falls in the specified range (end values included).
The following example illustrates testing condition-names associated with both one value and a range of values:
WORKING-STORAGE SECTION. 01 STUDENT-REC. 05 YEAR-ID PIC 99. 88 FRESHMAN VALUE IS 1. 88 SOPHOMORE VALUE IS 2. 88 JUNIOR VALUE IS 3. 88 SENIOR VALUE IS 4. 88 GRADUATE VALUE IS 5 THRU 10. . . . PROCEDURE DIVISION. . . . IF FRESHMAN ... IF SOPHOMORE ... IF JUNIOR ... IF SENIOR ... IF GRADUATE ... |
Condition-Name | Test Is True When the Value of the Conditional Variable YEAR-ID Equals: |
---|---|
FRESHMAN | 1 |
SOPHOMORE | 2 |
JUNIOR | 3 |
SENIOR | 4 |
GRADUATE | 5, 6, 7, 8, 9, or 10 |
When your program evaluates a conditional variable and its
condition-name, the procedure is the same as the one used with
the relation condition. (See Section 6.5.1.)
6.5.4 Switch-Status Condition
The switch-status condition tests the on or off setting of an external logical program switch. Its general format is as follows:
You use the SWITCH clause of the SPECIAL-NAMES paragraph to associate condition-name with a logical switch setting. (See the Section 4.1.3 paragraph in Chapter 4.) The condition is true if the switch setting in effect during program execution is the same one assigned to condition-name.
The translated value of the OpenVMS Alpha or I64 logical name COB$SWITCHES or the Tru64 UNIX environment variable COBOL_SWITCHES specifies logical program switch settings. (Refer to the description of program switches in the HP COBOL User Manual.) |
6.5.5 Sign Condition
The sign condition determines if the algebraic value
of an arithmetic expression is less than, greater than, or equal to
zero.
Its general format is as follows:
An operand is defined as:
arithmetic-expression must contain at least one reference to a variable.
NOT and the key word following it are treated as a unit. For example, NOT ZERO tests for a nonzero condition.
Previous | Next | Contents | Index |