- java.lang.Object
-
- name.benjaminjwhite.zdecimal.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:
The PART-STOCK-LEVEL would be stored in memory as zone decimal and occupy 7 bytes. The implied decimal does not reserve any storage01 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).
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 decimalstatic void
longToZone(long lnum, byte[] bytearray, int offset, int len)
Convert long to zone decimal and store in byte arraystatic byte[]
stringToZone(java.lang.String znstr)
Converts a java String to System Z zoned decimalstatic void
stringToZone(java.lang.String str, byte[] bytearray, int offset, int len)
Converts java.lang.String to zone decimal and store in byte arraystatic long
zoneToLong(byte[] bytearrayi)
Convert byte array containing zone decimal numberstatic long
zoneToLong(byte[] bytearray, int offset, int len)
Convert selected bytes of array of zone decimal format to longstatic java.lang.String
zoneToString(byte[] znbytesi)
Converts a byte array of zoned decimal to a stringstatic java.lang.String
zoneToString(byte[] znbytes, int offset, int len)
Converts byte array of zone decimal to string
-
-
-
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 convertbytearray
- Target byte arrayoffset
- Into byte arraylen
- Length of field in byte array- Throws:
java.io.UnsupportedEncodingException
- Invalid code pageDecimalOverflowException
- 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 charactersjava.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 stringbytearray
- Output byte arrayoffset
- Into output byte arraylen
- of sub array- Throws:
DecimalOverflowException
- Input number too big for outputDataException
- Invalid charactersjava.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 numberoffset
- Into byte arraylen
- 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 numberoffset
- Into byte arraylen
- Length of zone decimal field- Returns:
- Java String of number
- Throws:
java.io.UnsupportedEncodingException
- Invalid code page
-
-