skip to main content

Calling isCOBOL from Java : The EasyLinkage feature

The EasyLinkage feature
The isCOBOL Compiler can generate bridge classes that a Java program can use to easily call your COBOL programs. These bridge classes include an object for each Linkage Section data item; such object allows to set and inquire the data item value. The bridge class provides a method named run() that allows to call the COBOL program.
Note that only standard COBOL programs identified by a PROGRAM-ID can be called through EasyLinkage. It’s not possible to call COBOL objects that are identified by a CLASS-ID.
In order to make the Compiler generate bridge classes, the EasyLinkage feature must be activated through the following configuration setting:
See Properties for the EasyLinkage feature for all the configuration settings that affect the EasyLinkage feature.
EasyLinkage and its settings can also be set directly in the source code through the SET Directive.
The generated bridge class is produced according to the current compiler options. For example, if the -od option is used on the command line, then the bridge classes will be generated in the folder specified by such option; if the -jj option is used on the command line, then the Java source of the bridge program will be left on disc; and so on.
Let’s analyze a small practical example.
Consider the following COBOL program:
       program-id. prog1.
       linkage section.
       77 p1 pic 9.
       procedure division using p1.
           add 1 to p1.
The EasyLinkage feature, run with default settings, generates a bridge class named linkPROG1 that includes an object named p1.
The following Java program calls PROG1 through the bridge class by passing the p1 parameter set to 1 and expecting it set to 2 when PROG1 returns.
public class test {
   public static void main (String[] args) throws Exception {
     //create an instance of linkPROG1
      //set the p1 parameter to 1
      //do the call
      //check if p1 was incremented by 1
      if (prog1.p1.toint() == 2) System.out.print("OK");
Note that the COBOL program uses the GOBACK statement in order to return to the calling Java program. If STOP RUN is used instead the whole JVM terminates.
If the COBOL program includes entry points, the Java program can call each entry point as a separate function. However, it’s important to call the main program first, like you would do with a caller COBOL program, otherwise the entry points are not available.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left