Interoperable data types for OO COBOL and Java
A subset of COBOL data types can be used for interoperation between OO COBOL and Java™.
You can specify the interoperable data types as arguments in COBOL INVOKE statements and as the RETURNING item in COBOL INVOKE statements. Similarly, you can pass these types as arguments from a Java method invocation expression and receive them as parameters in the USING phrase or as the RETURNING item in the PROCEDURE DIVISION header of a COBOL method.
The following table lists the primitive Java types and the COBOL data types that are supported for interoperation and the correspondence between them.
Java data type | COBOL data type |
---|---|
boolean1 | Conditional variable and two condition-names of
the form:
|
byte | Single-byte alphanumeric, PIC X or PIC A |
short | USAGE BINARY, COMP, COMP-4, or COMP-5, with a PICTURE clause of the form S9(n), where 1 <= n <= 4 |
int | USAGE BINARY, COMP, COMP-4, or COMP-5, with a PICTURE clause of the form S9(n), where 5 <= n <= 9 |
long | USAGE BINARY, COMP, COMP-4, or COMP-5, with a PICTURE clause of the form S9(n), where 10 <= n <= 18 |
float2 | USAGE COMP-1 |
double2 | USAGE COMP-2 |
char | Single-character national: PIC N USAGE NATIONAL
(an elementary data item of category national) |
class types
(object references) |
USAGE OBJECT REFERENCE class-name |
|
In addition to the primitive types, Java Strings and arrays of Java primitive types can interoperate with COBOL. This requires specialized mechanisms provided by the COBOL runtime system and the Java Native Interface (JNI).
In a Java program, to pass array data to COBOL or to receive array data from COBOL, you declare the array types using the usual Java syntax. In the COBOL program, you declare the array as an object reference that contains an instance of one of the special classes provided for array support. Conversion between the Java and COBOL types is automatic at the time of method invocation.
In a Java program, to pass String data to COBOL or to receive String data from COBOL, you declare the array types using the usual Java syntax. In the COBOL program, you declare the String as an object reference that contains an instance of the special jstring class. Conversion between the Java and COBOL types is automatic at the time of method invocation. The following table lists the Java array and String data types and the corresponding special COBOL data types.
Java data type | COBOL data type |
---|---|
boolean[ ] | object reference jboooleanArray |
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 |
The following java array types are not currently supported:
Java data type | COBOL data type |
---|---|
float[ ] | object reference jfloatArray |
double[ ] | object reference jdoubleArray |
You must code an entry in the repository paragraph for each special class that you want to use, just as you do for other classes. For example, to use jstring, code the following entry:
Configuration Section.
Repository.
Class jstring is "jstring".
Alternatively, for the String type, the COBOL repository entry can specify an external class name of java.lang.String:
Repository.
Class jstring is "java.lang.String".
Callable services are provided by the Java Native Interface (JNI) for manipulating the COBOL objects of these types in COBOL. For example, callable services can be used to set COBOL alphanumeric or national data into a jstring object or to extract data from a jstring object. For details on use of JNI callable services for these and other purposes, see Accessing JNI services in the Enterprise COBOL Programming Guide.
For details on repository entries for class definitions, see REPOSITORY paragraph. For examples, see External class-names and Java packages in the Enterprise COBOL Programming Guide.