Getting and Setting Array Elements

You set array elements using the CJAVA-SETARRAYELEMENT op-code and passing in an array handle, the position in the array to set, and the value to set. In the following example, the first element of an array is set with the first value from an integer table that is USAGE IS SIGNED-INT OCCURS 10.

CALL "C$JAVA" USING CJAVA-SETARRAYELEMENT, ARRAY-HANDLE, 1, INT-TABLE(1), GIVING STATUS-VAL.

Getting array elements is done using a similar syntax with the op-code CJAVA-GETARRAYELEMENT. This call requires an array handle, the position in the array to get, and the variable into which the array value will be placed. Here is an example:

CALL "C$JAVA" USING CJAVA-GETARRAYELEMENT, ARRAY-HANDLE, 5, INT-TABLE(1), GIVING STATUS-VAL.

In this case, we are getting element 5 from the array and placing it in the first element of an integer table.