OpenSeq and ReadSeq not working in routine

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
girishoak
Participant
Posts: 65
Joined: Wed Oct 29, 2003 3:54 am

OpenSeq and ReadSeq not working in routine

Post by girishoak »

Hi,

I have source file which contains 13 columns. In that last 11 columns contains rates for year 1 to 11. I want to create 11 records from one line. For that I have written following routine. But while testing itself it hangs the routine. I think it hangs while opening or reading the file. Can any body help me out.

Or is there any other way to the same thing in datastage other than use of basics.

FncSplitYearRate (SourceFile,TargetFile)

Code: Select all

$INCLUDE DSINCLUDE JOBCONTROL.H


mycovcd=""
myyears=0
fr_term=0
to_term=0
mynrate=0
myprate=0
myrate=0
errcode=0
paramerr=0

print "hello "
openseq SourceFile to rfilevar  then  errcode = 0 else errcode = -1
print "source errcode " : errcode

openseq TargetFile to wfilevar  then  errcode = 0 else errcode = -1

print "target errcode " : errcode

if errcode = 0
then
    Loop
        readseq rfileline from rfilevar then *errcode = 0 else errcode = -1
        print "Line read is " : rfileline

        AgreementSeqNbr = field(rfileline, ",",1)
        Fr_Term = field(rfileline, ",",2)
        myrate1 = field(rfileline,",",3)
        myrate2 = field(rfileline,",",4)
        myrate3 = field(rfileline,",",5)
        myrate4 = field(rfileline,",",6)
        myrate5 = field(rfileline,",",7)
        myrate6 = field(rfileline,",",8)
        myrate7 = field(rfileline,",",9)
        myrate8 = field(rfileline,",",10)
        myrate9 = field(rfileline,",",11)
        myrate10 = field(rfileline,",",12)
        myrate11 = field(rfileline,",",13)
   
  
  fr_term=0
  to_term=0

      if myrate1 > 0 
      then 
          nRate= myrate1
          nYear=1
          gosub Myroutine
      end
 
      if myrate2 > 0 
      then 
          nRate= myrate2
          nYear=2
          gosub Myroutine
      end
 
      if myrate3 > 0 
      then 
          nRate= myrate3
          nYear=3
          gosub Myroutine
      end
 
      if myrate4 > 0 
      then 
          nRate= myrate4
          nYear=4
          gosub Myroutine
      end
 
      if myrate5 > 0 
      then 
          nRate= myrate5
          nYear=5
          gosub Myroutine
      end
 
      if myrate6 > 0 
      then 
          nRate= myrate6
          nYear=6
          gosub Myroutine
      end
 
      if myrate7 > 0 
      then 
          nRate= myrate7
          nYear=7
          gosub Myroutine
      end
 
      if myrate8 > 0 
      then 
          nRate= myrate8
          nYear=8
          gosub Myroutine
      end
 
      if myrate9 > 0 
      then 
          nRate= myrate9
          nYear=9
          gosub Myroutine
      end
 
      if myrate10 > 0 
      then 
          nRate= myrate10
          nYear=10
          gosub Myroutine
      end
 
      if myrate11 > 0 
      then 
          nRate= myrate11
          nYear=11
          gosub Myroutine
      end
      
    Repeat
     end
Print "Closing Files"
closeseq rfilevar
closeseq wfilevar
Print "Files Closed"
       
Myroutine:
  print "In routine ";
*       if mynrate <> myprate then

*        fr_term = fr_term + 1
*        to_term = to_term + 1

*       myprate = mynrate
*      wfileline = mycovcd : "," : myyears : "," : fr_term : "," : to_term : "," : mynrate
*    print "fr term " : fr_term
*    print "to term " : to_term
*    print "mynrate " : mynrate

       wfileline = AgreementSeqNbr : "," : Fr_Term : ",": nYear : "," : nRate 
 print wfileline
       writeseq wfileline to wfilevar then errcode = 0 else errcode = -1
*  end
 
Return (0);

errorCode = 0


Ans=0

Thanks in advance

Girish Oak[/code]
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

Just write a job with 11 output links from the transformer. Each link has a constraint for 1 of the 11 columns. This is a good design when you have a low, fixed number of pivoted rows.

Code: Select all

seq --->  xfm ---> seq1
              ---> seq2
              ---> seq3
              ---> seq4
              ---> seq5
              ---> seq6
              ---> ... you get the idea
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
girishoak
Participant
Posts: 65
Joined: Wed Oct 29, 2003 3:54 am

Post by girishoak »

Thanks Ken for your idea.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You've written an infinite loop containing ReadSeq statements.
That is, there is no exit from this loop.

Try

Code: Select all

Loop
While ReadSeq rfileline from rfilevar 
 * statements
