Skip to main content

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."
            quit
            }
    
        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
        }
  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 = ""
         }
  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."
        }
  4. Update the phone procedure of mylookupobj by changing this line:

        set ph = $order( ^PersonI("Phone", ph), 1, loopid)
    

    to this:

        set ph = $order( ^PersonI("Phone", ph))
        set:( ph '= "") loopid = $order( ^PersonI("Phone", ph, ""))
    
FeedbackOpens in a new tab