Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples
Left Hand Pointer


M[UMPS] by Example

Right Hand Pointer

Introduced in the 1990 ANSI M[UMPS] language standard.

This function returns information about other defined information in a data-structure, based on the collating sequence in use for that data-structure.

Assume that a global variable ^A exists as depicted in the diagram with the function $Order. The code:
Set REF="^A"
For I=1:1:20 Set REF=$Query(@REF) Write " ",REF

will produce the following print-out:

^A(–34) ^A(–4) ^A(–3) ^A(–2) ^A(2) ^A(3) ^A(3,1)
^A(3,2) ^A(3,10) ^A(3,10,3) ^A(4) ^A(34) ^A("–5A")
^A("5A") ^A("A") ^A("AB") ^A("AD) ^A(B")  ^A(–34)

Kill ^ABC
Set ^ABC(1,2,3)="Demo"
Set X=$Query(^ABC(1,""))

The effect of this reference to the function $Query is not portable. Use of the empty string as a subscript is only portable in the context of the function $Order.
While some implementations may return the value "^ABC(1,2,3)" in local variable X, others may return an error.

Kill ^X
Set ^X(1,2,1)=""
Set ^X(1,2,2)=""
Set ^X(1,3)=""
Set A=$Query(^X(1,1))

will return the value "^X(1,2,1)" in local variable A.

Kill ^X
Set ^X("–80 apples")="X"
Set ^X(–30)="N"
Set ^X(–7)="A"
Set ^X(–3.5)="B"
Set ^X(0)="W"
Set NAM="^X"
For  Set NAM=$Query(@NAM) Quit:NAM="" Write " ",@NAM

Note that the string "–80 apples" collates after the highest number.

Addition in the 1995 ANSI M[UMPS] language standard.

The return value of $Query contains an environment specification if and only if the parameter value contains an environment specification.

Assume that a process is operating in an environment called "first" and that the following variables exist:
lvn(1) = "local"
^one = 1
^one(1) = 1
^one(3) = 3

Also, assume that in an environment called "second" the following variables exist:
^two = 2
^two(2) = 22

Reference Value
$Query(lvn) "lvn(1)"
$Query(^one) "^one(1)"
$Query(^|"first"|one) "^|""first""|one(1)"
$Query(^|"second"|two) "^|""second""|two(2)"
$Query(^one(^|"second"|two)) "^one(3)"
Set x=^|"second"|two(2)
Set y=$Query(^(2))
Set x=$Query(^|"second"|two)
Set y=$Query(lvn)
Set x=$Query(^|"second"|two)
Set y=$Query(^one)

Additions in a future M[UMPS] language standard.

Kill ^ABC
Set ^ABC(1,2,3)="Demo"
Write "-->""",$Reference,""""
Set A=$Query(^ABC(1))
Write "-->""",A,""", and """,$Reference,"""."
-->"^ABC(1,2,3)", and "".

After a reference to the function $Query, the naked indicator becomes undefined, which means that $Reference becomes equal to the empty string.

Reverse $Query will work in a manner analogous to reverse $Order:
$Query(^A("–5A"),–1) = "^A(34)"

When the function $Query returns the name of a standardized structured system variable, the name will be returned in a "canonical" form. In its canonical form, the parts of these names that may be abbreviated will be fully spelled, and those parts of these names that are case insensitive will be converted to upper case only.

E.g. $Query(^$C("M")) could return "^$Character("M","COLLATE")"

Examples with naked references:

Set ^ABC(1,2)="reset naked indicator"
; naked indicator is now ^ABC(1,
Set x=$Query(^(3,4))

; 1. fetch ^(3,4) = ^ABC(1,3,4)
; 2. the naked indicator becomes undefined after a reference to $Query

Button for 1977 Button for 1984 Button for 1990 Button for 1995 Button for MDC Button for notes Button for examples

Copyright © Standard Documents; 1977-2019 MUMPS Development Committee;
Copyright © Examples: 1995-2019 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2019 Ed de Moel.

The information in this page is NOT authoritative and subject to be modified at any moment.
Please consult the appropriate (draft) language standard for an authoritative definition.

Some specifications are "approved for inclusion in a future standard". Note that the MUMPS Development Committee cannot guarantee that such future standards will indeed be published.

This page most recently updated on 13-Sep-2014, 21:38:53 .

For comments, contact Ed de Moel (demoel@jacquardsystems.com)