While loop in Datastage

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

Shreya
Participant
Posts: 8
Joined: Mon Nov 10, 2008 4:06 am

While loop in Datastage

Post by Shreya »

I m facing one prob while running while loop in job control .
In our job we put while i<8 but it goes into infinite loop .Do we need any patch for running while loop in datastage ,coz we r facing this prob after migrating it to new server.

Thanks
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Re: While loop in Datastage

Post by sachin1 »

please paste your code for while loop for us to check, below syntax works fine with 7.5.1a version.

loop while i < 8 do
print i
i=i+1
repeat
Shreya
Participant
Posts: 8
Joined: Mon Nov 10, 2008 4:06 am

Post by Shreya »

Can you plz tell me where does the result show for print i (location)
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Use DSLogInfo
Shreya
Participant
Posts: 8
Joined: Mon Nov 10, 2008 4:06 am

Post by Shreya »

but nothing is there in dslog .its not showing me any path .
if any one can tell me do we need any patch to run while loop ,because its running fine on other server .
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Post by sachin1 »

when you do testing of any routine( transform) you can see output in Test output.

after running your code.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You don't need a patch, you need to post your code and explain more fully the nature of your problem. And where exactly you are using this code. :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
Shreya
Participant
Posts: 8
Joined: Mon Nov 10, 2008 4:06 am

Post by Shreya »

In our job we put while i<8 but it goes into infinite loop .
we are facing this prob after migrating it to new server ,before that it was fine.

Code: Select all

      LOOP
**This will be the no how many time u want to run the loop
      WHILE i<=8 DO
**Calling the first job that will check in DW and write in a file
         handle1=DSAttachJob("SrcLoadF5609001Date",DSJ.ERRFATAL)
         handle1=DSPrepareJob(handle1)
         err1=DSRunJob(handle1,DSJ.RUNNORMAL)
         sleep 5
**Reading the file to see the data
         DirPath = $Staging
         BaseName = "\E1DateFile.txt"
         FileName = DirPath : BaseName
         OpenSeq FileName to FileVar
         Then
            ReadSeq FileLine from FileVar
            Then
               extractdate=FIELD(FileLine,",",1)
               year1=FIELD(trim(extractdate),"-",1)
               month1=FIELD(trim(extractdate),"-",2)
               date1=FIELD(trim(extractdate),"-",3)
               newdate= date1:"/":month1:"/":year1
               datein=@DATE
               dateext = Oconv(datein, "D/E")
               [b]**goes into infine loop after this [/b]
               IF newdate EQ dateext
               THEN
                  handle2=DSAttachJob("GLMasterControlJob_FINAL_DV",DSJ.ERRFATAL)
                  handle2=DSPrepareJob(handle2)
                  err2=DSRunJob(handle2,DSJ.RUNNORMAL)
                  Exit
               END
            END
            Else
               var=""
**Wait for 20mins (1200 secs), here u specify data how long u want to wait in sec
               SLEEP 1200
               i=i+1
               If i = 6
               Then
                  handle2=DSAttachJob("E1Email1",DSJ.ERRFATAL)
                  handle2=DSPrepareJob(handle2)
                  err2=DSRunJob(handle2,DSJ.RUNNORMAL)
                  handle3=DSAttachJob("E1Email2",DSJ.ERRFATAL)
                  handle3=DSPrepareJob(handle3)
                  err3=DSRunJob(handle3,DSJ.RUNNORMAL)
                  handle4=DSAttachJob("E1Email3",DSJ.ERRFATAL)
                  handle4=DSPrepareJob(handle4)
                  err4=DSRunJob(handle4,DSJ.RUNNORMAL)
                  handle5=DSAttachJob("E1Email4",DSJ.ERRFATAL)
                  handle5=DSPrepareJob(handle5)
                  err5=DSRunJob(handle5,DSJ.RUNNORMAL)
               End
               CONTINUE
**it will go to loop start which will run the first job to check data from DB
            END
         END
      REPEAT
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Wrap your code in Code tags so we can see the indenting. The typical reason for infinite loop is that there is a code path that does not update the loop index variable.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

To help him out I just popped his code into the BASIC engine and used "Format" on it to get it indented, then went back and updated it with "code" markers.

Unfortunately I'm out of time to actually diagnose the issue right now...

Content Editor...

P.S. - Replying to topic to let you know the update happened...
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

ray.wurlod wrote:Wrap your code in Code tags so we can see the indenting. The typical reason for infinite loop is that there is a code path that does not update the loop index variable. ...
And according to me thats the exact problem in this code.

**goes into infine loop after this.

Yes because if its able to read the file i think its not going to the statement where the index is updated.

1. I can't see where you are initializing the counter. I generally prefer to do that.
2. Watch End tags to find the blocks end and see how the flow goes.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Does U work at your site? If not, why mention him in your documentation (comments)?

If OpenSeq takes its THEN clause, the loop variable is never incremented.

As already noted, it's never given an initial value either. You are relying on "nice" behaviour from the engine: "variable unassigned, zero used" will probably appear in your job log as the engine makes this substitution for you.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Shreya
Participant
Posts: 8
Joined: Mon Nov 10, 2008 4:06 am

Post by Shreya »

This code was working fine from last 0ne year,
its giving me problem when we moved this job to new server.
Shreya
Participant
Posts: 8
Joined: Mon Nov 10, 2008 4:06 am

Post by Shreya »

Can we ve other way ton write this code in job control .it will be gr8 help for me .
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Shoar. Try this site for examples.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply