views:

1696

answers:

8

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. What I think of is a library which taking into account the copybooks 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.

Do you know a library providing this kind of functionality? Or any other techniques to cope with the problem of reading cobol data?


There are some commercial tools which provide this functionality. They are, however, very expensive. Do you know any open-source alternative or a combination of different tools to provide the entire functionality? For example the cb2xml reads copybook structures and transforms them into xml. A later step would be to generate a record reader based on the cb2xml xml information. Or to use a record reader which is configurable. Do you know a cobol record reader (decoder)?

+2  A: 

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.

Pablo Santa Cruz
Your 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.
lewap
Sure. What would you like? A tutorial on how to access Metadata information with JDBC?
Pablo Santa Cruz
It 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.
lewap
+1  A: 

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.

Brian Agnew
Thanks, 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.
lewap
You could use Apache's XMLBEANS to create java data structures from XML.
Pablo Santa Cruz
Or 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...
Brian Agnew
A: 

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.

nzpcmad
+2  A: 

You could look at JRecord - http://sourceforge.net/projects/JRecord/ or cb2java http://sourceforge.net/projects/cb2java/ both allow you to access cobol files but neither will generate the full classes

Bruce
+1  A: 

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.

Darron
A: 

Have a look at Javolution Struct http://javolution.org/target/site/apidocs/index.html You can then use a macro to convert your COBOL datat into Struct.

Ayman
A: 

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.

Ernest Hill
They had this feature on a special version of RAD called "RAD for z". Have they moved the functionality to base RAD now?
zkarthik
+1  A: 

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.

Anil Bhatia