How to unpack COMP digits using Java?

391 Views Asked by At

I had found this useful link for unpacked COMP-3 digit, but i need to unpack COMP digit this time, is anyone know how to unpack it? Thanks a lot!

2

There are 2 best solutions below

0
Bruce Martin On BEST ANSWER

In most Cobol compilers Comp is a big endian binary integer. For the mainframe only 2/4/8 bytes are supported. So For signed values

  03  Signed-Num     pic s9(4) comp.

if you have the value in an array of bytes you can do

BigInteger value = new BigInteger(byteArray);

Alternatively you could use the readShort(), readInt() and readLong() methods of DataInputStream

Finally JRecord will let you read Cobol files with a Cobol copybook

0
Hogstrom On

IBM Provides a library of Java methods to simplify interactions with z/OS services and data formats. An overview can be found here jZOS Toolkit

Here is a link to PackedDecimal Operations

Here are others for managing binary data ByteArrayUnmarshaller