Page 1 of 1

problem in transversing the file

Posted: Wed Feb 14, 2007 5:34 am
by parvathi
Hi all,
I have requirement like this

I have the DSParam file in the projects folder of the datastage.

I have to get the parametervalue for a particular parameter.

I am struck with transversing the file.

The file looks like
It contains many line arranged irregularly.

and the last it has parametersyntax like this

"paramname"\1\"paramvalue

i am attaching a sample file that i am reading
***************
[functions]
Abs\1\Absolute value of any numeric expression\Mathematical\int32\int32:number\abs
.
.
[serveronly-functions]
Ascii\1\EBCDIC to ASCII string conversion\Conversion\\:string

[parallelonly-functions]
AlNum\1\Return whether the given string consists of alphanumeric characters\String\int8\anystring:string\is_alnum,u_is_alnum
.
.
.
[EnvVarDefns]
ARCHIVE_DIR\User Defined\-1\String\\0\Project\ARCHIVE_DIR\
.
.
..
[EnvVarValues]
"ARCHIVE_DIR"\1\"archive"
"xxxx"\1\"zzzz"

*******

i have traversed to the line where it is equal to " [EnvVarValues]"

After that i have to traverse further and check if the param name is "xxx"

ihave to get the its value that is ZZZ
I am struct up after getting the line as "[EnvVarValues]" how to move further


i have attached the code for looping that i have used

*********

OpenSeq ParamFile To ParamFileVar

On Error
Msg = 'Error opening parameters file, ' : SQuote(ParamFile ): ', status = ' : Status()
Call DSLogFatal(Msg, TransformName )
Abort
End
Else
Msg = 'Cannot open parameters file, ' : SQuote(ParamFile ): ', status = ' : Status()
Call DSLogFatal(Msg, TransformName )
Abort
End
Loop
While ReadSeq Line From ParamFileVar
If Trim(Line)="[EnvVarValues]" Then
Field( Trim(Line),"/",1,1)= ParamName
ParamValue = Field(Trim(Line),"/",1,2)

Repeat

********

Advice me on this

Posted: Wed Feb 14, 2007 7:17 am
by ArndW
I would use a variable to store the current section, or "state" while reading the file.

Code: Select all

   Line = TRIM(Line)
   IF Line[1,1]='[' THEN Section = Line[2,LEN(Line)-2]
Then you can put an IF-THEN construct in to check the lines if you are in the section "EnvVarValues"

Posted: Wed Feb 14, 2007 8:13 am
by DSguru2B
Wont the OP be better off doing this in a shell script? Wont it be faster? Right now she is reading each line one by one and DSParams file is not a small file. :roll:

Posted: Wed Feb 14, 2007 8:35 am
by ArndW
The DataStage read of sequential files is pretty efficient; and DSParams is small file (if the file had millions of records I might reconsider, but this is going to take milliseconds to process).

Posted: Wed Feb 14, 2007 8:54 am
by DSguru2B
ArndW wrote:The DataStage read of sequential files is pretty efficient; and DSParams is small file (if the file had millions of records I might reconsider, but this is going to take milliseconds to process).
Thanks for the clarification ArndW.

Posted: Wed Feb 14, 2007 9:16 am
by parvathi
ArndW wrote:I would use a variable to store the current section, or "state" while reading the file.

Code: Select all

   Line = TRIM(Line)
   IF Line[1,1]='[' THEN Section = Line[2,LEN(Line ...[/quote]

can you please expand the the code  a bit further. I could get a little bit of it

Posted: Wed Feb 14, 2007 11:10 am
by ArndW
Parvathi, that overall response is a premium one, since I felt it contained something somewhat more complex than just reading in a manual. As mentioned elsewhere, the premium membership makes that post and many more (and more informative) posts visible and accessible to you.

But the important part was visible to you (there isn't much more to my post, anyway). First of all, trim your input string just ONCE. Then use a variable to store which section of the DSParam file you are currently in.

Posted: Wed Feb 14, 2007 2:43 pm
by ray.wurlod
Why are you reading DSParams? If the environment variable is set, you can simply obtain its value from the environment!

Posted: Wed Feb 14, 2007 11:13 pm
by parvathi
ray.wurlod wrote:
Why are you reading DSParams? If the environment variable is set, you can simply obtain its value from the environment!
i want the parametervalue of a particular parameter in a server routine.
I thought i could read from the DSParams.

If there is any other way please let me know

Posted: Thu Feb 15, 2007 12:27 am
by ray.wurlod

Code: Select all

Call DSExecute("UNIX", "echo $MyVariable", Result, ExitStatus)

Posted: Fri Feb 16, 2007 12:36 am
by parvathi
ray.wurlod wrote:

Code: Select all

Call DSExecute("UNIX", "echo $MyVariable", Result, ExitStatus)
...
Please correct if I am wrong.

I have executed the command given above. iam not able to echo the value.

Since my os is unix. I am echoing the value from my user id. where as the variable value that i want is set In DSParams file.
In this file the variable is not assigned

it is given as below.

"paramname"\1"paramvalue"

Can i echo a variable which is given like this.?

Another thing that i have seen is when a variable is set in my .Profileh.
I am able to echoonly those varaibles.

I just wanted to know what ever the varibales that are defined in the adiminstrator are only written to the DSParams file?

When i triiger my master sequencer what is the process flow of the varibles that i am using in the sequencer

Posted: Fri Feb 16, 2007 1:21 am
by ray.wurlod
Can you verify that the environment variables are picked up when the job is run? There is a logged event (second in the job run) showing all the environment variables that are used.

In the interim, rather than using an echo command you could use a grep command.

Code: Select all

Call DSExecute("UNIX", "grep MyVariable DSParams", Result, ExitStatus)
Then parse out the environment variable's value (use the Field() function).

Posted: Fri Feb 16, 2007 7:40 am
by DSguru2B
Doing it at the unix level was my initial thought as well. But since the OP had already started it doing with a BASIC program, I did not say much earlier.
About your second query, what exactly do you mean? Whatever parameters you define in your Master Sequence Job, they will be assigned to other sub sequences and jobs. It will flow down. Is that what your asking?

Posted: Fri Feb 16, 2007 7:44 am
by chulett
parvathi wrote:I have executed the command given above. iam not able to echo the value.
You have executed this where? Anything declared via the Administrator will be available when jobs are run. If you are 'Test'ing it via a routine or 'executing' this in some other fashion...