Chapter Contents

Previous

Next
SAS Component Language: Reference

Passing Dynamic Arrays to Methods

Passing a dynamic array to a method is no different than passing a static array, but the dynamic array must have been created by MAKEARRAY, REDIM, COPYARRAY, or an assignment statement. If the dynamic array is not created before the method call, then an error condition will occur.

Dynamic arrays can be resized via a method if the method's parameter is a reference array and an output parameter. See ARRAY for more information on reference arrays.

Suppose you have defined the resizeDynamicArray method as follows:

resizeDynamicArray:method parm1[*]:O:num;
declare num rc = redim(parm1, 5);
endmethod;
The parameter PARM1 is output parameter and a reference array. When you call this method, it will resize the dynamic array passed to it into an array with a low bound 1 and a high bound of 5. In the following code, resizeDynamicArray resizes an array with 3 elements into an array with 5 elements:
declare num a[*] = MAKEARRAY(3);
object.resizeDynamicArray(a);
put a;
The output for this code would be:
a[1] = .
a[2] = .
a[3] = .
a[4] = .
a[5] = .
Because PARM1 is a reference array, it is using the same memory as the dynamic array A.

You can now resize the array using MAKEARRAY, REDIM, COPYARRAY, DELARRAY, or an assignment statement.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.