Page 1 of 1

Using Locate Statement

Posted: Tue Feb 10, 2009 12:28 am
by DS_SUPPORT
Hi All,

I am building a dynamic array, by reading a flatfile. My Flatfile will have the values like

Code: Select all

JOB1,Y,N
JOB2,N,N
JOB3,Y,Y
So i am building the dynamic array (JOBLIST) also in the same manner.
So my dynamic array will look like

Code: Select all

JOB1,Y,N:@AM:
JOB2,N,N:@AM:
JOB3,Y,Y:@AM:
And inside the jobcontrol, i am reading the job names from DS_JOBS, so based on the jobname, i need to fetch the corresponding settings. So when i read the name JOB1 from DS_JOBS , i need the retrive the values Y,N from the dynamic array.

So I am using Locate statement, as it will be Very fater than For ... Next loop, and i can avoid running loop for every job.

I am using the Locate Statement like

Code: Select all

Locate JobName IN JOBLIST Setting POS Then
                  JobSettings = Field(JOBLIST<POS>,",",2,2)
               End Else
                  JobSettings = ""
               End

Here JobName will contain the value from DS_JOBS. The above Locate is not working because the actual string in the dynamic array looks like "JOB1,Y,N", where as i am searching the dynamic array only with a part of String. (with JOB1 alone). It is guranteed that each job will have a single row in the dynamic array.

How to achieve this with the Locate Statement itself?
Or is there I can change while building the dynamic array itself, because i am creating the dynamic array.

Posted: Tue Feb 10, 2009 4:46 am
by ray.wurlod
LOCATE will not do a partial string search. You need the FINDSTR statement. By the way, if you OPEN the directory and READ the entire file in a single read statement, you will automatically have your dynamic array.

Posted: Tue Feb 10, 2009 11:07 am
by DS_SUPPORT
Thanks for the information Ray, I will try that tomorrow. BTW how to read the entire file in a READ statement, in the help i am seeing only READSEQ statement.

Posted: Tue Feb 10, 2009 2:09 pm
by ray.wurlod
Look in the DataStage BASIC manual.

DataStage BASIC can treat a directory as if it were a "table", with the file names in the directory being the "record keys" and the actual files being the "records". In this sense, after you use OPEN or OPENPATH to open the parent directory, a READ of a file yields a field-mark delimited dynamic array.

Posted: Tue Feb 10, 2009 9:24 pm
by DS_SUPPORT
Thanks, I resolved it by using FINDSTR.