从 Java 中读取 COBOL 数据结构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/802122/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 19:37:56  来源:igfitidea点击:

Reading COBOL datastructures from Java

javadata-structurescobolcopybook

提问by paweloque

Is there a way to read COBOL data in a Java program? More concretely I'm confronted with the following case:

有没有办法在 Java 程序中读取 COBOL 数据?更具体地说,我面临以下情况:

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.

我有一个包含固定长度数据记录的文件。数据定义是作为 COBOL 字帖完成的。我想到了一个图书馆,它考虑了抄写本并且能够阅读这些记录。

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.

理想情况下,应该可以根据字帖信息生成基本的 Java 类和结构。在后面的步骤中,将解析数据记录并将数据填充到那些生成的类的对象中。

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

您知道提供这种功能的库吗?或者任何其他技术来应对读取 COBOL 数据的问题?



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)?

有一些商业工具提供此功能。然而,它们非常昂贵。您是否知道任何开源替代方案或不同工具的组合来提供整个功能?例如,cb2xml 读取 copybook 结构并将它们转换为 XML。后面的步骤是根据 cb2xml XML 信息生成记录阅读器。或者使用可配置的记录阅读器。您知道 COBOL 记录阅读器(解码器)吗?

采纳答案by Bruce Martin

You could look at JRecordor cb2java. Both allow you to access COBOL files, but neither will generate the full classes.

您可以查看JRecordcb2java。两者都允许您访问 COBOL 文件,但都不会生成完整的类。



Update Jan 2011

2011 年 1 月更新

Since the original answer:

由于原始答案:

  • JRecord continues be developed. There is now a JRecord Code generatoravailable as either a standalone program or in the Recordeditor. This Code Generatorwill build JRecord JRecordcode from a COBOL Copybook. See RecordEditor Jrecord CodeGen)
  • Development on cb2javahas stopped
  • cobol2jhas been written. There have been no updates for a year.
  • There is also Legstaragain nothing published for a few years
  • JRecord 继续被开发。现在JRecord Code generator可以作为独立程序或在Recordeditor 中使用。这Code Generator将从JRecord JRecordCOBOL Copybook构建代码。请参阅RecordEditor Jrecord CodeGen
  • cb2java上的开发已停止
  • cobol2j已经写好了。已经一年没有更新了。
  • 还有Legstar又是几年没发表了

Update Aug 2017

2017 年 8 月更新

The RecordEditorhas a Generate option for generating Java / JRecordcode from a COBOL Copybook. See RecordEditor Code Generation notesfor details.

RecordEditor具有用于产生生成选项的Java / JRecord从一个COBOL字帖代码。有关详细信息,请参阅RecordEditor 代码生成说明

Update Jan 2018

2018 年 1 月更新

There is some information on generating Java~JRecordcode in this question / answer:

这个问题/答案中有一些关于生成Java~JRecord代码的信息:

How do you generate java~jrecord code for a Cobol copybook

你如何为Cobol字帖生成java~jrecord代码

回答by Pablo Santa Cruz

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.

是的。我以前这样做过。我使用 ODBC 连接到 COBOL 文件,然后使用 jdbc:odbc 网桥,我使用元数据信息生成类、读取数据并将其全部移植到 Oracle。

Hereis a nice tutorial on how to access metada information with JDBC. Hereis another one.

是一个关于如何使用 JDBC 访问元数据信息的很好的教程。是另一个。

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.

请记住,您不需要 JDBC:ODBC 桥接方法。如果你能得到一个本地 JDBC 驱动程序来连接到你的 Cobol 数据源,那就更好了。在这方面,我也使用了 IBM 原生驱动程序。不过不记得名字了。很久以前了。

回答by Brian Agnew

There appear to be some commercial solutionsfor this. Alternatively you can use cb2xmlto convert the copybooks to XML, and then import the XML into Java using whatever mechanism you require.

似乎有一些商业解决方案。或者,您可以使用cb2xml将副本转换为 XML,然后使用您需要的任何机制将 XML 导入 Java。

回答by nzpcmad

Microfocusprovide a way of calling OO COBOL from Java.

Microfocus提供了一种从 Java 调用 OO COBOL 的方法。

"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."

“您可以在 OO COBOL 中编写类,这些类可以从 Java 程序中调用,就好像它们是 Java 类一样。您可以通过提供一个 Java 包装类来实现这一点,该类为 OO COBOL 类中的每个方法提供一个函数。Net Express 类和通过在生成 COBOL 代码的同时生成 Java 代码,方法向导使您可以轻松实现这一点。”

They also provide a tool called Enterprise Server which allows COBOL to interact with web services.

他们还提供了一个名为 Enterprise Server 的工具,它允许 COBOL 与 Web 服务交互。

If you have a COBOL program A, the tool allows you to expose A's interface section as a web service.

如果您有一个 COBOL 程序 A,该工具允许您将 A 的接口部分公开为 Web 服务。

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.

当然,由于 A 现在拥有 Web 服务,因此任何其他类型的程序(命令行、Windows 应用程序、Java、ASP 等)现在也可以调用它,从而将 COBOL 数据传递给 Java 程序。

回答by Darron

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.

BEA 曾经有一个名为 JAM 的产品,用于与大型机 COBOL 程序进行通信。它包括一个工具,可以读取字帖并生成相应的 Java POD 类和数据转换代码。

I don't know if this is still available, I lost track of it when I left BEA.

我不知道这是否仍然可用,我离开 BEA 时忘记了它。

回答by Ayman

Have a look at Javolution Struct.

看看Javolution 结构

You can then use a macro to convert your COBOL datat into Struct.

然后,您可以使用宏将 COBOL 数据转换为Struct.

回答by Ernest Hill

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.

Rational Application Developer 可以读取 COBOL 源代码并生成 Java 类。生成的类具有用于访问 COBOL 数据结构的各个部分的方法。生成的类与J2EE 连接器体系结构兼容。要在您的项目中创建一个类,请选择 File、New、Other,然后选择 J2C 下的 CICS/IMS Java Data Binding 向导。点击下一步。选择 COBOL 到 Java 进行映射。选择您的 COBOL 文件。选择您希望为其生成 Java 类的结构,然后单击“完成”就可以了。当然,您可以选择我没有提到的许多选项。有关更多信息,请搜索 J2C 的帮助。

回答by Ernest Hill

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.

我在我的项目中使用了 Bruce 的 JRecord(来自 sourceforge)包。只用了几天就学会了使用它,并节省了我几个月的时间来自己推出一个不太通用的解决方案。我强烈推荐它。