To call COBOL from Java using the CVM, perform the following steps:
- Install and correctly configure the ACUCOBOL-GT runtime. Optionally, install AcuBench® if the system will also be used for
COBOL development.
- Install and correctly configure a Java Runtime Environment (JRE) Version 1.4.2 or later. Optionally, install a J2SE Software
Developer's Kit (SDK) if the same system will also be used for Java development.
- Place the path to the JRE /bin directory in the PATH environment variable. Here is an example:
PATH =D:/j2sdk1.4.2_04/bin.
If the ACUCOBOL-GT installation directory is not the current directory, then that directory should also be placed on the path.
The runtime path must be correctly configured so that a call to LoadLibrary("wrun32.dll") or loading the shared library "libruncbl.so"
succeeds.
- Place the path to "CVM.jar" in the CLASSPATH environment variable. Also ensure that the class or JAR (Java Archive) file that
contains the declaration of main is included in the classpath. For JAR files, include the filenames in the classpath. For
class files, include the directory where the class files reside. Here is a Windows example:
CLASSPATH=d:\cobol7\bin\acuUtilities.jar;d:\cobol7\bin\CVM.jar;c:\cobol7\JavaProject
For UNIX platforms, use a colon as a delimiter instead of a semicolon.
- Add the location of the runtime DLLs and shared libraries to the variable LD_LIBRARY_PATH. For example, on Windows:
LD_LIBRARY_PATH=C:\Program Files\Acucorp\Acucbl900\AcuGT\bin
On UNIX or Linux, the shared libraries are located in /AcuGT/lib.
- Do one of the following:
- Place a copy of the COBOL program to be called in the same directory as the ACUCOBOL-GT runtime. This would be the compiled
".acu" file that contains the COBOL program.
- Pass the fully qualified filename of the COBOL program to be called to the runtime.
- Use a configuration variable to identify the location of the COBOL program.
- Ensure that all configuration options located in the configuration file are set up correctly. This includes the location of
the JRE, preloading the JVM, and the command line that will be passed to the JVM.
- The Java class being used to call COBOL must provide a main function such as this:
public static void main(String[] args)
- The Java program calling COBOL must include an import statement that imports the ACUCOBOL-GT Java class that is used. Here
is an example:
import com.acucorp.acucobolgt.*;
- The Java program calling COBOL must declare two objects: one of type CVM and one of type CALL_OPTIONS. The following is sample
Java code that shows how to call a COBOL program, passing two parameters, using the "CVM.class":
CVM cvm = CVM.GET_INSTANCE();
cvm.setErrorsOut("/tmp/errfile");
cvm.setConfigFile("c:/myproject/config");
cvm.initialize();
CALL_OPTIONS co = new CALL_OPTIONS();
co.setOption("debug_method", "1");
Object objInt = new Integer(1);
Object objString = new String("Test String Parameter");
Object params[] = {
objInt,
objString
};
cvm.callProgram("TestJavaToCobol", params, co);
cvm.cancelProgram("TestJavaToCobol");
cvm.shutdown();
- The COBOL program being called must provide a Linkage Section that matches the order and type of the Java parameters passed
in the Java Object array. This is done by the COBOL programmer. Here is an example of a Linkage Section that does this for
the above program:
linkage section.
77 test-integer-parameter usage is signed-int.
77 test-string-parameter pic x(21) value spaces.