COBCH1942E Number of elements declared in variable differs from number of elements in value

The number of elements declared for a table does not match the number of elements specified in its corresponding value clause.

A table of a managed native type has been declared (either at an 01 level in the data division, or by use of a DECLARE statement), with a fixed number of elements. If this data declaration also specifies a value using a TABLE OF construct, then this error is produced if the number of elements in the TABLE OF is not the same as the number of elements specified in the OCCURS. In such cases, the table will be created with the size indicated by the TABLE OF construct.

Using the following example, myArray1 is generated with 3 elements (due to the TABLE OF clause), but is referenced using subscript 4, which will cause an error at run time.

       01 myArray1 binary-long occurs 4 value table of binary-long(1 2 3).

           declare myArray2 as binary-long occurs 3 = table of binary-long(4 5 6 7)
           display myArray2(1)
           display myArray2(2)
           display myArray2(3)
           display myArray2(4)

           display myArray1(1)
           display myArray1(2)
           display myArray1(3)
           display myArray1(4)    *> This will produce an error at run time...