+

Search Tips   |   Advanced Search

COBOL call stub Java class usage example

The COBOL call stub Java class usage example shows how a batch application can invoke a COBOL procedure using the COBOL container.

In the example, the events take place in the following order:

  1. The COBOL container is created.

  2. The COBOL procedure call stub is created.

  3. The parameter data is set into the COBOL procedure call stub.

  4. A shared DB2 connection is set on the container.

  5. The COBOL procedure is invoked using the 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) {

}


Related concepts

  • COBOL container overview


    Related tasks

  • Develop COBOL container batch applications
  • Create a COBOL call stub Java class
  • Compiling COBOL call stub Java classes
  • Dynamically updating a COBOL module
  • Generating COBOL call stubs