Dynamic Arrays

Dynamic arrays map the structure of InfoSphere® DataStage® file records to character string data. Any character string can be a dynamic array. A dynamic array is a character string containing elements that are substrings separated by delimiters. At the highest level these elements are fields separated by field marks ( F ) (ASCII 254). Each field can contain values separated by value marks ( V ) (ASCII 253). Each value can contain subvalues separated by subvalue marks ( S ) (ASCII 252).

A common use of dynamic arrays is to store data that is either read in from or written out to an InfoSphere DataStage file record. However, InfoSphere DataStage BASIC includes facilities for manipulating dynamic array elements that make dynamic arrays a powerful data type for processing hierarchical information independently of InfoSphere DataStage files.

The number of fields, values, or subvalues in a dynamic array is limited only by the amount of available memory. Fields, values, and subvalues containing the empty string are represented by two consecutive field marks, value marks, or subvalue marks, respectively.

The following character string is a dynamic array with two fields:

TOMSDICKSHARRYVBETTYSSUESMARYFJONESVSMITH

The two fields are:

TOMSDICKSHARRYVBETTYSSUESMARY

and:

JONESVSMITH

Conceptually, this dynamic array has an infinite number of fields, all of which are empty except the first two. References made to the third or fourth field, for example, return an empty string.

The first field has two values:

TOMSDICKSHARRY

and:

BETTYSSUESMARY

The first value has three subvalues: TOM, DICK, and HARRY. The second value also has three subvalues: BETTY, SUE, and MARY.

The second field has two values: JONES and SMITH. Each value has one subvalue: JONES and SMITH.

The following character string:

NAME AND ADDRESS

can be considered a dynamic array containing one field, which has one value, which has one subvalue, all of which are: NAME AND ADDRESS.

The following character string can be considered a dynamic array containing two fields:

JONESVSMITHVBROWNF$1.23VV$2.75

The first field has three values: JONES, SMITH, and BROWN. The second field has three values: $1.23, an empty string, and $2.75

Intrinsic functions and operators allow individual subvalues, values, and fields to be accessed, changed, added, and removed.

You can create a dynamic array in two ways: by treating it as a concatenation of its fields, values, and subvalues; or by enclosing the elements of the dynamic array in angle brackets, using the syntax:

array.name < field# , value# , subvalue# >

For example, to create the dynamic array A as:

JONESVSMITHF1.23S20V2.50S10

you can say:

A="JONES":@VM:"SMITH":@FM:1.23:@SM:20:@VM:2.50:@SM:10

or you can say:

A = ""
A<1,1> = "JONES"
A<1,2> = "SMITH"
A<2,1,1> = 1.23
A<2,1,2> = 20
A<2,2,1> = 2.50
A<2,2,2> = 10

The example has two fields. The first field has two values, and the second field has two values. The first value of the second field has two subvalues, and the second value of the second field also has two subvalues.

You must use the following statements to declare that the first field contains the two values JONES and SMITH:

A = ""
A<1,1> = "JONES"
A<1,2> = "SMITH"

The statement:

A = ""
A<1> = "JONES"

declares that the first field contains only JONES with no other values or subvalues. Similarly, the statement:

A<2,1> = 1.23

declares that the first value of the second field is 1.23 with no subvalues. The statements:

A<2,2,1> = 2.50
A<2,2,2> = 10

declare that the second value of the second field has two subvalues, 2.50 and 10, respectively.