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:
01 RECORD-DATA.
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 https://sourceforge.net/p/jrecord/discussion/678634/thread/176dcea6):
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(CobolSchemaReader.java:272)
at TestXform.main(TestJReader.java:56)
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:
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.