Reputation: 18904
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?
Upvotes: 24
Views: 27013
Reputation: 10553
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 Code generator
available as either a standalone program or in the Recordeditor.
This Code Generator
will build JRecord JRecord
code from a COBOL Copybook. See RecordEditor Jrecord CodeGen)The RecordEditor has a Generate option for generating Java / JRecord code from a COBOL Copybook. See RecordEditor Code Generation notes for details.
There is some information on generating Java~JRecord code in this question / answer:
How do you generate java~jrecord code for a Cobol copybook
Upvotes: 24
Reputation: 11585
Have a look at Javolution Struct.
You can then use a macro to convert your COBOL datat into Struct
.
Upvotes: 1
Reputation:
I have used Bruce's JRecord (from sourceforge) package for my project. It took only couple of days to learn to use it and saved me months of work in rolling out a much less general solution on my own. I recommend it highly.
Upvotes: 2
Reputation: 11
Rational Application Developer can read COBOL source code and generate Java classes. The generated classes have methods for accessing the various part of the COBOL data structure. The class that is generated is compatible with the J2EE Connector Architecture. To create a class in your project, select File, New, Other then select the CICS/IMS Java Data Binding wizard under J2C. Click next. Choose COBOL to Java for mapping. Select your COBOL file. Select the structure you wish to generate a Java class for then click Finish and there you go. There are of course a number of options you can select along the way that I didn't mention. For more information search Help for J2C.
Upvotes: 1
Reputation: 21620
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.
Upvotes: 1
Reputation: 46818
Microfocus provide a way of calling OO COBOL from Java.
"You can write classes in OO COBOL which can be called from Java programs as though they were Java classes. You do this by providing a Java wrapper class, which provides a function for each method in the OO COBOL class. The Net Express Class and Method Wizards make this easy for you, by generating the Java code at the same time as the COBOL code."
They also provide a tool called Enterprise Server which allows COBOL to interact with web services.
If you have a COBOL program A, the tool allows you to expose A's interface section as a web service.
Of course, because A now has a web service any other type of program (command line, Windows application, Java, ASP etc.) can now also call it and hence pass the COBOL data across to a Java program.
Upvotes: 1
Reputation: 181460
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.
Upvotes: 4
Reputation: 272417
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.
Upvotes: 2