Hi,
I am writing a routine which should read lines in a sequential file and compare the line number with the input argument which is also a number(passed as a argument).If the both the line no and the input value(passed as a argument) matched it should retrive the record to the Ans.
I am very new to writing routines and i tried to write the following code.But could not succeed on it.
$INCLUDE DSINCLUDE JOBCONTROL.H
PathName = Trim(FilePath):"/":Trim(FileName)
InitialCount = 0
Counter = 0
OpenSeq PathName To FileVar Else
Call DSLogWarn("Cannot open ":PathName, ExtractingString)
End
Loop
ReadSeq FileLine From FileVar
On Error
Call DSLogWarn("Cannot read ":PathName:" status=":Status(),"ExtractingString")
End
Then
Counter += 1
End
If Counter = Arg1
Then Ans = FileLine
End
End
Repeat
CloseSeq FileVar
Ans = FileLine
========================================================================================================================
It is throwing me an error as----
Compiling: Source = 'DSU_BP/DSU.ExtractingString', Object = 'DSU_BP.O/DSU.ExtractingString'
********************************************
0039 End
^
End of Line unexpected, Was expecting: END, "REPEAT", "UNTIL", "WHILE"
0044 Repeat
^
WARNING: Text found after final END statement
1 Errors detected, No Object Code Produced.
===============================================================================================================
What might be the possible reason
Comparing values in Routaine
Moderators: chulett, rschirm, roy
Comparing values in Routaine
Thanks and Regards!!
dspxlearn
dspxlearn
Code: Select all
$INCLUDE DSINCLUDE JOBCONTROL.H
PathName = Trim(FilePath):"/":Trim(FileName)
InitialCount = 0
Counter = 0
OpenSeq PathName To FileVar Else
Call DSLogWarn("Cannot open ":PathName, ExtractingString)
End
Loop
ReadSeq FileLine From FileVar
On Error
Call DSLogWarn("Cannot read ":PathName:" status=":Status(),"ExtractingString")
End
Then
Counter += 1
End
if Counter = Arg1
Then
EXIT
End
Repeat
CloseSeq FileVar
Ans = FileLine
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
That code does not handle the "not found" ("not matched") case. The Ans variable needs to be initialized. JOBCONTROL.H isn't needed. InitialCounter is not used. Here's a variation on the theme.
Code: Select all
FUNCTION FindLineInFile(DirPath, FileName, ValueToMatch)
DEFFUN OpenSequentialFile(PathName, OpenMode, WriteMode, LogFlag) Calling "DSU.OpenSequentialFile"
$INCLUDE UNIVERSE.INCLUDE FILEINFO.H
Ans = @NULL
Call !MAKE.PATHNAME(DirPath, FileName, FullPath, Status)
If Status = 0
Then
hFile = OpenSequentialFile(FullPath, "R", "A", "Y")
If FileInfo(hFile, FINFO$IS.FILEVAR)
Then
Counter = 0
Loop
While ReadSeq Line From hFile
Counter += 1
If Counter = ValueToMatch
Then
Ans = Line
Exit
End
Repeat
End
CloseSeq hFile
End
Else
Msg = 'Unable to create pathname.'
Call DSTransformError(Msg, RoutineName)
End
RETURN(Ans)
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.
Ray you are right. I removed only the compilation errors and made it work. Did not try to optimize it.That's why i mentioned that it is a rough draftray.wurlod wrote:That code does not handle the "not found" ("not matched") case. The Ans variable needs to be initialized. JOBCONTROL.H isn't needed. InitialCounter is not used. Here's a variation on the theme.
[ ...
Thanks for your suggestion.