# NOTEQUAL relational operator behavior with arrays

**URL:** <https://techcommunity.softwareag.com/t/notequal-relational-operator-behavior-with-arrays/302102>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes, NaturalONE\
**Created:** [October 30, 2024, 3:03pm UTC](https://techcommunity.softwareag.com/t/notequal-relational-operator-behavior-with-arrays/302102 "2024-10-30T15:03:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfenoy](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/pfenoy/32/35902_2.png) [@pfenoy](https://techcommunity.softwareag.com/u/pfenoy)\
**Post date:** [October 30, 2024, 3:03pm UTC](https://techcommunity.softwareag.com/t/notequal-relational-operator-behavior-with-arrays/302102/1 "2024-10-30T15:03:10Z")

</div>

Hi, I don’t understand why the NOTEQUAL operator tells that the two segments are the same.  
What I’m missing? Thanks in advance (NatOne 9.1.4)

```auto
DEFINE DATA 
LOCAL
1 TEST1 (A10)
1 REDEFINE TEST1
2 TEST1_A (A1/10)

1 TEST2 (A10)
1 REDEFINE TEST2
2 TEST2_A (A1/10)
1 I (I1)
END-DEFINE

MOVE 'ABC*' TO TEST1
WRITE TEST1_A(1:4)

MOVE 'ABCD' TO TEST2
WRITE TEST2_A(1:4)

IF TEST1_A(1:4) = TEST2_A(1:4)
   WRITE "Comparing with '=': equals"
ELSE 
   WRITE "Comparing with '=': not equals"
END-IF

IF TEST1_A(1:4) EQ TEST2_A(1:4)
   WRITE "Comparing with 'EQ': equals"
ELSE 
   WRITE "Comparing with 'EQ': not equals"
END-IF

IF TEST1_A(1:4) NOTEQUAL TEST2_A(1:4)
   WRITE "Comparing with 'NOTEQUAL': not same"
ELSE 
   WRITE "Comparing with 'NOTEQUAL': equals"
END-IF

```

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [October 30, 2024, 4:00pm UTC](https://techcommunity.softwareag.com/t/notequal-relational-operator-behavior-with-arrays/302102/2 "2024-10-30T16:00:33Z")

</div>

Please see the documentation: (NAT914 is out of support, but this area hasn’t changed) [Rules for Arithmetic Assignment](https://documentation.softwareag.com/natmf/9.2.3/en/webhelp/natmf-webhelp/pg/pg_furth_arithm.htm#comarison_operations), specifically:

> - **Condition A:**
> 
> IF #ARRAY1(1:2) NOT EQUAL #ARRAY2(1:2)
> 
> This is equivalent to:
> 
> IF (#ARRAY1(1) NOT EQUAL #ARRAY2(1)) AND (#ARRAY1(2) NOT EQUAL #ARRAY2(2))
> 
> Condition A is therefore true if the first occurrence of `#ARRAY1` does not equal the first occurrence of `#ARRAY2` _and_ the second occurrence of `#ARRAY1` does not equal the second occurrence of `#ARRAY2`.
> 
> - **Condition B:**
> 
> IF NOT #ARRAY1(1:2) = #ARRAY2(1:2)
> 
> This is equivalent to:
> 
> IF NOT (#ARRAY1(1)= #ARRAY2(1) AND #ARRAY1(2) = #ARRAY2(2))
> 
> This in turn is equivalent to:
> 
> IF (#ARRAY1(1) NOT EQUAL #ARRAY2(1)) OR (#ARRAY1(2) NOT EQUAL #ARRAY2(2))
> 
> Condition B is therefore true if _either_ the first occurrence of `#ARRAY1` does not equal the first occurrence of `#ARRAY2` _or_ the second occurrence of `#ARRAY1` does not equal the second occurrence of `#ARRAY2`.

Thus, you may want to use “IF NOT (TEST1\_A(1:4) = TEST2\_A(1:4))” as the NOTEQUAL test will only be false if all occurrences of TEST1\_A do not match the corresponding elements of TEST2\_A. If any occurrences of TEST1\_A match then the NOTEQUAL is false. The NOT (TEST1\_A(_) = TEST2\_A(_)) is false if any occurrence of TEST1\_A is not equal to corresponding occurrence of TEST2\_A.

---

<div class="post-metadata">

**Author:** ![pfenoy](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/pfenoy/32/35902_2.png) [@pfenoy](https://techcommunity.softwareag.com/u/pfenoy)\
**Post date:** [October 30, 2024, 4:31pm UTC](https://techcommunity.softwareag.com/t/notequal-relational-operator-behavior-with-arrays/302102/3 "2024-10-30T16:31:21Z")

</div>

Thank you Douglas, now it’s clear for me.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 28, 2025, 4:32pm UTC](https://techcommunity.softwareag.com/t/notequal-relational-operator-behavior-with-arrays/302102/4 "2025-04-28T16:32:05Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
