Java オブジェクト内のデータ メンバーの変更

制約事項: 次の説明はネイティブ コードのみに該当します。

ここでの例は前項の例に似ていますが、COBOL プログラムから返される値を使用して、Java オブジェクト内のデータ メンバーの 1 つの値を変更しています。

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
                         wsResult.
    evaluate wsOperation
    when "a"
        add wsOperand1 to wsOperand2
    when "s"
        subtract wsOperand1 from wsOperand2
    end-evaluate
    exit program returning wsResult

この Java クラス SimpleCall2 は、legacy2.cbllegacy2.ext というライブラリ ファイルに組み込まれていることを前提としています。このサブルーチンが別のライブラリ ファイルに組み込まれている場合には、legacy2 プログラムを呼び出す前に RuntimeSystem.cobload() メソッドを使用して、そのライブラリ ファイルをロードする必要があります。

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,
                             firstDemo.simpleInteger2,
                             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) ;
   }
}