It is currently Fri Oct 19, 2018 11:47 am


All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Unit 2 - Lesson 7: Expressions - Array Structure
PostPosted: Tue Jun 21, 2011 1:23 pm 
User avatar

Joined: Wed Nov 17, 2010 8:37 am
Posts: 136
Real Name: Terry L. Wiechmann
Began Programming in MUMPS: 0- 0-1971
The Array Structure lesson is an extension of the Symbol Names lesson.

Local, Global and Structured Special Variable Names (SSVN) are specialized by adding a subscripting mechanism. Subscripting provides a way to logically organize data. Subscripts can be expressions that evaluate to a string type. Subscripts are recursively defined. That is, an array node can be used as a subscript within an array subscript. An array subscript can not be a null string (often a source of errors when an expression evaluates to a null).

Another important feature of MUMPS arrays is that they are sparse and do not have to be dimensioned. Some languages required you to define the array in a declaration section of the program. MUMPS does not. You can simply set any array node for the first time and it will define the array. Other nodes do not have to be defined, hence the term 'sparse'.

The array concept is illustrated by the ^PARTS global. Pay particular attention to the ^PARTS global description. The workshop exercise at the end of the course will have you build a simple inventory system. This is a simplified structure used in File Manager. There are three node types of interest. They are:

Code:
Set ^PARTS(0)=1
Set ^PARTS(1)=”123^TIRE”
Set ^PARTS(“B”,123,1)=””
Set ^PARTS(“C”,”TIRE”,1)=””


The ^PARTS(0) node holds the last Internal Entry Number (IEN). It is a counter that represents the last entry in the global. When the program wants to add a new entry, it increments this number and uses it to file the next entry which makes it unique.

^PARTS(1) node contains a string that is the parts record. In this case, the record consists of fields (places to store data) that are delimited by the circumflex (up-arrow) character which assumes that the up-arrow will not appear in any of the field data entries. The subscript is the IEN.

Nodes ^PARTS(“B”,123,1) and ^PARTS(“C”,”TIRE”,1) are lookup indexes for the two field values. The first subscript “B” is assigned to the the Part Number field and “C” is assigned to the Description field. The second subscript is assigned to the data value. The third subscript is assigned to the Internal Entry Number. Consequently, field values will be indexed and accessible for all records stored in the global. Notice that only the subscripts are used to store data and the value is null.

This is not the only way to store data. When working with existing MUMPS applications you will undoubtedly see many different approaches.

Note: Structured Special Variable Names are essentially system globals. The standard identifies basic structures needed to complete functionality elsewhere such as collating sequences and character sets. However, it appears that each implementation treats them differently. GT.M appears to exclusively use Z prefixes on commands, special variables and functions to expose system information. Cache implements ^$ROUTINE, ^$GLOBAL, ^$LOCK and ^$JOB superficially and relies on Z commands, special variables and functions as well. However, MUMPSV1 relies heavily upon SSVN's and does not implement Z commands, special variables and functions. You will have to explore the implementation you are using for the supported SSVN's.

_________________
Terry L. Wiechmann


Top
Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created StylerBB.net