To compile COBOL source code that uses JNI services or contains OO syntax such as INVOKE statements or class definitions (that is, COBOL code that directly communicates with Java):
- Use the following compiler options: RENT, DLL, THREAD, and DBCS.
The RENT and DBCS options are IBM-supplied defaults.
- Set PGMNAME(LONGMIXED) for long name support.
- Set the RECURSIVE attribute on COBOL classes and methods or on COBOL programs that invoke Java methods.
Compiling the COBOL with DLL affects the overall COBOL program structure. In general, DLL-linkage-built COBOL programs can only call out to other external DLL-linkage-built programs. Similarly, dynamic call built COBOL programs can only call out to other external dynamic call built programs. However, static linking of objects with either two of these external program call mechanisms is allowed. This provides the bridging between the DLL linkage that Java requires and the traditional COBOL dynamic call.
The link step creates an executable DLL module. It is required to link the object file with the following two DLL side files:
libjvm.x, which is provided with your IBM Java SDK
igzcjava.x, which is provided in the lib/ subdirectory of the COBOL directory in the HFS. The typical complete path is
This DLL side file is also available as the member IGZCJAVA in the SCEELIB PDS (part of Language Environment).
If the application starts with a Java program or the main factory method of a COBOL class, the XPLINK environment is automatically started by the java command that starts the JVM and runs the application.
If an application starts with a COBOL program that invokes methods on COBOL or Java classes, you must specify the XPLINK(ON) runtime option so that the XPLINK environment is initialized. XPLINK(ON) is not recommended as a default setting. Use XPLINK(ON) only for applications that specifically require it.
In older versions of COBOL, using the COPY statement required the compiler option ‘lib’. This option is not required in Enterprise COBOL v5 and up, and it is always in effect.
For more information, see “Compiling, linking, and running OO applications” in the Enterprise COBOL for z/OS Programming Guide.
Java and COBOL under z/OS UNIX
When you compile, link, and run OO applications in a z/OS UNIX environment, application components reside in the HFS. The compilation and linking is done using z/OS UNIX shell commands, and application is launched via a shell command prompt or with the BPXBATCH utility from JCL or TSO/E.
For compilation use:
cob2 -c -qdll,thread
For linking use:
-bdll option specifies that the executable module is to be a DLL. In addition:
- The COBOL compiler uses the compiler options DLL, EXPORTALL, and RENT, which are required for DLLs.
- The link step produces a DLL definition side file that contains IMPORT control statements for each of the names exported by the DLL.
You need to specify the include subdirectory of the
JNI.cpy by using the
-I option of the cob2 command or by setting the SYSLIB environment variable. The
JNI.cpy resides under the
include subdirectory of the COBOL installation directory (typically,