# why the IF # x (\*) = 'command does not work?

**URL:** <https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [May 7, 2014, 4:48pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221 "2014-05-07T16:48:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antonio\_Barbara](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Antonio\_Barbara](https://techcommunity.softwareag.com/u/Antonio_Barbara)\
**Post date:** [May 7, 2014, 4:48pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221/1 "2014-05-07T16:48:07Z")

</div>

Would be possible that would help me understand the following situation:  
DEFINE DATA LOCAL  
TAB # 1 (A10 / 1:50)  
END-DEFINE  
MOVE '1111 'TO # TAB (5)  
IF # TAB (\*) = ’ ’  
WRITE ‘XXXX’  
ELSE  
WRITE ‘YYYY’  
END-IF  
END

HE ALWAYS WRITE XXXX.

as there is an occurrence should be filled out by yyyy  
If I put IF # TAB (5) works normally. He leaves to write yyyy

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [May 7, 2014, 5:02pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221/2 "2014-05-07T17:02:25Z")

</div>

```auto
IF #TAB (*) = ' '
```

means “if any occurrence of #TAB is blank.”

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [May 7, 2014, 5:26pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221/3 "2014-05-07T17:26:35Z")

</div>

Arrays can be tricky. Be very careful with negative logic:

```auto
IF #TAB(*) NE '1111'
```

means "If ANY occurrence of #TAB is NOT ‘1111’. In your example this would return TRUE.

```auto
IF #TAB(*) NE ' '
```

This would also return TRUE because occurrence 5 is not blank.

---

<div class="post-metadata">

**Author:** ![Antonio\_Barbara](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@Antonio\_Barbara](https://techcommunity.softwareag.com/u/Antonio_Barbara)\
**Post date:** [May 7, 2014, 6:45pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221/4 "2014-05-07T18:45:08Z")

</div>

thanks for the help. problem solved

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [May 7, 2014, 10:32pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221/5 "2014-05-07T22:32:06Z")

</div>

Just a warning:

As noted by Ralph

IF #TAB (\*) = ’ ’ is shorthand for IF #TAB (1) = ’ ’ OR #TAB (2) = ’ ’ OR #TAB (3) = ’ ’ etc  
in other words, an OR condition

HOWEVER

IF #TAB (_) = #OTHER-TAB (_) is shorthand for IF #TAB (1) = #OTHER-TAB (1)  
AND #TAB (2) = #OTHER-TAB (2)  
AND #TAB (3) = #OTHER-TAB (3) etc  
in other words, an AND condition

And, as noted by Jerome, if you use negatives, it gets very tricky, for example

define data local  
1 #a (a1/1:10)  
1 #b (a1/10)  
end-define  
\*\*\* move ‘q’ to #a (3)  
if #a (_) ne #b(_)  
write ‘not equal satisfied’  
else  
write ‘noooooo’  
end-if  
end

Run as is; the answer is noooooo

now get rid of the asterisks before the MOVE.

The answer is still noooooo

For the IF to be TRUE, all a-b pairs must be not equal.

in other words it is:

IF #TAB (_) NE #OTHER-TAB (_) is shorthand for IF #TAB (1) NE #OTHER-TAB (1)  
AND #TAB (2) NE #OTHER-TAB (2)  
AND #TAB (3) NE #OTHER-TAB (3) etc

---

<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 2, 2021, 3:31pm UTC](https://techcommunity.softwareag.com/t/why-the-if-x-command-does-not-work/176221/6 "2021-04-02T15:31:03Z")

</div>


