Product SiteDocumentation Site

7.4.23. DATATYPE


>>-DATATYPE(string--+-------+--)-------------------------------><
                    +-,type-+

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 the number of the last type listed, is needed; all characters surrounding it are ignored. Note that 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.
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).