How-to
Copying One Structure Variable to Another in Operator Terminal Expert
Short answer
Operator Terminal Expert 3.4 refuses a whole structure as a changeValue operand, so replace the one failing call with one scalar assignment per member, expanding nested structures and arrays to their leaf values. Gate the work on a clean compile plus a destination readback, and stage the copy when the consumer must act only on a complete set.
On this page
The error is a type restriction, and the fix is a different call shape, not different arguments. Operator Terminal Expert 3.4 refuses a whole user-defined structure wherever changeValue expects a value operand, which is exactly what a structure is not allowed here reports for Rec_Phase1 and API_Phase1. No rearrangement of that single line will copy the aggregates. The working method is one changeValue per scalar member, with nested structures expanded to their leaf values and arrays walked element by element, gated by a clean compile and a destination readback. The example type below needs 13 of those lines in one onClick event.
Why the editor rejects the call #
The line as written:
changeValue($Enums.WhenOver.Stop, $Enums.AssignmentOperator.Set, Rec_Phase1, API_Phase1);
fails on the last two operands, because both are aggregates. The user data type defines how Rec_Phase1 and API_Phase1 are laid out; changeValue defines what it accepts, and in Operator Terminal Expert 3.4 a structure is outside that set. Retyping the line, swapping the two variables, or changing either enum leaves the operand kinds unchanged, so the diagnostic stays. Sharing one user data type is what makes a member-to-member copy possible, because the members line up, but it does not turn this call into an aggregate move.
Map the copy before editing the event #
Decide the direction from the application, not from the names: one variable is the authoritative source, the other is the writable destination, and nothing in Rec_Phase1 or API_Phase1 says which. Write the direction down before touching the event.
Expand both declarations side by side and record every source-to-destination pair: standalone scalars, the leaf scalars inside nested structures, and each array element within the declared bounds. Where a member needs partial access, such as one bit inside a word, the addressing method is the one shown in How to Access One Bit of a Word in Operator Terminal Expert.
Check the destination binding for write access before any of this reaches a button. A variable the panel can only read accepts nothing, however correct the mapping is.
Replace the aggregate call with member assignments #
- Work offline or in a controlled commissioning state: these writes can reach variables that initiate machine actions.
- Pick one scalar member that exists in both structures, is easy to observe, and has no operational consequence. In the button's onClick event, replace the failing line with a single changeValue whose last two operands are that source member and destination member, keeping the two enum arguments in their positions. Build the member references with the editor's variable picker so the notation comes from the tool.
- Check the function signature in the installed help for which operand position carries the value and which carries the target, then compile and press the button once.
- Read both variables. The destination must hold the source value and the source must be unchanged; if the wrong side moved, the operands are swapped, so swap them in this line and in every line that follows. That one press fixes the direction for the whole copy.
- Add one line per remaining mapped pair, expanding nested structures until every operand is a supported scalar and walking arrays element by element.
- Convert explicitly wherever a source and destination member differ in type, instead of accepting a silent narrowing.
- Compile the finished event and clear every diagnostic before the next test.
One button event carrying several writes is an ordinary pattern, and How to Make One HMI Button Read and Write Two PLC Bits walks the same shape for two bits.
Count the writes with a worked example #
Take an illustrative recipe-phase type built from 6 standalone scalar members, 1 nested structure holding 2 scalar members, and 1 array of 5 INT elements:
Scalar writes = 6 standalone + 2 nested + 5 array elements = 13
The onClick event therefore carries 13 changeValue lines, and the test sheet carries 13 destination checks per dataset. Pressing the button twice with two datasets makes 13 x 2 = 26 comparisons, which is what exposes a line wired to a fixed value or to the wrong source member.
Decision for this example: 13 ordered writes inside one event are acceptable when the consumer reads the phase only on request. The trigger to change approach is coherence, not the count. The moment a consumer can act while some members still hold their previous values, stage the copy as described next or move it into the controller.
Keep the destination coherent #
Each line in the sequence is a separate update; nothing in changeValue ties them together, so anything that reads the destination can observe a half-copied phase.
Identify what updates the source, whether operator entry, a communication binding, or application logic, and identify what consumes the destination and when it acts. Recipe-style data consumed as one set needs staged acceptance: write the members into a staging area the consumer ignores, then write a single accept flag, or use an existing application handshake, so the consumer acts only on the complete set.
Read back after communication completes, not on the button's visual response. For controller-bound members a write can be delayed, rejected, or overwritten by controller logic, so compare the destination itself, member by member, against the test sheet.
Prove the copy end to end #
- Build a test sheet with one row per mapped member: source value and expected destination value. Use values that are distinguishable from each other and from the previous dataset, within the declared types and the permitted process limits.
- In the controlled state, press the button once and compare every destination member on the sheet, including nested leaves and array elements.
- Confirm the source is unchanged and that unmapped members were not touched.
- Repeat with a second dataset; a line that reproduces the first dataset's numbers is wired to a constant or to the wrong member.
- If members change after a download rather than after the button press, that is a different mechanism, covered in Why HMI Variable Values Reset After a Project Transfer.
Questions asked
Does the same restriction apply to an array of structures?
Yes. Each element is itself a structure, so no element can be an operand either. Expand to elements first, then to members: an array of 5 elements of a 4-member type needs 5 x 4 = 20 scalar assignments. Stay inside the declared bounds and let the editor's variable picker build each address, so the element notation comes from the tool rather than from typing.
Can I copy between two different user data types?
Only member by member, and only where each pair is type-compatible or carries an explicit conversion. Matching member names do not guarantee matching types: an INT source feeding a REAL destination widens cleanly, while a REAL feeding an INT truncates unless you convert it deliberately. A single aggregate assignment between two different user data types is unavailable for the same reason the original call failed.
Is it better to do the copy in the controller?
When both structures map to controller variables and the consumer must act on a complete set, yes. One controller-side copy routine executed in a single scan replaces the whole HMI sequence, and the button writes a single trigger bit. Keep the copy in the HMI event only when the consumer tolerates members arriving one write at a time.
Does the order of the member writes matter?
Only when something can act on a partially copied destination. Order the writes so nothing that enables action lands before the data it depends on: values first, then limits, then any enable or permissive bit last. Once the copy runs through a staging area with a single accept flag, the order inside the staged set no longer matters.