Repeat
However, why not do this with a DataStage job? Read the 13 columns and output one, containing line feeds and repeats of columns 1 and 2. This technique has been discussed in the past, do a search on the Forum. It's exceedingly fast.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

ray.wurlod wrote: However, why not do this with a DataStage job? Read the 13 columns and output one, containing line feeds and repeats of columns 1 and 2. This technique has been discussed in the past, do a search on the Forum. It's exceedingly fast.
He's doing the reverse, 1 row becomes 11. So, a splitter style transformer stage is the appropriate design. (Plus you caught his code error :shock: )
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Also, isn't there an issue with using GOSUB syntax within a Routine? I was under the impression that was a no-no as you tended to exit the routine when the first 'return' was encountered.

Or that the presence of the multiple 'return' statements irritated the compiler...
-craig

"You can never have too many knives" -- Logan Nine Fingers
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

chulett wrote:Also, isn't there an issue with using GOSUB syntax within a Routine? I was under the impression that was a no-no as you tended to exit the routine when the first 'return' was encountered.

Or that the presence of the multiple 'return' statements irritated the compiler...
Nope, just fine. This is how you do this. On a previous post I discussed the way RETURN statements work. Basically, a GOSUB pushes the current code address onto the stack and then does direct branch to the label. At the next RETURN statement encountered, the stack has the current address popped, so that branching goes back to the value pushed. If you do 3 nested GOSUBs, then you have 3 addresses on the stack. It takes 3 RETURNs to get you back to the original point. This is why soooo many people harp on GOTO statements, because people use them to circumvent the RETURN mechanisms and can potentially overflow a stack pointer.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

chulett wrote:Also, isn't there an issue with using GOSUB syntax within a Routine? I was under the impression that was a no-no as you tended to exit the routine when the first 'return' was encountered.

Or that the presence of the multiple 'return' statements irritated the compiler...
It is a known glitch in the compiler, but the glitch is actually when you use a RETURN statement that lacks an argument - that is, a RETURN statement rather than a RETURN function.
If you provide a RETURN function, as Girish has done with RETURN(0), the compiler is happy and - better - it runs properly. :D
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

ray.wurlod wrote:
chulett wrote:Also, isn't there an issue with using GOSUB syntax within a Routine? I was under the impression that was a no-no as you tended to exit the routine when the first 'return' was encountered.

Or that the presence of the multiple 'return' statements irritated the compiler...
It is a known glitch in the compiler, but the glitch is actually when you use a RETURN statement that lacks an argument - that is, a RETURN statement rather than a RETURN function.
If you provide a RETURN function, as Girish has done with RETURN(0), the compiler is happy and - better - it runs properly. :D
ehhhh? You can put internal subroutines anywhere, even within functions. Am I missing something? You can have subroutines gosub other subroutines. Am I needing to shutup and to go bed?
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Thank you for the clarifications, gentlemen.

And from one stooge to another - yes, Ken, it's bedtime. Night Night. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

kcbland wrote:
ray.wurlod wrote: However, why not do this with a DataStage job? Read the 13 columns and output one, containing line feeds and repeats of columns 1 and 2. This technique has been discussed in the past, do a search on the Forum. It's exceedingly fast.
He's doing the reverse, 1 row becomes 11. So, a splitter style transformer stage is the appropriate design. (Plus you caught his code error :shock: )
Yes, that's what I designed. Forgot to mention that you write it into a sequential file which you then read from.

The output column from Transformer stage is derived as

Code: Select all

c1:",":c2:",":c3:LF:c1:",":c2:",":c4:LF:c1:",":c2:",":c5:LF: ... :LF:c1:",":c2:",":c13
The inputs tab to the sequential file stage specifies 000 as the delimiter character and UNIX style end of line. (OP specified UNIX.)

The outputs tab from the sequential file stage specifies "," as the delimiter character and UNIX style end of line.

Go on, try it! :D
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

ray.wurlod wrote:
kcbland wrote:
ray.wurlod wrote: However, why not do this with a DataStage job? Read the 13 columns and output one, containing line feeds and repeats of columns 1 and 2. This technique has been discussed in the past, do a search on the Forum. It's exceedingly fast.
He's doing the reverse, 1 row becomes 11. So, a splitter style transformer stage is the appropriate design. (Plus you caught his code error :shock: )
Yes, that's what I designed. Forgot to mention that you write it into a sequential file which you then read from.

The output column from Transformer stage is derived as

Code: Select all

c1:",":c2:",":c3:LF:c1:",":c2:",":c4:LF:c1:",":c2:",":c5:LF: ... :LF:c1:",":c2:",":c13
The inputs tab to the sequential file stage specifies 000 as the delimiter character and UNIX style end of line. (OP specified UNIX.)

The outputs tab from the sequential file stage specifies "," as the delimiter character and UNIX style end of line.

Go on, try it! :D

fffftt! Brain fart. Got it.
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Post Reply