Local Variables - VAR

Local variables are declared in the declaration part of programming objects between the keywords VAR and END_VAR.

You can extend local variables with an attribute keyword.

You can access local variables for reading from outside the programming objects via the instance path. Access for writing from outside the programming object is not possible; this will be displayed by the compiler as an error.

In order to maintain the intended data encapsulation, it is strongly recommended not to access local variables of a POU from outside the POU – neither in read mode nor in write mode. (Other high-level language compilers also output read access operations to local variables as errors.) Furthermore, with library function blocks it cannot be guaranteed that the local variables of a function block will remain unchanged during subsequent updates. This means that it is possible that the application project can no longer be compiled correctly after the library update.

Also observe here rule SA0102 from the Static Analysis, which determines access to local variables for reading from outside.

Sample:

VAR
    nVar1 : INT;
END_VAR

See also: