How to loop till the end of file using a server routine?
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 28
- Joined: Thu Mar 13, 2008 11:24 pm
How to loop till the end of file using a server routine?
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
seeking help please
Pradeep
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 28
- Joined: Thu Mar 13, 2008 11:24 pm
do while
can u please tell me the syntax of do while here..i am unable to figure out..i am gettingl lot of errors
Pradeep
-
- Participant
- Posts: 28
- Joined: Thu Mar 13, 2008 11:24 pm
-
- Participant
- Posts: 28
- Joined: Thu Mar 13, 2008 11:24 pm
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
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
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.