Hi All,
I would like use array concept in basic routine for my requirement.
in basic routine i need to open a file and read record by record and based
on condition i need to build an array
i tried with using metaread but i could not scucceed please let me know
the correct command to use to build an array in routine by reading a file
Mahi
HOw to create arrays in datastage basic routines
Moderators: chulett, rschirm, roy
You have 2 types of arrays in DataStage BASIC - static and dynamic. The static arrays are one or two dimensions and declared as DIM MyArray({Ycols},{Ycols}). The other type are dynamic arrays and they are not limited in either total length or number of dimensions by DS.
Dynamic arrays are very powerful but a bit tricky to get an understanding of, since they are in effect just long strings with delimiters. The builtin delimiters such as @FM, @VM, @SM, @TM (field, value, subvalue and text marks) are not the only ones that can be used. The DS/Basic manual details how these dynamic arrays can be worked with in some detail.
Dynamic arrays are very powerful but a bit tricky to get an understanding of, since they are in effect just long strings with delimiters. The builtin delimiters such as @FM, @VM, @SM, @TM (field, value, subvalue and text marks) are not the only ones that can be used. The DS/Basic manual details how these dynamic arrays can be worked with in some detail.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
The fastest way to read a file into an array is like this:
The screen output of the command is return in a dynamic array variable called ScreenOutput.
To get the number of lines in the dynamic array, count them:
To loop thru the lines, use dynamic notation:
To dynamically build an array, use the <-1> appending logic:
To dynamically build a 2-D array, use @VM to separate values:
To count the values in an array element (called an attribute):
To loop thru the values in an attribute:
Code: Select all
UNIXcmd="cat /here/there/yourfile"
Call Execute("UNIX", UNIXcmd, ScreenOutput, ReturnCode)
To get the number of lines in the dynamic array, count them:
Code: Select all
LineCount=DCOUNT(ScreenOutput, @AM)
Code: Select all
For i=1 to LineCount
Line = ScreenOutput<i>
...
...
...
Next i
Code: Select all
Arr=""
Arr<-1>="line1"
Arr<-1>="line2"
Arr<-1>="line3"
Arr<-1>="line4"
Code: Select all
Arr=""
Arr<-1>="line1":@VM:"multivalue1"
Arr<-1>="line2":@VM:"multivalue2"
Arr<-1>="line3":@VM:"multivalue3"
Arr<-1>="line4":@VM:"multivalue4"
Code: Select all
VMCount=DCOUNT(Arr<3>, @VM)
Code: Select all
For j=1 To VMCount
MultiValue=Arr<3,j>
...
...
...
Next j
Last edited by kcbland on Fri Apr 28, 2006 9:32 am, edited 1 time in total.
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
You mean the @AM to @FM in the first quote
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>