Glossary · Automation fundamentals, platforms and components
Constant (programming)
Also known as: VAR CONSTANT
German: Konstante
In programming, a constant is a named value that cannot be changed while the program runs. In IEC 61131-3, constants are declared with the CONSTANT qualifier, for example in a VAR CONSTANT section, or written as literals.
- Automation components
- Standards
In one sentence
A constant is a named value that cannot change at runtime; IEC 61131-3 declares it with the CONSTANT qualifier.
Example
The maximum number of cartons per layer is declared as a constant MAX_CARTONS := 12, so the loop and the HMI check use the same value.
How it applies
- Engineering: Named constants replace magic numbers, make code easier to read and change, and let the compiler catch accidental writes.
- Maintenance: A constant can only be changed by modifying and downloading the program, which puts it under change control. Values that operators must adjust belong in parameters or recipes instead.
- Documentation: Programming guidelines should say which values are constants and which are parameters. Software documentation can list key constants with their unit and meaning.
Constant vs. parameter
A constant is fixed in the program. A parameter is a value that can be changed during operation or commissioning, for example via the HMI, without changing the program. Choosing the right one affects who may change a value and how that change is traced.