如何使用Java中的JRecord识别副本中字段的级别? [英] How do I identify the level of a field in copybook using JRecord in Java?

查看:193
本文介绍了如何使用Java中的JRecord识别副本中字段的级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试阅读一个EBCDIC文件,并借助于copybook将其转换为Java格式的ASCII格式。我正在使用JRecord来阅读这本字帖。那么现在,如何使用JRecord从字帖中获取字段级别?

I am trying to read a EBCDIC file and convert it to ASCII format in Java, with a help of copybook. I am using JRecord to read the copybook. So now, how do I get the field level from the copybook using JRecord?

编辑1:

请请原谅我一个含糊的问题。我没有大型机或cobol的经验。如果有帮助,我会添加更多细节。

Kindly excuse me for a vague question. I have no experience in mainframe or cobol. I am adding few more details if it could help.

我的源文件包含多个交易详情。该副本包含有关该交易的信息以及与该特定交易相关的字段。

My source file contains multiple transaction details. The copybook contains the information on the transaction and the fields relating to that particular transaction.

我必须将每个交易及其字段拆分为一个单独的文件(包含一个交易)

I have to split the each transaction and its fields to a separate file(containing one transaction and respective fields).

CopyBook

在附加的字帖中,第1行的字段可以包含从第2行到第4行的值。如果EXTRA-TYPE是01,那么我必须阅读第6行到第11行中的字段。类似地,如果EXTRA-TYPE是02,那么我必须将第12行中的字段读取到第16行。
我试图动态地拆分事务类型及其各自的字段。
(我需要获取与第1行中的事务类型相关的字段的开始和结束位置)如何在Java中实现此目的?

In attached copybook, the field in line 1 can have values from line 2 to line 4. If the EXTRA-TYPE is 01, then I have to read fields in line 6 to line 11. Similarly, if the EXTRA-TYPE is 02, then I have to read fields in line 12 to line 16. I am trying to split the Transaction type and its respective fields dynamically. (I need to get the start and end position of the fields with respect to the transaction type in line 1)How do I achieve this in Java?

感谢您的帮助。

推荐答案

为什么需要获得Field Level ???。要将文件转换为ascii,您不需要字段级别。

Why do you need to get the Field Level ???. To convert a file to ascii you do not need the Field Level.

要将 Cobol 文件转换为 ascii ,您可以使用其中一个实用程序:

To Convert a Cobol File to ascii you can use one of the utility programs:

  • Cobol2Csv sub-project - converts a Cobol data file to a Csv file
  • Cobol2Xml sub-project - converts a Cobol data file to a Xml file
  • Cobol2Json json utiltiy

如果您想对文件进行一些处理,可以使用生成
函数rel =nofol low noreferrer> RecordEditor
从Cobol copybook生成示例 JRecord 代码。

If you want to do some processing on the File, you can use the Generate function of the RecordEditor to generate sample JRecord code from the Cobol copybook.

如果您使用标准模板,则 RecordEditor 将生成以下代码:

If you use the standard template, the RecordEditor will generate code like:

    AbstractLine line;
    int lineNum = 0;

    try {
        ICobolIOBuilder iob = JRecordInterface1.COBOL
                                   .newIOBuilder(copybookName)
                                       .setFont("cp037")
                                       .setFileOrganization(Constants.IO_FIXED_LENGTH)
                                       .setSplitCopybook(CopybookLoader.SPLIT_NONE)
                                   ;  


        FieldNamesDtar020.RecordDtar020 rDtar020 = FieldNamesDtar020.RECORD_DTAR020;
        AbstractLineReader reader = iob.newReader(dataFile);
        while ((line = reader.read()) != null) {
            lineNum += 1;
            System.out.println(
                          line.getFieldValue(rDtar020.keycodeNo).asString()
                  + " " + line.getFieldValue(rDtar020.storeNo).asString()
                  + " " + line.getFieldValue(rDtar020.date).asString()
                  + " " + line.getFieldValue(rDtar020.deptNo).asString()
                  + " " + line.getFieldValue(rDtar020.qtySold).asString()
                  + " " + line.getFieldValue(rDtar020.salePrice).asString()
               );
        }

        reader.close();
    } catch (Exception e) {
        System.out.println("~~> " + lineNum + " " + e);
        System.out.println();

        e.printStackTrace();
    }



使用lineWrapper模板生成的代码



Code generated with lineWrapper template

  AbstractLine line;
    int lineNum = 0;

    try {
        ICobolIOBuilder iob = JRecordInterface1.COBOL
                                   .newIOBuilder(copybookName)
                                       .setFont("cp037")
                                       .setFileOrganization(Constants.IO_FIXED_LENGTH)
                                       .setSplitCopybook(CopybookLoader.SPLIT_NONE)
                                   ;  


       LineDtar020JR lineDtar020JR = new LineDtar020JR();


       AbstractLineReader reader = iob.newReader(dataFile);
       while ((line = reader.read()) != null) {
           lineNum += 1;
           lineDtar020JR.setLine(line);
           System.out.println(
                          lineDtar020JR.getKeycodeNo() 
                  + " " + lineDtar020JR.getStoreNo() 
                  + " " + lineDtar020JR.getDate() 
                  + " " + lineDtar020JR.getDeptNo() 
                  + " " + lineDtar020JR.getQtySold() 
                  + " " + lineDtar020JR.getSalePrice() 
               );
        }

        reader.close();
    } catch (Exception e) {
        System.out.println("~~> " + lineNum + " " + e);
        System.out.println();

        e.printStackTrace();
    }






通用Cobol处理



如果您想进行更多通用处理,可以使用 fieldIterator

FieldIterator fieldIterator = line.getFieldIterator("Record-Name");






JRecord示例



最新版本的 JRecord 0.81.4 Source / JRecord_IO_Builder_Examples / src 目录中有示例

如果您需要使用JRecord访问级别编号,请使用 CobolSchemaReader.newCobolSchemaReader(...)界面。

If you need to access level numbers with JRecord, use CobolSchemaReader.newCobolSchemaReader(...) interface.

您还可以查看 Cobol2Xml <的代码/ a>子项目。它通过扩展 CobolSchemaReader

这篇关于如何使用Java中的JRecord识别副本中字段的级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