- Home
- IEC 61131-3 Programming
- Programming ST
- Inserting Variables in ST
Inserting Variables in ST
While editing your ST code worksheet, variables can be inserted that are already declared or a new variable can be inserted and declared in one step.
The tooltip of a variable in the ST editor shows its name, data type and, if defined in the variables table, the user-defined comment.
What do you want to do?
Insert an already declared variable
- In the variables table, left-click into the row header of the desired variable, keep the mouse button pressed and drag the variable into the code worksheet and drop it at the desired position.or
- Set the cursor at the desired position in the code worksheet. Type the first character(s) of the variable, select the variable from the appearing Intellisense selection box and press <Enter>.To insert an input/output variable (formal parameter) of an FB instance or a member of a STRUCT variable, enter the function block instance or STRUCT variable followed by a dot. The appearing selection box lists all input and output variables of the corresponding FB instance resp. all members of the corresponding STRUCT variable.
Note
When you insert an existing global variable (declared as 'Global' variable in the Data List of the 'IEC 61131-3' node) into the code worksheet and no local variable with the same name exists in the 'Variables' table, the related external variable declaration ('Usage = External') is automatically added to the 'Variables' table.
Insert and declare a new variable
- In the code worksheet, type the desired variable name and complete the syntactically correct statement.
- Right-click on the variable and select 'Create New Variable > Variable type' from the appearing context menu. The appropriate declaration is inserted with the corresponding declaration keyword into the 'Variables' table.Variable Declaration Keywords" for details.Which variable types can be selected from the context menu depends on the current POU type. In programs and functions, for example, local and external variables can be declared. In FBs, additionally input and output variables are possible.
Note
If you declare an 'External' variable this way, the related global declaration (with the 'Global' keyword) is also entered automatically in the Data List of the 'IEC 61131-3' node provided that the POU is already instantiated (i.e., a program instance exists or an FB instance within a program instance).Note
IN and OUT ports for PLCnext Technology targets cannot be created via the context menu. - Set the variable properties in the 'Variables' table. In case of an FB instance, enter a valid instance name into the 'Name' field and select a function block in the 'Type' field.
Go to variable definition / user-defined function block
The context menu provided for a variable/function block instance inserted in the code worksheet provides the commands:
- 'Go to Definition'Calling this command for a selected variable in the code worksheet directly selects the corresponding variable declaration in the variable table.
- 'Go to Implementation'Calling this command for a selected user-defined function block instance in the code worksheet directly opens the related function block editor group with the code worksheet containing the FB code.
Assign a global variable to a process data item
The assignment of global variables to process data items (I/O terminals, made available by the I/O devices in the PLANT) has to be done in the 'Data List' of the 'IEC 61131-3' node or of the involved I/O device.
In the following example, the global variable 'TemperatureCurrent' of the standard (non-safety-related) controller is connected to the process data item 'IN01' provided by a temperature input module.
- Double-click the 'IEC 61131-3' node or the I/O device node in the PLANT ('IEC 61131-3' node in our example, see number (1) in the figure below).
- If not visible, open the 'Data List' table in the editors area (2).
Note
Depending on the selected element in the PLANT tree, the 'Data List' table shows more or less process data items. If opened for one specific device, only the process data items of this device are shown. For the 'IEC 61131-3' node, all standard (non-safety-related) process data items of all PLANT modules can be assigned. - In the 'Data List', table left-click into the 'Process Datum' cell of the variable to be connected (3) and select the desired process data item from the appearing selection list (4). The selection list provides only those process data items which are allowed to connect to the selected variable (suitable data type).
![]() | To remove the assignment of a process data item to a variable, right-click the variable and select 'Disconnect Process Datum'. Alternatively, select the variable and click the 'Disconnect Process Datum' button on the 'Data List' toolbar or press the <Del> key. |
![]() | Variables that are no longer needed in the 'Data List' table can be removed via the context menu command 'Remove all unused global variables' or the corresponding toolbar button. |
Editing the properties of the variable at the cursor position or marked variable
At the lower border of the code editor, a single line grid editor is available. It shows the properties of the variable at the cursor position or which is selected in the code. Instead of first switching to the variables grid of the POU, you can edit the properties of the variable without leaving the code editor. Exception: The variable name cannot be modified here. Use the variables grid or refactoring tool instead.