Skip to main content

SA0121: Missing VAR_EXTERNAL declarations

Detects the use of a global variable in function blocks without them being declared there as VAR_EXTERNAL

Justification: According to the IEC 61131-3 standard, access to global variables is permitted only by an explicit import by means of a VAR_EXTERNAL declaration.

Importance: Low

PLCopen rule: CP18

Example 104. Example
VAR_GLOBAL
    iGlob1 : INT;
END_VAR
PROGRAM PLC_PRG
VAR
    ivar : INT;
END_VAR
ivar := iGlob1;    // SA0121

Output in the Messages view:

  • sa_icon_message.png SA0121: VAR_EXTERNAL declaration required for variable 'iGlob1'



Example 105. Example for error avoidance
VAR_GLOBAL
    iGlob1:INT;
END_VAR
PROGRAM PLC_PRG
VAR
    ivar:INT;
END_VAR
VAR_EXTERNAL
    iGlob1:INT;
END_VAR
ivar:=iGlob1;    // OK