Product Site

7.4.23. DATATYPE

Returns NUM if you specify only string and if string is a valid Rexx number that can be added to 0 without error; returns CHAR if string is not a valid number.

If you specify type, it returns 1 if string matches the type. Otherwise, it returns 0. If string is null, the function returns 0 (except when the type is X or B, for which DATATYPE returns 1 for a null string). The following are valid types. (Only the capitalized letter, or 9 for the 9Digits option, is needed; all characters following it are ignored. For example, for the heXadecimal option, you must start your string specifying the name of the option with X rather than H.)
Alphanumeric

returns 1 if string contains only characters from the ranges a-z, A-Z, and 0-9.
Binary

returns 1 if string contains only the characters 0 or 1, or whitespace. Whitespace characters can appear only between groups of 4 binary characters. It also returns 1 if string is a null string, which is a valid binary string.
Internal whole number

returns 1 if string is a Rexx whole number that built-in functions will accept. Rexx built-in functions internally work with NUMERIC DIGITS 9 for 32-bit systems or NUMERIC DIGITS 18 for 64-bit systems.
Lowercase

returns 1 if string contains only characters from the range a-z.
Mixed case

returns 1 if string contains only characters from the ranges a-z and A-Z.
Number

returns 1 if DATATYPE(string) returns NUM.
lOgical

returns 1 if the string is exactly "0" or "1". Otherwise it returns 0.
Symbol

returns 1 if string is a valid symbol, that is, if SYMBOL(string) does not return BAD. (See Section 1.10.4.4, “Symbols”.) Note that both uppercase and lowercase alphabetics are permitted.
Uppercase

returns 1 if string contains only characters from the range A-Z.
Variable

returns 1 if string could appear on the left-hand side of an assignment without causing a SYNTAX condition.
Whole number

returns 1 if string is a Rexx whole number under the current setting of NUMERIC DIGITS.
heXadecimal

returns 1 if string contains only characters from the ranges a-f, A-F, 0-9, and whitespace (as long as the whitespace characters appear only between pairs of hexadecimal characters). It also returns 1 if string is a null string, which is a valid hexadecimal string.
9 digits

returns 1 if DATATYPE(string,"W") returns 1 when NUMERIC DIGITS is set to 9.

Here are some examples:
Example 7.30. Builtin function DATATYPE
DATATYPE(" 12 ")         -->   "NUM"
DATATYPE("")             -->   "CHAR"
DATATYPE("123*")         -->   "CHAR"
DATATYPE("12.3","N")     -->    1
DATATYPE("12.3","W")     -->    0
DATATYPE("Fred","M")     -->    1
DATATYPE("Fred","U")     -->    0
DATATYPE("Fred","L")     -->    0
DATATYPE("?20K","s")     -->    1
DATATYPE("BCd3","X")     -->    1
DATATYPE("BC d3","X")    -->    1
DATATYPE("1","O")        -->    1
DATATYPE("11","O")       -->    0

Note

The DATATYPE function tests the meaning or type of characters in a string, independent of the encoding of those characters (for example, ASCII or EBCDIC).