Data Conversion

March 31, 1996

Author: Tim McCormley
Date: 3/31/96
Category: Data Conversion
Keywords: non-numeric-data conversion-mainframe
Summary: Many COBOL compilers differ on how spaces are managed in numeric fields. The "-Zz" compile time option provides a mechanism for for handling spaces in numeric fields that is similar to many mainframe COBOL compilers.

When evaluating a USAGE DISPLAY data item, COBOL must convert the value in the field to a number before using it in a numeric fashion. By default, Acucobol-85 converts the value to a number by subtracting the ascii value of zero from the high order 4 bits for each byte of the data. This works fine if the value in the data item is a sensible ASCII value. That is, if the data item contains the ASCII digits zero through nine. E.g.

     01 a-number   pic 99 value 12.

This is stored internally as a two byte value, ASCII 31 and ASCII 32 (the ASCII value of "1" and "2"):

     Byte #1                Byte #2
     0011 0001 (31)         0011 0010 (32)
When subtracting "0" (ASCII 30) from the high order four bits, you end up with a two byte numeric field: 0000 0001 (1) and 0000 0010 (2). After you string all of it together, you end up with the number 12.

Difficulties arise if the data item does not contain a sensible ASCII value, like spaces, for example. In this case, you can use the "-Zz" compile time flag to change the default algorithm. When "-Zz" is used, Acucobol-85 simply sets the high order 4 bits to zero. This has the effect of converting a space, ASCII 20, to zero. E.g.

     Byte #1                after conversion
     0001 0000 (20)         0000 0000 (0) 

This option should be used with caution, as it does slow down some operations, since the runtime has to apply this conversion dynamically.

Your Session will expire in 90 minutes
Notification will be shown in:
600 seconds