# InventUpdate Class Code

**URL:** <https://www.dynamicsuser.net/t/inventupdate-class-code/52402>\
**Category:** Developer Forum\
**Created:** [April 28, 2014, 9:06am UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402 "2014-04-28T09:06:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![solaris](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@solaris](https://www.dynamicsuser.net/u/solaris)\
**Post date:** [April 28, 2014, 9:06am UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/1 "2014-04-28T09:06:57Z")

</div>

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 i`ve changed one simple check - but I cannot say i fully understand it - so if somebody has a clue why it`s 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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [April 28, 2014, 11:15am UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/2 "2014-04-28T11:15:07Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![solaris](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@solaris](https://www.dynamicsuser.net/u/solaris)\
**Post date:** [April 28, 2014, 11:41am UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/3 "2014-04-28T11:41:46Z")

</div>

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.

I`m not sure the binary AND works as you described, I`m 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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [April 28, 2014, 12:35pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/4 "2014-04-28T12:35:40Z")

</div>

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](http://msdn.microsoft.com/en-us/library/aa594120.aspx), my tests show that _&_ and _|_ have higher precedence than _==_ and _!=_. For example, _(1 | 0 == 0_) is _0_, while (_1 | (0 == 0)_) is _1_.

---

<div class="post-metadata">

**Author:** ![assen.krastev](https://avatars.discourse-cdn.com/v4/letter/a/46a35a/32.png) [@assen.krastev](https://www.dynamicsuser.net/u/assen.krastev)\
**Post date:** [April 28, 2014, 12:42pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/5 "2014-04-28T12:42:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![solaris](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@solaris](https://www.dynamicsuser.net/u/solaris)\
**Post date:** [April 28, 2014, 12:56pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/6 "2014-04-28T12:56:23Z")

</div>

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))**

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [April 28, 2014, 1:10pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/7 "2014-04-28T13:10:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![solaris](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@solaris](https://www.dynamicsuser.net/u/solaris)\
**Post date:** [April 28, 2014, 2:01pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/8 "2014-04-28T14:01:13Z")

</div>

Yes, and this is the reason for my confusion.  
I`m not asking about the way binary AND works in AX, I`m 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

---

<div class="post-metadata">

**Author:** ![MartinDrab](https://avatars.discourse-cdn.com/v4/letter/m/e0b2c6/32.png) [@MartinDrab](https://www.dynamicsuser.net/u/MartinDrab)\
**Post date:** [April 28, 2014, 2:19pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/9 "2014-04-28T14:19:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![solaris](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@solaris](https://www.dynamicsuser.net/u/solaris)\
**Post date:** [April 28, 2014, 2:42pm UTC](https://www.dynamicsuser.net/t/inventupdate-class-code/52402/10 "2014-04-28T14:42:43Z")

</div>

Thanks Martin,

now it all makes sense.

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

Best Regards  
Vladimir
