Manipulating Java arrays
To represent an array in a COBOL program, code a group
item that contains a single elementary item that is of the data type
that corresponds to the Java™ type
of the array. Specify an OCCURS
or OCCURS
DEPENDING ON
clause that is appropriate for the array.
About this task
For example, the following code specifies a structure to receive 500 or fewer integer values from a jlongArray object:
01 longArray.
02 X pic S9(10) comp-5 occurs 1 to 500 times depending on N.
To operate on objects of the special Java-array classes, call the services that the JNI provides. You can use services to access and set individual elements of an array and for the following purposes, using the services cited:
Service | Input arguments | Return value | Purpose |
---|---|---|---|
GetArrayLength |
|
The array length as a binary fullword integer | To get the number of elements in a Java array object |
NewBooleanArray, NewByteArray, NewCharArray, NewShortArray, NewIntArray, NewLongArray |
|
The array object reference, or NULL if the
array cannot be constructed |
To create a new Java array object |
GetBooleanArrayElements, GetByteArrayElements, GetCharArrayElements, GetShortArrayElements, GetIntArrayElements, GetLongArrayElements |
|
A pointer to the storage buffer | To extract the array elements from a Java array into a storage buffer. The services
return a pointer to the storage buffer, which you can use as the address
of a COBOL group data item defined in the LINKAGE SECTION . |
ReleaseBooleanArrayElements, ReleaseByteArrayElements, ReleaseCharArrayElements, ReleaseShortArrayElements, ReleaseIntArrayElements, ReleaseLongArrayElements |
|
None; the storage for the array is released. | To release the storage buffer that contains elements that have been extracted from a Java array, and conditionally map the updated array values back into the array object |
NewObjectArray |
|
The array object reference, or NULL if the
array cannot be constructed1 |
To create a new Java object array |
GetObjectArrayElement |
|
An object reference2 | To return the element at a given index within an object array |
SetObjectArrayElement |
|
None3 | To set an element within an object array |
|
Examples: COBOL applications that run using the java command
Example: processing a Java integer array