# mass confusion on MASK

**URL:** <https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-News-and-General-Topics\
**Created:** [February 14, 2007, 6:22am UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948 "2007-02-14T06:22:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jennifer](https://avatars.discourse-cdn.com/v4/letter/j/46a35a/32.png) [@Jennifer](https://techcommunity.softwareag.com/u/Jennifer)\
**Post date:** [February 14, 2007, 6:22am UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/1 "2007-02-14T06:22:48Z")

</div>

The help for MASK says that for ‘c’, then one or more positions are checked for c. But is c strictly alpha? What if I say: if blah = MASK(‘99’)? Am I asking it to search for 99 in the first two positions or anywhere in blah?

---

<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:** [February 14, 2007, 7:03am UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/2 "2007-02-14T07:03:36Z")

</div>

MASK is positional. To look for a string within a variable, use SCAN.

```auto
IF #VAR = SCAN '99' /* Does 99 exist within #VAR?
```

---

<div class="post-metadata">

**Author:** ![Wilfried\_B](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/wilfried_b/32/83_2.png) [@Wilfried\_B](https://techcommunity.softwareag.com/u/Wilfried_B)\
**Post date:** [February 14, 2007, 1:56pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/3 "2007-02-14T13:56:21Z")

</div>

> [@Ralph Zbrog](#):
>
> MASK is positional.

No, that’s not true. MASK can be positional and not positional, too. To look for ‘99’ in a string, you can use mask, too. And you can use it more efficient than SCAN, like in:

```auto
IF #VAR = MASK(*'99') /* Does 99 exist within #VAR?
IF #VAR = MASK('99') /* Does #VAR bgin with '99'?
IF #VAR = MASK(*'99'/) /* Does #VAR end with '99'?
```

MASK indeed is nearly as powerful as regular expressions, but not that complicated (in my opinion).

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [February 14, 2007, 3:47pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/4 "2007-02-14T15:47:52Z")

</div>

[quote="Wilfried B

---

<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:** [February 14, 2007, 5:57pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/5 "2007-02-14T17:57:24Z")

</div>

No argument, the wild card additions to MASK give it a lot more capability than SCAN.

However, in terms of performance, for the functionality that SCAN was designed for, SCAN is far more efficient than MASK.

For example;

DEFINE DATA LOCAL  
1 #LOOP (P9)  
1 #STRING (A20)  
1 #CPU-TIME (P9)  
1 #CPU-START (P9)  
END-DEFINE  
\*  
INCLUDE AATITLER  
INCLUDE AASETC  
\*  
MOVE _CPU-TIME TO #CPU-START  
SETA. SETTIME  
FOR #LOOP = 1 TO 500000  
IF #STRING = MASK (_‘X’)  
IGNORE  
END-IF  
END-FOR  
COMPUTE #CPU-TIME = \*CPU-TIME - #CPU-START  
WRITE 5T ‘MASK TIME’ \*TIMD (SETA.) 5X #CPU-TIME  
\*  
MOVE \*CPU-TIME TO #CPU-START  
SETB. SETTIME  
FOR #LOOP = 1 TO 500000  
IF #STRING = SCAN (‘X’)  
IGNORE  
END-IF  
END-FOR  
COMPUTE #CPU-TIME = \*CPU-TIME - #CPU-START  
WRITE 5T ‘SCAN TIME’ \*TIMD (SETB.) 5X #CPU-TIME  
\*  
END  
PAGE # 1 DATE: Feb 14, 2007  
PROGRAM: SCAN01 LIBRARY: SYSTEM

```
MASK TIME 49 489
SCAN TIME 39 388

```

SCAN is about 20 % faster and uses 25 % less CPU time.

If there was an X in the first position of #STRING, the output is:

```
PAGE # 1 DATE: Feb 14, 2007
PROGRAM: SCAN03 LIBRARY: SYSTEM

MASK TIME 36 355
SCAN TIME 35 345

```

The times above are on my PC; will run mainframe times later today (snowing, hailing and raining outside, so will stay in and play on the computer).

steve

---

<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:** [February 14, 2007, 6:18pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/6 "2007-02-14T18:18:46Z")

</div>

Okay, it’s later.

Mainframe numbers are very interesting.

First, here are the numbers with no X

MASK TIME 19 112  
SCAN TIME 9 61

The SCAN is twice as fast as the MASK.

With an X in the first position, the numbers are

MASK TIME 9 61  
SCAN TIME 9 61

So, if the functionality you are looking for requires “searching” for a text string anywhere in an alpha variable, use SCAN, not MASK.

steve

---

<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:** [February 14, 2007, 6:38pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/7 "2007-02-14T18:38:47Z")

</div>

Getting back to the original question:

IF #STRING = MASK(‘AB’)

will look for AB in positions 1 and 2

IF #STRING = MASK(??‘AB’)

will look for AB in positions 3 and 4

? . \_ can all be used to indicate "skip a single position

- % are the “wildcard” (any number of characters) characters

On the PC (mainframe results later) MASK (??‘XX’) is slightly faster (2%) than SCAN, however CPU time is 10% faster than SCAN.

steve

---

<div class="post-metadata">

**Author:** ![Matthias1](https://avatars.discourse-cdn.com/v4/letter/m/9fc348/32.png) [@Matthias1](https://techcommunity.softwareag.com/u/Matthias1)\
**Post date:** [February 14, 2007, 9:08pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/8 "2007-02-14T21:08:49Z")

</div>

> [@Steve Robinson](#):
>
> However, in terms of performance, for the functionality that SCAN was designed for, SCAN is far more efficient than MASK.

Your test on Solaris:

```auto
MASK TIME 56 562
SCAN TIME 47 468
```

But you can make it much more faster if you use an I4-field as a loop counter… 😉

```auto
MASK TIME 29 282
SCAN TIME 19 195
```

Anyway: SCAN is slightly faster

---

<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, 2:41pm UTC](https://techcommunity.softwareag.com/t/mass-confusion-on-mask/61948/9 "2021-04-02T14:41:03Z")

</div>


