replica clause

REPLICA Variables

A REPLICA variable is a special type of elementary item variable that has the same name and level number as a previously defined elementary item variable, and refers to the same physical variable in memory as the originally defined variable. REPLICA variables are useful when defining multiple group item variables that all require the same elementary item component; using a replica in these cases avoids the task of moving values back and forth between these elementary items.

REPLICA variables are defined with a level number, variable name, and the REPLICA keyword. PIC and VALUE clauses are not permitted in a REPLICA variable because they are not meaningful; this information is defined by the original variable (also called the replica parent), whose definition always precedes the REPLICA variable definition. Similarly, no VALUE clauses are permitted in replicas, and both the replica and the replica parent must be elementary item variables with the same level number. Here’s the basic REPLICA variable syntax:

<level-number> variable_name REPLICA.

And here’s a simple example of REPLICA usage:

1 group_variable_1.

5 component_1 PIC XXX VALUE `mS1`.

5 ` has a dollar value of `.

5 component_2 PIC $,999.99 value 125.99.

1 group_variable_2.

5 `The value in the component_1 replica variable is: `.

5 component_1 REPLICA.

DISPLAY group_variable_1.

DISPLAY group_variable_2.

MOVE `q72` TO component_1.

DISPLAY group_variable_1.

DISPLAY group_variable_2.

In the above example, the normal, full definition of component_1 occurs in the group_variable_1 group item definition; the second component_1, defined in group_variable_2, is a replica of the original component_1. Thus, component_1 inside group_variable_1 is the replica parent, and component_1 inside group_variable_2 is the replica. The output of the code above is:

mS1 has a dollar value of $125.99

The value in the component_1 replica variable is: mS1

q72 has a dollar value of $125.99

The value in the component_1 replica variable is: q72