Convert Mainframe Binary to Ascii Using any Open Source Code or Tool
Asked Answered
S

1

4

How can I convert a mainframe binary file (EBCDIC) having cobol copybook as record layout information to ASCII file by keeping in mind regarding the packed and zoned decimal format using any Java API or Open source tool?

Sinfonietta answered 3/7, 2013 at 12:29 Comment(1)
Check out jt400.jar which has such methods for i/AS400.Hoodoo
I
8

Reading in Java

If you want to Read Mainframe Cobol Files in java, have a look at

  • JRecord - You will have to specify the charset (font). For US EBCDIC use CP037.
  • Legstar - Have variety of Mainframe - Cobol Tools
  • CB2java - Has not been updated in a while (not supported any more and has problems)

Also the RecordEditor will let you view / Edit Mainframe Cobol Files

Conversion Utilities

For simple Cobol files these conversion utilities (based on JRecord) could be used:

RecordEditor

The RecordEditor has a Generate option for generating Java / JRecord code. See RecordEditor Code Generation notes

enter image description here

Note: I am the author of JRecord/RecordEditor

Illuse answered 3/7, 2013 at 12:46 Comment(10)
Just wondering what happens if a field in the copybook is defined as COMP/COMP-4/BINARY but the program writing the record was compiled with TRUNC(BIN), so effectively those USAGEs become COMP-5. Amending the layout would be easy enough, but youd'd need to know to do it.Capricecapricious
For JRecord / RecordEditor, it essentially treats all comp/comp-4/binary as is TRUNC(BIN), for the most part this does not matter. For many Cobols Compilers Comp is Big-Endian and Comp-5 is Native-Binary format. On the mainframe, both are Big-Endian, For many PC intel compilers, Comp-5 is little endian.Illuse
Hi Bruce I used JRecord but did not find any option of handling Redefine clauses. In my case there are multiple redefine clause which is referring to same memory location but only one of them needs to be used to get the expected data. Moreover for a particular field which has cobol datatype as PIC S9(5) COMP-3 gives me output f2f0f1 when I use getFieldValue method. Moreover the hex value for the field is also f2f0f1. But I should be getting some decimal values after conversion right? So is this an issue with the file itself or should I handle it some other way?Sinfonietta
Hi @BruceMartin I would like to add one more thing for a particular field which has datatype S9(6)V9(1) COMP-3 in copybook the corresponding HEX value is 4040 but after conversion I get the output as 404.0.But I have doubt here actually 40 means space character in EBCDIC so the output should be empty value right?Sinfonietta
First Answer: f2f0f1 are the characters "201" in Ebcdic . With comp-3, the number 123 is represented as x'123c' (from memopry). So this field value is not a comp-3 value.Illuse
For Redefines you could use CopybookLoader.SPLIT_REDEFINE for the split option but it really does not help you at all. Cobol does not have any built-in way of saying which redefine version to use. Normally the programer will define a Record-Type field (or something similar) which tells another programmer which Redefines version to use. You have to work which field/fields are performing this function and test them.Illuse
x'4040' is certainly spaces in Ebcdic. Some time Cobol programmers will initialise a record by moving spaces (or low values) to a whole record (which I suspect was done here). You can do a line.getFieldText(recordNumber, fieldNumber) and test this for spaces.Illuse
It might be an Idea to upload the Cobol Copybook either here (or in a Question at the JRecord site) so I can see what you have to deal with.Illuse
Thanks @BruceMartin for your quick reply. Regarding the first question the field defination in copybook is 03 URF-CYL-CU-ORIG-CITY-CD PIC S9(5) COMP-3. But for (Record 4) I am getting f2f0f1 using getField Value method but for (record 7) for the same field I am getting proper numeric value ex:2Sinfonietta
I not sure if you installed the full version with the Editor, but you can try out the various parameters and see what it looks like. I would use split=Redefines though. There are some notes on how the Editor parameters relate to JRecord: sourceforge.net/projects/jrecord/files/jrecord/Version_0.68.3/…Illuse

© 2022 - 2024 — McMap. All rights reserved.