Ask our Experts
Didn't find what you are looking for? Ask our experts!
Launch of Consumer/Home Owner registration process! We are pleased to announce the commencement of the Consumer/Home Owner Registration Process on Community. Consumers/Home Owners may now proceed to register by clicking on Login/Register. The process is straightforward and designed to be completed in just a few steps.
Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).
Search in
Link copied. Please paste this link to share this article on your social media post.
Posted: 2023-03-15 09:49 AM . Last Modified: 2023-05-02 11:47 PM
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
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2023-03-15 10:08 AM
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
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2023-03-15 10:08 AM
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
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2023-03-15 10:19 AM
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!
Link copied. Please paste this link to share this article on your social media post.
You’ve reached the end of your document
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.