How to loop till the end of file using a server routine?

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
pradeepkumar_b@thbs.com
Participant
Posts: 28
Joined: Thu Mar 13, 2008 11:24 pm

How to loop till the end of file using a server routine?

Post by pradeepkumar_b@thbs.com »

I am trying to return the records till the end of a sequential file using a server routine. I am able to do this giving using "for next" for fixed no of record but not for whole file. Also tried with " do while" but I am unable to figure out how to give condition for end of loop. thanx in advance.

seeking help please
Pradeep
BugFree
Participant
Posts: 82
Joined: Wed Dec 13, 2006 6:02 am

Post by BugFree »

You will have to use a combination of ReadSeq and STATUS() functions to loop through the file. STATUS returns 1 when it reaches the end of file. So that will be the condition for the loop.
Ping me if I am wrong...
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

Ans = ""
OpenSeq pathname To filevariable
Then
   Loop 
   While ReadSeq Line From filevariable
      Ans<-1> = Line
   Repeat
End
CloseSeq filevariable
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
pradeepkumar_b@thbs.com
Participant
Posts: 28
Joined: Thu Mar 13, 2008 11:24 pm

do while

Post by pradeepkumar_b@thbs.com »

can u please tell me the syntax of do while here..i am unable to figure out..i am gettingl lot of errors
Pradeep
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Post your code.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradeepkumar_b@thbs.com
Participant
Posts: 28
Joined: Thu Mar 13, 2008 11:24 pm

Post by pradeepkumar_b@thbs.com »

THANX FOR UR RESPONSE
Pradeep
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or not. All such syntax is spelled out in the BASIC.pdf manual installed on your PC.
-craig

"You can never have too many knives" -- Logan Nine Fingers
pradeepkumar_b@thbs.com
Participant
Posts: 28
Joined: Thu Mar 13, 2008 11:24 pm

Post by pradeepkumar_b@thbs.com »

i am using following code for the parsing sequential file. Its not giving output it is going for infinite loop.. Can u pls help me out here.





ParameterPathName = WorkDir : "\" : ParameterKey : ".txt"

OpenSeq ParameterPathName To hFile Then


LOOP WHILE STATUS()= 0
ReadSeq ParameterRecord From hFile Then
Call DSLogInfo(ParameterRecord , "ReadParameterFileRecord")
End Else
Call DSLogWarn("Unable to read parameter file (" : ParameterPathName : ") (" : Status() : ")", "ReadParameterFileRecord")
ParameterRecord = @NULL
End
Ans = ParameterRecord

REPEAT

CloseSeq hFile

End Else
Call DSLogWarn("Unable to open parameter file (" : ParameterPathName : ") (" : Status() : ")", "ReadParameterFileRecord")

Ans = @NULL
End
Pradeep
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Status() is still set to 0 at the end of the file. You need to exit from your loop when the ELSE clause of the ReadSeq statement is taken. One way is an EXIT statement. Look at the loop I posted earlier - it's much cleaner code. Just put your parsing logic between the WHILE and REPEAT statements.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply