Declaration of external variables in ST

Syntax
VAR_EXTERNAL (* optional_begin *) CONSTANT (* optional_end *)
name_1, name_2, ..., name_n : data-type;
name_3, name_4, ..., name_n : STRING[length] := 'initial-value';
name_5, name_6, ..., name_n : ARRAY [x..y] OF type := [initial-value_1, initial-value_2, .., initial-value_n];
name_7, name_8, ..., name_n : ARRAY [x1..y1, x2..y2, x3..y3] OF data-type; (* Here, initial values are possible as well. *)
END_VAR

Meaning

declaration of one or more →external variables, name_1, name_2 etc. must be →IEC-identifiers.
The declaration of more sections of this kind is allowed. The declaration of external variables is possible within declaration of a function block, the declaration of a function or within a →method. Such external variables are used to access →global variables with the same name and of the same type. These global variables are declared within a →program (within an ST-object) or within a →resource (within a PLC-object).
The declaration of external variables is possible within declaration of a program. Such external variables are used to access global variables which were declared within a resource (within a PLC-object).

Providing the optional keyword CONSTANT prevents all external variables of this section from being overwritten during program execution (makes them →constants). The keyword CONSTANT is mandatory if the corresponding global variable has been declared CONSTANT.
See "Supported data types" to learn which data types are supported for the declaration. It is also possible to declare:

Moreover, logi.CAD 3 allows you to specify additional data for the declaration . See " Defining description, comment or JSON string for variables and data types " for details.

Example 1
VAR_EXTERNAL
portSetting : INT;
upTime : TIME;
gVar1: ARRAY [1..2] of BOOL;
gVar2: STRING[10];
END_VAR

Example 2
VAR_EXTERNAL
VALVE_POS : INT;
END_VAR