3

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();
}
4

1 回答 1

2

没有“EBCDIC COMP-3 字段”之类的东西,它在 ASCII 码点中也没有等价物。它是一种二进制格式。因此,请了解您有混合字符和二进制格式的记录。

Comp-3 是压缩十进制。在不同的机器架构上,它们在哪里放置符号半字节和诸如此类的东西可能会有所不同,但它是一种二进制格式,因此任何使用字符集规则对其进行转换的尝试总是会失败。

到目前为止,解决这个问题的最简单方法是将任何打包的十进制数据转换为由字符组成的显示格式。因此,您实际上不是将 x'0123456C' 转换为 c'01234.56',然后您的标准 EBCDIC 到 ASCII 转换就可以正常工作。

于 2017-09-29T04:02:40.730 回答