Changing Data Members in a Java Object

Restriction: This applies to native code only.

The example in this section is similar to the example in the previous section, except that the result from the COBOL program is also used to change the value of one of the data members in the Java object.

thread-local-storage section.
copy "javatypes.cpy".

linkage section.
01 wsOperand1               jint.
01 wsOperand2               jint.
01 wsOperation              pic x.
01 wsResult                 jint.

procedure division using wsOperand1 wsOperand2 wsOperation
    evaluate wsOperation
    when "a"
        add wsOperand1 to wsOperand2
    when "s"
        subtract wsOperand1 from wsOperand2
    exit program returning wsResult

The Java class SimpleCall2 assumes that legacy2.cbl is built into a library file called legacy2.ext. However, if this subroutine were built into a different library file, you would need to use the RuntimeSystem.cobload() method to load the library file before making calls to the legacy program.

import com.microfocus.cobol.* ;
class SimpleCall2
   Integer simpleInteger1;
   Integer simpleInteger2;
   Integer simpleResult;
   public SimpleCall2(int a, int b)
      simpleInteger1 = new Integer(a);
      simpleInteger2 = new Integer(b);
      simpleResult   = new Integer(0);
   public String toString()
      return new String(
            "simple1Integer1 = "+simpleInteger1+"\n" +
            "simple1Integer2 = "+simpleInteger2+"\n" +
            "simpleResult    = "+simpleResult);   
   public static void main(String argv[]) throws Exception
      SimpleCall2 firstDemo = new SimpleCall2(4,7);
      Object theParams[] = { firstDemo.simpleInteger1,
                             new Byte((byte) 'a'),
                             firstDemo.simpleResult } 
      System.out.println("Before call\n"+firstDemo) ;
      int i = RuntimeSystem.cobcall_int("legacy2",theParams);
      System.out.println("After call\n"+firstDemo) ;