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
How to identify array length in Basic
Moderators: chulett, rschirm, roy
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:
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:
If you would rather return it as a delimited string, do 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:
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
Code: Select all
1@AM2@AM3@AM4@AM (where @AM is ASCII CHAR 254)
Code: Select all
CONVERT @AM TO "|" IN A
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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).
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.
Code: Select all
Dimension Rainfall(3,12)
Print INMAT(Rainfall) ; * prints 3}12
Dimension ColumnCollection(8)
Print INMAT(ColumnCollection) ; * prints 1}8
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.