Comparing values in Routaine

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
dspxlearn
Premium Member
Premium Member
Posts: 291
Joined: Sat Sep 10, 2005 1:26 am

Comparing values in Routaine

Post by dspxlearn »

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 :roll: :roll:
Thanks and Regards!!
dspxlearn
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

Where do you exit from the loop?

Try removing two "End" statement before "repeat".
dspxlearn
Premium Member
Premium Member
Posts: 291
Joined: Sat Sep 10, 2005 1:26 am

Post by dspxlearn »

Hi Balajisr,


I tried doing that..
But it isn't working.... :(
Thanks and Regards!!
dspxlearn
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

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 

I have added exit statement to come out of the loop and removed unnecessary end statement. This routine is just a rough draft enough to get you started.
dspxlearn
Premium Member
Premium Member
Posts: 291
Joined: Sat Sep 10, 2005 1:26 am

Post by dspxlearn »

Hi Balajisr,


Thanks a lot!!!
Your cleansing really works fine...
Thanks and Regards!!
dspxlearn
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

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.
balajisr
Charter Member
Charter Member
Posts: 785
Joined: Thu Jul 28, 2005 8:58 am

Post by balajisr »

ray.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.
[ ...
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 draft :)
Thanks for your suggestion.
Post Reply