Skip to main content

Browsing Class Definitions

Browsing Class Definitions

You can use the SQL pages of the Management Portal to browse the class definition classes.

Similarly, you can programmatically browse through the class definitions using the same techniques you would use to browse any other kind of data: you can use dynamic SQL and you can instantiate persistent objects that represent specific class definitions.

For example, from within an InterSystems IRIS® data platform process, you can get a list of all classes defined within the dictionary for the current namespace by using the %Dictionary.ClassDefinition:Summary() query:

  set stmt=##class(%SQL.Statement).%New()
  set status = stmt.%PrepareClassQuery("%Dictionary.ClassDefinition","Summary")
  if $$$ISERR(status) {write "%Prepare failed:" do $SYSTEM.Status.DisplayError(status) quit}

  set rset=stmt.%Execute()
  if (rset.%SQLCODE '= 0) {write "%Execute failed:", !, "SQLCODE ", rset.%SQLCODE, ": ", rset.%Message quit}

  while rset.%Next()
  {
    write rset.%Get("Name"),!
  }
  if (rset.%SQLCODE < 0) {write "%Next failed:", !, "SQLCODE ", rset.%SQLCODE, ": ", rset.%Message quit}

This sample method will write the names of all the classes visible in the current namespace (including classes in the system library). You can filter out unwanted classes using the various columns returned by the %Dictionary.ClassDefinition:Summary() query.

You can get detailed information about a specific class definition by opening a %Dictionary.ClassDefinitionOpens in a new tab object for the class and observing its properties. The ID used to store %Dictionary.ClassDefinitionOpens in a new tab objects is the class name:

 Set cdef = ##class(%Dictionary.ClassDefinition).%OpenId("Sample.Person")
 Write cdef.Name,!

 // get list of properties
 Set count = cdef.Properties.Count()
 For i = 1:1:count {
     Write cdef.Properties.GetAt(i).Name,!
 }

Note that you must fully qualify class names with their package name or the call to %OpenId() will fail.

FeedbackOpens in a new tab