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 usual algebraic manner. When parentheses are encountered (other than those that identify function calls), the entire sub-expression 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 terms without causing an error.

The terms you can use in a selection criteria expression are described below.

Literal strings
A literal string is a sequence including any characters and delimited by the quotation single 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 quotation marks ('') to represent a ' character within a string delimited by 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" */

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 is the same as the character "A".

Hexadecimal strings let you 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 may 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. Binary strings allow you 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 translated 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.

File Manager 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 Reference number prefixed by #. You can only refer to fields defined in the record you are currently working with. You cannot refer to fields defined in a different record type. In record identification criteria, you can only refer to fields defined in the static portion of the record (that is, the portion of the record 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, File Manager 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, File Manager 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 File Manager not to convert the number to a numeric character string. For example, if you wanted to test a two-byte binary numeric field (with a field reference number of 45) for a special value of X'FFFF', you could 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 record, might not exist. If you do refer to a non-existent field, the selection criteria cannot be 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 so defined, you cannot refer to any fields in the array or any fields in the record that follow the array.
Function call
A call to a REXX built-in function.
Sub-expressions
Terms in an expression bracketed within left and right parentheses.

Related concepts