Declaration of a function in ST

Syntax
FUNCTION name (* optional_begin *) : data-type (* optional_end *)
 
( * optional_begin *) USING  Namespace_1;
USING  Namespace_2; (* optional_end *)
 
(* optional: declaration of variables *)
 
(* optional: body of function *)
 
END_FUNCTION 
Meaning

declaration of a →function, name must be an →IEC-identifier.
The declaration is possible within an ST-object or an ST-interface of a C-/C++-block – the declaration is done either within the global →namespace or within a declared namespace. FUNCTION and END_FUNCTION are →keywords for the declaration of the function.

The data type : data-type is optional but is required if a return value is assigned within the function (see example "Assigning return value within a function") or the function is used as operand
See "Supported data types" to learn which data types are supported for the return value.

The USING namespace directive after the name or the data type of the function is optional. See "Namespaces in ST: usage" for details on this directive.

Example
FUNCTION Simple1
END_FUNCTION 
 
FUNCTION Simple2 : INT
END_FUNCTION

You are able to use the following language elements for ST within a function:

The usage of these language elements makes it possible to use other elements (e.g. declaration of STRING variables within the section VAR ... END_VAR ) as well. Such elements are not listed here.