Skip to main content

Storage Subroutine, continued

This section of the storage subroutine 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.

You might find it helpful to draw the tree for each global on a piece of paper as if you had entered three or four people, to see how they'll look. Whether or not you do that, use the Management Portal. Click System Explorer > Globals and click View to look at your two globals (^PersonD and ^PersonI).

public sub store()
    ' ...store subroutine continued from previous page...

    ' break name for storage in index
    ln = piece(name, ",", 1) : fn = piece(name, ",", 2)
 
    ' 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
    ^PersonI( "Name", ln, fn, id) = "" ' store the name
    ^PersonI( "Phone", phone) = id     ' store the UNIQUE phone
    ^PersonI( "DOB", intdob, id) = ""  ' store the DOB
    println "...stored"                ' done
end sub
FeedbackOpens in a new tab