Skip to main content

Storage Procedure

Let's focus on the storage procedure of mydatent. The user responds to the prompts, reviews the data, and then has the option of storing the data. As you'll see from the next few slides, you'll store the data in the global ^PersonD.

For each person, we must generate a new unique ID number, to be used as the subscript of ^PersonD. The very first time mydatent runs, ^PersonD doesn't exist, so we need to make sure that the first ID is 1, using $Increment(). This will make ^PersonD into an array similar in conceptual structure to “normal” arrays (although it's still really an ordered tree): a list of people. Each person's record is a three-piece string of their data. Here is the first section of the store subroutine:

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
   ; ...remainder of store subroutine continued on next page...
FeedbackOpens in a new tab