Useful functions

REXX provides a rich set of built-in functions, including character manipulation and conversion functions. Some of these functions might be of use when you are writing your comparison expressions, and they are described below. Z Data Tools also provides some functions that might be of use. They are also described below. To call a function, type the function name directly followed by one or more arguments within parentheses. There can be no space between the function name and the left parenthesis. For example:

function(arguments)

A function call can contain up to 20 arguments separated by commas. Each argument can be one or more of the following:

Argument
Example
Blank
function( )
Constant
function(55)
Symbol
function(#5)
Literal string
function('With a literal string')
Option recognized by function
function(option)
Another function
function(function(arguments))
Combination of argument types
function('Literal string', #5, option)

Some of the built-in functions provided by REXX that you might find useful are:

ABS()
Read syntax diagramSkip visual syntax diagram
Syntax

>>-ABS--(number)-----------------------------------------------><

Returns the absolute value of a number. For example, if you want to select records in which field #12 contains a value in the range -10 to +10, you could specify:

ABS(#12) <= 10
MAX()
Read syntax diagramSkip visual syntax diagram
Syntax

          .-,------.     
          V        |     
>>-MAX--(---number-+-)-----------------------------------------><

Returns the largest number from the list specified. For example, if you want to select records in which any of fields #10, #11, or #12 contains a value greater than 55, you could specify:

MAX(#10, #11, #12) > 55
MIN()
Read syntax diagramSkip visual syntax diagram
Syntax

          .-,------.     
          V        |     
>>-MIN--(---number-+-)-----------------------------------------><

Returns the smallest number from the list specified. For example, if you want to select records in which any of fields #10, #11, or #12 contains a value less than 0, you could specify:

MIN(#10, #11, #12) < 0
POS()
Read syntax diagramSkip visual syntax diagram
Syntax

>>-POS--(-needle--,--haystack-+--------+-)---------------------><
                              '-,start-'     

Returns the position of one string, needle, in another, haystack. Returns 0 if needle is a null string, or is not found in haystack, or if start is greater than the length of haystack. By default the search starts at the first character of haystack (that is, the value of start is 1). You can override this by specifying start (which must be a positive whole number), the point at which the search starts. For example, if you want to select records in which any character in field #22 is a blank, you could specify:

POS(' ',#22) > 0.
SUBSTR()
Read syntax diagramSkip visual syntax diagram
Syntax

>>-SUBSTR--(-string,n-+-----------------------+-)--------------><
                      '-,-+--------+-+------+-'     
                          '-length-' '-,pad-'       

Returns the substring of string that begins at the nth character and is of length length, padded with pad if necessary. n is a positive whole number. If n is greater than the length of string, then only pad characters are returned.

If you omit length, the rest of the string is returned. The default pad character is a blank.

For example, if you want to select records in which characters 4-6 of field #22 are the string 'NOT', you could specify:
SUBSTR(#22,4,3) == 'NOT'

The functions provided by Z Data Tools that you might find useful are shown below.

FLD()
Refer to a field from the current input record. For details, see FLD.
COntains()
Check a field for a list of character values. For details, see CONTAINS.
NCOntain()
Check a field for a list of numeric values. For details, see NCONTAIN.