Structure of an SCL Source File
9.3 Complex Data Types
SCL supports the following complex data types:
Table 9-3 Complex Data Types
Data Type Description
DATE_AND_TIME DT
Defines an area of 64 bits (8 bytes). This data type stores date and time (as a binary coded decimal) and is a predefined data type in SCL.
STRING
Defines an area for a character string of up to 254 characters (DATA TYPE CHAR).
ARRAY
Defines an array consisting of elements of one data type (either elementary or complex).
STRUCT
Defines a group of data types in any combination of types. It can be an array of structures or a structure of structures and arrays.
Overview
9.3.1 DATE_AND_TIME Data Type
The data type DATE_AND_TIME is made up of the data types DATE and TIME. It defines an area of 64 bits (8 bytes) for specifying the date and time.
The data area stores the following information (in binary coded decimal format): year–month–day–hours: minutes: seconds.milliseconds.
DATE_AND_TIME#
DT#
Time
Date –
DATE_AND_TIME
Figure 9-1 Syntax of DATE_AND_TIME
Table 9-4 Bit widths and value ranges
Type Keyword Bits Range of Values
Date and time
DATE_AND_TIME
(=DT) 64
DT#1990-01-01:0:0:0.0 to DT#2089-12-31:23:59:59.999
The precise syntax for the date and time is described in Chapter 11 of this manual. Below is a valid definition for the date and time 20/10/1995 12:20:30 and 10 milliseconds.
DATE_AND_TIME#1995-10–20–12:20:30.10 DT#1995–10–20–12:20:30.10
Note
There are standard FCs available for accessing the specific components DATE or TIME.
Overview
Value Range
Data Types
9.3.2 STRING Data Type
A STRING data type defines a character string with a maximum of 254 characters.
The standard area reserved for a character string consists of 256 bytes. This is the memory area required to store 254 characters and a header consisting of two bytes.
You can reduce the memory required by a character string by defining a maximum number of characters to be saved in the string. A null string, in other words a string containing no data, is the smallest possible value.
STRING Data Type Specification
[ Simple ]
expression String dimension STRING
Figure 9-2 Syntax of the STRING Data Type Specification
The simple expression (string dimension) represents the maximum number of characters in the string.
The following are some examples of valid string types:
STRING[10]
STRING[3+4]
STRING[3+4*5]
STRING max. value range (default 254 characters)
Any characters in the ASCII character set are permitted in a character string.
Chapter 11 describes how control characters and non-printing characters are treated.
Note
In the case of return values, input and in/out parameters, the standard length of the data type STRING can be reduced from 254 characters to a number of your choice, in order to make better use of the resources on your CPU.
Select the Customize menu command in the Options menu and then the
“Compiler” tab. Here, you can enter the required number of characters in the
“Maximum String Length” option box.
Overview
Value Range
9.3.3 ARRAY Data Type
The array data type has a specified number of components of particular data type. In the syntax diagram for arrays shown in Figure. 9-3, the data type is precisely specified by means of the reserved word OF. SCL distinguishes between the following types of array:
S The one-dimensional ARRAY type.
(This is a list of data elements arranged in ascending order).
S The two-dimensional ARRAY type.
(This is a table of data consisting of rows and columns. The first dimension refers to the row number and the second to the column number).
S The multidimensional ARRAY type.
(This is an extension of the two-dimensional ARRAY type adding further dimensions. The maximum number of dimensions permitted is six).
ARRAY Data Type Specification
[ .. ]
Data type specification OF
,
ARRAY Index Index
Index specification
1 n
Figure 9-3 Syntax of ARRAY Data Type Specification
This describes the dimensions of the ARRAY data type as follows:
S The smallest and highest possible index (index range) for each dimension.
The index can have any integer value (–32768 to 32767).
S The limits must be separated by two full stops.
S The individual index ranges must be separated by commas. The entire index specification is enclosed in square brackets.
The data type specification is used to declare the data type of the array components. The permissible data types are all those detailed in this section.
The data type of an ARRAY can also be a structure.
Overview
Index Specification
Data Type Specification
Data Types
9.3.4 STRUCT Data Type
A STRUCT data type describes an area consisting of a fixed number of components that can be of different data types. These data elements are specified in Figure 9-4 immediately following the STRUCT keyword in the component declaration. The main feature of the STRUCT data type is that a data element within it can also be structured. This means that nesting of STRUCT data types is permitted. Chapter 10 explains how to access the data of a structure.
STRUCT
Component
declaration END_STRUCT
STRUCT
Figure 9-4 Syntax of STRUCT Data Type Specification
This is a list of the various components in a structure. As shown in the syntax diagram in Figure 9-5, this list consists of:
S 1 to n identifiers
S the assigned data type and
S optional specification of an initial value Component Declaration
: ;
IDENTIFIER Data type
specification Data type initialization Component name
Figure 9-5 Syntax of a Component Declaration
This is the name of a structure element to which the subsequent data type specification is to apply.
Overview
Component Declaration
Identifier
You have the option of specifying an initial value for a specific structure element after the data type specification. Assignment is made by means of a value assignment as described in Chapter 10.
The example below illustrates a definition of a STRUCT data type.
//START of component declaration STRUCT
A1 :INT;
A2 :STRING[254];
A3 :ARRAY [1..12] OF REAL;
//END of component declaration END_STRUCT
Component names Data type specifications
Example 9-1 Definition of a STRUCT Data Type Data Type
Initialization
Example
Data Types