bmTas / JRecord

Cobol IO for Java/JVM languages via a Cobol Copybook
GNU Lesser General Public License v3.0
35 stars 25 forks source link

JRecord Code Gen: Does not support Depends On for 1D arrays #10

Open johnathani opened 3 years ago

johnathani commented 3 years ago

The code gen does not generate code that supports resizing 1D arrays based on a "DEPENDS ON" defined in the copy book.

Example: 05 TOP. 07 TOP-GROUP. 09 TOP-GUN. 11 HEADER-COUNT PIC 9(1).

          09  HEADER OCCURS 0 TO 5
                   DEPENDING ON HEADER-COUNT.
                11  SOURCE-ITEM        PIC 9(03).

The stub code will always try to read and write 5 SOURCE-ITEM(s) no matter what the value of HEADER-COUNT is set to. This will cause failing of reading a line that has HEADER-COUNT=2 and only 2 SOURCE-ITEM entries as it will always try to read 5 item entries.

To fix, the velocity mappings need to be updated to support depends on. Internally, the depends on is not defined in the FieldDef .. you would need to rely on getFieldDetails referencing a complex expression like ....getFieldDetail().getDependingOnDtls().getDependingOn().getField().getName()} So FieldDef should be updated with a short cut to have .getDependingOn() available Example ...getDependingOn().getField().getName()

The velocity scripts for POJO should be fixed to support at least 1D array that depends on a field for its size

bmTas commented 3 years ago

The occurs depending was always an add-on. Will have a think about it

johnathani commented 3 years ago

Thanks The merge has an implementation for 1d array depends on which seems to be working