How to decode Signed Display field in Cobol response to BigDecimal in Java

513 views Asked by At

I'm using the CopyBook4Java library where I can find decoding options that are not completely resolving my case with mainframe signed display field to BigDecimal type variable. Below you can see my test:

assertEquals(new BigDecimal("0.00"), typeConverter.to("00000000000000ä".getBytes(StandardCharsets.ISO_8859_1), 0, 15, 2, true));
assertEquals(new BigDecimal("-200541.00"), typeConverter.to("00000002005410ä".getBytes(StandardCharsets.ISO_8859_1), 0, 15, 2, true));
assertEquals(new BigDecimal("33258.91"), typeConverter.to("00000000332589A".getBytes(StandardCharsets.ISO_8859_1), 0, 15, 2, true));

CopyBookFieldSigningType.LAST_BYTE_EBCDIC_BIT5 give me the possibility to process the response but unfortunately decoded values are wrong, especially for:

  • decimal fields 0.01-0.09
  • zero value 0.00
  • negative values i.e -200541.00

I suppose that I need to modify:

(signingType == CopyBookFieldSigningType.LAST_BYTE_EBCDIC_BIT5) {
            byte res = (byte)(bytes[bytes.length -1] & 240); // Read last byte and zero first 4 bits of the result, 11110000
            byte[] bytesCopy = Arrays.copyOf(bytes, bytes.length - 1);
            if((byte)(res ^ 208) == 0 ||(byte)(res ^ 176) == 0) { // 208 = 11010000, 176 = 10110000
                strValue = "-" + getString(bytesCopy, offset, length -1, removePadding, 1) + String.valueOf(bytes[bytes.length -1] & 15);
            } else {
                strValue = getString(bytesCopy, offset, bytesCopy.length, removePadding, 1) + String.valueOf(bytes[bytes.length -1] & 15);
            }

        }

I have no idea how to properly modify the algorithm for my case. Can anybody suggest me how to properly decode the response from mainframe to BigDecimal format?

Here you can check my repository with the unit test: https://repl.it/@epredator/copybook4java#copybook4java/src/test/java/com/nordea/oss/copybook/converters/SignedDecimalToBigDecimalLastByteTest.java

below you can see sample of the response copybook:

           09 exchangerate               PIC S9(6)V9(7).
           09 accountBalance             PIC S9(13)V9(2).

sample mainframe response:

20200931        1234567C  ADAM1 NO ZOO TESTACCOUNT O, SAMPLE SITE1L
 0212013000105101YYY SAMPLECO                                            Currentacc                       EUR000000000000000000000332589A00000000000000ä00000002005410ä00000000332589A00000000000000ä00000000000000ä91193000105037XXX SAMPLECO                                            Checkingac                       EUR000000000000000000002786655I00000000000000ä00000000000000ä00000000000000ä00000000000000ä00000000000000ä
1

There are 1 answers

0
MarkAddison On

Unfortunately my reputation is not sufficient to make a comment!

I'm not sure there is sufficient detail in the question to answer this. It suspect the character stream you receive needs to be transformed.

I suggest referring to the ASCII and EBCDIC Translation Tables to see if you get any inspiration.