Getting Started with TRANSACT (32247-90007)

Chapter 8 127
Special Topics
Arrays
Lines 2.1 through 4 define the part number array and the individual items within the
array that we need to access. Line 2.1 defines the array to contain 20 occurrences of 8 bytes
each. Lines 2.2 through 4 define individual items within the array that we will use for
storing, retrieving, and comparing.
The verbs used for IMAGE access cannot refer to subscripted items. The items must be
parent items. Thus, line 23 retrieves the next part-number from the database. If we have
not reached the end of the dataset, line 25.1 moves the part-number retrieved into the next
array occurrence of part-table. Notice the double set of parentheses around the item count.
The innermost set denotes that we are subscripting a reference to each-part. The next set
denotes that we are using an item named count to contain the array occurrence to be
accessed.
Using a fixed data structure rather than a dynamic data structure allows us to delete
several lines of code that were needed to manipulate the dynamic data structure. These
lines are identified as <<deleted>> throughout the example.
The balance of the example is very similar to the dynamic data structure implementation
of the bubble sort problem. However, there is one other area of the example worth
mentioning. Notice that line 4 defines to-part to start in the ninth byte of the part-table
array. This differs from the definition of from-part which starts in the first byte of the
part-table array (line 3). This allows us to access two different occurrences of part-number
in the array using the same subscript value, as is illustrated in lines 58-64. For example, if
count has the value 1, then using from-part references the first part-number in the array
and using to-part references the second part-number in the array.
Sometimes one-dimensional arrays contain multiple occurrences of more than one item.
The following example illustrates this.