SA0121: Missing VAR_EXTERNAL declarations
Function | Determines the use of a global variable in the function block, without it being declared as VAR_EXTERNAL (required according to the standard). |
Reason | According to the IEC 61131-3 standard, access to global variables is only permitted via an explicit import through a VAR_EXTERNAL declaration. |
Importance | Low |
PLCopen rule | CP18 |
![]() | In TwinCAT 3 PLC it is not necessary for variables to be declared as external. The keyword exists in order to maintain compatibility with IEC 61131-3. |
Sample:
Global variables:
VAR_GLOBAL
nGlobal : INT;
END_VARProgram Prog1:
PROGRAM Prog1
VAR
nVar : INT;
END_VARnVar := nGlobal; // => SA0121Program Prog2:
PROGRAM Prog2
VAR
nVar : INT;
END_VAR
VAR_EXTERNAL
nGlobal : INT;
END_VARnVar := nGlobal; // no error