3.2.20. DATATYPE(string[,option])

With only one parameter, this function identifies the “datatype”
of string. The value returned will be “NUM” if string is a valid
REXX number. Otherwise, “CHAR” is returned.  Note that the
interpretation of whether string is a valid number will depend on
the current setting of NUMERIC.

If option is specified too, it will check if string is of a
particular datatype, and return either “1” or “0” depending on
whether string is or is not, respectively, of the specified
datatype. The possible values of option are:

[A]
     (Alphanumeric) Consisting of only alphabetic characters (in
     upper, lower or mixed case) and decimal digits.

[B]
     (Binary) Consisting of only the two binary digits 0 and 1.
     Note that blanks are not allowed within string, as would have
     allowed been within a binary string.

[L]
     (Lower) Consisting of only alphabetic characters in lower
     case.

[M]
     (Mixed) Consisting of only alphabetic characters, but the
     case does not matter (i.e. upper, lower or mixed.)

[N]
     (Numeric) If string is a valid REXX number, i.e.
     DATATYPE(string) would return NUM.

[S]
     (Symbolic) Consists of characters that are legal in REXX
     symbols.  Note that this test will pass several strings that
     are not legal symbols. The characters includes plus, minus
     and the decimal point.

[U]
     (Upper) Consists of only upper case alphabetic characters.

[W]
     (Whole) If string is a valid REXX whole number under the
     current setting of NUMERIC. Note that 13.0 is a whole number
     since the decimal part is zero, while 13E+1 is not a whole
     number, since it must be interpreted as 130 plus/minus 5.

[X]
     (Hexadecimal) Consists of only hexadecimal digits, i.e. the
     decimal digits 0-9 and the alphabetic characters A-F in
     either case (or mixed.) Note that blanks are not allowed
     within string, as it would have been within a hexadecimal
     string.

If you want to check whether a string is suitable as a variable
name, you should consider using the SYMBOL() function instead,
since the Symbolic option only verifies which characters string
contains, not the order. You should also take care to watch out
for lower case alphabetic characters, which are allowed in the
tail of a compound symbol, but not in a simple or stem symbol or
in the head of compound symbol.

Also note that the behavior of the options A, L, M and U might
depend on the setting of language, if you are using an interpreter
that supports national character sets.

     DATATYPE(‘ - 1.35E-5 ‘)            –>   ‘NUM’
     DATATYPE(‘1E999999999’)            –>   ‘CHAR’
     DATATYPE(‘1E9999999999’)      –>   ‘CHAR’
     DATATYPE(‘!@#&#$(&*%`’)            –>   ‘CHAR’
     DATATYPE(‘FooBar’, ‘A’)            –>   ‘1’
     DATATYPE(‘Foo Bar’, ‘A’)      –>   ‘0’
     DATATYPE(‘010010111101’, ‘B’)      –>   ‘1’
     DATATYPE(‘0100 1011 1101’, ‘B’)    –>   ‘0’
     DATATYPE(‘foobar’, ‘L’)            –>   ‘1’
     DATATYPE(‘FooBar’, ‘M’)            –>   ‘1’
     DATATYPE(‘ -34E3 ‘, ‘N’)      –>   ‘1’
     DATATYPE(‘A_SYMBOL!?!’, ‘S’)       –>   ‘1’
     DATATYPE(‘1.23.39E+4.5’, ‘S’)      –>   ‘1’
     DATATYPE(‘Foo bar’, ‘S’)      –>   ‘0’
     DATATYPE(‘FOOBAR’, ‘U’)            –>   ‘1’
     DATATYPE(‘123deadbeef’, ‘X’)       –>   ‘1’



PREV NEXT