Exception loading copybook with nested Occurs-Depending
Read Cobol data files in Java
Status: Beta
Brought to you by:
bruce_a_martin
I am seeing an error when loading a copybook with nested instances of 'occurs-depending'. Here is the copybook:
01 ARRAY-COPYBOOK.
03 NUM-PEOPLE pic 9(12).
03 PEOPLE occurs 0 to 3 times depending on NUM-PEOPLE.
05 F-NAME pic X(40).
05 L-NAME pic X(40).
05 NUM-ID pic 999.
05 ID-X occurs 0 to 2 times depending on NUM-ID.
10 ID pic 99999.
This is the stack trace:
java.lang.RuntimeException: Error With Occurs Depending On Field: NUM-ID
at net.sf.JRecord.External.Def.DependingOn.updateField(DependingOn.java:151)
at net.sf.JRecord.External.Def.DependingOn.updateField(DependingOn.java:160)
at net.sf.JRecord.Details.RecordDetail.setDependingOn(RecordDetail.java:1100)
at net.sf.JRecord.External.ToLayoutDetail.toRecordDetail(ToLayoutDetail.java:178)
at net.sf.JRecord.External.ToLayoutDetail.getLayout(ToLayoutDetail.java:81)
at net.sf.JRecord.External.CopybookLoaderFactory.getLayout(CopybookLoaderFactory.java:270)
at OccursDependingTest.main(OccursDependingTest.java:11)
And the program doing the loading:
import net.sf.JRecord.Details.LayoutDetail;
import net.sf.JRecord.External.CopybookLoaderFactory;
import net.sf.JRecord.Log.TextLog;
public class OccursDependingTest {
public static void main(String[] args) {
String copybookFileName = "NestedOccursDepending.cbl";
CopybookLoaderFactory f = CopybookLoaderFactory.getInstance();
try {
LayoutDetail layout =(f.getLayout(CopybookLoaderFactory.COBOL_LOADER, copybookFileName, 0, "CP037", 0, new TextLog()));
} catch (Exception e) {
e.printStackTrace();
}
}
}
This is with version 0.81.1. Here is a similar issue from a while back which might be related: https://sourceforge.net/p/jrecord/bugs/14/.
Anonymous
View and moderate all "bugs Discussion" comments posted by this user
Mark all as spam, and block user from posting to "Bugs"
The issue might be that the second 'occurs-depending' field depends on a field that isn't at the 03 level. If I change the copybook to
it loads fine.
The problem is definitely with NUM-ID being part of the array. It is looking a plain field called
NUM-ID, not an array-field NUM-ID (Array-Index).
Unfortunatly there is no easy way to change this. The depending on fields can not be part of the parent array.
How essential is this ??? because it will be a lot of work to handle ???
Thanks for taking a look at this. Unfotunately, I am writing an application which is intended to handle arbitrary copybooks, so I just won't be able to handle ones like that.
I suspect that:
I posted the original Copybook in a Cobol Forum:
The nesting NUM-ID in a Occurs depending array is not supported by IBM Cobol:
Some thought Microfocus Cobol might support this
IBM Cobol requires occurs depending field to be in a
Fixedposition. Even the nested occurs depending started as an IBM extension to the standard CobolJohn, I have started work on supporting
Complex Occurs Depending, there is a new version of JRecord:This should work with the last Cobol2Xml:
I have done some testing on 2 level Complex OD but not 3 level OD (yet).
It would be useful If some one could check check against real
Livefiles as I do not have any. There are more changes and Testing before I do a full release of the JRecord. Probably a couple of weeksWill look at.
I have now added support for nested Occurs Depending: