How to pass structure field arrays

You can pass a structure field array to a called program. You must follow a special convention in both the call statement and in the parameter list of the called program.
For example, consider the following Record part:
Record MyRecordPart type basicRecord
   10 myInt INT[5];
   10 myChar CHAR(1);
end
Here is a record declaration:
myRecord MyRecordPart;
If you are calling the MyProgram program and need to pass the structure field array rather than a single element or the whole record, one task is to code the call statement as follows:
call MyProgram( myRecord.myInt[*] );

The bracketed asterisk ([*]) means “treat the preceding variable as a structure field array.” If you specify myRecord.myInt, without the brackets, the program receives only the first element in the array, as if you coded myRecord.myInt[1].

A second task is to define the parameter list in the program itself:
Program MyProgram type BasicProgram ( myInt INT[5]! )
   
end

The exclamation point indicates that the preceding variable is a structure field array rather than a dynamic array that can be re-sized in the called program. The array size and exclamation point are required after each array dimension.

If you use the conventions described here, the call might be slower than would be the case if you passed the entire record. For example, consider a record that is based on the following Record part:
Record X type BasicRecord
	10 myChar CHAR(4)[2];
		20 mySubChar01 char(2);
		20 mySubChar02 char(2);
end

When you pass mySubChar01 or mySubChar02 array, the fields are passed in a contiguous block of memory even though the fields are not stored contiguously. The data must be copied, and the extra processing takes time.

In general, the performance issue occurs in the following case:

For details on how multidimensional structure field arrays are stored, see “Arrays.”


Feedback