M[UMPS] Functions - $DE[XTRACT]

Approved for inclusion in a future ANSI M[UMPS] language standard.

This function works on substrings of strings that are specified as parameters. This function is intended to be used in conjunction with data structures that store multiple values in a single string. The main difference with the function $EXTRACT is that this function is capable of working on multiple substrings at the same time.

SET FMT="5,,,-6,,,9"
SET X=$DEXTRACT("",FMT,A+5,B,,,,D)

Stores values into a data record.
The first parameter specifies the starting string. The record format specification relies on the function $EXTRACT to define the record fields. The first parameter specifies the string in which the substitution will occur (an empty string in this example). The second parameter specifies the individual field widths, separated by commas. Omitted field specifiers default to the same width and alignment as their immediate predecessor. Positive numbers imply left-aligned fields, negative numbers imply right-aligned fields. As a result, fields 1, 2 and 3 are left-aligned and have a width of 5 characters, fields 4, 5 and 6 have a width of 6 characters and are right-aligned, and field 7 is left-aligned and has a width of 9 characters.

This example would store the value of A+5 into the first field, the value of B into the second field, and the value of D into the sixth field. In other words, the above example is equivalent to:

SET X="",PAD=$JUSTIFY("",5)
SET $EXTRACT(X,1,5)=$EXTRACT(A+5_PAD,1,5)
SET $EXTRACT(X,6,10)=$EXTRACT(B_PAD,1,5)
SET $EXTRACT(X,28,33)=$EXTRACT($JUSTIFY(D,6),1,6)

SET FMT="5,,-7,,4"
SET $DEXTRACT(FMT,^DB,A,B:4,,D)=X

Extracts values out of a data record.
The value of local variable X is the data record that is being accessed, and the values of some data fields will be extracted and stored into other variables. The value of the first field (as described by the value of FMT) will be stored in global variable ^DB; the value of the second field will be stored in local variable A, the value of the fourth field into local variable B and the value of the sixth field into local variable D. In other words, the above example is equivalent to:

SET t=$EXTRACT(X,1,5)
FOR  QUIT:$EXTRACT(t,$LENGTH(t))'=" "  SET t=$EXTRACT(t,1,$LENGTH(t)-1)
SET ^DB=t
SET t=$EXTRACT(X,6,10)
FOR  QUIT:$EXTRACT(t,$LENGTH(t))'=" "  SET t=$EXTRACT(t,1,$LENGTH(t)-1)
SET A=t
SET t=$EXTRACT(X,18,24)
FOR  QUIT:$EXTRACT(t,1)'=" "  SET t=$EXTRACT(t,2,$LENGTH(t))
SET B=t
SET t=$EXTRACT(X,29,32)
FOR  QUIT:$EXTRACT(t,$LENGTH(t))'=" "  SET t=$EXTRACT(t,1,$LENGTH(t)-1
SET D=t


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.