Skip to main content

Storage Procedure, continued

This section of the storage procedure begins by separating the name into last name and first name pieces, for indexing. The next three statements are the strangest statements you'll see during this tutorial, because they're so unlike statements in other languages. Two of the statements only store data in the subscripts; there's “nothing” on the right side of the equals sign! But it makes sense if you think of the tree.

Each last name, first name, and ID combination, for example, is stored in the subscripts. Since the names will be sorted alphabetically, this will create an index of the database, by last name, and then by first name, with similar indices for phone numbers and dates of birth. The global ^PersonI will be a tree with three large branches, one for each index. Note that the line that builds the phone index is different (ID isn't stored in the subscripts) to help enforce uniqueness among the phone numbers.

Once you complete the storage procedure, you'll run it and start adding data to your global. As you do this, you might find it helpful to draw the tree for each global on a piece of paper, to see how it looks. Whether or not you do that, once you add data, use the Management Portal. Click System Explorer > Globals and click View to look at your two globals (^PersonD and ^PersonI).

store()  [name, phone, intdob]
  ; procedure continued from previous page...
  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
FeedbackOpens in a new tab