HOw to create arrays in datastage basic routines

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
mahi_mahi
Charter Member
Charter Member
Posts: 45
Joined: Mon Aug 01, 2005 10:02 am

HOw to create arrays in datastage basic routines

Post by mahi_mahi »

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
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

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.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

The fastest way to read a file into an array is like this:

Code: Select all

UNIXcmd="cat /here/there/yourfile"
Call Execute("UNIX", UNIXcmd, ScreenOutput, ReturnCode)
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:

Code: Select all

LineCount=DCOUNT(ScreenOutput, @AM)
To loop thru the lines, use dynamic notation:

Code: Select all

For i=1 to LineCount
   Line = ScreenOutput<i>
   ...
   ...
   ...
Next i
To dynamically build an array, use the <-1> appending logic:

Code: Select all

Arr=""
Arr<-1>="line1"
Arr<-1>="line2"
Arr<-1>="line3"
Arr<-1>="line4"
To dynamically build a 2-D array, use @VM to separate values:

Code: Select all

Arr=""
Arr<-1>="line1":@VM:"multivalue1"
Arr<-1>="line2":@VM:"multivalue2"
Arr<-1>="line3":@VM:"multivalue3"
Arr<-1>="line4":@VM:"multivalue4"
To count the values in an array element (called an attribute):

Code: Select all

VMCount=DCOUNT(Arr<3>, @VM)
To loop thru the values in an attribute:

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
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Ken

Edit your post and change @FM to @VM.
Mamu Kim
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You mean the @AM to @FM in the first quote :)
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Okay, I just freehanded the junk, F and V are close together on the keyboard. :oops:
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
Post Reply