COBOL represents Java String data in Unicode. To represent a Java String in a COBOL program, declare the string as an object reference of the jstring class. Then use JNI services to set or extract COBOL alphanumeric or national (Unicode) data from the object.
Services for Unicode: Use the following standard services to convert between jstring object references and COBOL USAGE NATIONAL data items. Access these services by using function pointers in the JNINativeInterface environment structure.
| Service | Input arguments | Return value |
|---|---|---|
| NewString1 |
|
jstring object reference |
| GetStringLength |
|
The number of Unicode characters in the jstring object reference; binary fullword |
| GetStringChars1 |
|
|
| ReleaseStringChars |
|
None; the storage for the array is released. |
|
||
Services for EBCDIC: Use the following z/OS services, an extension of the JNI, to convert between jstring object references and COBOL alphanumeric data (PIC X(n)). Access these services by using function pointers in the JNI environment structure JNINativeInterface.
| Service | Input arguments | Return value |
|---|---|---|
| NewStringPlatform |
|
Return code as a binary fullword
integer:
|
| GetStringPlatformLength |
|
Return code as a binary fullword
integer:
Returns, in the third argument, the needed length in bytes of the output buffer to hold the converted Java string, including the terminating null byte referenced by the second argument. |
| GetStringPlatform |
|
Return code as a binary fullword
integer:
|
|
||
These EBCDIC services are packaged as a DLL that is part of your IBM Java 2 Software Development Kit. For details about the services, see jni_convert.h in the IBM Java 2 Software Development Kit.
Use CALL literal statements to call the services. The calls are resolved through the libjvm.x DLL side file, which you must include in the link step of any COBOL program that uses object-oriented language.
For example, the following code creates a Java String object from the EBCDIC string 'MyConverter'. (This code fragment is from the J2EE client program, which is shown in full in Example: J2EE client written in COBOL.)
Move z"MyConverter" to stringBuf
Call "NewStringPlatform"
using by value JNIEnvPtr
address of stringBuf
address of jstring1
0
returning rc
If the EBCDIC services are the only JNI services that you call from a COBOL program, you do not need to copy the JNI.cpy copybook. You also do not need to establish addressability with the JNI environment pointer.
Services for UTF-8: The Java Native Interface also provides services for conversion between jstring object references and UTF-8 strings. These services are not recommended for use in COBOL programs due to the difficulty in handling UTF-8 character strings on the z/OS platform.