Problem:
A Java application is trying to call a COBOL program, which does nothing except throw out some displays. The code in the Java is extracted from the MF examples:
private void callInterface() {
int retcode;
Object[] params = {record};
try {
retcode = runtime.cobcall("TESTCALL", params);
} catch (Exception e) {
e.printStackTrace();
}
}
"record" implements "DataType" as required.
When executing this (as a JUnit test within Eclipse), this gives a CobolException - program not found. The COBOL dll is in a folder on the path, the folder is on the classpath, and has also been placed in the MF/bin folder, but the cobcall() method can't find it.
Resolution:
In this case, the Program Not Found error is occurring because the COBOL program .DLL was not linked with the multi-threaded run-time system.
When working in a Java environment, all COBOL programs MUST be linked to the multi-threaded COBOL run-time system. This is documented in the Distributed Computing manual under the section for Java calling COBOL.
If the programs are in a Net Express project, you can select Project>Build Settings from the IDE menu, select your .DLL in the file list and click on the Link tab. Select the options for Shared and Multi-threaded. You can also select Dynamic if you wish for the COBOL run-time system to be located at run-time by using the settings in the Registry created when installing Net Express, Application Server or Enterprise Server.
If you are compiling and linking from the command line without a project you can use the following options for the cbllink command.
cbllink -d -fm testprog.cbl // to create a .dll using the shared multi-threaded run-time
or
cbllink -d -rm testprog.cbl // to create a .dll using the dynamic shared multi-threaded run-time