When you send COBOL data to Java, it is converted to an appropriate Java data type. Similarly, when a Java program sends Java data back to COBOL, it is converted to a COBOL data type. The table below defines the conversions which happen when data is passed between Java and COBOL. Some data types are handled differently depending on whether you are using procedural COBOL or the OO COBOL Java domain. The COBOL column in the table shows you the conversion rules for procedural COBOL, and the OO COBOL column shows you the rules for the OO COBOL Java domain.
Java Data Type | COBOL Data Type Used with .cobcall(...) | OO COBOL Data Type Used with .cobinvoke() | Description |
---|---|---|---|
byte | pic s99 comp-5 | pic s99 comp-5
pic s99 comp |
Signed 1-byte integer |
short | pic s9(4) comp-5 | pic s9(4) comp-5
pic s9(4) comp |
Signed 2-byte integer |
int | pic s9(9) comp-5 | pic s9(9) comp-5
pic s9(9) comp |
Signed 4-byte integer |
long | pic s9(18) comp-5 | pic s9(18) comp-5
pic s9(18) comp1 |
Signed 8-byte integer |
boolean | pic 99 comp-5 | pic 99 comp-5 | Zero value is false, non-zero is true |
char (Unicode) | pic 9(4) comp-5 | pic s9(4) comp | All characters in Java are represented by 2-byte Unicode characters |
float | comp-11 | comp-1 1 | Floating-point number |
double | comp-2 1 | comp-2 1 | Double-precision floating-point number |
String | mf-jstring2
pointer3 |
pic x(n) | The capacity is always zero. You should consider a string passed into a COBOL program as read-only, and not to be amended. |
StringBuffer4 | mf-jstring
2
pointer 3 |
pic x(n) | The capacity is the total size of the buffer, and the size the length of the string currently held in the buffer. |
objects | pointer | object reference | Any Java object. The pointer returned to procedural COBOL can be used with JNI calls (see the section Using JNI with COBOL in the chapter Calling Procedural COBOL from Java). |
object[] | pointer | object reference to instance of class jarray | An array of Java objects. The pointer returned to procedural COBOL can be used with JNI calls (see the section Using JNI with COBOL in the chapter Calling Procedural COBOL from Java). jarray is an OO COBOL class for accessing the contents of Java arrays, and is described in the section Using the Jarray Class. |
DataType | structure | structure | Complex data structure |
Comp3 | comp-3 | comp-3 | COMP(UTATIONAL)-3 or Packed-Decimal |
Pointer(StringBuffer)
Pointer(String, int capacity) |
pic x(99) | pic x(99) | Wraps a String, StringBuffer so it can safely be passed to COBOL with the right size allocated for the receiving COBOL to modify the Java object.
StringBuffer capacity is used as the largest possible length that COBOL can edit. |
java.sql.Date(long)
CobolDate(date) |
0x jyear pic 9(4).
0x filler pic x. 0x jmonth pic 99. 0x filler pic x. 0x jday pic 99. |
same as for cobcall | Standard SQL Date type |
java.sql.time(long)
CobolTime(time) |
0x jhour pic 99.
0x filler pic x. 0x jminute pic 99. 0x filler pic x. 0x jseconds pic 99. |
same as for cobcall | Standard SQL Time type |
CobolBigDecimal(java.math.BigDecimal) |
pic s9(19)v9(19) comp-3 | same as for cobcall | The CobolBigDecimal wrapper class enables COBOL to update the value of a BigDecimal. The constructor for CobolBigDecimal() takes an initial value and the updated value can be obtained by using the .getValue() method. |
CobolBigInteger(java.math.BigInteger) |
pic S9(38) comp-3 | same as for cobcall | The CobolBigInteger wrapper class enables COBOL to update the value of a BigInteger. The constructor for CobolBigInteger() takes an initial value and the updated value can be obtained by using the .getValue() method. |
CustomRecord | Structure | Structure | Complex data structure represented in Java as an array of objects. |
CobolN ational | pic x(n) usage is national. | same as for cobcall | This java class enables you to create UTF-16 strings that you can pass to COBOL. |
1 The parameter can be passed only by reference. For long data types on 32-bit platforms the parameter can be passed by reference only, and on 64-bit platforms by reference or by value only. 2 Use mf-jstring for .cobcall(...). mf-jstring requires the receiving COBOL program to use ptr2string pointer to access the Java String or StringBuffer. Using mf-jstring gives you access to the size and capacity of the Java object. 3 Use pointer for .cobcall(...). 4 StringBuffer objects can be received by OO COBOL methods as pic x(n) data items but pic x(n) cannot be used to pass data to a Java method with a StringBuffer parameter. |
The conversion of COBOL data types that are not listed in the COBOL or OO COBOL columns of the above table is not supported. If you need to use a COBOL data item of a type not listed above, use an intermediate data item of a supported type and move your data to and from the intermediate data item as necessary.