You are here: Core Reference > Coding > Logic > Declaring a Method in a DATABASE_OBJECT Structure

Declaring a Method in a DATABASE_OBJECT Structure

You can also declare methods in a DATABASE_OBJECT structure. This allows you to group methods with database fields.

As with defining variables in a DATABASE_OBJECT structure, the main advantages of declaring methods in a DATABASE_OBJECT structure are:

If you declare methods in a DATABASE_OBJECT that is used with an SQL query, you can use the SQL to return methods in the RESULTSET instead of values. For example, you can override any points that have CurrentQuality Desc values of 'Bad'.

NOTE: Aggregate methods cannot be declared in a DATABASE_OBJECT structure.

To declare methods in a DATABASE_OBJECT structure, you need to use the following format:

Where:

<database item name> is the name of the database item to which the methods apply.

DATABASE_OBJECT instructs the program that the methods are part of a database object structure.

(<class of database item>) is the class with which the method is associated. This may be the class for the database item or one of its parent classes. For example, it could be CSCADAPackMPoint for a SCADAPack Modbus point or CDBPoint for all types of point.

<Method name> is the name that you are going to use to identify the method in your program. For methods that are defined in DATABASE_OBJECT structures, you have to enter a name that matches the name of the method in the ClearSCADA database. For example, for an Acknowledge Alarm method, you have to define its name as Accept (as that is the name of the method in the ClearSCADA database).

METHOD instructs the program that the type of value in the DATABASE_OBJECT is a method. You need to repeat the <Method name>:METHOD; line for each separate method that is to be included.

END_DATABASE_OBJECT; ends the database object structure definition and END_TYPE ends the type declaration.

Example: 1

  • TYPE
    • AlarmConditions: (AlarmNormal, AlarmDisabled, AlarmAcceptedUncleared, AlarmUnacceptedCleared, AlarmUnacceptedUncleared);
  • END_TYPE
  • TYPE
    • AlarmDBOBJ: DATABASE_OBJECT (CDBPoint)
    • AlarmState:AlarmConditions;
    • Accept: METHOD;
    • END_DATABASE_OBJECT;
  • END_TYPE

In the program, the following ST is used to set the Input1 point so that its UnacknowledgedCleared alarms are acknowledged automatically:

  • VAR
    • Input1 AT %O(Input1) :AlarmDBObj;
  • END_VAR;
  • PROGRAM
    • IF(Input1.AlarmState = UnacknowledgedCleared) THEN
    • Input1.Accept();
    • END_IF;
  • END_PROGRAM

This program uses an enumerated data type (see Using Enumerated Data Types to Create Names for State Values). The enumerated data type defines a value named AlarmConditions that has 5 state values. The ClearSCADA Database Schema defines the states as:

  • State 0—Normal
  • State 1—Disabled
  • State 2—AcknowledgedUncleared
  • State 3—UnacknowledgedCleared
  • State 4—UnacknowledgedUncleared

The encapsulated data type is named and has its state values defined in the first TYPE declaration.

NOTE: You can use any names for the states in encapsulated data types (they do not have to match the names of states in the ClearSCADA Database Schema).

The second TYPE declaration is used to define the DATABASE_OBJECT structure for the methods. It is named AlarmDBOBJ, and it is set to be a DATABASE_OBJECT that uses the CDBPoint class. The following values and methods are included in the DATABASE_OBJECT:

  • AlarmState:AlarmConditions;
  • Accept: METHOD;

The AlarmState value returns a value for the AlarmConditions data type. This means it returns a value that corresponds to one of the AlarmConditions states.

The Accept value defines the method that is used in the program (the Acknowledge method). The name of the Accept value has to match the name of the method as it appears in the ClearSCADA database schema, so in this case it is Accept as the name of the Acknowledge Alarm method is Accept. The METHOD part of the value instructs the program that the value is a method.

In the program, the VAR list contains:

  • Input1 AT %O(Input1) :AlarmDBObj;

This defines a value (Input1) that is a database item (%O). The Input1 value is associated with the Input1 database item and its values are returned for the AlarmConditions database object structure. This means that the program will use the Input1 item's values that correspond to the values that are specified in the AlarmDBObj structure.

  • PROGRAM
    • IF(Input1.AlarmState = UnacknowledgedCleared) THEN Input1.Accept();
    • END_IF;
  • END_PROGRAM

This part of the program defines the Logic of the program, that is, the behavior that is defined by the program. The Logic references one of the values that is defined in the AlarmDBObj method (Accept). Referencing a method is referred to as calling a method (see Calling a Method). In this case, the Acknowledge method is applied to the Input1 item when its AlarmState value is Unacknowledged Cleared.

 

Example: 2

First, we define a database object called 'CDBPoint' which has a method called 'Override' with an LREAL argument (the point override value).

  • TYPE
  • AlarmDBOBJ: DATABASE_OBJECT (CDBPoint)
  • Override: METHOD (LREAL);
  • END_DATABASE_OBJECT;
  • END_TYPE

The following ST program block then defines a variable called 'Point' which represents the database point 'Analog Point 1'. The program then overrides this point with a value of 20.0 by using the 'Override' method.

  • PROGRAM NewStructuredTextProgram
  • VAR
    • Point AT %O(Analog Point 1) : AlarmDBOBJ;
  • END_VAR;
  • Point.Override (20.0);
  • END_PROGRAM

Further Information

Using Database Object Structures to Access Direct Variables


ClearSCADA 2015 R2