Examples of Merge

Example:

        GTM>SET ^gbl1="one"
        GTM>SET ^gbl1(1,1)="oneone"
        GTM>SET ^gbl1(1,1,3)="oneonethree"
        GTM>SET ^gbl1(1,2,4)="onetwofour"
        GTM>SET ^gbl2(2)="gbl2_2"
        GTM>SET ^gbl2(2,1,3)="gbl2_2_1_3"
        GTM>SET ^gbl2(2,1,4,5)="gbl2_2_1_4_5"
        GTM>MERGE ^gbl1(1)=^gbl2(2)
        GTM>WRITE $REFERENCE
        ^gbl1(1)
        GTM>ZWRITE ^gbl1
        ^gbl1="one"
        ^gbl1(1)="gbl2_2"
        ^gbl1(1,1)="oneone"
        ^gbl1(1,1,3)="gbl2_2_1_3"
        ^gbl1(1,1,4,5)="gbl2_2_1_4_5"
        ^gbl1(1,2,4)="onetwofour"
        GTM>ZWRITE ^gbl2
        ^gbl2(2)="gbl2_2"
        ^gbl2(2,1,3)="gbl2_2_1_3"
        ^gbl2(2,1,4,5)="gbl2_2_1_4_5"
        GTM>
        

The example illustrates how MERGE copies a sub-tree of one global into another. The nodes in the sub-tree of ^gbl(2), for which $DATA() value is 1 or 11, are copied to sub-tree of ^gbl1(1) as follows:

        ^gbl1(1) is updated with value of ^gbl2(2)
        ^gbl1(1,1,3) is updated with value of ^gbl2(2,1,3)
        ^gbl1(1,1,4,5) is updated with value of ^gbl2(2,1,4,5)
        

Since ^gbl1(2,1) and ^gbl2(2,2,4) do not have values ($DATA()=0), the corresponding nodes ^gbl1(1,1) and ^gbl(1,2,4) respectively are left unchanged. The naked indicator takes the value ^gbl(1) as if SET replaced MERGE. Notice that the MERGE command does not change ^gbl2(2) or its descendants. Ancestor nodes of ^gbl(1) are also left unchanged.

Example:

        GTM>KILL
        GTM>SET ^gbl(1,2)="1,2"
        GTM>MERGE lcl(3,4)=^gbl(1)
        GTM>SET ^("naked")=2
        GTM>ZWRITE ^gbl
        ^gbl(1,2)="1,2"
        ^gbl("naked")=2
        GTM>ZWRITE lcl
        lcl(3,4,2)="1,2"
        GTM>
        

The example illustrates how MERGE creates a sub-tree of a variable when the variable does not exist. Also, notice how the naked indicator is set when the source of the MERGE is a global and the destination a local.