Page 1 of 1

DataStage Routine

Posted: Thu Nov 20, 2014 4:28 am
by Amin
I need to read data from a text file using DataStage routine. I have a piece of code but its not working.

Filename is an Argument which have the File Path.

Code: Select all

OPENSEQ Filename TO H.FILE1 THEN
CALL DSLogInfo("******************** File " : H.FILE1 : " opened successfully", "JobControl")
END ELSE
CALL DSLogInfo("Unable to open file", "JobControl")
ABORT
END 

READSEQ FILE1.RECORD FROM H.FILE1 ELSE
Call DSLogWarn("******************** File is empty", "JobControl")
END

Ans = Trim(FILE1.RECORD," ","A") 
Call DSLogInfo("******************** Record read: " : Ans, "JobControl")
CLOSESEQ H.FILE1
And other one is

Code: Select all

Ans=''

Delimiter='='

OpenSeq Filename To File
   Else Print "Error Opening File " : Filename

Loop
   While ReadSeq Text From File
   ParName = Field(Text,Delimiter,1)
   *ParValue = Field(Text,Delimiter,2,10)  
   ParValue = Field(Text,Delimiter,2,Len(Text))
   If UpCase(ParName) = UpCase(Name) Then 
      Ans = ParValue
   End 

Posted: Thu Nov 20, 2014 8:26 am
by chulett
Define 'not working'. Times two.

Posted: Thu Nov 20, 2014 1:19 pm
by ArndW
At first blush the first program looks OK, but the second cannot work (hint: a Loop needs a beginning and an end, and this routine has no end and won't even compile). But as Craig has stated, telling us that something doesn't work is no use to anyone, but telling us what it does produce as output or how it doesn't work is a lot more useful.

Posted: Thu Nov 20, 2014 3:12 pm
by ray.wurlod
Two points.

OPENSEQ has four possible clauses. The ON ERROR clause is taken in the event of system error, and the LOCKED clause is taken in the event that the file is open by another process.

You need a REPEAT statement to terminate your uncounted loop.

Posted: Fri Nov 21, 2014 1:29 am
by Amin
As I have a file with data and a delimeter '='. I want to read data and passes to parameters using uservariable stage in Sequence Job. But routine is not reading the data. I haven't DS Routine commands which read the file.

Code with loop is giving nothing it returns the default value of 'Ans' as defined at start.

where other code give result as '<<ERROR>>'

Posted: Fri Nov 21, 2014 3:01 am
by ray.wurlod
No, I suspect you are populating Ans each time through the loop, and that the last line in the file is empty.

Try this.
Replace

Code: Select all

Ans = ParValue
with

Code: Select all

Ans<-1> = ParValue
Where does Name come from?

Posted: Fri Nov 21, 2014 8:22 am
by chulett
Or it is simply not finding the 'parameter name' it is looking for so returning nothing. Seems to me they are passing it a 'ParName' to look for on the left side of the name/value pairs in a parameter file and when found it returns the 'ParValue', the right side. Not found - return nothing.

Not looking for an array of values, just a single value. And I'm assuming 'Name' is an argument to the function (along with 'Filename') but they're either not showing us where it is declared or it is not happening.