Using JRccord to access COBOL schema

I'm trying to use JRecord version 0.93 to parse a COBOL copybook to understand the individual fields present in the record. I'm a complete newbie to JRecord and I'm struggling to get what seems like a simple task done.

In the file "test.cbl", I have this:

    05 KEY-FIELD PIC X(8).
    05 DATA-FIELD PIC X(72). 

I hope to get a list of the field names, their data types and lengths.

I found the beginnings of an example (here

ICobolSchemaReader reader = CobolSchemaReader.newCobolSchemaReader("test.cbl");
CobolSchemaDetails schemaDetails = reader.getCobolSchemaDetails();

Unfortunately, while the above compiles cleanly, it doesn't seem to work:

java.lang.ClassCastException: net.sf.JRecord.schema.CobolSchemaReader incompatible with net.sf.JRecord.schema.ICobolSchemaReader
    at net.sf.JRecord.schema.CobolSchemaReader.newCobolSchemaReader(
    at TestXform.main(

Has anyone done this sort of thing before? Any better approach or examples online that I might learn from?


  • After trying a few different things, I found an approach that seems to work:

     IIOBuilder iob = JRecordInterface1.COBOL
     LayoutDetail ld = iob.getLayout();             
     String [] fields = ld.getFieldDescriptions(0, 0);
     for (int i = 0; i < fields.length; i++)
        IFieldDetail fd = ld.getField(0, i);
        System.out.println("Field #" + i + " = " + fd.getGroupName() + fields[i] + 
                           ", Len = " + fd.getLen() + 
                           ", Type = " + fd.getType() + 
                           ", Decimal " + fd.getDecimal());

    There's more to do - I notice if I define a field in the copybook as an array, there doesn't seem to be an indicator in the IFieldDetail telling me that. But at least I feel like I'm on the right track now.