You are here: Core Reference > Coding > Logic > Example of Data Structures

Example of Data Structures

Let us assume that you want to create a Logic program that needs to use internal values for a pump. It needs to use the pump status, alarm count, and latest value. You can group these values in a data structure:

TYPE PUMP:


STRUCT


Status: BOOL;


AlarmCount: INT;


LatestUpdate: DATE_AND_TIME;


END_STRUCT;


END_TYPE


The name of the data structure is defined as PUMP. For each internal variable, the name of the value is defined and so is its data type (BOOL, INT, DATE_AND_TIME). The data structure is defined within STRUCT and END_STRUCT keywords which are enclosed within the TYPE and END_TYPE keywords.

The data structure feature becomes more useful when the data structure needs to be used to represent the internal values for multiple items. So, rather than using the PUMP data structure for 1 pump, let's look at how it can be used for 3 pumps:

TYPE


STRUCT PUMP:


Status: BOOL;


AlarmCount: INT;


LatestUpdate: DATE_AND_TIME;


END_STRUCT;


END_TYPE


The 3 pumps can refer to the PUMP data structure. By grouping the data for each pump into a data structure, it is easier to recognize the source of each value. It is also easier to use the values in the program.

Once the data structure has been defined, it needs to be added as a variable in the VAR list. As with other types of variable, each data structure requires a variable name. As the PUMP data structure needs to be used to provide the values for 3 separate items, there has to be 3 variables with PUMP as their data type:

VAR


Pump1Data :PUMP;


Pump2Data: PUMP;


Pump3Data: PUMP;


END_VAR


Pump1Data is the name allocated to the PUMP data structure for Pump 1. The other variables have similar names, for example, Pump3Data uses PUMP to access data for Pump 3. The data types for the data structure variables have to match the data structure name.

In the Logic program, any references to the values in the data structures use the following format:

<Variable name>.<value name>


This means that a reference to the AlarmCount value of Pump 3 would be entered as:

Pump3Data.AlarmCount


A reference to the LatestUpdate value of Pump 1 would be entered as:

Pump1Data.LatestUpdate



ClearSCADA 2015 R2