REDIM

# REDIM

Resizes a dynamic array

 Category: Array

## Syntax

 rc=REDIM(array,dim1<,dim2<,dim3....<,dimN>...>>);

rc
indicates whether the operation was successful.
 0 successful 0 not successful

Type: Numeric

array
is the dynamic array to be resized. A non-dynamic array causes an error condition.

Type: Array

dim1...dimN
is the size of each specified dimension. If you specify negative sizes or an invalid number of dimensions, an error condition occurs.

Type: Numeric

You can use the REDIM function to resize a dynamic array. You cannot change the numbers of dimensions or type of the array, only the bounds. The REDIM function will preserve the data in the array. However, if you resize the array to a smaller size, you will lose the data in the eliminated elements. There is no limit to the number of times that you can resize an array.

### Example 1: Create an Array and Resize It Preserving the Data

The example creates a one-dimensional array of 5 elements and resizes it, preserving the data, to 10 elements.

```DCL num a(*);
rc = makearray(a,3);
do i=1 to dim(a);
a[i]=i;
end;
rc = redim(a,5);
put a=;
rc=delarray(a);```

The output would be:

```a=
a[1]=1
a[2]=2
a[3]=3
a[4]=.
a[5]=.```

### Example 2: Create an Array and Resize it Without Preserving the Data

The example creates a two-dimensional 5x5 array, resizes it to a 10x10 array and does not preserve the data.

```DCL num a(*);
rc = makearray(a,3);
do i=1 to dim(a);
a[i]=i;
end;
rc = makearray(a,5);
put a=;
rc = delarray(a);```

The output would be:

```a=
a[1]=.
a[2]=.
a[3]=.
a[4]=.
a[5]=.```