jarray クラスは、オブジェクト指向 COBOL で Java 配列を操作するためのラッパーです。詳細についてはは、COBOL 開発ステム インストールの help\mfcobol.docs.zip (Windows) or docs/mfcobol.docs.zip (UNIX) にある「Java Run-time Class Library Reference」を参照してください。
次の COBOL プログラムは Java オブジェクトから配列を受け取り、次元を検出して、配列の内容を表示します。
$set ooctrl(+p-f) Program-id. ReadArray. class-control. arraydemo is class "$Java$arraydemo" . thread-local-storage section. 01 aJavaObj object reference. 01 theTotal pic 9(9). 01 CDims pic x(4) comp-5. 01 Dims. 03 Dims-entry pic x(4) comp-5 occurs 256. 01 Bounds. 03 Bounds-entry pic x(4) comp-5 occurs 256. 01 ind0 pic x(4) comp-5. 01 ind1 pic x(4) comp-5. 01 arrayElement pic x(4) comp-5. 01 wsTable object reference. 01 wsResult pic x(4) comp-5. procedure division. invoke arraydemo "new" returning aJavaObj invoke aJavaObj "getArray" returning wsTable *> find out the number of elements in the array invoke wsTable "getDimensions" returning CDims display "The array has " CDims " dimension(s)" *> get the number of elements in each dimension display "dimensions are " with no advancing invoke wsTable "getBounds" using Bounds perform varying ind0 from 1 by 1 until ind0 > CDims display Bounds-entry(ind0) with no advancing if ind0 < CDims display " by " with no advancing end-if end-perform display " " *> display each element in the array perform varying ind0 from 0 by 1 until ind0 = Bounds-entry(1) move ind0 to Dims-entry(1) perform varying ind1 from 0 by 1 until ind1 = Bounds-entry(2) move ind1 to Dims-entry(2) invoke wsTable "getElement" using by value CDims by reference Dims by reference arrayElement display "Element " ind0 "," ind1 " is " arrayElement *> modify the contents of the array add 50 to arrayElement invoke wsTable "putElement" using by value CDims by reference Dims by reference arrayElement end-perform end-perform
この ReadArray プログラムで使用される arraydemo クラスの実装を次に示します。このプログラムは2次元配列を生成します。
import com.microfocus.cobol.*; import java.io.*; public class arraydemo extends RuntimeSystem { int myArray[][]; public arraydemo() { myArray = new int[5][2]; int i,j; for (i = 0; i < 5; i++) { for (j = 0; j < 2; j++) myArray[i][j] = i * 100 + j; } } public int[][] getArray() { return myArray; } }