Page 1 of 2

While loop in Datastage

Posted: Thu Mar 05, 2009 4:54 am
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

Re: While loop in Datastage

Posted: Thu Mar 05, 2009 5:22 am
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

Posted: Thu Mar 05, 2009 5:45 am
by Shreya
Can you plz tell me where does the result show for print i (location)

Posted: Thu Mar 05, 2009 5:57 am
by Sainath.Srinivasan
Use DSLogInfo

Posted: Thu Mar 05, 2009 6:09 am
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 .

Posted: Thu Mar 05, 2009 6:26 am
by sachin1
when you do testing of any routine( transform) you can see output in Test output.

after running your code.

Posted: Thu Mar 05, 2009 6:29 am
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. :?

Posted: Thu Mar 05, 2009 6:39 am
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

Posted: Thu Mar 05, 2009 3:24 pm
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.

Posted: Fri Mar 06, 2009 9:40 am
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...

Posted: Fri Mar 06, 2009 10:20 am
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.

Posted: Fri Mar 06, 2009 1:17 pm
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.

Posted: Mon Mar 09, 2009 10:28 pm
by Shreya
This code was working fine from last 0ne year,
its giving me problem when we moved this job to new server.

Posted: Mon Mar 09, 2009 10:29 pm
by Shreya
Can we ve other way ton write this code in job control .it will be gr8 help for me .

Posted: Mon Mar 09, 2009 10:45 pm
by ray.wurlod
Shoar. Try this site for examples.