Find out how SCADA systems and networks, like EcoStruxure Geo SCADA Expert, help industrial organizations maintaining efficiency, processing data for smarter decision making with IoT, RTU and PLC devices.
Posted: 2 weeks ago
I have a data set that's populated from data set rows in instances of group templates. The number of rows in the data set varies from project to project. I'd like to sum each field/column of the data set and assign each sum to a variable.
I've tried several approaches but I can't quite figure it out. I think I've narrowed it down to using ST logic to query the data set and assign the results to variables.
Here's my sandbox code but I'm getting "Compile error: at line: 19, column: 21; invalid value of type STRUCT, REAL expected".
TYPE
SumResult: STRUCT
Value: REAL;
END_STRUCT;
END_TYPE
PROGRAM TypeSum
VAR NOCACHE
TotalA AT %S(SELECT SUM(FieldA) AS "Value" FROM DATASET): RESULTSET OF SumResult;
TotalB AT %S(SELECT SUM(FieldB) AS "Value" FROM DATASET): RESULTSET OF SumResult;
END_VAR
VAR
SumA AT %M(.TypeATotal): REAL;
SumB AT %M(.TypeBTotal): REAL;
END_VAR
SumA := TotalA.Value;
SumB := TotalB.Value;
END_PROGRAM
Posted: 2 weeks ago
The two SQL queries are only selecting a single database field so you don't need a STRUCT for the result set:
VAR NOCACHE
TotalA AT %S(SELECT SUM(FieldA) AS "Value" FROM DATASET): RESULTSET OF REAL;
TotalB AT %S(SELECT SUM(FieldB) AS "Value" FROM DATASET): RESULTSET OF REAL;
END_VAR
Posted: 2 weeks ago
The two SQL queries are only selecting a single database field so you don't need a STRUCT for the result set:
VAR NOCACHE
TotalA AT %S(SELECT SUM(FieldA) AS "Value" FROM DATASET): RESULTSET OF REAL;
TotalB AT %S(SELECT SUM(FieldB) AS "Value" FROM DATASET): RESULTSET OF REAL;
END_VAR
Posted: 2 weeks ago
Ok... that did confuse me. I tried changing it to DATABASE_OBJECT but basically had similar results. I deleted the TYPE logic and changed it to resultset of REAL and then "Compile... Success". I check the variable values and it looks correct. Thank you for the assistance!
Create your free account or log in to subscribe to the forum - and gain access to more than 10,000+ support articles along with insights from experts and peers.