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. When 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.

REXX statements are free format. This means you can insert extra spaces between words without causing an error.

The terms you can use in a selection criteria expression are described below. The operators you can use are described on following panels.
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.

With hexadecimal strings you can 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 might 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. Using binary strings, you can 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 translated to uppercase. Any symbol that begins with a # is treated as a reference to a field in the segment being processed, and the value of the field is used. All other symbols are treated as constants.

FM/IMS assigns to each field defined in a template a unique field reference number. When 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 segment you are currently working with. You cannot refer to fields defined in a different segment type. Note also that, in segment identification criteria, you can only refer to fields defined in the static portion of the segment (that is, the portion of the segment that precedes any variable-length array defined with the OCCURS DEPENDING ON clause).

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, when you refer to a numeric field, FM/IMS 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 or PL/I PICTURE clause of 999V99, FM/IMS 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 or PL/I 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/IMS not to convert the number to a numeric character string. For example, if you want to test a two-byte binary numeric field (with a field reference number of 45) for a special value of X'FFFF', you can code:
#u45 = 'FFFF'x

When 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), you should ensure that you do not refer to an occurrence of the field that, for any given segment, might not exist. If you do refer to a non-existent field, the selection criteria is not satisfied, and the segment 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 segment as the array (that is, the portion of the segment that precedes any variable-length array defined with the OCCURS DEPENDING ON clause). If the object of the OCCURS DEPENDING ON clause is not so defined, you cannot refer to any fields in the array or any fields in the segment that follow the array.
Function call
A call to REXX built-in function.
Subexpressions
Terms in an expression bracketed within left and right parentheses.