BASIC LOOP Not exiting

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
muascdev
Charter Member
Charter Member
Posts: 51
Joined: Tue Oct 10, 2006 5:48 pm

BASIC LOOP Not exiting

Post by muascdev »

i have a file that has product id and email id, what i need to do is concatenate all prod ids that have the same email id, so that i send the email only once. I wrote a basic program to do this. this would read the file and concatenate prod ids that have similar email id. this data would be writeen into an output seq file. The problem I have is LOOP seems to run for ever. I seem to have coded everything write, but routine is not ending. pl help

Code: Select all


* Read the Sequential file 1st and get the key

      PathName="D:\ETL_PROJECTS\GeneralLedger\Data\Source\email_distro.txt"

      Ans="Nothin"

 

      openSeq "D:\ETL_PROJECTS\GeneralLedger\Data\Source\email_distro.txt" To FileVar Else

         Call DSLogWarn("Cannot open ":PathName, RoutineName)

         GoTo ErrorExit

      End

 

 

 

      OpenSeq "c:\test\Testfff.txt" To writeV then

         WeofSeq writeV

      end

 

      ReadSeq FileLine From FileVar

      On Error

         GoTo ErrorExit

      End

      Then

         prevEmailId = Field(FileLine,"|",2)

         prevProdKey = Field(FileLine,"|",1)

         Ans=prevEmailId

      end

      concatProdIds=prevProdKey

      endOfFileReached=0

      Loop

         ReadSeq FileLine From FileVar

         On Error

            GoTo ErrorExit

         End

         Then

            WriteSeq STATUS() to writeV else

               Ans=@NULL

            end

 

            if (STATUS() = 1) then

 

               endOfFileReached=1

            end

            else

               endOfFileReached=0

               EmailId = Field(FileLine,"|",2)

               ProdId = Field(FileLine,"|",1)

 

               if (prevEmailId = EmailId) then

                  concatProdIds = concatProdIds:",":ProdId

                  Ans=concatProdIds

               end

 

               else

                  val = concatProdIds :"|":prevEmailId

                  prevEmailId = EmailId

                  prevProdKey = ProdId

                  concatProdIds = ProdId

                  WriteSeq val to writeV else

                     Ans=@NULL

                  end
                 
               end

            end

         end

           if (endOfFileReached =1 ) then

            EXIT

         end

 

      UNTIL endOfFileReached=1 REPEAT


ErrorExit:

 

         CloseSeq FileVar

         CloseSeq writeV


xcb
Premium Member
Premium Member
Posts: 66
Joined: Wed Mar 05, 2003 6:03 pm
Location: Brisbane, Australia
Contact:

Post by xcb »

Hi,

I haven't gone thorugh all your code, but I don't think your exit condition is ever going to be met so you will be in an infinite loop.

If you want to loop through all lines of email_distro.txt then your code should look more like this.

Code: Select all

Loop
  ReadSeq FileLine From FileVar Else endOfFileReached=1
Until endOfFileReached
  ...
  * Your code here
  ...
Repeat
If you initialise your variables prior to entering the loop you can avoid the first read that you are doing eg.

Code: Select all

  prevEmailId = ""
  prevProdKey = ""
  EmailId = ""
  ProdId = ""
This assumes that your file won't be empty and that the first read will put some valid values into EmailId and ProdId. If this isn't the case you can initialise the variables with something other than "" to ensure that the first read will not match to an empty string.

You can do all your checking for previous values etc within the main body of the loop eg.

Code: Select all

  EmailId = Field(FileLine,"|",2) 
  ProdId = Field(FileLine,"|",1)
  If prevEmailId = EmailId Then 
    ...
    * Do what ever it is you were doing here
    ...
  End Else
    * Assign the previous id from the current id's for the next iteration of the loop
    prevEmailId = EmailId 
    prevProdKey = ProdId 
    ...
    * Do what ever it is you were doing here
    ...
  End
Obviously you will have to implement all the extra logic you have in order to achieve your expected results.

I am not sure why you want to write the output of Status() to Testfff.txt??

You've also assigned to PathName the path of email_distro.txt but then you don't use this variable when you are opening the file?

Hopefully this will help you a little and put you on the right path.
Cameron Boog
muascdev
Charter Member
Charter Member
Posts: 51
Joined: Tue Oct 10, 2006 5:48 pm

Post by muascdev »

that helped a lot. it worked. thank you very much
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Might be nice to mark the thread as resolved, then?
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