Glossary · PLC and control programming
In-out variable
Also known as: VAR_IN_OUT, Input-output variable
German: Ein-/Ausgangsvariable
In IEC 61131-3 programming, an in-out variable is a parameter declared with VAR_IN_OUT that is passed by reference, so the called program organization unit can read and modify the caller's variable directly.
- PLC programming
- Standards
In one sentence
An in-out variable (VAR_IN_OUT) is passed by reference, so a function block can read and change the caller's variable directly.
Example
A function block that sorts a production queue receives the queue array as VAR_IN_OUT, so it works on the original data instead of a copy.
How it applies
- Engineering: In-out variables avoid copying large structures and arrays and let a block modify data that belongs to the caller. They must be assigned at every call; the block cannot be called without its in-out parameters.
- Risk: Because the block writes directly into the caller's data, side effects are harder to see. Coding guidelines often restrict VAR_IN_OUT to large data or to cases where modification is the explicit purpose.
- Testing: Tests should check the caller's data after the call, not only the block outputs.
- Documentation: In the block's interface table, mark in-out parameters clearly and state what the block changes. Treat the block interface like any Interface specification: direction, type, unit and meaning for each parameter.
In-out variable vs. input and output variables
An Input variable is copied into the block at the call; an Output variable is copied out after it. An in-out variable is shared: there is only one copy, owned by the caller.