Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EBCDIC to ASCII in Java

Status
Not open for further replies.

koolraul

Programmer
Aug 20, 2003
10
US
I have a flat file that was generated by a COBOL program which contains a combination of ASCII characters and pack decimals which I think are in binary format. The pack decimals are of COMP type (in Cobol). Can I use some of the io classes to convert these pack decimals to ASCII? Thanks.
 
If you know how many bits each of these characters make up a character in Java, then you could use the DataInputStream and the method readByte() to convert the chars.

(There may be an easier way, but that is the only one I can think of right now).

--------------------------------------------------
Free Database Connection Pooling Software
 
Yes you can use java.io, but you will need a conversion table to do the translation depending on the meaning that EBCDIC characters will have for you.

Cheers.

Dian
 
Thanks sedj and Diancecht for your responses. I have the following snippet of codes to read the flat file that was generated by a COBOL program which contains a combination of ASCII characters and pack decimals which I think are in binary format. I was able to read and write the file but the binary coded decimals were still not being converted to ASCII. Any suggestions to improve or correct this? Thanks.

private static void convertAsciiToEbcdic(File file) {
try {
File ofile = new File("c:\\koolstuff\\ProductionSupport\\IFMSS\\us_err_files\\", "ofile.dat");
DataInputStream in = new DataInputStream(
new BufferedInputStream(
new FileInputStream(file)));
DataOutputStream out = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(ofile)));

int aChar = 0;
while ((aChar = in.read()) > 0) {
out.write(aChar);
}

in.close();
out.close();
} catch (IOException e) {
System.out.println(e);
}
}
 
I don't remember many things about this, but I think that packed COBOL format needs to be interpreted to convert it to ASCII numbers, and for that you need to know how are they being encoded.

Cheers.

Dian
 
All that code is going to do is read and write the file without changing it.

The point of using a DataInputStream is so you can read the file on a byte by byte basis, and then convert your characters accordingly.

But you need to know the mapping between COBOL and Java characters - something YOU will have to write. Different languages and different OS's treat characters differently.

For example, on most OS's, a 'char' in C/C++ is a data type that is made up of 8 bits. But in Java, a 'char' takes up 16 bits. So if you were going to convert, then you would need to handle this by doing some bit shifting operations. See ? You need to know how many bits a 'char' is in COBOL/

--------------------------------------------------
Free Database Connection Pooling Software
 
Ok folks! I got the idea! Life is just not that easy... but fun anyway. Thanks a lot for your enlightenment.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top