I don't believe I use that call to retrieve aggregate values, I use JDB_FetchAggregate. The API call can return a recordset along with the aggregates or just the aggregates. If you have more than one aggregate in the query, simply pass an array of MATH_NUMERICS in the aggregate return buffer param. Here is some example code (the simplest example I could find) that is in PD.
<font class="small">Code:</font><hr /><pre>
/**************************************************************************
* Function: I56CWB54_GetExistingOrderOpenAmt
*
* Notes:
*
* Returns:
*
* Parameters:
**************************************************************************/
static ID I56CWB54_GetExistingOrderOpenAmt(LPBHVRCOM lpBhvrCom, LPVOID lpVoid, HUSER hUser,
LPMATH_NUMERIC pmnSoldTo, LPMATH_NUMERIC pmnAmt)
{
HREQUEST hreq=(HREQUEST)NULL;
NEWSELECTSTRUCT select[2]={0};
AGGRGFUNCSTRUCT agrFuncs[1] = {0};
ushort nSelIdx=0;
ZeroMathNumeric(pmnAmt);
nSelIdx = 0;
jdeNIDcpy( select[nSelIdx].Item1.szDict, NID_AN8);
jdeNIDcpy( select[nSelIdx].Item1.szTable, NID_F4211);
select[nSelIdx].Item1.idInstance = (ID)0;
jdeNIDcpy( select[nSelIdx].Item2.szDict, _J("") );
jdeNIDcpy( select[nSelIdx].Item2.szTable, _J("") );
select[nSelIdx].Item2.idInstance = (ID)0;
select[nSelIdx].lpValue = pmnSoldTo;
select[nSelIdx].nValues = 1;
select[nSelIdx].nCmp = JDEDB_CMP_EQ;
select[nSelIdx].nAndOr = JDEDB_ANDOR_AND;
select[nSelIdx++].nParen = JDEDB_PAREN_NONE;
jdeNIDcpy( select[nSelIdx].Item1.szDict, NID_NXTR);
jdeNIDcpy( select[nSelIdx].Item1.szTable, NID_F4211);
select[nSelIdx].Item1.idInstance = (ID)0;
jdeNIDcpy( select[nSelIdx].Item2.szDict, NID_NXTR);
jdeNIDcpy( select[nSelIdx].Item2.szTable, NID_F56CWB12);
select[nSelIdx].Item2.idInstance = (ID)0;
select[nSelIdx].lpValue = NULL;
select[nSelIdx].nValues = 0;
select[nSelIdx].nCmp = JDEDB_CMP_LT;
select[nSelIdx].nAndOr = JDEDB_ANDOR_AND;
select[nSelIdx++].nParen = JDEDB_PAREN_NONE;
jdeNIDcpy(agrFuncs[0].Item.szDict, NID_AEXP);
jdeNIDcpy(agrFuncs[0].Item.szTable, NID_F4211);
agrFuncs[0].Item.idInstance = 0;
agrFuncs[0].nFunction = JDB_AGGRGFUNC_SUM;
if(JDB_OpenView(hUser, ID_BV56CWB12A, (JCHAR *)NULL, &hreq) != JDEDB_PASSED ||
JDB_SetAggregate(hreq, agrFuncs, DIM(agrFuncs),
JDB_AGGRGFUNCTION_OPT_FUNC_ONLY) != JDEDB_PASSED ||
JDB_SetSelectionX(hreq, select, nSelIdx, JDEDB_SET_REPLACE) != JDEDB_PASSED ||
JDB_SelectKeyed(hreq, (ID)0, (void *)NULL, (short)0) != JDEDB_PASSED)
{
if(hreq)
JDB_CloseView(hreq);
return acmeErrorSetTableOpen(lpBhvrCom, lpVoid, (ID)0, ID_BV56CWB12A);
}
JDB_FetchAggregate(hreq, (void *)NULL, pmnAmt);
JDB_CloseView(hreq);
return ER_SUCCESS;
}
</pre><hr />