M[UMPS] Functions - $QS[UBSCRIPT]

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

This function returns the value of a subscript in a name- reference.

Assume that X is defined as in the example with the function $QLENGTH (X="^|""XXX""|ABC(1,2,3,5,6)").

Reference   Value
$QSUBSCRIPT(X,-2)   reserved (may be error)
$QSUBSCRIPT(X,-1)   "XXX"
$QSUBSCRIPT(X,0)   "^ABC"
$QSUBSCRIPT(X,1)   "1"
$QSUBSCRIPT(X,2)   "2"
$QSUBSCRIPT(X,3)   "3"
$QSUBSCRIPT(X,4)   "5"
$QSUBSCRIPT(X,5)   "6"
$QSUBSCRIPT(X,6)   ""
$QSUBSCRIPT(X,7)   ""

$QSUBSCRIPT is a lot easier to use than $PIECE with parentheses and commas as separators, especially when there are string-subscripts that contain commas and quotes:

SET Q="""",C=","

Reference   Value
SET X=$NAME(^ABC(1,Q,C,9_Q_C_8))   X="^ABC(1,"""""""","","",""9"""",8"")"
(or, without all those confusing double quotes, and using {curly braces} instead to delimit strings)
^ABC(1,{"},{,},{9",8})
$QSUBSCRIPT(X,1)   "1"
$QSUBSCRIPT(X,2)   """"
$QSUBSCRIPT(X,3)   ","
$QSUBSCRIPT(X,4)   "9"",8"

Note that this function only operates on the string that contains the name of a variable. The variable that is identified in this string is never accessed by this function. Therefore, this function only affects the naked incator if the string in question is stored in a global variable.

SET ^NUM(5,6)=2
SET ^FOO(2,4,6)=$NAME(^A(1,"abc",9))

Reference   Value
$QSUBSCRIPT(^FOO(2,4,6),^NUM(5,6))   "abc"

in this example, the naked indicator becomes "^NUM(5,".

For additional examples of this function, see the function $NAME.

Approved for addition in a future ANSI M[UMPS] Language Standard:

It is allowed to specify a reference to $QSUBSCRIPT on the left hand side of the equal sign in a SET command.

SET N="^|""where""|ABC(11,22,33)"

Reference   Value
SET $QSUBSCRIPT(N,-1)="A"   N="^|""A""|ABC(11,22,33)"
SET $QSUBSCRIPT(N,0)="xxx"   N="^|""A""|xxx(11,22,33)"
SET $QSUBSCRIPT(N,2)=9   N="^|""A""|xxx(11,9,33)"
SET $QSUBSCRIPT(N,10)=123   N="^|""A""|xxx(11,9,33,"","","","","","",123)"


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.