使用 JRccord 访问 COBOL 模式

问题描述 投票:0回答:1

我正在尝试使用 JRecord 版本 0.93 来解析 COBOL copybook 以了解记录中存在的各个字段。我是 JRecord 的新手,我正在努力完成看似简单的任务。

在文件“test.cbl”中,我有这个:

01 RECORD-DATA.
    05 KEY-FIELD PIC X(8).
    05 DATA-FIELD PIC X(72). 

我希望获得字段名称、数据类型和长度的列表。

我找到了一个示例的开头(此处https://sourceforge.net/p/jrecord/discussion/678634/thread/176dcea6):

ICobolSchemaReader reader = CobolSchemaReader.newCobolSchemaReader("test.cbl");
CobolSchemaDetails schemaDetails = reader.getCobolSchemaDetails();

不幸的是,虽然上面的编译很干净,但它似乎不起作用:

java.lang.ClassCastException: net.sf.JRecord.schema.CobolSchemaReader incompatible with net.sf.JRecord.schema.ICobolSchemaReader
    at net.sf.JRecord.schema.CobolSchemaReader.newCobolSchemaReader(CobolSchemaReader.java:272)
    at TestXform.main(TestJReader.java:56)

以前有人做过这样的事情吗?有更好的方法或在线示例可供我学习吗?

java cobol jrecord
1个回答
0
投票

查看代码https://sourceforge.net/p/jrecord/code/HEAD/tree/Source/JRecord_Project/JRecord/src/net/sf/JRecord/schema/CobolSchemaReader.java#l103 - 只需使用

CobolSchemaReader reader = CobolSchemaReader.newCobolSchemaReader("test.cbl");
CobolSchemaDetails schemaDetails = reader.getCobolSchemaDetails();

说明:仅读者

implements implements ISchemaIOBuilder
,而不是
ICobolSchemaReader
- 无论出于何种原因;但这个对象确实有一个
getCobolSchemaDetails()
方法。

© www.soinside.com 2019 - 2024. All rights reserved.