Validates the specified name string as a legal identifier.
Synopsis
$ZNAME(string,n,lang)
Parameters
string The name to evaluate, specified as a quoted string.
n Optional — An integer code specifying the type of name validation to perform. The default is 0.
lang Optional — An integer code specifying the language mode to use when validating string. The default is to use the current language mode.
Description
$ZNAME returns 1 (true) if the string parameter is a legal identifier. Otherwise, $ZNAME returns 0 (false). The optional n parameter determines what type of name validation to perform on the string. If this parameter is omitted, the validation defaults to local variable name conventions. The optional lang parameter specifies what language mode conventions to apply to the validation.
The valid identifier characters for your locale are defined in the National Language Support (NLS) Identifier locale setting; they are not user-modifiable. Refer to Customized National Language Translations for further details on NLS.
$ZNAME only performs character validation; it does not perform string length validation for identifiers.
Parameters
string
A quoted string to validate as a legal identifier name. The characters a valid string can contain depend both on the type of identifier to validate (specified by n), the language mode (lang), and the definition of your locale. By default, the following are valid identifier characters in Caché:
n
An integer code specifying the type of name validation to perform:
Value Meaning Restricted Characters
0 Validate a local variable name.
First character only: %
Subsequent characters only: digits 0–9
1 Validate a routine name.
First character only: %
Subsequent characters only: digits 0–9 and the period (.) character. A period cannot be the first or last character in a routine name.
2 Validate a tag (label) name. First character only: %
3 Validate a global name.
First character only: %
Subsequent characters only: digits 0–9 and the period (.) character. A period cannot be the first or last character in a global name.
4 Validate a fully-qualified class name.
First character only: %
Subsequent characters only: digits 0–9
5 Validate a method name.
First character only: %
Subsequent characters only: digits 0–9
6 Validate a property name
First character only: %
Subsequent characters only: digits 0–9
If n = 0 (or not specified), an identifier that passes validation may be used for any type of Caché ObjectScript name. The first character of a valid identifier must be either a percent sign (%) or a valid letter character. The second and subsequent characters of a valid identifier must be either a valid letter character or a digit.
If n = 1, an identifier that passes validation may be used for routine names. In Caché ObjectScript routine names, the first character must be either a percent sign (%) or a valid letter character. The second and subsequent characters of a routine name may be either a valid letter character, a digit, or a period. A period cannot be the first or last character in a routine name. Thus, routine names differ from other types of names because they can include a period.
lang
An integer code specifying the language mode to use for validation. Caché applies the conventions of the specified language mode to the validation without changing the current language mode. The default is for $ZNAME to use the language mode conventions of the current language mode. To determine or to change the current language mode, and for a list of available language mode, see the $ZUTIL(55) function.
Examples
The following example shows the $ZNAME function validating the expressions as true (1). Note that the last two examples contain periods, which are permitted in routine names (n=1) and global names (n=3):
   WRITE !,$ZNAME("A")
   WRITE !,$ZNAME("A1")
   WRITE !,$ZNAME("%A1",0)
   WRITE !,$ZNAME("%A1",1)
   WRITE !,$ZNAME("A.1",1)
   WRITE !,$ZNAME("A.1",3)
 
The following example fails validation (returns 0) because the first character of a local variable name cannot be a digit.
   WRITE $ZNAME("1A")
 
The following example fails validation because with n = 0, $ZNAME performs a local variable name validation; such names cannot contain a percent sign unless it is the first character of the name:
   WRITE $ZNAME("A%1",0)
 
The following example shows the full set of valid identifier characters for local variable names. These valid identifier characters include the letter characters ASCII 192 through ASCII 255 (with the exceptions of ASCII 215 and ASCII 247, which are arithmetic symbols):
   FOR n=1:1:500  {
   IF $ZNAME("A"_$CHAR(n),0) & $ZNAME($CHAR(n),0){
      WRITE !,$ZNAME($CHAR(n))," ASCII code=",n," Char.=",$CHAR(n) }
   ELSEIF $ZNAME($CHAR(n),0){
      WRITE !,$ZNAME($CHAR(n))," ASCII code=",n," 1st Char.=",$CHAR(n) }
   ELSEIF $ZNAME("A"_$CHAR(n),0){
      WRITE !,$ZNAME("A"_$CHAR(n))," ASCII code=",n," Subseq. Char.=",$CHAR(n) }
   ELSE { }
  }
   WRITE !,"All done"
 
Notes
Not all legal identifiers may be used for global variable names; wide characters cannot be used in global variable names.
A valid label name may have a digit as its first character. Therefore, you must specify n=2 when validating a label name, rather than using $ZNAME default validation.
SQL identifiers may include punctuation characters (underscore (_), at sign (@), pound sign (#), and dollar sign ($)) that are not valid characters in Caché ObjectScript identifiers. SQL routine names may not include the percent sign (%) at any location other than the first character. For further details, see Identifier in the Caché SQL Reference.
See Also