Class ZoneDec


  • public class ZoneDec
    extends java.lang.Object
    Utility class to handle IBM System Z zone decimal data in Java. All zone decimal number operands must be valid format with valid sign. Java long will not hold the maximum size number. java.math.BigDecimal can be used to handle larger numbers than will fit in java long. "Zone decimal" format is a method of representing numbers in the IBM System Z computers. It was also present in the 360, 370 and 390 series. Decimal digits are stored as lower 4 bits of each byte. The upper 4 bits are binary 1111 except for the last byte. The first four bits are the last byte is the sign of the number. Positive are binary 1010, 1100 1110 and 1111. Negative is 1011 and 1101. COBOL is a popular mainframe language that has a number format with a "USAGE" of "DISPLAY". When a "USAGE DISPLAY" number has a sign on the picture, the number is stored a s zone decimal. An example:
        01 PART-NUMBER.
           05  PART-NAME                   PIC X(20).
           05  PART-NUMBER                 PIC 9(5) USAGE IS COMP-3.
           05  PART-COST                   PIC 9(5)V99 USAGE IS COMP-3.
           05  PART-STOCK-LEVEL            PIC S9(5)V99 USAGE IS DISPLAY.
           05  FILLER                      PIC X(10).
     
    The PART-STOCK-LEVEL would be stored in memory as zone decimal and occupy 7 bytes. The implied decimal does not reserve any storage
    Z/Series, 360, 370 and 390 is a trademark of IBM Corporation
    Version:
    5
    Author:
    zdecimal [ at ] benjaminjwhite.name
    See Also:
    IBM.COM, Z Decimal for java project home page
    • Constructor Summary

      Constructors 
      Constructor Description
      ZoneDec()  
    • Method Summary

      Modifier and Type Method Description
      static byte[] longToZone​(long lnum)
      Converts Java long to zone decimal
      static void longToZone​(long lnum, byte[] bytearray, int offset, int len)
      Convert long to zone decimal and store in byte array
      static byte[] stringToZone​(java.lang.String znstr)
      Converts a java String to System Z zoned decimal
      static void stringToZone​(java.lang.String str, byte[] bytearray, int offset, int len)
      Converts java.lang.String to zone decimal and store in byte array
      static long zoneToLong​(byte[] bytearrayi)
      Convert byte array containing zone decimal number
      static long zoneToLong​(byte[] bytearray, int offset, int len)
      Convert selected bytes of array of zone decimal format to long
      static java.lang.String zoneToString​(byte[] znbytesi)
      Converts a byte array of zoned decimal to a string
      static java.lang.String zoneToString​(byte[] znbytes, int offset, int len)
      Converts byte array of zone decimal to string
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ZoneDec

        public ZoneDec()
    • Method Detail

      • longToZone

        public static byte[] longToZone​(long lnum)
                                 throws java.io.UnsupportedEncodingException
        Converts Java long to zone decimal
        Parameters:
        lnum - long number
        Returns:
        byte array of zone decimal
        Throws:
        java.io.UnsupportedEncodingException - Invalid codepage
      • longToZone

        public static void longToZone​(long lnum,
                                      byte[] bytearray,
                                      int offset,
                                      int len)
                               throws java.io.UnsupportedEncodingException,
                                      DecimalOverflowException
        Convert long to zone decimal and store in byte array
        Parameters:
        lnum - Number to convert
        bytearray - Target byte array
        offset - Into byte array
        len - Length of field in byte array
        Throws:
        java.io.UnsupportedEncodingException - Invalid code page
        DecimalOverflowException - Number will not fit in field.
      • stringToZone

        public static byte[] stringToZone​(java.lang.String znstr)
                                   throws DataException,
                                          java.io.UnsupportedEncodingException
        Converts a java String to System Z zoned decimal
        Parameters:
        znstr - input number
        Returns:
        byte array of Zone decimal number
        Throws:
        DataException - Invalid characters
        java.io.UnsupportedEncodingException - Invalid code page
      • stringToZone

        public static void stringToZone​(java.lang.String str,
                                        byte[] bytearray,
                                        int offset,
                                        int len)
                                 throws DecimalOverflowException,
                                        DataException,
                                        java.io.UnsupportedEncodingException
        Converts java.lang.String to zone decimal and store in byte array
        Parameters:
        str - Input string
        bytearray - Output byte array
        offset - Into output byte array
        len - of sub array
        Throws:
        DecimalOverflowException - Input number too big for output
        DataException - Invalid characters
        java.io.UnsupportedEncodingException - Invalid code page
      • zoneToLong

        public static long zoneToLong​(byte[] bytearrayi)
                               throws java.io.UnsupportedEncodingException
        Convert byte array containing zone decimal number
        Parameters:
        bytearrayi - input number
        Returns:
        long number
        Throws:
        java.io.UnsupportedEncodingException - Invalid code page
      • zoneToLong

        public static long zoneToLong​(byte[] bytearray,
                                      int offset,
                                      int len)
                               throws java.io.UnsupportedEncodingException
        Convert selected bytes of array of zone decimal format to long
        Parameters:
        bytearray - Input zone decimal number
        offset - Into byte array
        len - Length of byte array field
        Returns:
        long number
        Throws:
        java.io.UnsupportedEncodingException
      • zoneToString

        public static java.lang.String zoneToString​(byte[] znbytesi)
                                             throws java.io.UnsupportedEncodingException
        Converts a byte array of zoned decimal to a string
        Parameters:
        znbytesi - zone decimal byte array
        Returns:
        Java String of number
        Throws:
        java.io.UnsupportedEncodingException - Invalid code page
      • zoneToString

        public static java.lang.String zoneToString​(byte[] znbytes,
                                                    int offset,
                                                    int len)
                                             throws java.io.UnsupportedEncodingException
        Converts byte array of zone decimal to string
        Parameters:
        znbytes - byte array zone decimal number
        offset - Into byte array
        len - Length of zone decimal field
        Returns:
        Java String of number
        Throws:
        java.io.UnsupportedEncodingException - Invalid code page