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 sectionNext section

Exercise 4: Add Storage Procedure

  1. Start Studio, and open the mydatent routine. The finished routine is also available in the SAMPLES namespace as datent.mac.

  2. Edit the main routine. Call the store procedure after calling display.

        do display()
        do store()
    Copy code to clipboard
  3. Add an If construct to the $$validPhone function, that checks to see if the phone exists in the index already, just after the line that adds the default area code.

        set:(phone?3n1"-"4n) phone = "617-" _ phone ; add default area code
        if $data( ^PersonI( "Phone", phone)) {
            write !, "Phone number in use"
            quit 0
        else {
            quit phone 
    Copy code to clipboard
  4. Add the following new store procedure.

    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 id = $increment( ^PersonD )              ; use $increment to generate a new ID
      set rec = name _ "^" _ phone _ "^" _ intdob  ; concatenate data into a record
      set ^PersonD( id ) = rec                     ; store the record
      set ln = $piece(name, ",", 1),
          fn = $piece(name, ",", 2)                ; break name for storage in index
      /* the next three statements store data in subscripts
         because of the automatic sorting of subscripts,
         this has the effect of building 3 indices: name, phone, and DOB */
      set ^PersonI( "Name", ln, fn, id) = ""       ; store the name
      set ^PersonI( "Phone", phone) = id           ; store the UNIQUE phone
      set ^PersonI( "DOB", intdob, id) = ""        ; store the DOB
      write "...stored"                            ; done
    Copy code to clipboard
  5. Store some people, and look at the globals with the Management Portal.