Function
A relation condition causes a comparison of two operands, each of which may be a literal, an index or an arithmetic expression.
Format
|
|
|
Syntax rules
The first and the second operand of a relational condition must not both be literals. Nor may both operands be NULL at the same time.
Relational-operator must be one of the operators listed in Table 20. It must be preceded and followed by a space.
Operator
Meaning
IS [NOT] GREATER THAN
IS [NOT] >[Not] greater than
IS [NOT] LESS THAN
IS [NOT] <[Not] less than
IS [NOT] EQUAL TO
IS [NOT] =[Not] equal to
IS GREATER THAN OR EQUAL TO
IS >=Greater than or equal to
IS LESS THAN OR EQUAL TO
IS <=Less than or equal to
Table 20: Relational operators
The special symbols <, > and = are not underlined in could be mistaken for other symbols.
The relational operator specifies the type of comparison to be made in a relation condition.
If data of the class object or pointer is involved in a relation condition, only relational operators with the meaning "equal to" or "not equal to" may be used.
If data of the class object or pointer is involved in a relation condition, the left and right operands must be of the same category.
Strongly typed group items may not be compared. Only the elementary items from strongly typed group items may be compared with each other.
All allowable comparisons and the type of comparison are shown in table 21:
Right operand Left operand | Group | Alphabetic | Alphanumeric | National | Numeric | Expression | Index name | Index data item | Object | Pointer |
Group | an | an | an | - | an | - | - | - | - | - |
Alphabetic | an | an | an | ant | - | - | - | - | - | - |
Alphanumeric | an | an | an | ant | anu,i,d | - | - | - | - | - |
National | - | ant | ant | nt | nnu,i | - | - | - | - | - |
Numeric | an | - | anu,i,d | nnu,i | nu | nu | ix2,i | - | - | - |
Expression | - | - | - | - | nu | nu | ix2,i | - | - | - |
Index name | - | - | - | - | ix2,i | ix2,i | ix1 | ix3 | - | - |
Index data item | - | - | - | - | - | - | ix3 | ix3 | - | - |
Object | - | - | - | - | - | - | - | - | ob | - |
Pointer | - | - | - | - | - | - | - | - | - | pt |
Table 21: Permissible comparisons between operands 1)
1) | Table entries: | |
i | = Only for integers | |
d | = In the case of alphanumeric literals, only permitted for numeric items with USAGE DISPLAY | |
- | = Comparison is not permitted | |
nu | = Comparison of numeric operands | |
an | = Comparison of alphanumeric operands | |
nt | = Comparison of national operands | |
ix | = Comparison of index names or index data items | |
ob | = Comparison of object references | |
pt | = Comparison of pointers | |
ant | = Comparison of alphanumeric and national operands | |
anu | = Comparison of alphanumeric and integral numeric operands | |
nnu | = Comparison of national and integral numeric operands |
Comparison of numeric operands (nu)
When two numeric operands are compared, their algebraic values are compared regardless of the data formats (USAGE clause). Their lengths (that is, the number of digits they contain) are not significant.
Unsigned numeric operands are considered to be positive for purposes of comparison.
Zero is considered to be a unique value, regardless of sign.
Example 8-5
-50 is less than +5
+75 is greater than +5
-100 is less than -10
-0 is equal to + 0
Comparison of alphanumeric operands with integral numeric operands (anu)
The numeric operand must be an integral literal or an integral data item with USAGE DISPLAY. However, the compiler described here also permits other data formats.
If the alphanumeric operand is an elementary item or an alphanumeric literal, the numeric operand is treated as if it had been moved to an alphanumeric elementary item in accordance with the rules of the MOVE statement. The length of the alphanumeric data item corresponds to the number of digits in the description of the numeric data item; any scaling position character P are not counted.
If the alphanumeric operand is a group item, the numeric operand is treated as if it had been moved to a group item of the same size as the numeric data item in accordance with the rules of the MOVE statement.
In both cases the conceptual data item is then compared with the alphanumeric operand.
This is done in accordance with the rules for the comparison of alphanumeric operands (an).
Comparison of national operands with integral numeric operands (nnu)
The numeric operand must be an integral literal or an integral data item. It is treated as if it had been moved to a national elementary item in accordance with the rules of the MOVE statement. The length of the national data item corresponds to the number of digits in the description of the numeric data item; any scaling position characters P are not counted.
The conceptual national data item is then compared with the national operand. This is done in accordance with the rules for comparing national operands (nt).
Comparison of alphanumeric operands (an)
When two non-numeric operands are compared, the comparison is made with respect to the collating sequence of the PROGRAM COLLATING SEQUENCE (see section "OBJECT-COMPUTER paragraph").
There are two cases to consider:
Comparison of operands of equal size
The program compares characters in corresponding character positions, starting at the high-order end (that is, leftmost), and continuing until it encounters two unequal characters or until it reaches the low-order end of the operands.
If all pairs of corresponding characters are equal, the operands are considered to be equal. Two operands with the size zero are equal, too.
If the object program encounters a pair of unequal characters, it determines which character has a higher position in the collating sequence. The operand containing the higher character is considered to be the greater operand.Example 8-6
left operand
right operand
no COLLATING SEQUENCE or
COLLATING SEQUENCE NATIVECOLLATING SEQUENCE
ALPHATAB (see “Example 6-5” in section "ALPHABET clause" )+-*
ABC
’less than’
The 1st character left operand "+" is less than the 1st character right operand "A".’greater than’
The 1st character left operand "+" is greater than the 1st character right operand "A" because "A" has the position 1 in the collating sequence ALPHATAB.RADE
RABE
’greater than’
The 3rd character left operand "D" is greater than the 3rd character right operand "B".’equal to’
The 3rd character left operand "D" is equal to the 3rd character right operand "B" because "D" and "B" have the position 1 in the collating sequence ALPHATAB.XYZ
XYZ
’equal to’
All pairs of corresponding characters are equal.’equal to’
All pairs of corresponding characters are equal.Comparison of operands of unequal size
The comparison proceeds as though the shorter operand were extended on the right by sufficient alphanumeric spaces to make the operands of equal size.
Then follow the rules described in a) "Comparison of operands of equal size".
Example 8-7
left operand
right operand
no COLLATING SEQUENCE or
COLLATING SEQUENCE NATIVECOLLATING SEQUENCE ALPHATAB (see “Example 6-5” in section "ALPHABET clause")
SMITH
SMITHY
’less than’
The left operand is filled with blanks to "SMITH’BLANK’". The 6th character left operand "'BLANK'" is less than the 6th character right operand "Y".
’less than’
The left operand is filled with blanks to "SMITH’BLANK’". The 6th character left operand "’BLANK’" is less than the 6th character right operand "Y".
AB
ABBA
’less than’
The left operand is filled with blanks to "AB’BLANK’ ’BLANK'". The 3rd character left operand "'BLANK'" is less than the 3rd character right operand "B".
’greater than’
The left operand is filled with blanks to "AB'BLANK''BLANK'". The 3rd character left operand "'BLANK'" is greater than the 3rd character right operand "B" because "B" has position 1 in the collating sequence ALPHATAB.
Comparison of national operands (nt)
There are two cases to consider:
Comparison of operands of equal size
The program compares characters in corresponding character positions, starting at the high-order end (that is, leftmost), and continuing until it encounters two unequal characters or until it reaches the low-order end of the operands.
If all pairs of corresponding characters are equal, the operands are considered to be equal. Two operands with the size zero are equal, too.
If the object program encounters a pair of unequal characters, it determines which character has a higher position in the national collating sequence. The operand containing the higher character is considered to be the greater operand.Comparison of operands of unequal size
The comparison proceeds as though the shorter operand were extended on the right by sufficient national spaces to make the operands of equal size.
Then follow the rules described in a) "Comparison of operands of equal size".
Comparison of alphanumeric and national operands (ant)
The alphanumeric operand is treated as if it has been moved and converted to a national elementary item in accordance with the rules of the MOVE statement. The national data item has exactly as many character positions as the alphanumeric data item.
The conceptual data item is then compared with the national operand. This is done in accordance with the rules for comparing national operands (nt).
Example 8-8
left, alphanumeric operand | right, national operand | Result of the comparison |
123 | XYZ | ’less than’ |
AB | ABBA | ’less than’ |
Comparison of index names or index data items (ix)
If the two operands are index names, the two table element numbers which correspond to the two indices are compared with each other (ix1).
If one operand is numeric (integer only), this number is regarded as a table element number and compared with the table element number which corresponds to the index name (ix2).
If one operand is an index data item, the current values of the items are compared (without conversion to table element numbers!) (ix3).
Comparison of object references (ob)
The condition ’equal’ is only true if identifier-1 and identifier-2 reference the same object.
Comparison of pointers (po)
The condition ’equal’ is only true if identifier-1 and identifier-2 reference the same memory location.