File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Convert from ASCII to EBCDIC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Convert from ASCII to EBCDIC" Watch "Convert from ASCII to EBCDIC" New topic
Author

Convert from ASCII to EBCDIC

Raji Manne
Greenhorn

Joined: Sep 23, 2009
Posts: 3
Reposting this topic with code format

Hi,

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?


Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18110
    
    8

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.
Benjamin White
Greenhorn

Joined: Oct 21, 2009
Posts: 1
You might want to check out my project http://sourceforge.net/projects/zdecimal/. Some of the code fragments look like older version of my code. Glad it is being used.

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Convert from ASCII to EBCDIC
 
Similar Threads
Using Comp-3 value in Java
Basic Authentication Servlet Redirect
Convert from ASCII to EBCDIC
problem base64 encoding the 3 hex bytes E2 80 A9
Packed decimal conversion - Java