Is this possible to convert EBCDIC Comp-3 file to ASCII file values using java?

穿精又带淫゛_ 提交于 2021-02-09 09:21:57

问题


I am trying to convert the EBCDIC COMP-3 fields to ASCII values but which is not working.But Binary COMP-3 fields could be converted to ASCII values.Please help me to understand is this possible or not? Even using any other java library is ok for me.I tried and searched may but no concrete answer I could see.

Update:

In my previous one binary should be the one which will work.This what I received as answer but there was no clarity about EBCDIC COMP-3.

COPYBOOK:

001700 01 EMP-RECORD.                                                           
001900        10  EMP-NO                     PIC 9(10).                         
002000        10  EMP-NAME                   PIC X(30).                         
002100        10  EMP-ADDRESS                PIC X(30).                         
002200        10  EMP-SALARY                 PIC S9(8)V9(2) COMP-3.             
002200        10  EMP-ZIPCODE                PIC 9(4).                          

BINARY COMP-3 file: could be converted

  ËÍ>ÁÁ% ,Í_/Ê Ê                Â/>Å/%?ÊÁ                        Á~                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ¢|ëá&ç                        ïçñèá ãñá<à                     ÊÊ>     

EBCDIC COMP-3:not able to convert

0000001001suneel kumar r                city                       e¡5671   

Program:

public static void main(String args[]) throws Exception {
    String salesFile = "empcompnewbinary.txt";
    String copybookName = "EMPCOPYBOOK.txt";
    AbstractLine saleRecord;

    int fileStructure = Constants.IO_FIXED_LENGTH;
    CobolIoProvider ioProvider = CobolIoProvider.getInstance();
    AbstractLineReader reader = ioProvider.getLineReader(fileStructure, Convert.FMT_MAINFRAME,
            CopybookLoader.SPLIT_NONE, copybookName, salesFile);

    while ((saleRecord = reader.read()) != null) {
        System.out.print(saleRecord.getFieldValue("EMP-NO").asString() + "-"
                + saleRecord.getFieldValue("EMP-NAME").asString() + "-"
                + saleRecord.getFieldValue("EMP-ADDRESS").asString() + "-"
                + saleRecord.getFieldValue("EMP-SALARY").asDouble() + "-"
                + saleRecord.getFieldValue("EMP-ZIPCODE").asString());
    }
    reader.close();
}

回答1:


There is no such thing as an "EBCDIC COMP-3 field", and it has no equivalent in ASCII code points. It is a binary format. So understand you have a record mixed of character and binary formats.

Comp-3 is packed decimal. It can vary a bit on different machine architectures as to where they put the sign nibble and whatnot, but it is a binary format, so any attempt to convert it using character set rules will always fail.

The easiest way to deal with this, by far, is to convert any packed decimal data to a display format, made up of characters. So instead of x'0123456C', you actually convert that to c'01234.56', and then your standard EBCDIC to ASCII conversion will work fine.



来源:https://stackoverflow.com/questions/46326448/is-this-possible-to-convert-ebcdic-comp-3-file-to-ascii-file-values-using-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!