Thanks Prakash
So that should work for character encodings for the strings but how would I go about adding the packed fields like PIC S9(03)V99 COMP-3?
David
Main Topics
Browse All TopicsI have been given the task of recreating a number of mainframe files that are currently created by Cobol and stored in EBCDIC format. We are re-designing a legacy system and the system creates several files that are pushed out to other systems which are not changing, so the file format needs to remain the same as it is today.
I have been given some documentation that describes the file layout in a manner such as:
field1 PIC X(4)
field2 PIC S9(03)V99 COMP-3.
field3 PIC S9(07) COMP-3.
field4 PIC S9(4)V9
I have a general idea what these formats mean, X(4) represents a 4 character string (abcd) where each character is represented has a single byte. S9(07) represents a 7 digit signed integer (1254782) which is represented by 4 bytes. And S9(4)V9 is a decimal number with one digit after the decimal (1234.5). I know that COMP-3 means that its a packed field (the details of what that really means eludes me a bit).
I need to able to construct these files using Java running on a Unix machine can any one offer me some guidance on the best way to approach it.
Thanks
David
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
So I'm trying to encode the following string 0100715052T0102091998 into the EBCDIC format with this type of code:
FileOutputStream fos = new FileOutputStream(...);
String myString = "0100715052T0102091998";
byte [] myBytes = myString.getBytes("8859-1"
fos.write(myBytes);
fos.flush();fos.close();
I also tried it with myString.getBytes("ISO-885
But I guess my install doesn't have that charset encoding or something because ASCII is what is getting written to the file. (Its the same has when I don't specify an encoding, myString.getBytes();
Thanks
I don't think this is the solution that you are looking for, but it may work if you have to go to plan "B" or an alternate solution.
Assuming your files were created in an IBM environment, you might want to look into one of the utility programs available with the system. The program "IEBGENER" can process files and also reformat the contents. Using this approach, you could convert the Packed fields to numeric Character fields, and also separate each field with a delimiter such as a comma.
I realize this is not necessarly the cleanest way of solving the problem, but I believe it is do-able.
Good luck
Business Accounts
Answer for Membership
by: prakash_parvathPosted on 2007-09-12 at 23:19:11ID: 19881927
Hi
);
As you have to create files which are not ASCII and which are EBCDIC
you need to supply the encoding information along with the I/O Streams
ex : FileInputStream fin = new FileInputStream(filename);
Reader inReader = new BufferReader(new InputStreamReader(fin, "8859_1"));
byte [] myBytes = myString.getBytes("8859_1"
** where "8859_1" represents the ISO8859_1 encoding which is IBM-1047 (EBCDIC) encoding.