# Compressing Zeros

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?

COMPRESS FULL does the trick.

``````
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``````

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

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

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

Is there any particular reason you do not simply

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

???

steve

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!!!

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

``````
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                                   ``````

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