Purpose
Compares two values.
Each value can be a variable data field, an arithmetic expression, a built-in function, or a numeric, nonnumeric, multi-bit binary, or figurative constant.
A comparison condition also compares two EBCDIC, DBCS, or unsigned zoned decimal character strings to determine if the first string matches or contains the second string.
Syntax
►►──┬─ value comparison-operator value ────────────┬────────────────────────►◄ │ │ └─ string-value ──┬─ MATCHES ─┬── mask-value ───┘ └─ CONTAINS ─┘
Parameters
Identifies the operands being compared. Value is specified according to the rules presented in Introduction to Process Language.
The comparison operators are:
|
Operator |
Synonym |
Meaning |
|---|---|---|
|
EQ |
= |
Equal |
|
NE |
|
Not equal to |
|
GT |
> |
Greater than |
|
LT |
< |
Less than |
|
GE |
|
Greater than or equal to |
|
LE |
|
Less than or equal to |
Either the name of an elementary EBCDIC, DBCS, or unsigned zoned decimal data field that contains the character string being compared, or the string itself enclosed in single quotation marks.
Compares the left operand to the right operand, one character at a time, beginning with the leftmost character in each operand.
The length of the string that is compared is set to the length of the shorter of the two operands. If a character in the left operand does not match the corresponding character in the right operand, the outcome of the comparison is false.
Searches the left operand for an occurrence of the right operand.
The length of the right operand must be less than or equal to the length of the left operand. If the right operand is not entirely contained in the left operand, the outcome of the comparison is false.
Either the name of a variable data field that contains the mask value or the value itself enclosed in single quotation marks.
Usage
Considerations
Special mask characters in mask-value match characters in value according to the following conventions:
Any other character in mask-value matches only itself in value.
'String-value' in either MATCHES or CONTAINS must be defined as either EBCDIC (PIC X) or as unsigned zoned decimal (PIC 9).
Example 1: Using a simple comparison
The comparison condition in the following IF statement is true when the value in the SALES field is greater than or equal to 5000:
IF SALES GE 5000 ...
Example 2: Using a compound comparison
The comparison condition in the following IF statement is true when the value in the CODE field is not equal to X3 and the value in the QTY field is less than 15:
IF CODE NE 'X3' AND QTY LT 15 ...
Example 3: Searching for a given string occurrence
The comparison condition in the following IF statement is true when the character string TOM occurs in the character string contained in the NAME field:
IF NAME CONTAINS 'TOM' ...
Example 4: Using a comparison to a given string value
The comparison condition in the following IF statement is true when the character string contained in the PART-ID field matches the mask value **@398:
IF PART-ID MATCHES '**@398' ...
|
Copyright © 2014 CA.
All rights reserved.
|
|