InventUpdate Class Code

Hi all,
Our customer (AX2009) got some strange error messages while posting Transfer and Purchase Orders ( InventTrans.inventMovement has been used incorrectly. )
In order to fix this ive changed one simple check - but I cannot say i fully understand it - so if somebody has a clue why its written this way I`ll appreciate the hint.

Class InventUpdate , method updateDimReservePhysical
Original Code :

if (changeDimFixed & inventTransIssue.InventDimFixed != 0)

What is that binary AND doing here while comparying DimIDs - in the current case one of them was 128, and the other 262144 (or similar).
This code is the same for AX2009, AX2012 R2/R3

Thanks in advance
Vladimir

The error means that InventTrans.inventMovement() failed to create an InventMovement instance. Debug the code to see where it went wrong.

The difference between & and && is that the former evaluate both sides, while the latter ignores the right expression if the left one is false (therefore the expression won’t be true regardless of the value of the right expression).

Dear Martin,
First of all thank you for the prompt response.
I have one comment I like to share - I think the main idea of this piece of code in the method is to find if both DimIds are != 0.

Im not sure the binary AND works as you described, Im not a master in X++, but based on my experience it works like follows :

int i, j;

i = 2; j = 1;

if ( i & j != 0 )

info(‘true’);

info(‘end’);

With the upper example result is → end

With values i = 3, j = 1 , the result is → true , end
As I explain this to myself - values 01 & 10 binary equals to 0
values 01 & 11 binary equals to 1

Looking forward to your response
Best Regards

Vladimir

Yes, you’re right; it’s the usual binary AND. The evaluation works as I described, but if you have numbers instead of boolean values, the result will be a number as well and not just true or false. In my previous answer, I thought that changeDimFixed is a boolean value.

Now I think that the condition in question indeed works at binary level, comparing whether there is at least one position with values in both changeDimFixed and inventTransIssue.InventDimFixed.

Regardless of what I can see in the documentation, my tests show that & and | have higher precedence than == and !=. For example, (1 | 0 == 0) is 0, while (1 | (0 == 0)) is 1.

There are only 10 kind of people. those who understand binary and those who don’t…

Thanks Martin,
So - I have to ask again for the current problem I`m facing.
The original code is making, in my opinion by mistake, binary AND and comparing the result with 0 , which is not the same as comparing the two DimensionIDs != 0.

Basically my question comes to this: this is just a minor bug and there shouldn`t be any bit operations with those IDs - just the != 0 check of both of them ?

orignal code:

if (changeDimFixed & inventTransIssue.InventDimFixed != 0)

my code

if ( (changeDimFixed != 0 ) && (inventTransIssue.InventDimFixed != 0))

We have different expectations about what the code should do. My understanding is that it checks “whether there is at least one position with values in both changeDimFixed and inventTransIssue.InventDimFixed” and yours is “comparing the two DimensionIDs != 0”.

If it should do the latter, it’s wrong, but if it should do the former, it’s correct.

I believe it shouldn’t merely check whether both has some values but whether there is a value for the same dimension. For example, 10 and 01 have values for different dimensions and the result is 0.

Yes, and this is the reason for my confusion.
Im not asking about the way binary AND works in AX, Im asking about the business logic in this method.

I think the idea is to check if two DimIDs has values. I cannot think of a reasonable cause to write it the way it`s in the standard code, because if they are equal the IF clause will work - i agree, but if they are different ( like 1 and 3 ) they will appear equal again which is incorrect.
( 1 & 3 != 0 ) returns true;
( 1 & 2 != 0 ) returns false;
both are not equal and nonzero but the result is different in both cases.

I can not decide if the logic in this method is to check if they are equal ( DimId1 == DimId2 ), or if there are whatever values for both dimension ids ( (DimId1 != 0) && (DimId2 != 0)).
I put my money on the second case - and i was asking for opinion if I`m wrong.

Thanks
Best Regards

They are not dimension IDs! They have even different base type (int) than InventDimId (string).

InventDimFixed represent a selection of dimensions (implemented as a bitmap). Look into InventDimFixedClass::inventDimFieldsDifferent() to see how the value of changeDimFixed variable, for example, is calculated.

Thanks Martin,

now it all makes sense.

I`ll dig into this bitmap generation method for details.

Best Regards
Vladimir