Skip to main content

Caché Methods

The Person class also provides some built-in methods for your use. Methods are ObjectScript procedures that perform some action on objects. You can use the following methods:

  • %New creates a new Person object in local memory.

  • %OpenId loads a persistent Person object into local memory. %OpenId supports both exclusive and shared locks.

  • %Save verifies the data in a Person object in local memory, and if the data verifies correctly, saves the data. A %Save of an object is automatically performed as a transaction.

To create new Person objects, you'll use %New, set the data (using “dot syntax” that you'll see below), and %Save. For editing existing objects, you use %OpenId, update the data (again using dot syntax), and %Save. To refer to the properties of a Person object, you use dot syntax (object.property).

Here's an example. Note that you can't try this example until you convert your globals (refer to the next page). The first line below opens an existing Person object whose ID is 2. Then you can use per to refer to the properties of the person object without caring about how the data is stored. Set per to “” to destroy the local copy of the person object.

SAMPLES>set per = ##class(CosTutorial.Person).%OpenId(2)

SAMPLES>write per.Name
Agee,Tommie
SAMPLES>write per.Phone
617-333-3333
SAMPLES>write per.DOB
37110
SAMPLES>set per = ""

SAMPLES>
FeedbackOpens in a new tab