When you communicate with Java, declare arrays by using the special array classes, and declare strings by using jstring. Code the COBOL data types shown in the table below.
| Java data type | Corresponding COBOL data type |
|---|---|
| boolean[ ] | object reference jbooleanArray |
| byte[ ] | object reference jbyteArray |
| short[ ] | object reference jshortArray |
| int[ ] | object reference jintArray |
| long[ ] | object reference jlongArray |
| char[ ] | object reference jcharArray |
| Object[ ] | object reference jobjectArray |
| String | object reference jstring |
To use one of these classes for interoperability with Java, you must code an entry in the REPOSITORY paragraph. For example:
Configuration section.
Repository.
Class jbooleanArray is "jbooleanArray".
The REPOSITORY paragraph entry for an object array type must specify an external class-name in one of these forms:
"jobjectArray" "jobjectArray:external-classname-2"
In the first case, the REPOSITORY entry specifies an array class in which the elements of the array are objects of type java.lang.Object. In the second case, the REPOSITORY entry specifies an array class in which the elements of the array are objects of type external-classname-2. Code a colon as the separator between the specification of the jobjectArray type and the external class-name of the array elements.
The following example shows both cases. In the example, oa defines an array of elements that are objects of type java.lang.Object. aDepartment defines an array of elements that are objects of type com.acme.Employee.
Environment Division.
Configuration Section.
Repository.
Class jobjectArray is "jobjectArray"
Class Employee is "com.acme.Employee"
Class Department is "jobjectArray:com.acme.Employee".
. . .
Linkage section.
01 oa usage object reference jobjectArray.
01 aDepartment usage object reference Department.
. . .
Procedure division using by value aDepartment.
. . .
Examples: COBOL applications that run using the java command
The following Java array types are currently not supported for interoperation with COBOL programs.
| Java data type | Corresponding COBOL data type |
|---|---|
| float[ ] | object reference jfloatArray |
| double[ ] | object reference jdoubleArray |
related tasks
REPOSITORY paragraph for defining a class