STOP-AFTER phrase

The STOP-AFTER phrase specifies a time-out value for a DO, FOR, or REPEAT block.

Syntax

STOP-AFTER time-limit
time-limit
An integer expression which specifies the number of seconds each iteration of a block has until a time-out occurs.

If a time-out occurs, the AVM raises the STOP condition on the current statement and throws a Progress.Lang.StopAfter object. Use an ON STOP phrase on the block (or an enclosing block) to alter the default STOP condition handling. Alternatively you can catch a Progress.Lang.StopAfter object using a CATCH block to provide alternate STOP condition handling. For more information, see the Progress.Lang.StopAfter class.

The STOP-AFTER time limit is the maximum time allowed for a single block iteration. For example, if you have STOP-AFTER 3 on a FOR EACH statement, each loop iteration must complete within 3 seconds or a STOP condition is raised.

If a block with a STOP-AFTER phrase contains a nested block with a STOP-AFTER phrase, then each is governed by it's own time limit. If the outer block time limit is reached while the inner block is executing, the STOP condition is raised even if the time limit for the inner block has not been reached.

If the STOP condition is handled and execution resumes within the scope of a block with a STOP-AFTER phrase, the time limit is not in effect until the next iteration of the block

If time-limit evaluates to zero or less, this is the equivalent of not specifying a STOP-AFTER phrase.

Examples

Example 1

The following example shows how the STOP-AFTER phrase can be used for placing a time limit on a query.

FOR EACH Customer WHERE <insert complicated query here> STOP-AFTER 5: 
   <ABL statements>   
   CATCH eStopAfter AS PROGRESS.Lang.StopAfter:
      MESSAGE "Query time limit exceeded" VIEW-AS ALERT-BOX.    
   END.
END.

Example 2

The following example demonstrates how a STOP-AFTER phrase on an outer block also limits the time allowed for an inner block.

DEFINE VARIABLE ctr AS INTEGER INITIAL 0.

DO STOP-AFTER 5 ON STOP UNDO, LEAVE:  
    
   MESSAGE "Start of DO BLOCK. Time is: " STRING(TIME,"HH:MM:SS").
   
   FOR EACH Customer STOP-AFTER 10:  
      REPEAT:    // infinite loop  
         ctr = ctr + 1. 
      END.    
      MESSAGE "After REPEAT block.".  // this message will never display
   END. 
    
   MESSAGE "After FOR EACH block.".  // this message will never display
  
   CATCH eStopAfter AS Progress.Lang.StopAfter:
       MESSAGE "Time limit reached. Time is: " STRING(TIME,"HH:MM:SS") " ctr = " ctr   
          VIEW-AS ALERT-BOX. 
   END CATCH. 
   
END.

MESSAGE "Procedure complete."

If you run this code, the outer DO block establishes a 5 second time limit for the work of the DO block and all inner blocks.

When the inner FOR EACH block starts, a separate time limit is set for each iteration of this block due to the STOP-AFTER 10 phrase.

Execution then continues to the REPEAT block which is an infinite loop. At some point, the outer 5 second time limit of the DO block is reached and the AVM raises the STOP condition. The STOP condition is raised on the statement the AVM is executing when the time limit is reached. Normal STOP handling proceeds from that point.

Because a CATCH statement on a block takes precedence over an ON STOP phrase, the STOP condition is caught and the "Time limit reached..." message displays. Notice that 5 seconds elapse from the "Start of DO BLOCK..." message to the "Time limit reached..." message.

Normal execution resumes following the DO block, and the "Procedure complete." message displays.

Notes

See also

CATCH statement, DO statement, FOR statement, ON STOP phrase, Progress.Lang.StopAfter class, REPEAT statement