Reading COBOL datastructures from Java
Solution 1
You could look at JRecord or cb2java. Both allow you to access COBOL files, but neither will generate the full classes.
Update Jan 2011
Since the original answer:
- JRecord continues be developed. There is now a
JRecord Code generator
available as either a standalone program or in the Recordeditor. ThisCode Generator
will buildJRecord JRecord
code from a COBOL Copybook. See RecordEditor Jrecord CodeGen) - Development on cb2java has stopped
- cobol2j has been written. There have been no updates for a year.
- There is also Legstar again nothing published for a few years
Update Aug 2017
The RecordEditor has a Generate option for generating Java / JRecord code from a COBOL Copybook. See RecordEditor Code Generation notes for details.
Update Jan 2018
There is some information on generating Java~JRecord code in this question / answer:
How do you generate java~jrecord code for a Cobol copybook
Solution 2
Yes. I have done that before. I used an ODBC connection to COBOL files, and then with jdbc:odbc bridge, I used metadata information to generate classes, read data and port it all to Oracle.
Here is a nice tutorial on how to access metada information with JDBC. Here is another one.
Keep in mind that you don't need the JDBC:ODBC bridge approach. If you can get a native JDBC driver to connect to your Cobol DataSource, it will be better. In this regard, I also used an IBM native driver. Don't remember the name though. It was a long time ago.
Solution 3
There appear to be some commercial solutions for this. Alternatively you can use cb2xml to convert the copybooks to XML, and then import the XML into Java using whatever mechanism you require.
Solution 4
BEA used to have a product named JAM that was used to communicate with mainframe COBOL programs. It included a tool that would read copybooks and generate both corresponding Java POD classes and data conversion code.
I don't know if this is still available, I lost track of it when I left BEA.
Solution 5
Have a look at Javolution Struct.
You can then use a macro to convert your COBOL datat into Struct
.
Related videos on Youtube
paweloque
My current projects: https://orbit7.ch https://gobugfree.com Follow me on Twitter: @paweloque
Updated on July 09, 2022Comments
-
paweloque almost 2 years
Is there a way to read COBOL data in a Java program? More concretely I'm confronted with the following case:
I have a file with fixed length records of data. The data definition is done as COBOL copybooks. I think of a library which is taking into account the copybooks and would be able to read those records.
Ideally, it should be possible to generate basic Java classes and structures based on the copybook information. In a later step the datarecords would be parsed and the data filled into objects of those generated classes.
Are there any other techniques to cope with the problem of reading COBOL data?
-
paweloque almost 15 yearsWhy are you asking? The cobol platform doesn't change the problem, or does it?
-
-
paweloque almost 15 yearsYour way to access cobol datastructures sounds interesting. Can you provide more information on how you did it? I didn't know that odbc supports accessing cobol datastructures.
-
paweloque almost 15 yearsThanks, however, the cb2xml only reads data definition and transforms it into xml. What I need is also a tool to read the actual data and transform it into java structures.
-
Pablo Santa Cruz almost 15 yearsSure. What would you like? A tutorial on how to access Metadata information with JDBC?
-
Pablo Santa Cruz almost 15 yearsYou could use Apache's XMLBEANS to create java data structures from XML.
-
Brian Agnew almost 15 yearsOr JAXB. Or handle-roll your own mechanism (a little more hard work admittedly) The cb2xml only gets you halfway, but it does take the COBOL and transforms it into something from which you can implement various different solutions...
-
paweloque almost 15 yearsIt is not about accessing the metadata, that part I do understand. However, the question is more how to use a odbc connection to access data stored in a cobol data-record file. Such a file doesn't per se contain information about the structures used.
-
user5403501 over 14 yearsThey had this feature on a special version of RAD called "RAD for z". Have they moved the functionality to base RAD now?
-
Peter Mortensen about 4 yearsThe fourth link is to a local file (drive F: on a Windows system).