• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cobol to Java Record Format Conversion  RSS feed

 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need to generate Java classes from COBOL record layouts of a flat file.

Does anyone have anything to share or know where I can find something to
1) Read the COBOL record layout.
2) Build a Java class with the COBOL field names converted into Java global variables of the same name.
3) Recognize the COBOL field types and convert those to Java matched with the name.
4) Parse the COBOL record into the Java appropriate global variables.

Actually, I'm consulting at a PL/I shop right now but I should be able to tweak either the COBOL input or the code to recognize PL/I in place of COBOL. Even better if it already does PL/I.

Thank You in Advance for Your Help,

Lou
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There must be some products out there that do this. For example IBM has JCA connectors to CICS ECI and other vendors like Attachmate have their own integraiton engines. Can you afford to purchase an integration product?

Several challenges:

1) Parsing a copybook or COBOL source code. I've seen it done (in COBOL) and it didn't look too bad. But you can get the compiler to do it for you. I wrote something to extract fieldnames, data type, offset & length in the 01 level from a COBOL compiler listing. See if your PL/I listings have something easy to pull out.

2) Generate matching Java. I don't think you could guarantee matching Java structures without restricting thes use of hierarchies and redefines in COBOL. You could have a getFieldX() routine that would substring any COBOL field and convert the type. If you need setFieldX(value) too you might store the record as a byte or char array.

3) Populate a Java object. If you used the getFieldX() approach, you would only have populate a string representing the full record and generate the getters.

For those without a COBOL background, here's a structure you can't really translate to Java. It's been at least 10 year since I actually compiled any COBOL but this ought to be close enough ...

We can move a string (display format) "12/31/1985" to Date-Of-Birth, do arithmetic on the numeric year and move the string back out.
[ May 21, 2005: Message edited by: Stan James ]
 
Lou Pelagalli
Ranch Hand
Posts: 150
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello again Stan,

What I need most is to parse the record by starting position and length. Tweaking the java classes or making the PL/I look like COBOL would be no big deal - they are similar enough.

Getters and setters can be generated by Eclipse after I have the correct global names and data type.

Purchasing something is probably out of the question.

Do you have something to share that I could look at?

Thanks,

Lou
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, sorry. The parser was in a vendor product and I didn't keep a copy. My listing reader was for a specific, now-obsolete IBM compiler. The COBOL II compiler from IBM had the info that I produced in the listing so my tool went the way of the dinosaur.

You might see if there is a COBOL grammar for one of the Java parsers out there. The Tiny-COBOL project had a link to a parser.

Parsing the data section yourself is not that hard if you just want to get field names, data types and lengths. You do have to test with lots of data format options - packed, decimal points, binary, etc - to be sure you got it all.
 
Peter Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you will find this project interesting http://cb2xml.sourceforge.net/

I assume you are talking about parsing a COBOL copybook. This project will help you to do that. At the moment conversion of any valid copybook into XML is stable. I don't think you need to create a Java class - a routine to convert to and from a java HashMap should be enough.

Hope this helps!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!