The COBOL call stub Java class usage example shows how a batch application can invoke a COBOL procedure using the COBOL container.
Steps 1, 2 and 5 are the minimum steps required to invoke a COBOL procedure using the container. Steps 3 and 4 are optional. Step 3 is necessary only if the COBOL procedure receives parameters, and step 4 is necessary only if the COBOL procedure accesses DB2.
import com.ibm.websphere.batch.ilc.ILContainerFactory;
import com.ibm.websphere.batch.ilc.ILContainer;
import com.ibm.websphere.batch.ilc.ILContainerException;
import com.ibm.websphere.batch.ilc.ILProcedureException;
import com.ibm.ws.batch.ilc.sample.Sample;
import com.ibm.ws.batch.ilc.sample.parameters.SampleDataBinding;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import java.sql.Connection;
try {
// Create the container.
ILContainer container = ILContainerFactory.getFactory().create();
// Create target procedure using call stub.
Sample proc = new Sample();
// Set parameters.
SampleDataBinding binding = proc.getSampleDataBinding();
binding.setCDummy("foo");
binding.setIlen((short)employeeNumber);
// Set db2 connection for use by COBOL (if necessary).
// InitialContext ic = new InitialContext();
// DataSource datasourceType2 = (DataSource) ic.lookup(jdbcJndi);
// Connection connectionType2 = datasourceType2.getConnection();
// container.setDB2Connection(connectionType2);
// Invoke the COBOL procedure.
int rc = container.invokeProcedure(proc);
}
catch (ILProcedureException) {
…
}
catch (ILContainerException) {
…
}