Expressions and Conditions

Review the following information about expressions and conditions.
view122
Review the following information about expressions and conditions.
Contents
2
Expression
An 
expression
 can be a field name, a constant, a function, or an operation, as described in the following table:
Field Name
Description
Field name
A database field name, defined field name, or a reserved field name
Constant
A data value that has an unchanging, self-defined value
For instance, 1 and ABC are constant values that are not altered during the execution of the statements.
Function
A special routine that is set up to convert, extract, or manipulate data values
Functions you can use are as follows:
BINARY(
expression
)
Converts the specified expression to internal binary format, resulting in a signed 4-byte binary number
CHAR(
expression
)
Converts the specified expression to character format
DATE(
expression
)
Converts the specified expression to internal date format.
If
expression
is a character field, the character string must be formatted in the default date format with a date separator character (typically a slash) between the month, day, and year. If expression is a binary or packed field, the field specifies a Julian date with the century indicator in form,
CYYDDD
.
EDIT(
exp-1,exp-2
)
exp-1
specifies the expression whose value is to be edited
exp-2
specifies the edit-pattern to be used for editing
exp-1
;
exp-2
is a constant (for example, '
ZZZZ9
')
 
The edit-pattern character for a character field is as follows:
 
X
Specifies substitution of a character from
exp
 
Edit-pattern characters for a numeric field (binary or packed) are as follows:
 
$
Specifies the substitution of a currency symbol or a floating currency symbol
 
*
Specifies that an asterisk or a rolling asterisk is to be substituted in place of a leading zero
 
-
Specifies the substitution of a sign or floating sign for a negative value, blank for a positive value. + - specifies
the substitution of a sign or floating sign. + is substituted for a positive and - for a negative value
 
.
Specifies the substitution of a decimal point
 
,
Specifies the substitution of a comma
The substitution and suppression of this character can be affected by floating edit characters and zero suppression edit characters.
 
Edit-pattern characters for date fields are as follows:
 
X
Specifies the substitution of a numeric character
 
Z
Specifies the substitution of a numeric character; if the corresponding digit is a leading zero, blank is substituted
 
9
Specifies the substitution of a numeric character
 
D
Specifies the substitution of a one-digit day
 
DD
Specifies the substitution of a two-digit day
 
DDD
Specifies the substitution of a Julian day
 
M
Specifies the substitution of a one-digit month
 
MM
Specifies the substitution of a two-digit month
 
Y
Specifies the substitution of a one-digit year
 
YY
Specifies the substitution of a two-digit year
 
YYY
Specifies the substitution of a three-digit year
The three-digit year is the number of year from 1900. Year 2000 is represented as 100.
 
YYYY
Specifies the substitution of a full four-digit year
 
Z
Specifies the substitution of one character from data in the form
YYYYMMDD YYYDDD
(Gregorian and Julian)
 
9
Specifies the substitution of one digit from data in the form
MMDDYYYY YYYDDD
(Gregorian and Julian)
Function
Editing examples:
 
Sending Field
Edit-pattern
Resulting Field
 
'ABCDEF'
X-X-X
A-B-C
 
'A2534RW'
XXX/XXX/XXX
A25/34R/W
 
'BDF'
AXCXEX
ABCDEF
 
0
9999
0000
 
0
ZZZZ
 
 
123
ZZ,ZZ9
123
 
395
**,**9
***395
 
960
$$,$$9
$960
 
1005
ZZ,ZZ9
1,005
 
1256
-----9
1256
 
3471
+++++9
+3471
 
-523
--,--9
-523
 
-7000
++,++9
-7,000
 
-9275
ZZ,ZZ9
9,275-
 
24569
Z,ZZZ.99+
245.69+
 
192543
XX:XX:XX
19:25:43
 
999999
ZZZ9
****
 
36554 (date)
MM/DD/YYYY
01/30/2000
 
36583 (date)
YYYY.MM.DD
2000.02.28
 
36645 (date)
DD/MM/YY.DDD
30/04/00.121
 
36671 (date)
99/99/9999 999.999
05/26/2000 100.147
Function
PACK(
expression
)
Converts the specified expression to internal packed format
The resulting value is an 8-byte signed, packed number.
PREV(
field-name
)
Specifies the usage of the previous data value for
field-name
SUBSTR(
expression,pos,len
)
Specifies the usage of a subset of the specified expression
The SUBSTR expression must result in or be a character value.
pos
specifies the beginning character to be extracted.
len
specifies the number of characters to be extracted.
TRANS(
field
,
expression-value
,
expression-result
[
expression-value
,
expression-result
,…])
Specifies the matching of two values (
expression
and
expression
-
value
) and the use of a translated result
(expression-result)
Expression-value and expression-result can be repeated for each required value and result. An asterisk can be specified as expression-value to indicate any value. If a matching value is not found after interrogation of all values, the value contained in the field is used as the translated result.
Operation
A group of field names, constants, or functions separated by operators:
field/constant/function op field/constant/function
The valid operators (
op
) are:
+ for adding fields
- for subtracting fields
* for multiplying fields
/ for dividing fields
|| for concatenating fields
The evaluation and computation of an operation is from left to right in the following order:
1. Concatenation
2. Multiplication and division
3. Addition and subtraction
The order of evaluation and computation can be altered by enclosing a portion or portions of an operation in parentheses. These parenthetic sections are evaluated first and follow the same order of evaluation as the total operation.
Condition
condition
 is a group of expressions separated by comparison operators and logical operators. In other words, a condition compares two or more sets of expressions.
Syntax
expression-1
 co 
expression-2
 [lo 
expression-3
 co 
expression-4
 ...]
where:
expression-1
expression-2
, and, optionally, 
expression-3
 and 
expression-4
 specify an expression whose value is compared. In addition, 
expression-2
 and 
expression-4
 can contain a list of expressions (for example, ('ABC','DEF',...)). Enclose the list of expressions in parentheses.
For date field comparisons, expression-2 and expression-4 can be a specific date, Julian date, relative day, or year. For a specific date, specify the full date with date separator characters within quotes. A Julian date is specified in the 
CYYDDD
 format. A relative day, specified as a negative number, is the number of days relative to the current date where -0 is the current day, -1 is yesterday, and so forth. Years are specified as a four-digit year.
For comparisons with the GEN, HGEN, and LGEN fields, expression-2 and expression-4 can be a specific or relative generation. A relative generation, specified as a negative number, is the number of generations relative to the current generation where -0 is the current backup generation number, -1 is the previous backup generation number, and so forth.
co
 is a comparison operator as follows:
EQ equal
= equal 
NE not equal
^= not equal
=^ not equal
<> not equal
>< not equal
LT less than
< less than
GT greater than
> greater than
GE greater than or equal to
^< greater than or equal to (not less than)
<^ greater than or equal to (not less than)
>= greater than or equal to
=> greater than or equal to
LE less than or equal to
^> less than or equal to (not greater than)
>^ less than or equal to (not greater than)
<= less than or equal to
=< less than or equal to
LIKE less than
LE less than
The LIKE comparison operator can only be used for character fields. The expression to the right of the comparison operator (expression-2, expression-4, and so forth) specifies a filtering field. Three special filtering characters are provided as pattern matching characters. All other characters reference a match of that specific character.
The special filtering characters are as follows:
* Matches any string of characters
This character is a fuzzy match character which can reference any number of characters as well as no characters. For example, '*' matches everything, 'A*' matches data starting with A, '*A' matches data ending with A (“A”, “LA”, “FLORIDA”, and so forth), and '*A*' matches A anywhere in the data (“A”, “LA”, “OHARE”, “MAINE”, and so forth)
? Match any single character including a blank
¬ Match a single non blank character
lo
 is a logical operator as follows:
AND Conditions on both sides of the logical operator must be true
& Conditions on both sides of the logical operator must be true
OR Either condition surrounding the logical operator can be true
| Either condition surrounding the logical operator can be true
A condition is broken down into groups separated by the OR logical operator if there is any. If this group or any one of these groups is evaluated as true, the total condition is evaluated the same. The process of grouping can be altered by enclosing a portion or portions of the condition in parentheses.
Examples
Check if job name is equal to P25135:
JOB = 'P25135'
Check if SYSOUT ID begins with an R, S, or T:
ID LIKE ('R*','S*','T*')
Check if archive date is equal to today:
ARCHDATE = -0
Check if pages are between 5000 and 10000 lines (inclusive):
PAGES => 5000 AND PAGES <= 10000