problem in transversing the file

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
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

problem in transversing the file

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

Post 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"
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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:
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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).
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

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

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Why are you reading DSParams? If the environment variable is set, you can simply obtain its value from the environment!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Call DSExecute("UNIX", "echo $MyVariable", Result, ExitStatus)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Post 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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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).
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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...
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply