The example in
Figure 1 shows the C interface
DLL to use when calling COBOL.
Figure 1. Example: C interface DLL for calling
COBOL from Java/ c99 -o libc_to_cobol.so -Wc,exportall -Wl,
dll -I/usr/lpp/java/J6.0.1/include
-I/usr/lpp/java/J6.0.1/include/zos c_to_cobol.c
#include <jni.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include "com_ibm_zos_batch_container_test_Java_Calls_Cobol.h"
void (*fetch(const char *name))();
typedef void cfunc();
JNIEXPORT jint JNICALL
Java_com_ibm_zos_batch_container_test_Java_1Calls_1Cobol_CallCOBOL(JNIEnv * jenv, jobject jobj)
{
cfunc *cobfetch_ptr;
cobfetch_ptr = (cfunc *) fetch("XMPCOBJ3"); // loads fetched module
if (cobfetch_ptr == NULL){
printf("\tfetch failed\n");
}
else
{
printf("\tShould be going off to COBOL\n\n");
(*cobfetch_ptr)(); // sets up the proper linkage for the call
}
return(0);
}