Difference between revisions of "MUMPS Code Examples"

From VistApedia
Jump to: navigation, search
(MUMPS Code to iterate over Data Dictionary Number of every FileMan File & Subfile)
(MUMPS Code to iterate over every subscript of the global ^XTMP)
 
(6 intermediate revisions by the same user not shown)
Line 4: Line 4:
 
  === Title for explanation of code purpose ==
 
  === Title for explanation of code purpose ==
 
  NOTE: Standard MUMPS
 
  NOTE: Standard MUMPS
<code>
+
<tt><pre>
</code>
+
some code
 +
</pre></tt>
 
</nowiki></pre>
 
</nowiki></pre>
  
Line 12: Line 13:
 
NOTE: this is NON-STANDARD MUMPS.  Known to work on GT.M
 
NOTE: this is NON-STANDARD MUMPS.  Known to work on GT.M
  
<code>
+
<tt><pre>
SET GBLNAME="^%" FOR  SET GBLNAME=$o(@GBLNAME) Q:GBLNAME=""  DO Something(GBLNAME)
+
SET GBLNAME="^%" FOR  SET GBLNAME=$ORDER(@GBLNAME) QUIT:GBLNAME=""  DO Something(GBLNAME)
</code>
+
</pre></tt>
 +
=== MUMPS Code to iterate over every value of the first subscript of the global ^XTMP ===
 +
 
 +
NOTE: Standard MUMPS
 +
Note: the following code immediately stops if there are no subscripts to ^XTMP
 +
 
 +
<tt><pre>
 +
SET SUB="" FOR  SET SUB=$ORDER(^XTMP(SUB)) QUIT:SUB=""  DO Something(SUB)
 +
</pre></tt>
  
 
=== MUMPS Code to iterate over every FileMan File ===
 
=== MUMPS Code to iterate over every FileMan File ===
 
NOTE: Standard MUMPS
 
NOTE: Standard MUMPS
  
<code>
+
<tt><pre>
 
S FILE=0 F  S FILE=$O(^DIC(FILE)) Q:FILE'=+FILE  D Something(FILE)
 
S FILE=0 F  S FILE=$O(^DIC(FILE)) Q:FILE'=+FILE  D Something(FILE)
</code>
+
</pre></tt>
  
 
=== MUMPS Code to iterate over Data Dictionary Number of every FileMan File & Subfile ===
 
=== MUMPS Code to iterate over Data Dictionary Number of every FileMan File & Subfile ===
 
NOTE: Standard MUMPS
 
NOTE: Standard MUMPS
  
<code>
+
<tt><pre>
 
S DDNUM=0 F  S DDNUM=$O(^DD(DDNUM)) Q:DDNUM'=+DDNUM  D Something(DDNUM)
 
S DDNUM=0 F  S DDNUM=$O(^DD(DDNUM)) Q:DDNUM'=+DDNUM  D Something(DDNUM)
</code>
+
</pre></tt>
  
 
=== Getting the {K} closed root for a Data Dictionary Number ===
 
=== Getting the {K} closed root for a Data Dictionary Number ===
Line 37: Line 46:
 
until the {K} text is replaced with either a constant or a variable.
 
until the {K} text is replaced with either a constant or a variable.
  
<code>
+
<tt><pre>
 
S RESULT=$$ROOT^DMSQU(ddnum)
 
S RESULT=$$ROOT^DMSQU(ddnum)
</code>
+
</pre></tt>
  
 
Example:
 
Example:
 
PATIENT File #2 has a Field #1900 the "APPOINTMENT" multiple that is in DDNUM 2.98
 
PATIENT File #2 has a Field #1900 the "APPOINTMENT" multiple that is in DDNUM 2.98
  
<code>
+
<tt><pre>
 
MUMPS> W !,$$ROOT^DMSQU(2.98)
 
MUMPS> W !,$$ROOT^DMSQU(2.98)
  
 
^DPT({K},"S",{K})
 
^DPT({K},"S",{K})
</code>
+
</pre></tt>

Latest revision as of 20:47, 27 February 2010

Instructions for page

For each of these code fragments, be sure to put them in CODE tags, and note whether the code is Standard MUMPS, and if not, what MUMPS systems it works on.

<nowiki>
 === Title for explanation of code purpose ==
 NOTE: Standard MUMPS
<tt><pre>
some code
</tt>

</nowiki></pre>

MUMPS Code to iterate over every global

NOTE: this is NON-STANDARD MUMPS. Known to work on GT.M

SET GBLNAME="^%" FOR  SET GBLNAME=$ORDER(@GBLNAME) QUIT:GBLNAME=""  DO Something(GBLNAME)

MUMPS Code to iterate over every value of the first subscript of the global ^XTMP

NOTE: Standard MUMPS Note: the following code immediately stops if there are no subscripts to ^XTMP

SET SUB="" FOR  SET SUB=$ORDER(^XTMP(SUB)) QUIT:SUB=""  DO Something(SUB)

MUMPS Code to iterate over every FileMan File

NOTE: Standard MUMPS

S FILE=0 F  S FILE=$O(^DIC(FILE)) Q:FILE'=+FILE  D Something(FILE)

MUMPS Code to iterate over Data Dictionary Number of every FileMan File & Subfile

NOTE: Standard MUMPS

S DDNUM=0 F  S DDNUM=$O(^DD(DDNUM)) Q:DDNUM'=+DDNUM  D Something(DDNUM)

Getting the {K} closed root for a Data Dictionary Number

NOTE: Standard MUMPS Given a Data Dictionary number generates a closed root with the "variables" expressed as as the three letters: "{K}" Note this allows one to iterate through all of the "constant" parts of root using $PIECE and two argument $LENGTH. The result CANNOT be used directly with indirection i.e. @ROOT@(something) until the {K} text is replaced with either a constant or a variable.

S RESULT=$$ROOT^DMSQU(ddnum)

Example: PATIENT File #2 has a Field #1900 the "APPOINTMENT" multiple that is in DDNUM 2.98

MUMPS> W !,$$ROOT^DMSQU(2.98)

^DPT({K},"S",{K})