Page 1 of 1

Start Loop Activity Stage - want to source a parmfile.txt

Posted: Tue Jan 17, 2006 1:10 pm
by lpadrta
I'm working on a JobSequencer that calls a server job inside a loop. It's possible to use the Start_Loop_Activity stage to pass delimited parameter values to a server job inside a loop, one for each trip through the loop. But I want to get the parameters from a text file.

I've tried to do this in the GUI designer, but I can't seem to figure out how to do it. I've tried giving the path and file to the Start_Loop_Activity stage, along with a carriage return/newline delimiter, but I haven't been able to make it work. So I'll probably just code this.

Has anybody come across a way to get the Start_Loop_Activity stage to source a set of parameters directly from a text file?

For example, here's what I would put in a text file:
Row1 - Parameter1_value, Parameter2_value
Row2 - Parameter1_value, Parameter2_value
Row3 - Parameter1_value, Parameter2_value

Thanks,
Lynda

Posted: Tue Jan 17, 2006 3:48 pm
by ray.wurlod
Assuming that there aren't too many lines in the file, you could read the entire file into an array, or a delimited string, using a Routine activity, then use something like a Field() function to extract the appropriate line number. Make use of the fact that DataStage BASIC translates line terminator characters into field marks (@FM).

Code: Select all

FUNCTION ReadFile(Pathname)
* Returns contents of file as @FM-delimited string
Ans = ""

* Decompose pathname into directory and entry name portions
Call !GET.PATHNAME(Pathname, Directory, EntryName, Status)

* Open directory as if it were a table
OpenPath Directory To Dir.fvar
Then

   * Read entire file as if it were a record in a table
   Read Ans From Dir.fvar, EntryName
   Else
      Ans = ""  ; * file does not exist
   End

   Close Dir.fvar  ; * file no longer needed - free file handle

End  ; * end of OpenPath statement

RETURN(Ans)
Line number N from this file is obtained with the expression

Code: Select all

Field(RoutineActivity.$ReturnValue, @FM, N, 1)
Note that this technique does not work in versions earlier than 7.5, in which expressions become available in derivations.

Posted: Tue Jan 17, 2006 4:34 pm
by lpadrta
Thanks for the help, Ray! Seems there is always a way to do what you want in DataStage, or even more than one way.

I'll give it a try tomorrow after I've had a little beauty sleep.

Lynda