Merges global nodes or subtrees from source into destination.
where mergeargument is:
||Optional A postconditional expression.
|destination and source
||Local variables, process-private globals, or globals to be merged. If specified as a class property, the source variable must be a multidimensional (subscripted) variable.
MERGE destination=source copies source into destination and all descendants of source into descendants of destination. It does not modify source, or kill any nodes in destination.
MERGE simplifies the copying of a subtree (multiple subscripts) of a variable to another variable. Either variable can be a subscripted local variable, process-private global, or global. A subtree is all variables that are descendants of a specified variable. MERGE offers a one-command alternative to the current technique for doing subtree copy: a series of SET commands with $ORDER references.
MERGE issues a <COMMAND> error if the source and destination have a parent-child relationship.
The MERGE command can take longer than most other ObjectScript commands to execute. As a result, it is more prone to interruption. The effect of interruption is implementation-specific. Under InterSystems IRIS, an interruption may cause an unpredictable subset of the source to have been copied to the destination subtree.
MERGE is a non-atomic operation. When executing MERGE while other processes are performing concurrent data modification operations, the contents of destination will be the state of the data at the time that MERGE was initiated, minus any variables that were KILLed at the time the MERGE operation concluded. Other data modifications that occurred during MERGE processing may not be reflected in the contents of destination.
An optional postconditional expression. InterSystems IRIS executes the MERGE
command if the postconditional expression is true (evaluates to a nonzero numeric value). InterSystems IRIS does not execute the command if the postconditional expression is false (evaluates to zero). For further details, refer to Command Postconditional Expressions
in Using ObjectScript
destination and source
Variables to be merged. Either variable can be a local variable, a process-private global, or a global. If destination is undefined, MERGE defines it and sets it to source. If source is undefined, MERGE completes successfully, but does not change destination.
You can specify multiple, comma-separated destination=source pairs. They are evaluated in left-to-right order.
can reference a destination
pair by indirection
. For example, MERGE @tMergeString
The following example copies a subtree from one global variable (^a) to another global variable (^b). In this case, the merge is being used to create a smaller global ^b, which contains only the ^a(1,1) subtree of the information in ^a.
SET ^a(1)="The Flintstones",^a(2)="The Simpsons"
SET ^a(1,1)="characters",^a(1,2)="place names"
SET ^a(1,1,1)="Flintstone family"
SET ^a(1,1,2)="Rubble family"
WRITE ^b,!,^b(2),!,^b(2,1)," and ",^b(2,2)
The following example shows how a destination global variable looks after it has been merged with a subtree of a source global variable.
Suppose you execute the following:
The following figure shows the resulting logical structure of ^X and ^Y.
Initial Structure of ^X and ^Y
Consider the following MERGE command:
When you issue the previous statement, InterSystems IRIS copies part of ^Y into ^X(2,3). The global ^X now has the structure illustrated in the figure below.
Result on ^X and ^Y of MERGE Command
When both destination and source are local variables, the naked indicator is not changed. If source is a global variable and destination is a local variable, then the naked indicator references source.
When both source
are global variables, the naked indicator is unchanged if source
is undefined ($DATA
)=0). In all other cases (including $DATA
)=10), the naked indicator takes the same value that it would have if the SET
command replaced the MERGE
command and source
had a value. For more details on the naked indicator, see Naked Global Reference
in Using Globals
Merge to Self
When the destination and source are the same variable, no merge occurs. Nothing is recorded in the journal file. However, the naked indicator may be changed, based on the rules described in the previous section.
The MERGE command supports watchpoints. If a watchpoint is in effect, InterSystems IRIS triggers that watchpoint whenever that MERGE alters the value of a watched variable. To set watchpoints, use the ZBREAK command.
Content Date/Time: 2019-09-20 05:47:55