ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Endless loop with no commit

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Endless loop with no commit

    I have created a situation. I have an RPGLE program that is in a endless do-while loop running embedded sql statements to update data. It is done its work, but due to a logic problem it never reaches the exit point of the loop. It's in a *new activation group, and so if I end the job it never commits and I lose all of the work it has done. I would much rather find a way to end the program and commit the changes.

    Any ideas?

  • #2
    Just to confirm - you want to know if there is a way to manually end an existing running job that has activation group *NEW, so that it will commit all outstanding updates?

    Comment


    • #3
      put the job in debug & force the condition to exit the loop is the only way i can think of
      I'm not anti-social, I just don't like people -Tommy Holden

      Comment


      • #4
        Thanks for the replies, I had to end the job and restart. The do while condition was 1=1 and so I couldn't force the change in debug.

        Comment


        • #5
          In the future, if you have an endless loop with some code you need to run after the loop, use the %SHTDN built-in function within the loop to see if the job is trying to end. If %SHTDN returns true, then exit the loop. (And make sure you end the job *CNTRLD to give it time to do the code after the loop.)

          Code:
          dow 1 = 1;
             ... some code ...
          [COLOR=#FF0000]   if %SHTDN();
                leave;
             endif;[/COLOR]
          enddo;

          Comment


          • #6
            Barbara,

            wouldn't ON-EXIT work, too?

            Code:
            Dow 1=1;
              ... whatever you do
            EndDo;
            
            On-Exit;
              Commit;
               ... or whatever you want to do
            Birgitta

            Comment


            • #7
              Originally posted by Barbara Morris View Post
              In the future, if you have an endless loop with some code you need to run after the loop, use the %SHTDN built-in function within the loop to see if the job is trying to end. If %SHTDN returns true, then exit the loop. (And make sure you end the job *CNTRLD to give it time to do the code after the loop.)

              Code:
              dow 1 = 1;
              ... some code ...
              [COLOR=#FF0000] if %SHTDN();
              leave;
              endif;[/COLOR]
              enddo;
              I know I'm weird - but having something exit a loop from within is one of those OCD things that drives me crazy - I tend to treat loops like procedures - one entry point and one exit point....

              Code:
              exitloop = %SHTDN();
              dou exitloop;
              ... some code ...
                 exitloop = %SHTDN();
              enddo;
              This allows you to get into debug and set exitloop to '1' manually for debugging purposes. You have 1 entry point - DOU - and one exit - ENDDO

              Comment


              • john.sev99
                john.sev99 commented
                Editing a comment
                Lol, I think I have the same OCD problem, I've never liked infinite loops and code in the same way as you. I also think it's more human readable.

            • #8
              Hi Birgitta, I can't believe I forgot about ON-EXIT. That would work perfectly for this.

              Comment

              Working...
              X