106 Java Stand-alone Applications on z/OS Volume II
In the following sections we describe how Java and COBOL can be integrated in
an easier way by using the new object-oriented syntax in IBM Enterprise COBOL
for z/OS and enhancements in the COBOL compiler.
6.4.1 IBM Enterprise COBOL for z/OS introduction
IBM Enterprise COBOL for z/OS supports the new object-oriented syntax, which
makes the integration of Java applications and COBOL programs much simpler.
The syntax is based upon the facilities of the Java Native Interface, the primary
means that Java provides for interoperating with non-Java programs.
Object-oriented COBOL enables you to define Java classes, with methods
implemented in COBOL.
For a detailed discussion of object-oriented COBOL programming, refer to
Enterprise COBOL for z/OS Programming Guide, SC27-1412, which is available
In the remainder of this section, we provide simple examples of object-oriented
COBOL programs which demonstrate interoperability of Java applications and
COBOL programs.
6.4.2 Preparing object-oriented applications under UNIX
Here we describe how integrated Java/COBOL application should be prepared in
the UNIX environment.
Compiling object-oriented applications under UNIX
When you compile object-oriented applications in a UNIX shell, use the cob2
command to compile COBOL client programs and class definitions, and the
javac command to compile Java class definitions to produce bytecode (suffix
To compile COBOL source code that contains object-oriented syntax such as
INVOKE statements or class definitions, or that uses Java services, you must
use these compiler options: RENT, DLL, THREAD, and DBCS. (The RENT and
DBCS options are defaults.)
Important: The sample programs used throughout this chapter are included
in the additional material for this IBM Redbook. See Appendix A, “Additional
material” on page 147 for details.
Chapter 6. Java Native Interface (JNI) 107
A COBOL source file that contains a class definition must not contain any other
class or program definitions.
When you compile a COBOL class definition, two output files are generated:
򐂰 The object file (.o) for the class definition.
򐂰 A Java source program (.java) that contains a class definition that
corresponds to the COBOL class definition. Do
not edit this generated Java
class definition in any way. If you change the COBOL class definition, you
must regenerate both the object file and the Java class definition by
recompiling the updated COBOL class definition.
If a COBOL client program or class definition includes the JNI.cpy file by using a
COPY statement, specify the include subdirectory of the COBOL install directory
(typically /usr/lpp/cobol/include) in the search order for copybooks. You can do
this by using the -I option of the cob2 command, or by setting the SYSLIB
environment variable.
Preparing object-oriented applications under UNIX
Use the cob2 command to link object-oriented COBOL applications.
To prepare an object-oriented COBOL client program for execution, link the
object file with the following DLL side files to create an executable module:
򐂰 libjvm.x, which is provided with your IBM Java 2 Software Development Kit.
򐂰 igzcjava.x, which is provided in the lib subdirectory of the COBOL directory in
the HFS. The typical complete path is /usr/lpp/cobol/lib/igzcjava.x. This DLL
side file is also available as member IGZCJAVA in the SCEELIB PDS (part of
Language Environment).
To prepare a COBOL class definition for execution, follow these steps
1. Link the object file using the DLL side files to create an executable DLL
You must name the resulting DLL module to libClassname.so, where
Classname is the external class-name. If the class is part of a package and
thus there are periods (.) in the external class-name, you must change the
periods to underscores (_) in the DLL module name.
For example, if class Account is part of the com.acme package, the external
class name (as defined in the REPOSITORY paragraph entry for the class)
must be com.acme.Account, and the DLL module for the class must be
2. Compile the generated Java source with the Java compiler to create a class
file (.class).

Get Java Stand-alone Applications on z/OS Volume II now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.