Requirement is : Once user enters a decimal number , it should be stored in Db2 as PAcked Decimal (COMP3)
Application is running on AIX(Encoding : ASCII) and DB2 is in Mainframe(Encoding : EBCDIC )
JDK Version: 1.5
The follwoing logic is used to convert decimal to PACKEDDEIMAL and then to EBCDIC Encoding.
Problem is : When the number "154.10" is converted to EBCDIC it is stored as 254.10. When 154.10 and 254.10 ae converted, we are getting the same bytes after encoding (for both numbers). For other numbers (For ex 321.90, 78.6, 345.78, etc) it is working fine. This problem is occurrent when 1 followed by 5 (For Ex: 154.10, 451.56 , etc..). Please advise if there is any problem with JDK1.5 encoding or Is there any other way to convert deciaml numbers into Packed decimal format?
So you pack the sequences "15" and "25" into the bytes 21 and 37. Which are x'15' and x'25' respectively. That part is correct. But converting those bytes to a String using CP037 converts them both in the the character whose Unicode value is 10. (This isn't all that surprising because both of them represent line-ending characters in EBCDIC and you are actually saying "These bytes represent a string in EBCDIC, so convert them to a Unicode string".)
It's possible that there are other situations besides this one where the conversion maps two bytes to the same character, but I haven't done that test.
I assume you're doing this EBCDIC-to-Unicode conversion because sending the result string to the database does a Unicode-to-EBCDIC conversion automatically for text data, and you're attempting to do the inverse so the end result is the original bytes you packed. But here it doesn't work because the bytes you produce aren't actually EBCDIC characters. So it's a cheap hack which turns out not to work.
I vaguely remember thinking this sort of thing was a good idea several years ago, but I quickly found it wasn't. It was just a pain in the behind. I found that making the fields on the mainframe NOT be packed decimal (but zoned decimal instead) was much easier to deal with. Or using JDBC to access well-structured records, that worked well too.
EBCDIC and ASCII are just two different code pages. Packed decimal is a way for IBM Z series computers ( and others) to encode numbers, four bits per digit with the last four bits as a sign.
There are machine instructions or operation code that can compute using packed decimal format on the IBM Z series. Zone decimal is almost printable numbers, with the first four bits of the last character being a sign.