Progress
Language Reference


DO Statement

Interfaces
OS
SpeedScript
All
All
Yes

Groups statements into a single block, optionally specifying processing services or block properties. Use an END statement to end a DO block.

SYNTAX

[ label : ]
  DO
    { [ FOR record [ , record ] ... ] }
    [ preselect-phrase ]
    [ query-tuning-phrase ]
    [ variable = expression1 TO expression2 [ BY k ] ]
    [ WHILE expression ]
    [ TRANSACTION ] 
    [ on-endkey-phrase ]
    [ on-error-phrase ]
    [ on-quit-phrase ]
    [ on-stop-phrase ]
    { [ frame-phrase ] } 

FOR record [ , record ] ...

Names the buffer you want to work with in the block and scopes the buffer to the block. The scope of a record determines when the buffer for that record is cleared and written back to the database. See the Progress Programming Handbook for more information on record scoping.

To work with a record in a table defined for multiple databases, you must qualify the record’s table name with the database name. See the Record Phrase reference entry for more information.

preselect-phrase

The PRESELECT Phrase finds selected records from one or more tables. You can access those preselected records with statements such as FIND NEXT.

SYNTAX
PRESELECT
  [ EACH | FIRST | LAST ] record-phrase
  [ , [ EACH | FIRST | LAST ] record-phrase ] ...
  [ 
     [ BREAK ]
     { BY expression [ DESCENDING ] } ...
  ] 

For more information, see the PRESELECT Phrase reference entry.

query-tuning-phrase

Allows programmatic control over the execution of a DataServer query.

SYNTAX
QUERY-TUNING (
  {
     [ BIND-WHERE | NO-BIND-WHERE ]
     [ CACHE-SIZE integer ]
     [ DEBUG { SQL | EXTENDED } | NO-DEBUG ]
     [ INDEX-HINT | NO-INDEX-HINT ]
     [ JOIN-BY-SQLDB | NO-JOIN-BY-SQLDB ]
     [ LOOKAHEAD | NO-LOOKAHEAD ]
     [ SEPARATE-CONNECTION | NO-SEPARATE-CONNECTION ]
  }
  ) 

For more information, see the Progress DataServer Guides, Progress DataServer for ODBC Guide and Progress DataServer for ORACLE Guide.

variable = expression1 TO expression2 [ BY k ]

The name of a field or variable whose value is incremented in a loop. The expression1 is the starting value for variable on the first iteration of the loop. The k is the amount to add to variable after each iteration, and it must be a constant. The k defaults to 1. The variable, expression1 and expression2 must be integers.

When variable exceeds expression2 (or is less than expression2 if k is negative) the loop ends. Since expression1 is compared to expression2 at the start of the first iteration of the block, the block can be executed zero times. The expression2 is re-evaluated on each iteration of the block.

WHILE expression

Indicates that the DO block continues processing the statements within it. Using the WHILE option turns a DO block into an iterating block. The block iterates as long as the condition specified by the expression is TRUE. The expression is any combination of constants, operators, field names, and variable names that yield a logical value.

TRANSACTION

Identifies the DO block as a system transaction block. Progress starts a system transaction for each iteration of a transaction block if there is not already an active system transaction. See the Progress Programming Handbook for more information on transactions.

on-endkey-phrase

Describes the processing that takes place when the ENDKEY condition occurs during a block. This is the syntax for a ON ENDKEY Phrase.

SYNTAX
ON ENDKEY UNDO [ label1 ] [ , LEAVE label2 ] 

ON ENDKEY UNDO [ label1 ] [ , NEXT label2 ] 

ON ENDKEY UNDO [ label1 ] [ , RETRY label1 ] 

ON ENDKEY UNDO [ label1 ] 
  [
    , RETURN [ ERROR | NO-APPLY ] [ return-string ]
  ] 

For more information, see the ON ENDKEY Phrase reference entry.

on-error-phrase

Describes the processing that takes place when there is an error during a block. This is the syntax for ON ERROR phrase.

SYNTAX
ON ERROR UNDO [ label1 ] [ , LEAVE label2 ] 

ON ERROR UNDO [ label1 ] [ , NEXT label2 ] 

ON ERROR UNDO [ label1 ] [ , RETRY label1 ] 

ON ERROR UNDO [ label1 ] 
  [
    , RETURN [ ERROR | NO-APPLY ] [ return-string ]
  ] 

For more information, see the ON ERROR Phrase reference entry.

on-quit-phrase

Describes the processing that takes place when a QUIT statement is executed during a block. This is the syntax for ON QUIT phrase.

SYNTAX
ON QUIT UNDO [ label1 ] [ , LEAVE label2 ] 

ON QUIT UNDO [ label1 ] [ , NEXT label2 ] 

ON QUIT UNDO [ label1 ] [ , RETRY label1 ] 

ON QUIT UNDO [ label1 ] 
  [
    , RETURN [ ERROR | NO-APPLY ] [ return-string ]
  ] 

For more information, see the ON QUIT Phrase reference entry.

on-stop-phrase

Describes the processing that takes place when the STOP conditions occurs during a block. This is the syntax for the ON STOP Phrase.

SYNTAX
ON STOP UNDO [ label1 ] [ , LEAVE label2 ] 

ON STOP UNDO [ label1 ] [ , NEXT label2 ] 

ON STOP UNDO [ label1 ] [ , RETRY label1 ] 

ON STOP UNDO [ label1 ] 
  [
    , RETURN [ ERROR | NO-APPLY ] [ return-string ]
  ] 

For more information, see the ON STOP Phrase reference entry.

frame-phrase

Specifies the overall layout and processing properties of a frame. For more information on frame-phrase, see the Frame Phrase reference entry.

EXAMPLE

This procedure goes through the customer table and, for those customers whose credit-limit is over 80000, reduces credit-limit to 80000. The procedure uses an unmodified DO block to process two statements if credit-limit is over 80000. Unmodified DO blocks are most useful in conditional, or IF. . .THEN. . .ELSE situations.

r-do.p
FOR EACH customer:
  DISPLAY name credit-limit.
  PAUSE 3.
  IF credit-limit > 80000 THEN DO:
       credit-limit = 80000.
       DISPLAY name credit-limit.
  END.
END. 

NOTES

SEE ALSO

FIND Statement, FOR Statement, Frame Phrase, ON ENDKEY Phrase, ON ERROR Phrase, ON QUIT Phrase, ON STOP Phrase, Record Phrase, REPEAT Statement


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095