97BPLC concepts
4.4 Data types
S7-1200 Programmable controller
System Manual, 11/2011, A5E02486680-05
91
String
The CPU supports the String data type for storing a sequence of single-byte characters. The
String data type contains a total character count (number of characters in the string) and the
current character count. The String type provides up to 256 bytes for storing the maximum
total character count (1 byte), the current character count (1 byte), and up to 254 characters,
with each character stored in 1 byte.
You can use literal strings (constants) for instruction parameters of type IN using single
quotes. For example, ‘ABC’ is a three-character string that could be used as input for
parameter IN of the S_CONV instruction. You can also create string variables by selecting
data type "String" in the block interface editors for OB, FC, FB, and DB. You cannot create a
string in the PLC tags editor.
You can specify the maximum string size in bytes by entering square brackets after the
keyword "String" (once the data type "String" is selected from a data type drop-list). For
example, "MyString[10]" would specify a 10-byte maximum size for MyString. If you do not
include the square brackets with a maximum size, then 254 is assumed.
The following example defines a String with maximum character count of 10 and current
character count of 3. This means the String currently contains 3 one-byte characters, but
could be expanded to contain up to 10 one-byte characters.
Table 4- 23 Example of a String data type
Total Character
Count
Current Character
Count
Character 1
Character 2
Character 3
...
Character 10
10
3
'C' (16#43)
'A' (16#41)
'T' (16#54)
...
-
Byte 0
Byte 1
Byte 2
Byte 3
Byte 4
...
Byte 11
ASCII control characters can be used in Char and String data. The following table shows
examples of control character syntax.
Table 4- 24 Valid ASCII control characters
Control characters
ASCII Hex value
Control function
Examples
$L or $l
0A
Line feed
'$LText', '$0AText'
$N or $n
0A and 0D
Line break
The new line shows two characters in the
string.
'$NText', '$0A$0DText'
$P or $p
0C
Form feed
'$PText', '$0CText'
$R or $r
0D
Carriage return (CR)
'$RText','$0DText'
$T or $t
09
Tab
'$TText', '$09Text'
$$
24
Dollar sign
'100$$', '100$24'
$'
27
Single quote
'$'Text$'','$27Text$27'
Arrays
You can create an array that contains multiple elements of the same data type. Arrays can
be created in the block interface editors for OB, FC, FB, and DB. You cannot create an array
in the PLC tags editor.