Skip to main content

$CLASSNAME

Returns the name of a class.

Synopsis

$CLASSNAME(n)

Parameter

Argument Description
n Optional — An object reference (OREF) to an class instance. If omitted, the class name of the current class is returned.

Description

$CLASSNAME returns the name of a class. Commonly, it takes an object reference (OREF) and returns the corresponding class name. $CLASSNAME with no argument returns the name of the current class. $CLASSNAME always returns the full class name (for example, %SQL.Statement), not the short version of the class name omitting the package name (for example, Statement).

$CLASSNAME is functionally equivalent to the %ClassName(1)Opens in a new tab method of the %Library.BaseOpens in a new tab superclass. The $CLASSNAME function gives better performance than the %ClassName(1) method for returning the full class name. To return the short version of the class name, you can use either %ClassName() or %ClassName(0).

For information on OREFs, see “OREF Basics” in Using Caché Objects.

Examples

The following example creates an instance of a class. $CLASSNAME takes the instance OREF and returns the corresponding class name:

   SET dynoref = ##class(%SQL.Statement).%New()
   WRITE "instance class name: ",$CLASSNAME(dynoref)

In the following example, $CLASSNAME with no parameter returns the class name of the current class context. In this case, it is the DocBook.Utils class. This is the same class name contained in the $THIS special variable:

   WRITE "class context: ",$CLASSNAME(),!
   WRITE "class context: ",$THIS

The following example shows that the $CLASSNAME function and the %ClassName(1) method return the same values. It also shows use of the %ClassName() method (with no argument or with a 0 argument) to return the short version of the class name:

CurrentClass
   WRITE "current full class name: ",$CLASSNAME(),!
   WRITE "current full class name: ",..%ClassName(1),!
   WRITE "current short class name: ",..%ClassName(0),!
   WRITE "current short class name: ",..%ClassName(),!!
ClassInstance
   SET x = ##class(%SQL.Statement).%New()
   WRITE "oref full class name: ",$CLASSNAME(x),!
   WRITE "oref full class name: ",x.%ClassName(1),!
   WRITE "oref short class name: ",x.%ClassName(0),!
   WRITE "oref short class name: ",x.%ClassName()

See Also

FeedbackOpens in a new tab