You are on page 1of 3

Basics of PLC data types (UDT)

Basics of PLC data types (UDT)

Description
A PLC data type (UDT) is a complex, user-defined data type that is used for the declaration
of a tag. It represents a data structure made up of several components of different data
types. The components can also be derived from another PLC data type, from an ARRAY
or directly using the STRUCT keyword as a structure. The nesting depth is hereby limited
to 8 levels.
You can change a PLC data type (UDT) centrally and use it repeatedly in the program
code. All locations of use are updated automatically.
Advantages of the PLC data types:
• Simple data exchange via block interfaces among several blocks
• Group data according to the process control
• Transferring a parameter as a data unit

Using a PLC data type


You can declare PLC data types as a type when creating data blocks. Based on this type,
you can create a number of data blocks, all of which have the same data structure. These
data blocks can be adapted by entering different actual values for the corresponding task.
For instance, create a PLC data type for a recipe for blending paints. You can then assign
this data type to several data blocks, each of which contains different quantity information.
The following figure shows this application:

PLC data types can be used for the following applications:


• PLC data types can be used as data types for tags in the tag declaration of logic blocks
or in data blocks.
• PLC data types can be used as templates for the creation of global data blocks with
identical data structures.
• PLC data types can be used in S7-1200 and S7-1500 as a template for the creation of
structured PLC tags.

Nesting depth and potential number of PLC data types


A maximum of 64K objects of FCs, FBs, DBs and PLC data types are defined (the total
number is restricted accordingly for CPUs, however).

-1-
Basics of PLC data types (UDT)

A maximum of 16K components can be defined per hierarchy level for each structure de-
scription (for example, a DB or a PLC data type (UDT)). These components can also be an
ARRAY or a STRUCT data type. When a structured component is hereby derived from an
explicitly declared PLC data type, there is no restriction. In other words, 16K components
of PLC data type (UDT)/SDT are supported for each hierarchy level. However, a maximum
of 252 of the 16K components can have "anonymous structures".
PLC data types can be nested to a depth of 8 hierarchy levels. This nesting depth is inde-
pendent of the CPU used.

Disadvantages of anonymous structures


The components of the structured tags can be identically addressed. This is regardless of
whether the declaration has been made using a PLC data type or an anonymous structure.
The following disadvantages apply when using anonymous structures:
• Reusability of the same structure by copying. This makes it difficult to change the struc-
ture
• Anonymous structures are not compatible with PLC data types (UDT) of the same struc-
ture
• Performance, since the matching types for structural components are checked during
runtime
• The high limit is more easily reached when using anonymous structures, since all com-
ponents must be evaluated individually.

Example
The following example shows the data type definition of the "MyUDT" PLC data type:

PLC data types generated by the system


Some instructions generate their own PLC data types during instancing which are saved in
the "PLC data types" project folder. Do not use these PLC data types created by the sys-
tem in a library, because this may result in undesirable system behavior. If necessary,
these PLC data types are created by the system, which means they must not be stored in
a library.

Generating external sources from blocks


When generating external sources from blocks, the changes made directly in the block in-
terface to the default values of PLC data types are not exported to the sources. This
means that these values are not available when the sources are imported once again. The
default values are applied instead. To prevent this loss of data for the modified default val-
ues, the changes must be made directly in the PLC data type and not in the block inter-
face. In this case, the changes are also exported when external sources are generated.

-2-
Basics of PLC data types (UDT)

Additional information on the PLC data types (UDTs)


Note
Declaring PLC data types (UDTs):
Structure of the declaration table for PLC data types
Programming recommendations for PLC data types:
Using PLC data types (UDT)
Using the DB_ANY data type
Comparison of PLC data types (UDTs) in the program:
Comparing PLC data types

Note
You can find more information on the PLC data types in the Siemens Industry On-
line Support in the following contributions:
How can you initialize structures in optimized memory areas at the S7-1500 in STEP 7
(TIA Portal)?
https://support.industry.siemens.com/cs/ww/de/view/78678760
How do you create a PLC data type (UDT) at an S7-1500 control system?
https://support.industry.siemens.com/cs/ww/de/view/67599090
How is the specific application of own PLC data types (UDT) effected in STEP 7 (TIA
Portal)?
https://support.industry.siemens.com/cs/de/de/view/67582844
Why should complete structures be transferred at a block call for S7-1500 instead of
many individual components?
https://support.industry.siemens.com/cs/ww/de/view/67585079

See also
Addressing PLC data types (UDT)
Declaring tags based on a PLC data type
Declaring tags based on a PLC data type
Comparing PLC tags
Creating structured PLC tags
Permissible addresses and data types of PLC tags
CMP ==: Equal (S7-1200, S7-1500)
Transferring a tag of the PLC data type (UDT)

-3-

You might also like