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

$DEXTRACT

M[UMPS] by Example

Approved for inclusion in a future 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

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-2024 MUMPS Development Committee;
Copyright © Examples: 1995-2024 Ed de Moel;
Copyright © Annotations: 2003-2008 Jacquard Systems Research
Copyright © Annotations: 2008-2024 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 15-Nov-2023, 10:46:50.

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