Note: The following applies to
JVM COBOL only.
You can use any existing COBOL program in a multiple user environment in
Java. Do this as follows:
- Create a COBOL class library project and add your procedural COBOL program to that project.
- Rebuild the project.
Note: JVM COBOL
code that uses EXEC SQL statements (including program, class, enum, and valuetype code) must exist in a managed run unit.
If the code requires a multi-user environment or a thread pool environment for proper execution, then the use of managed
run units is also recommended, but is not required provided that the code is engineered for thread safety.
Whether the COBOL program to be called is procedural or native OO COBOL, you need a program to call it:
- Create a project for the calling program.
- In the calling program, create a run unit using the
- Use the
Try ... Finally syntax to ensure that the program destroys the run unit if the program fails.
- Either use the
RunUnit.Call() method to call the COBOL class, or:
- Make sure that any parameters are Java primitive data types.
- Create an instance of the procedural COBOL program to be called.
- Add the program instance to the new run unit, using the
- Invoke the program instance within the new run unit.
- Use the
method to destroy the run unit when you have finished with it.
- If the run unit causes a run-time error, a
java.lang.RuntimeException is thrown.
- In native OO COBOL programs in a mixed language environment, do not use static methods and data as they cause run-time errors.
- Ensure that data access is synchronized, as each run unit executes in a different thread.
For details of the RunUnit class and further examples, see the