DD display decimals in aggregate function

AlexRO

AlexRO

Well Known Member
Hello all,

I have a simple BSFN in which I cumulate the AG field from F03B11. I thought I could use an aggregate function in order to avoid using sequential fetches. So I've used a JDB_SetAggregate with SUM and it works (partially). I get the results but the math numeric is without decimals (eg: 1234 instead of 12.34). Is this normal, or I'm doing something wrong?

I guess I can use the normal fetches in a loop, or I can query the number of decimals for the AG data item.

Any comments would be appreciated,

Thanx,
Dan.
 
While I question that this is "Normal", I do believe it works as designed.

I also found that to be the case. It sure would have been nice if they had designed JDB_GetAggregateValue to work like its counterpart, JDB_GetTableColValue, but this is JDE "normal".

My code uses the data item (from the AGGRFUNCSTRUCT) to fetch to the data dictionary to get the display decimals. Then I just update the nDecimalPosition element of the Aggregate value's MATH_NUMERIC structure.

It's kind of a pain, but seems to be the only work-around I've found.
 
Thank you JMR for your response. I thought that wold be the case. I will use that same approach, get the DD and update the decimal position.

Thank you for the clarification.

Cheers,
Dan.
 
Wait, what??? I use aggregates all the time and have never had a problem with decimals.
 
Brian,
Try doing a sum aggregate on AEXP in F4211 and see if you get a return value (using JDB_GetAggregateValue) with the nDecimalPosition of the math_numeric structure set correctly (ie 2).

If that works for you, I will need to know what you're doing differently than I am.
 
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 />
 
Brian,
You're right, I use JDB_FetchAggregate also, but I generically use JDB_GetAggregateValue to get a specific aggregate. Either way, I still have the same issue...

When I look at the elements of the MATH_NUMERIC structure in debug immediately following the FetchAggregate, the nDecimalPosition seems to always be 0 (using AEXP as the data item of the DBREF).

Can you put a breakpoint on your code immediately after your FetchAggregate and tell me what your MATH_NUMERIC elements look like, specifcally the nDecimalPosition element?
 
I will get the debug screen shot here in a little bit. The example I sent you gets called via xmlCallObject so hopefully I have a unit test for it.

Are my calls pretty much the same thing you are doing? I would have thought that if I had a precision issue something would have come up by now. I don't think our BAs would have missed something like that during testing.

You have me worried now.
confused.gif


Do you think the underlying DB vendor has anything to do with it?
 
I debugged a different BSFN (source and debug screen shot attached) and I get nDecimalPosition==2.

The DD items are different but they have display decimals of 2.
 

Attachments

  • 178886-SrcAndScreenShotForAggr.zip
    99.5 KB · Views: 77
Dan,

Is you presentation of decimals different from the data dictionary values you are passing through... and do you have multi-currency turned on?

Issue - there's a bug/enhancement/BUG with changing the display value of a currency field on systems with multi-currency.

If that situation fits your environment - there's a KG article that explains the issue and provides a work around.

(db)
 
Well crap!
mad.gif
I don't what to make of this now. I have no idea how this could work differently. I am running my tests on DEMO. I wonder if there could be any user-specific setup that might cause this?
 
Did you see DB's post on multi-currency. Could there be something there?

We don't run multi-currency btw.
 
J,

When you are debugging - notice the currency. If Multi-Currency, you could have values that come in with Currency and values W/O Currency...

I won't even comment to how that magic all happens, but I've noticed that Multi-Currency has been a bastion to decimalization at several clients.

Quick fix, if you want to test: Add a <blank> currency value to the F0013 (exactly match the default currency, probably USD?)... Otherwise, you have to define the Decimalization via a BSFN (if this is your issue). Note: The application does not allow you to create a <blank>, you might have to hack it =D. If that doesn't fix-test things, make sure you back out the <blank>.

<snip>
E1: RDA: How to Change the Display Decimals for an Amount on a Report in Multi-Currency Environment? [ID 626461.1]

Solution
If Multi-Currency is activated in an EnterpriseOne environment and the user changes the display decimals on a column or variable that is an amount field associated with a currency, the currency decimal setting overrides the display decimals and the change in display decimals is not seen on the report. This is working as designed.

Workaround
The Business Function B0000164 (Currency Decimals Set) allows the user to change the display decimals associated with a column or variable on a report. (Note: Do not select B0000164 - Display Decimals Set. It should be B0000164 - Currency Decimals Set).
</snip>

Now the quirk - if a currency is passed in that is not valid (<blank>), all Hades can break through the wall...

(db)
 
DB and Brian,
Thanks for the insight. I finally got a chance to dig in. Being the currency noob that I am, I don't understand how it all works internally.

I was running on my DEMO 9.0 and I checked my Multi-Currency Conversion setting in the General Accounting Constants. It was set to 'Z'. I changed it 'N' and, sure enough, my JDB_FetchAggregate worked as Brian's did...it had the 2 decimal positions.

I still don't like how JDB_GetTableColValue / JDB_FetchKeyed automatically seem to deal with decimal places and JDB_GetAggregateValue / JDB_FetchAggregate leave it up to the developer to make sure the results are correct
frown.gif
 
Hello all,

Daniel, we use multi-currency but we keep the number of decimals the same as the DD. We can not modifiy the multi-currency to N and so we will keep the solution mentioned above to query the decimal position and manually set it.

I guess from my point of view the issue is solved
grin.gif

Thank you all for the knowledge you shared.

Cheers,
Dan.
 
The Aggregate function has to take into account that you can be adding up different currencies that have different decimal places (and currency conversion rates). Since the end result isn't a "real" amount, the best the function can do is give you a hash total. That's why it doesn't display the decimal position.
 
Steve,
Valid point. I haven't worked at a site where a company would store currency information that used a display-decimals value other than 2. It presents an interesting challenge in the case where values are stored with different display decimals.

Question 1: if AEXP is defined as 2 display decimals in the DD and a transaction for $10 is stored for a currency with 3 decimals, will the database value be 10000?

Question 2: does the multi-currency setup only apply to data items in the CURRENCY class?
 
Jeremy,

It's a bit more complicated than that. The AEXP field is converted to the base currency of the F0010.CO record. Depending on which table you are looking at the foreign input amount is stored in one of the foreign amount fields. I know there's a table trigger on the F0911 that takes care of converting the amount fields to the correct display decimals/storage places based on the currency setup table. I'm assuming the other affected tables have the same type of trigger but I don't have access tonight to check.

It's probably best to team up with a currency knowledgeable Business Analyst and the 2 of you work through the details. There also may be a KG paper on this. I'm mainly a BA with some technical hacking skills and learned currency the hard way many years ago before the internet..., but wouldn't recommend that path to enlightenment.
 
Back
Top