log_exp - Comparison Operators for All Data Types
The following table lists the comparison operators for comparisons between operands of various data types.
Operator |
Description |
=, EQ |
Equal: True, if the content of operand1 matches the content of operand2. |
<>, NE |
Not Equal: True, if the content of operand1 does not match the content of operand2. |
<, LT |
Lower Than: True, if the content of operand1 is smaller than the content of operand2. |
>, GT |
Greater Than: True, if the content of operand1 is greater than the content of operand2. |
<=, LE |
Lower Equal: True, if the content of operand1 is lower than or equal to the content of operand2. |
>=, GE |
Greater Equal: True, if the content of operand1
is greater than or equal to the content of operand2. |
|
The way in which the contents are compared depends on the data types of the operands (see below).
Notes
- It is recommended that you only use the operators =,
<>, <,
>, <=,
>= or only the operators EQ,
NE, LT, GT, LE, GE.
Comparing Compatible Elementary Types
If operand1 and operand2 have elementary data types and are
compatible, their contents are compared by the following rules and without prior conversion:
- In the case of operands with a numeric data type
(i, f,
p), the number values are compared. Since platform-specific rounding errors can occur with
the data type f, a comparison for equality is rarely useful in the case of floating point numbers.
- For operands with a character-type data type (c,
d, n, t, string) the contents are compared from left to right. Based on the order in the
code page used, the first different character from the left decides which operand is larger.
- For operands with a byte-type data type (x,
xstring), the contents are compared from left to right. Based on the byte values, the first different byte from the left decides which operand is larger.
The following individual behavior results from the rule for character-type types:
- With operands of the type c and
string, the contents are compared lexicographically; the system distinguishes between uppercase and lowercase letters.
- With operands of the type n, the contents are compared according to the number values displayed.
- With operands of the type d and
t that contain a valid date or a valid time specification, the later time is greater than the earlier one.
Comparing Incompatible Elementary Types
If operand1 and operand2 have elementary data types and are not
compatible, their contents are converted and compared according to the following rules:
Operands of the same type with different lengths
- With operands of the type p, the number values are compared.
- For operands of the type c, the shorter field is extended to the length of the longer field by adding blanks on the right and the comparison is then executed.
- Operands of the data type string with different lengths
are always unequal. If the content of the operands matches the length of the shorter operand, the shorter
operand is smaller than the longer one. Otherwise, excess places in the longer field are truncated on the right before the size comparison is executed from left to right character-by-character.
- For operands of the data type n, the shorter field is filled with zeros on the left and thus extended to the length of the longer field.
- For operands of the data type x, the shorter field
is filled with hexadecimal zeros on the left and thus extended to the length and thus extended to the length of the longer field.
- Operands of the data type xstring with different lengths
are always unequal. If the content of the operands matches the length of the shorter operand, the shorter
operand is smaller than the longer one. Otherwise, excess places in the longer field are truncated on the right before the size comparison is executed byte-by-byte from left to right.
Operands of different elementary types
If the operands have different data types, conversions take place according to the conversion tables and the following hierarchy:
-
If one of the operands has a numeric data type (i,
f, p), the other operand is converted to the relevant numeric data type with the largest
value area; the value area of the data
type f is greater than that of
p, which in turn is greater than that of i.
-
If one of the operands has the data type d or t and the other operand has a numeric data type
(i, f,
p), the content of the date or time field is converted to the numeric data type.
-
If one of the operands has the data type d or
t and the other operand has a character-type data type other than d or t
(c, n,
string), the content of the data or time field is also treated as character-type. If one
of the operands has the data type d and the other has the data type t, an exception than cannot be handled occurs.
-
If one of the operands has the data type n and the other
operand has the data type c, string,
x, or xstring, the content of both data types is converted to the data type p.
-
If one of the operands has a data type of fixed length
(c or x) and the other operand has a data type of variable length
(string or xstring), the operand of fixed length is converted to the corresponding data type of variable length
(c to string,
x to xstring).
-
If one of the operands has a byte-type type (x, xstring) and the other operand has a character-type type
(c, string), the content of the operand with the byte-type type is converted to the corresponding character-type data type
(x to c, xstring to string).
Comparing Reference Variables
Data references can be compared with data references and object can be compared with object references,
but data references cannot be compared with object references. Two references are equal if they point
to the same object. A size comparison is defined internally and always returns matching results in matching situations.
Note
In the case of data references, it is not sufficient for equality if the operands contain the same references; the data type of the referenced objects must be
compatible. For example, if two reference variables, of which one
points to a structure and the other to the first component of this structure, contain the same memory
address, they are still not equal since the data type of the operands is incompatible. Reference variables
filled using GET REFERENCE
can be unequal, even if they point to the same data object, if GET REFERENCE is executed for a field symbol to which the data object was assigned using
casting.
Comparing Structures
Structures can be compared with structures and elementary fields:
- Compatible structures are compared component-by-component; nested
structures are dissolved recursively. Two structures are equal if the content of their components matches. For unequal structures, the first unequal pair of components decides the outcome of the comparison.
- It is possible to compare incompatible structures and structures with elementary fields if these structures are flat.
In non-Unicode programs,
the involved structures are converted into elementary fields of the type
c before conversion; the conversion is then executed in the same way as for elementary fields.
When comparing two flat incompatible structures in a Unicode program, the
Unicode fragment views must
match the length of the shorter structure. Before the comparison, the shorter structure is filled up
to the length of the longer structure. All character-type components are filled with blanks and all other components are filled with type-specific
initial values. The comparison takes place section-by-section according to the Unicode fragment view.
When comparing a flat structure and an elementary field the following rules apply in Unicode programs:
- If a flat structure is character-type, it is treated like an elementary field of the type c during comparison.
- If a flat structure is not purely character-type, the elementary field must be of the type
c and the first Unicode fragment of the structure must be character-type and at least as
long as the elementary field. If the elementary field is shorter than the structure, it is extended
to the length of the structure before comparison and implicitly treated like a structure. The character-type
portions of the extension are filled with blanks, while all other components are filled with the type-specific initial value.
Comparing Internal Tables
Internal tables can be compared with other internal tables if their row types are comparable. Internal tables are compared according to the following hierarchy:
-
The internal table that has more rows than the other internal table is larger.
-
Internal tables with the same number rows are compared row by row. If an internal table contains nested
internal tables, they are compared recursively. In the case of equal internal tables, the content matches row for row. With unequal internal tables, the first unequal pair of rows defines the result of the comparison.
Note
When specifying an internal table with header line as operand of a logical expression, in almost all
operand positions the header line is addressed instead of the
table body. To address the table body of a table with header line, you must append [] to the name.