Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous section

Exercise 8: Object Versions of Data Entry and Lookup

  1. The new store procedure of mydatentobj.

    store() [name, phone, intdob]
        ; store the data
        read !, "Store? (y/n): ", yn                 ; see if user wants to store
        if ( yn '= "y" ) {                           ; only go on if user says yes
            write "...not stored."
        set per = ##class(CosTutorial.Person).%New() ; create a new person
        set per.Name = name
        set per.Phone = phone
        set per.DOB = intdob
        do per.%Save()       ; store the record, in a transaction, 
                             ; including storage in indices!
        set per = ""         ; release the person
        write "...stored"    ; done
    Copy code to clipboard
  2. The new load procedure of mylookupobj.

    load(id) [name, phone, intdob] ; load a person into local variables
         set per = ##class(CosTutorial.Person).%OpenId(id)
         set name = per.Name
         set phone = per.Phone
         set intdob = per.DOB
         set per = ""
    Copy code to clipboard
  3. The new update procedure of mylookupobj.

    update(id) [newname, newphone, newintdob] ; update ^PersonD and ^PersonI
        set per = ##class(CosTutorial.Person).%OpenId(id)
        set per.Name = newname
        set per.Phone = newphone
        set per.DOB = newintdob
        do per.%Save()                    ; this updates indices too,
                                          ; all within a transaction!
        set per = ""
        write "...updated."
    Copy code to clipboard
  4. Update the phone procedure of mylookupobj by changing this line:

        set ph = $order( ^PersonI("Phone", ph), 1, loopid)
    Copy code to clipboard

    to this:

        set ph = $order( ^PersonI("Phone", ph))
        set:( ph '= "") loopid = $order( ^PersonI("Phone", ph, ""))
    Copy code to clipboard