Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


Reading an EBCIDC file using JRecord (Not able to read COMP fields)

  • Hi Bruce,
    I have a EBCIDIC file which is of type as below.
    JHON 123456789445600000007894000000grHË›³×™œ|ž²ª"
    RALPH 789456789445600000007894000000š,Yäì×ûm™œ|ž
    KELLY 456678991245600000007894000000"÷¬=0²ž«|ªª"
    DONALD 124578986545600000007894000000g­n/Dl g™^d™ª"
    JENIFFER 456578985445600000007894000000–—k‡Ë$Y±žÝ¨±™"
    REYAN 159357456445600000007894000000_ )âݲÛ™|g™
    And below is the copybook..
    10 TEST-NAME PIC X(20).
    15 TEST -NUM1 PIC 9(10).
    15 TEST -NUM2 PIC 9(10).
    15 TEST -NUM3 PIC 9(10).
    15 TEST -NUM4 PIC 9(10) COMP.
    15 TEST -NUM5 PIC 9(10) COMP-3.
    15 TEST -NUM6 PIC 9(10) COMP-3.
    And here is the java program I have written to convert the EBCIDIC file into readable text format..
    package com.recordj.test;
    import net.sf.JRecord.Common.Constants;
    import net.sf.JRecord.Details.AbstractLine;
    import net.sf.JRecord.External.CopybookLoader;
    import net.sf.JRecord.IO.AbstractLineReader;
    import net.sf.JRecord.IO.CobolIoProvider;
    import net.sf.JRecord.Numeric.Convert;
    public class CompCopyBookTest {
    * @param args
    public static void main(String[] args) {
    String vendorFile = "C:\Users\jeetendra_biswal\Desktop\WCC\Comp_file.txt";
    String copybookName= "C:\Users\jeetendra_biswal\Desktop\WCC\Comp_testcopy.cbl";

    CobolIoProvider ioProvider = CobolIoProvider.getInstance();
    int lineNumber = 0;
    AbstractLine line;
        AbstractLineReader reader  = ioProvider.getLineReader(
                Constants.IO_TEXT_LINE, Convert.FMT_INTEL,
                  CopybookLoader.SPLIT_NONE, copybookName, vendorFile);
        while ((line = reader.read()) != null) {
                           lineNumber += 1;
                                          "  "    + line.getFieldValue("CONTACT-NAME").asString()
                                          + "  \t " + line.getFieldValue("CONTAT-NUM1").asString()
                                       + "  \t " + line.getFieldValue("CONTAT-NUM2").asString()
                                       + "  \t " + line.getFieldValue("CONTAT-NUM3").asString()
                                       + "  \t " + line.getFieldValue("CONTAT-NUM4").asString()
                                       + "  \t " + line.getFieldValue("CONTAT-NUM5").asString()
                                       + "  \t " + line.getFieldValue("CONTAT-NUM6").asString());
    }catch(Exception e){

    It is able to read the Normal text but not able to convert the COMP fields.It is converting the COMP variables into a Unreadable format.So could you please give some suggestions, where I am making wrong.

    • Hi Jeetendra.
      Did you success in that conversion ?
      I´m looking for something similar to your problem, convert years of Mainframe datasets in ASCII, to keep them in security in another plataform and turn off our mainframe machine. The challenger is how to descompact "comp-3" fields, after download it off in another plataform with java, for exemple. I was hope tha Jrecord could help me.
      I´m very interested for your experience and appreciate for you attention...
      thank you.

  • Bruce Martin
    Bruce Martin

    Joao, there is a bit more of a conversation here https://sourceforge.net/p/jrecord/discussion/678634/thread/6d121cd0/

    I suspect when Jeetendra transferred the file from the Mainframe he/she did a ascii translation. This will screw up comp / comp-3 values for example the number 64 is x'40' in a comp field but that is also the EBCIDIC value for the space (' ') character. When the EBCIDIC -> Ascii translater gets hold of it the x'40' becomes x'20'

    The 2 solutions are
    Convert the comp/comp-3 values on the mainframe to normal character numbers
    Do a binary transfer from the Mainframe to the PC / unix box.

    JRecord can read raw EBCIDIC files, you just tell it the charset (Font field) is CP037 (US EBCIDIC) or whatever EBCIDIC version you are using