# Compressing Zeros

**URL:** <https://techcommunity.softwareag.com/t/compressing-zeros/74923>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [July 2, 2007, 3:15pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923 "2007-07-02T15:15:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriramp](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sriramp](https://techcommunity.softwareag.com/u/sriramp)\
**Post date:** [July 2, 2007, 3:15pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/1 "2007-07-02T15:15:17Z")

</div>

Hi,

Can we not compress a numeric value zero into an alphanumeric variable??

Suppose,  
i want to compress some 3 zeros one by one in a for loop.  
I tried this with

COMPRESS ‘0’ TO #VAR1 LEAVING NO SPACE,  
but it gives the result of having only one zero.

Can anyone help me out of this?

---

<div class="post-metadata">

**Author:** ![Klaus\_Sponagel](https://avatars.discourse-cdn.com/v4/letter/k/3bc359/32.png) [@Klaus\_Sponagel](https://techcommunity.softwareag.com/u/Klaus_Sponagel)\
**Post date:** [July 2, 2007, 3:34pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/2 "2007-07-02T15:34:47Z")

</div>

COMPRESS FULL does the trick.

```auto

0010 DEFINE DATA LOCAL
0020 1 N(N4)
0021 1 A(A40)
0030 END-DEFINE
0040 COMPRESS FULL 'yy' N 'zz' INTO A
0050 WRITE A
0060 END
```

---

<div class="post-metadata">

**Author:** ![sriramp](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sriramp](https://techcommunity.softwareag.com/u/sriramp)\
**Post date:** [July 2, 2007, 4:14pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/3 "2007-07-02T16:14:40Z")

</div>

Thanks for your reply,

But i want to have only the character ‘0’ (zero) and nothin else

---

<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:** [July 2, 2007, 4:51pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/4 "2007-07-02T16:51:58Z")

</div>

> [@isam777](#):
>
> I tried this with
> 
> COMPRESS ‘0’ TO #VAR1 LEAVING NO SPACE,  
> but it gives the result of having only one zero.

If you insist in doing it in a FOR loop this needs to be

```auto
COMPRESS '0' #VAR1 INTO #VAR1 LEAVING NO SPACE
```

---

<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:** [July 2, 2007, 5:51pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/5 "2007-07-02T17:51:36Z")

</div>

Is there any particular reason you do not simply

COMPRESS ‘000’ #VAR1 INTO #VAR1 LEAVING NO SPACE

???

steve

---

<div class="post-metadata">

**Author:** ![sriramp](https://avatars.discourse-cdn.com/v4/letter/s/bc79bd/32.png) [@sriramp](https://techcommunity.softwareag.com/u/sriramp)\
**Post date:** [July 3, 2007, 11:05am UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/6 "2007-07-03T11:05:17Z")

</div>

Yea Steve,  
I want to prefix some zeros before a number based on some count value.

So, the number of zeros before the number is dynamic.

This is the reason, i wanted to have zeros before a number.

And, Thanks for the solution. It worked!!!

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [July 3, 2007, 12:30pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/7 "2007-07-03T12:30:57Z")

</div>

Instead of using the COMPRESS statement, you might use the RESET statement by redefining your variable as a numeric array:

```auto

DEFINE DATA LOCAL            
1 #COUNT-VALUE (I4)     
1 #VAR1 (A50)    
1 REDEFINE #VAR1             
  2 #VAR1-N (N1/50)  
END-DEFINE                   
#COUNT-VALUE := 3            
RESET #VAR1-N(1:#COUNT-VALUE)
WRITE #VAR1                 
END                                   
```

---

<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:** [July 3, 2007, 4:37pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/8 "2007-07-03T16:37:04Z")

</div>

If the number of zeroes is variable (say #COUNT), try this code:

DEFINE DATA LOCAL  
1 #STRING (A50) INIT \<‘QWERT’\>  
1 #COUNT (P3) INIT \<4\>  
1 #ZEROES (A10) INIT FULL LENGTH \<‘0’\>  
END-DEFINE  
\*  
COMPRESS SUBSTRING (#ZEROES,1,#COUNT) #STRING INTO #STRING  
LEAVING NO SPACE  
WRITE ‘1234567890’ / #STRING  
END

steve

---

<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:48pm UTC](https://techcommunity.softwareag.com/t/compressing-zeros/74923/9 "2021-04-02T14:48:30Z")

</div>


