Previous Topic Next topic Print topic


Arrays of Bytes in JVM COBOL Interoperation

In JVM COBOL, arrays of bytes are stored using the JVM special type java.lang.Byte[]. Byte arrays must be declared at the 01 level, as a COBOL table. Their size can be defined as part of the 01 definition or left undefined by using the ANY keyword. For example:

 01 b java.lang.Byte occurs any.

Arrays of type byte are objects but can be passed by reference to native entry points. This applies to single dimensional arrays only.

The bytes contained in the array are copied unchanged into a section of native memory of equal size and a reference to this piece of memory is passed to the native code. In COBOL this is equivalent to pic x data and in C to char* data. For example:

JVM COBOL:

 01 b java.lang.Byte occurs any. 
 01 i binary-long. 
 01 b-ptr procedure-pointer.
 set size of b to 1024
 perform varying i from 1 by 1 until i > 1024 
   set b(i) to i /8 
 end-perform 
 set b-ptr to entry "doStuff" 
 call "doStuffWith1k" using by reference b

Native COBOL:

 linkage section. 
 01 b pic x(1024). 
 ... 
 entry "doStuffWith1k" using by reference b. 
 ...
Previous Topic Next topic Print topic