DataStage Routine

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
Amin
Premium Member
Premium Member
Posts: 27
Joined: Fri Oct 24, 2014 10:02 am

DataStage Routine

Post 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 
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Define 'not working'. Times two.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Amin
Premium Member
Premium Member
Posts: 27
Joined: Fri Oct 24, 2014 10:02 am

Post 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>>'
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply