M[UMPS] Functions - $NA[ME]

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

This function returns the 'canonic representation' of the name of the variable that is passed as a parameter.

SET ^ABC(1,2)="Define naked indicator"

Reference   Value
$NAME(^(3,4))   "^ABC(1,3,4)"
$NAME(^X(123+456_" apples"))   "^X(""579 apples"")"

SET X="^ABC(11,22,33,44)"

Reference   Value
$NAME(@X)   "^ABC(11,22,33,44)"
$NAME(@X,0)   "^ABC"
$NAME(@X,1)   "^ABC(11)"
$NAME(@X,3)   "^ABC(11,22,33)"
$NAME(@X,9)   "^ABC(11,22,33,44)"
$NAME(@X,-1)   Error (M39)
$NAME(X,1)   "X"
$NAME(^A(3,"A",4+3))   "^A(3,""A"",7)"
$NAME(^A(3,"A",7),2)   "^A(3,""A"")"
$NAME(^A(3,4,5),0)   "^A"
$NAME(^A(1,2,3,4),8)   "^A(1,2,3,4)"
$NAME(^A)   "^A"
$NAME(^A(1,2,3,4),-1)   error (M39)

SET X=^A(1,2,3)

Reference   Value
$NAME(^(4,5))   "^A(1,2,4,5)"

The application of the functions $NAME, $QLENGTH and $QSUBSCRIPT is tightly coupled, which can be seen in the following example.

Note that this function merely operates on the name of a variable. The variable that is identified by this name is never accessed by this function. Therefore, this function only affects the naked indicator if a global variable needs to be accessed to evaluate the reference to the name in question.

So:
SET x=$GET(^two(1)) WRITE $NAME(^one(2))," ",$NAME(^(3))
will produce
^one(2) ^two(3)

The routine below scans a structure and totals the information stored at the various levels of this structure into an array.

SET START=$NAME(^SOMENAME(SOME,ARBITRARY,DEPTH))
SET STORE=$NAME(TOTALS)
DO SCAN(START,STORE)
;...
SCAN(START,TOT) ;
NEW G,HEAD,MAJOR,MINOR,SS1,SS2
SET HEAD=$QLENGTH(START)
SET MAJOR=HEAD+1,MINOR=HEAD+2
KILL @TOT
SET G=START
FOR  SET G=$QUERY(@G) QUIT:$NAME(@G,HEAD)'=START  DO
. SET SS1=$QSUBSCRIPT(G,MAJOR)
. IF $QLENGTH(G)=MAJOR SET @TOT@(SS1)=@G QUIT
. SET SS2=$QSUBSCRIPT(G,MINOR)
. SET @TOT@(SS1,SS2)=$GET(@TOT@(SS1,SS2))+@G
. QUIT
QUIT

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

Reference   Value
$NAME(^|HERE|ABC)   "^|""PRD,MST""|ABC"
$NAME(^ABC)   "^ABC"

The 'canonic' names of structured system variables are always fully spelled:

Reference   Value
$NAME(^$C("M","COLLATE"))   ^$CHARACTER("M","COLLATE")
$NAME(^$CHARACTER("M","COLLATE"))   ^$CHARACTER("M","COLLATE")

Examples with naked references:

$NAME(GLVN)
SET ^ABC(1,2)="reset naked indicator"
; Naked indicator is now ^ABC(1,
SET ^(3,4)=$NAME(^(5,6))

; 1. fetch ^(5,6) = ^ABC(1,5,6) (naked indicator is still ^ABC(1,)
; 2. store ^(3,4) = ^ABC(1,3,4)
; Naked indicator is now: ^ABC(1,3,

$NAME(GLVN,SUB)
SET ^ABC(1,2)="reset naked indicator"
; Naked indicator is now ^ABC(1,
SET ^(3,4)=$NAME(^(5,6),^(7,8))

; 1. fetch ^(5,6) = ^ABC(1,5,6) (naked indicator is still ^ABC(1,)
; 2. fetch ^(7,8) = ^ABC(1,7,8)
; 3. store ^(3,4) = ^ABC(1,7,3,4)
; Naked indicator is now: ^ABC(1,7,3,


This document is © Ed de Moel, 1995-2005.
It is part of a book by Ed de Moel that is published under the title "M[UMPS] by Example" (ISBN 0-918118-42-5).
Printed copies of the book are no longer available.