Group By and aggregation as Sum in RunTime Query:
Query query;
QueryRun queryRun;
QueryBuildDataSource ds;
QueryBuildRange range1;
CustAccount accountNum;
CustTrans custTrans;
query = new Query();
ds = query.addDataSource(tableNum(CustTrans));
ds.addGroupByField(fieldNum(CustTrans, AccountNum));
range1 = SysQuery::findOrCreateRange(ds, fieldNum(CustTrans, AccountNum));
range1.value(queryValue(accountNum));
ds.addSelectionField(fieldNum(CustTrans, AmountMST),SelectionField::Sum);
Query query;
QueryRun queryRun;
QueryBuildDataSource ds;
QueryBuildRange range1;
CustAccount accountNum;
CustTrans custTrans;
query = new Query();
ds = query.addDataSource(tableNum(CustTrans));
ds.addGroupByField(fieldNum(CustTrans, AccountNum));
range1 = SysQuery::findOrCreateRange(ds, fieldNum(CustTrans, AccountNum));
range1.value(queryValue(accountNum));
ds.addSelectionField(fieldNum(CustTrans, AmountMST),SelectionField::Sum);