How to identify array length in Basic

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
girishoak
Participant
Posts: 65
Joined: Wed Oct 29, 2003 3:54 am

How to identify array length in Basic

Post by girishoak »

Hi,

I want to find out the length of an array is their any way to find out the array length in Basic. Is there anything like Ubound?

Also wanted to know can I return an array as an output of routine.
and how to read this array.

Thanks in advance

Girish Oak
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

A dynamic array is a text string. Using LEN(array) will return the entire number of characters in the array, including @AM characters which delimit single dimension array elements.

So, experiment with a DS function using the following code:

Code: Select all

A=""
A<-1> = 1
A<-1> = 2
A<-1> = 3
A<-1> = 4

ElementCount = DCOUNT(A, @AM)
LengthOfA = LEN(A)
Ans = "Element Count ":ElementCount:" Length of A ":LengthOfA
Yes, you can return an array. Use the above experiment and you'll see that A is passed back as array. You will have to be aware that it will look like:

Code: Select all

1@AM2@AM3@AM4@AM  (where @AM is ASCII CHAR 254)
If you would rather return it as a delimited string, do a:

Code: Select all

CONVERT @AM TO "|" IN A
This replaces the @AM characters with a pipe, effectively making it a pipe delimited array. Also, you can reverse a delimited string an array using:

Code: Select all

CONVERT "|" TO @AM IN A
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The size of a dimensioned array is returned by the INMAT() function in DataStage BASIC. This returns two values (the extents of each of the two dimensions) separated by a value mark (@VM).

Code: Select all

Dimension Rainfall(3,12)
Print INMAT(Rainfall)   ; * prints 3}12
Dimension ColumnCollection(8)
Print INMAT(ColumnCollection)   ; * prints 1}8
Dynamic arrays can be converted to dimensioned arrays using the MATPARSE statement.
Dimensioned arrays can be converted to dynamic arrays using the MATBUILD statement.
You should rarely, if ever, need either of these statements in DataStage BASIC.

As Ken said, the number of elements at a particular level (fields, values or sub-values) can be obtained using the DCOUNT() function. Where you have more than one kind of delimiter this is a bit trickier - it depends on exactly what it is you want to know.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply