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();
}
sunleo
  • 8,787
  • 30
  • 98
  • 173
  • 1
    Possible duplicate of [How to unpack COMP-3 digits using Java?](https://stackoverflow.com/questions/20342804/how-to-unpack-comp-3-digits-using-java) – SaggingRufus Sep 20 '17 at 15:50
  • 1
    I believe jt400.jar (for AS/400 aka i) contains helper methods you might find useful. – Thorbjørn Ravn Andersen Sep 20 '17 at 16:08
  • Can you provide the raw files ???; perhaps upload them at https://sourceforge.net/projects/jrecord/ – Bruce Martin Sep 20 '17 at 21:20
  • This answer about using the Code-Generator in the RecordEditor may help: https://stackoverflow.com/questions/46313332/how-do-you-generate-javajrecord-code-fror-a-cobol-copybook/46313341#46313341 – Bruce Martin Sep 21 '17 at 02:27
  • 1
    @BruceMartin in that answer you have mentioned as "To transfer a Binary file from the Mainframe".But I don't have binary file.I have EBCDIC file. – sunleo Sep 21 '17 at 05:29
  • 1
    A binary mainframe will be an ebcdic file. I will update the question – Bruce Martin Sep 21 '17 at 07:19

1 Answers1

2

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.

Joe Zitzelberger
  • 4,168
  • 1
  • 26
  • 40