Overview of REXX expressions

REXX expressions consist of one or more terms interspersed with zero or more operators that denote operations to be carried out on terms. Expressions are evaluated left to right, modified by parentheses and by operator precedence in the typical algebraic manner. If parentheses are encountered (other than those that identify function calls) the entire subexpression between the parentheses is evaluated immediately when the term is required. Expressions are wholly evaluated, unless an error occurs during evaluation. The REXX language uses a free format. This means you can insert extra spaces between words without causing an error.

The following list shows the terms you can use in a selection criteria expression. The operators you can use are described on the pages that follow.
Literal strings
A literal string is a sequence including any characters and delimited by the single quotation mark (') or the double quotation mark ("). Use two consecutive double quotation marks ("") to represent a " character within a string delimited by double quotation marks. Use two consecutive single quotation marks ('') to represent a ' character within a string delimited by single quotation marks. A literal string is a constant and its contents are never modified when it is processed.
These are valid strings:
'Fred'
"Don't Panic!"
'You shouldn''t'        /* Same as "You shouldn't" */

Note that a string followed immediately by a ( is considered to be the name of a function. If followed immediately by the symbol X or x it is considered to be a hexadecimal string. If followed immediately by the symbol B or b it is considered to be a binary string.

A hexadecimal string is a literal string, expressed using a hexadecimal notation of its encoding. It is any sequence of zero or more hexadecimal digits (0-9, a-f, A-F), grouped in pairs. A single leading 0 is assumed, if necessary, at the front of the string to make an even number of hexadecimal digits. The groups of digits are optionally separated by one or more blanks, and the whole sequence is delimited by single or double quotation marks, and immediately followed by the symbol X or x. (Neither x nor X can be part of a longer symbol. A hexadecimal string is a literal string formed by packing the hexadecimal digits given. Packing the hexadecimal digits removes blanks and converts each pair of hexadecimal digits into its equivalent character, for example: 'C1'X A.

You can use hexadecimal strings to include characters in a program even if you cannot directly enter the characters themselves. These are valid hexadecimal strings:
'ABCD'x
"1d ec f8"X
"1 d8"x

A binary string is a literal string, expressed using a binary representation of its encoding. It is any sequence of zero or more binary digits (0 or 1) in groups of 8 (bytes) or 4 (nibbles). The first group can have fewer than four digits; in this case, up to three 0 digits are assumed to the left of the first digit, making a total of four digits. The groups of digits are optionally separated by one or more blanks, and the whole sequence is delimited by matching single or double quotation marks and immediately followed by the symbol b or B.

A binary string is a literal string formed by packing the binary digits given. If the number of binary digits is not a multiple of eight, leading zeros are added on the left to make a multiple of eight before packing. You can use binary strings to specify characters explicitly, bit by bit.

These are valid binary strings:
'11110000'b        /* == 'f0'x                  */
"101 1101"b        /* == '5d'x                  */
'1'b               /* == '00000001'b and '01'x  */
'10000 10101010'b  /* == '0001 0000 1010 1010'b */
''b                /* == ''                     */
Symbols
Character strings, without quotation marks, which are converted to uppercase. Any symbol that begins with a # is treated as a reference to a field in the record being processed, and the value of the field is used. All other symbols are treated as constants.

FM/Db2 assigns to each field defined in a template a unique field reference number. If you want to refer to a field in a selection criteria expression, you specify the field's field reference number prefixed by #. Note that you can only refer to fields defined in the record you are currently working with.

REXX expression evaluation only processes data in the form of typeless character strings (typeless because they are not, as in the case of COBOL, of a particular data type such as binary, packed-decimal, and so forth). Therefore, if you refer to a numeric field, FM/Db2 converts the value of the field to a numeric character string that can be processed by REXX when evaluating the selection criteria expression. The number of integer and decimal digits in the character string is determined by the field definition in your template. For example, if you refer to a packed-decimal field with a COBOL PICTURE clause of 999V99, FM/Db2 converts the value of the field to a character string consisting of numeric digits, a period for the virtual decimal place, and, if the value of the field is negative, a leading sign character (such as -123.45). Note that all numeric fields are treated as signed, regardless of whether the COBOL PICTURE clause contains a sign symbol.

Occasionally, you might want to evaluate the value of a numeric field without converting it to a numeric character string. To do this, prefix the field reference number by #u instead of #. This tells FM/Db2 not to convert the number to a numeric character string. For example, if to test a 2-byte binary numeric field (with a field reference number of 45) for a special value of X'FFFF', code:
#u45 = 'FFFF'x

If you refer to a field in an array, you must qualify the field reference with the required number of subscripts enclosed in parentheses and separated by commas. The number of subscripts you specify must equal the number of dimensions in the array that contains the field you are referencing. In COBOL terms, there must be a subscript for each OCCURS clause in the hierarchy containing the field, including any OCCURS clause for the field itself. Each subscript you specify must be a positive integer in the range 1 to the maximum number of occurrences of the field as specified in the OCCURS clauses. If the field you refer to is in a variable-length array (specified using the OCCURS DEPENDING ON clause), ensure that you do not refer to an occurrence of the field that, for any given record, might not exist. If you do refer to a non-existent field, the selection criteria is not satisfied, and the record is not selected.

Note: The object of an OCCURS DEPENDING ON clause must be defined as a field in the static portion of the same record as the array (that is, the portion of the record that precedes any variable-length array defined with the OCCURS DEPENDING ON clause). If the object of the OCCURS DEPENDING ON clause is not defined in this way, you cannot refer to any fields in the array or any fields in the record that follow the array.
Function call
A call to REXX built-in function.
Subexpressions
Terms in an expression bracketed within left and right parentheses.