This example demonstrates how an object-oriented COBOL application invokes a Java program on UNIX System Services (USS).

For COBOL applications calling Java, you need the LIBPATH to point to the path for the Java libraries.

LIBPATH=/usr/lpp/java/IBM/J7.1/bin/classic:$LIBPATH

Also, use the _CEE_RUNOPTS environment variable to set the XPLINK(ON) option :

_CEE_RUNOPTS="XPLINK(ON)"

Exporting _CEE_RUNOPTS=”XPLINK(ON)” so that it is in effect for the entire z/OS UNIX shell session is not recommended, however. Suppose for example that an OO COBOL application starts with a COBOL program called App1. One way to limit the effect of the XPLINK option to the execution of the App1 application is to set the _CEE_RUNOPTS variable on the command-line invocation of App1Driver as follows:

_CEE_RUNOPTS="XPLINK(ON)" App1

The following example demonstrates how an OO COBOL application invokes a Java program by using INVOKE.

The COBOL program is compiled and linked as follows, where a typical installation path for COBOL is /usr/lpp/cobol and a typical installation path for Java is /usr/lpp/java. Replace with your own paths for your environment.

/usr/lpp/cobol/bin/cob2 -c -qthread,dll helloTest.cbl
/usr/lpp/cobol/bin/cob2 -bdll helloTest.cbl -o hello /usr/lpp/java/IBM/J7.1/bin/j9vm/libjvm.x /usr/lpp/cobol/lib/igzcjava.x -I /usr/lpp/cobol/include

helloTest.cbl

Process thread,pgmname(longmixed)
IDENTIFICATION DIVISION.
PROGRAM-ID. "HELLOWORLD" is recursive.
*
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. RM-COBOL.
OBJECT-COMPUTER. RM-COBOL.
       
Repository.
    Class HelloJ is "HelloJ".
DATA DIVISION.
FILE SECTION.
       
PROCEDURE DIVISION.
       
MAIN-LOGIC SECTION.
BEGIN.
    DISPLAY " " .
    INVOKE HelloJ "sayHello".
    DISPLAY "Hello world!".
    STOP RUN.
MAIN-LOGIC-EXIT.
    EXIT.

The following HelloJ.java program is compiled and exported by using the following commands in USS:

/usr/lpp/java/IBM/J7.1/bin/javac HelloJ.java

export _CEE_RUNOPTS="XPLINK(ON)"
export LIBPATH=/usr/lpp/java/IBM/J7.1/bin:/usr/lpp/java/IBM/J7.1/bin/classic:$LIBPATH
export CLASSPATH=:$CLASSPATH

HelloJ.java

class HelloJ {
   public static void sayHello() {
     System.out.println("Hello World, from Java!");
   }
}

Join The Discussion

Your email address will not be published. Required fields are marked *