Problem:
Release: 3.1 When you invoke the putElement method on the SafeArray object you pass it an array which contains the same number of elements as there dimensions in the SafeArray.
So when you have a 2 dimensional SafeArray like the example in the book you need to pass it an array containing the position for the first dimension of the table and the second dimension of the table.
Resolution:
The iIndex array that you are passing will contain the following each time putElement is called:
iIndex (1) = 0
iIndex (2) = 0
iIndex (1) = 0
iIndex (2) = 1
iIndex (1) = 0
iIndex (2) = 2
iIndex (1) = 1
iIndex (2) = 0
iIndex (1) = 1
iIndex (2) = 1
iIndex (1) = 1
iIndex (2) = 2
iIndex (1) = 2
iIndex (2) = 0
etc.
The iIndex(1) is passed to the method because the address of the first element is actually the same as a pointer to the table itself. It would be the same as if you specified:
01 TheTable.
05 iIndex pic x(4) comp-5 occurs 2.
and passing TheTable as the parameter to the method instead of iIndex(1)
The putElement method expects a table of indices so if it knows the beginning address of the table then it can calculate the other offsets from this.