Programming concepts
5.6 Variable table
S7-200 SMART
System Manual, 09/2015, A5E03822230-AC
105
Declaration types for local variables
The type of local variable assignment you can make depends on the POU where you are
making the assignment. The main program (OB1), interrupt routines, and subroutines can
use temporary (TEMP) variables. Temporary variables are only available while the block is
being executed and are then free to be overwritten when the block is completed.
Data values can be passed as parameters in and out of a subroutine as follows:
● If you want to pass a data value into a subroutine, then create a variable in the
subroutine's variable table and specify its declaration type as IN.
● If you want to pass a data value established in the subroutine back to the calling routine,
then create a variable in the subroutine's variable table and specify its declaration type as
OUT.
● If you want to pass an initial data value into a subroutine, perform an operation that may
modify the data value, and pass the modified result back to the calling routine, then
create a variable in the subroutine's variable table and specify its declaration type as
IN_OUT.
Input parameter provided by the calling POU.
OUT Output parameter returned to the calling POU.
IN_OUT Parameter whose value is supplied by the calling POU, modified by the subrou-
tine, and then returned to the calling POU.
TEMP Temporary variable that is saved temporarily in the local data stack. Once the
POU has been executed completely, the value of the temporary variable is no
longer available. Temporary variables do not keep their value between POU exe-
Data type checking for local variables
When you pass local variables as parameters for a subroutine, the data type that you have
assigned in the Local Variable Table of that subroutine must match the data type of the value
in the calling POU.
You call SBR0 from OB1, using a global symbol called INPUT1 as an input parameter of the
subroutine.
Inside the Local Variable Table of SBR0, you have defined a local variable called FIRST as
an input parameter.
When OB1 calls SBR0, the value of INPUT1 is passed to FIRST.
The data types of INPUT1 and FIRST must match.
If INPUT1 is a REAL and FIRST is a REAL, the data types match. If INPUT1 is a REAL but
FIRST is an INT, the data types do not match and the program cannot be compiled until this
error is corrected.