Vector Functions
Vector functions process lists of data rather than single values. By using the VEC.MATH (or V) option of the $OPTIONS statement, the arithmetic operators ( +, -, *, / ) can also operate on dynamic arrays as lists of data.
The operations performed by vector functions or operators are essentially the same as those performed by some standard functions or operators. The difference is that standard functions process all variables as single-valued variables, treating delimiter characters as part of the data. On the other hand, vector functions recognize delimiter characters and process each field, value, and subvalue individually. In fact, vector functions process single-valued variables as if they were dynamic arrays with only the first value defined.
Vector functions have been implemented as subroutines for compatibility with existing InfoSphere® DataStage® BASIC programs. Each subroutine is assigned a name made up of the function's name preceded by a hyphen. For example, the name of the subroutine that performs the ADDS function is -ADDS. Because the subroutines are cataloged globally, they can be accessed using the method described in the CALL statement.
The first column of Table 1 shows the functions for manipulating dynamic arrays that are available with InfoSphere DataStage BASIC. The second column shows the corresponding instructions to use for single-valued variables. In this table, m1 and m2 represent dynamic arrays; s1 and s2 represent single-valued variables; p1, p2, and so on, represent single-valued parameters. The value of the function is the resulting dynamic array.
Vector Function | Corresponding Instruction for Single-Valued Field |
---|---|
ADDS (m1, m2) | s1 + s2 |
ANDS (m1, m2) | s1 AND s2 |
CATS (m1, m2) | s1 : s2 |
CHARS (m1) | CHAR (s1) |
COUNTS (m1, p1) | COUNT (s1, p1) |
DIVS (m1, m2) | s1 / s2 |
EQS (m1, m2) | s1 EQ s2 |
ISNULLS (m1) | ISNULL (s1) |
NES (m1, m2) | s1 NE s2 |
LES (m1, m2) | s1 LE s2 |
LTS (m1, m2) | s1 LT s2 |
GES (m1, m2) | s1 GE s2 |
fGTS (m1, m2) | s1 GT s2 |
NOTS (m1) | NOT (s1) |
FIELDS (m1, p1, p2, p3) | FIELD (s1, p1, p2, p3) |
FMTS (m1, p1) | FMT (s1, p1) |
ICONVS (m1, p1) | ICONV (s1, p1) |
IFS (m1, m2, m3) | IF s1 THEN s2 ELSE s3 |
INDEXS (m1, p1, p2) | INDEX (s1, p1, p2) |
LENS (m1) | LEN (s1) |
MODS (m1, m2) | MOD (s1, s2) |
MULS (m1, m1) | s1 * s2 |
NUMS (m1) | NUM (s1) |
OCONVS (m1, p1) | OCONV (s1, p1) |
ORS (m1, m2) | s1 OR s2 |
SEQS (m1) | SEQ (s1) |
STRS (m1, p1) | STR (s1, p1) |
SPACES (m1) | SPACE (s1) |
SPLICE (m1, p1, m2) | s1 : p1 : s2 |
SUBSTRINGS (m1, p1, p2) | s1 [p1, p2] |
SUBS (m1, m1) | s1 - s2 |
TRIMS (m1) | TRIM (s1) |
When a function or operator processes two dynamic arrays, it processes the lists in parallel. In other words, the first value of field A and the first value of field B are processed together, then the second value of field A and the second value of field B are processed together, and so on.
Consider the following example:
A = 123V456S7890S2468V10F3691V33S12
B = 13V57S912F1234V8
$OPTIONS VEC.MATH
X = A + B
First, the function processing isolates the first field of each dynamic array, which can be written as:
A <1> = 123V456S7890S2468V10
B <1> = 13V57S912
Then the first values of the first fields are isolated:
A <1, 1> = 123
B <1, 1> = 13
Then the first subvalues of the first values of the first fields are isolated and added:
A <1, 1, 1> = 123
B <1, 1, 1> = 13
This produces the first subvalue of the first value of the first field of the result:
X <1, 1, 1> = 136
Since there are no more subvalues in the first value of either first field, the second values of the first fields are isolated:
A <1, 2> = 456S7890S2468
B <1, 2> = 57S912
The first subvalues of the second values of the first fields are isolated and added:
A <1, 2, 1> = 456
B <1, 2, 1> = 57
This produces the first subvalue of the second value of the first field of the result:
X <1, 2, 1> = 513
Next the subvalues:
A <1, 2, 2> = 7890
B <1, 2, 2> = 912
are isolated and added to produce:
X <1, 2, 2> = 8802
Then the subvalues:
A <1, 2, 3> = 2468
B <1, 2, 3> = ""
are isolated and added to produce:
X <1, 2, 3> = 2468
Since B <1, 2, 3> does not exist, it is equal to an empty string. In arithmetic expressions an empty string equals zero.
Since there are no more subvalues in either second value of the first fields, these values are isolated:
A <1, 3> = 10
B <1, 3> = ""
Then the subvalues:
A <1, 3, 1> = 10
B <1, 3, 1> = ""
are isolated and added to produce:
X <1, 3, 1> = 10
Since there are no more subvalues or values in either first field, the second fields of each dynamic array are isolated and the process repeats down to the subvalue levels. The second fields can be written as follows:
A <2> = 3691V33S12
B <2> = 1234V8
Then the first values of the second fields are isolated:
A <2, 1> = 3691
B <2, 1> = 1234
Then the first subvalues of the first values of the second fields are isolated and added:
A <2, 1, 1> = 3691
B <2, 1, 1> = 1234
This produces the first subvalue of the first value of the second field of the result:
X <2, 1, 1> = 4925
Then the second values of the second fields are isolated:
A <2, 2> = 33S12
B <2, 2> = 8
Then the first subvalues of the second values of the second fields are isolated and added:
A <2, 2, 1> = 33
B <2, 2, 1> = 8
This produces the first subvalue of the second value of the second field of the result:
X <2, 2, 1> = 41
Then the second subvalues of the second values of the second fields are isolated and added:
A <2, 2, 2> = 12
B <2, 2, 2> = ""
This produces the second subvalue of the second value of the second field of the result:
X <2, 2, 2> = 12
Since there are no more elements in either dynamic array, the result is:
X <1, 1, 1> = 136
X <1, 2, 1> = 513
X <1, 2, 2> = 8802
X <1, 2, 3> = 2468
X <1, 3, 1> = 10
X <2, 1, 1> = 4925
X <2, 2, 1> = 41
X <1, 2, 2> = 12
These elements are put into the resultant dynamic array, separated by the delimiter mark corresponding to the highest levels that are different (for example, X<1,1,1> and X<1,2,1> have different value levels, so they are separated by a value mark). This yields the following:
X = 136V513S8802S2468V10F4925V41S12