RPG/400 Help

DOUxx (Do Until)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| DOUXX   | Comparand     | Comparand       |                |               |
*---------*---------------*-----------------*----------------*---------------*

The DOUxx operation begins a group of operations you want to process more than once (but always at least once). An associated ENDDO statement marks the end of the group. For further information on DO groups and the meaning of xx, see Structured Programming Operations.

Factor 1 and factor 2 must contain a literal, a named constant, a field name, a table name, an array element, a figurative constant, or a data structure name. Factor 1 and factor 2 must be either both character or both numeric.

On the DOUxx statement, you indicate a relationship xx. To specify a more complex condition, immediately follow the DOUxx statement with ANDxx or ORxx statements. The operations in the DO group are processed once, and then the group is repeated while the relationship exists between factor 1 and factor 2 or the condition specified by a combined DOUxx, ANDxx, or ORxx operation exists. The group is always processed at least once even if the condition is not true at the start of the group.

In addition to the DOUxx operation itself, the conditioning indicators on the DOUxx and ENDDO statements control the DO group. The conditioning indicators on the DOUxx statement control whether or not the DOUxx operation begins. The conditioning indicators on the associated ENDDO statement can cause a DO loop to end prematurely.

The DOUxx operation follows these steps:

  1. If the conditioning indicators on the DOUxx statement line are satisfied, the DOUxx operation is processed (step 2). If the indicators are not satisfied, control passes to the next operation that can be processed following the associated ENDDO statement (step 6).
  2. The DOUxx operation is processed by passing control to the next operation that can be processed (step 3). The DOUxx operation does not compare factor 1 and factor 2 or test the specified condition at this point.
  3. Each of the operations in the DO group is processed.
  4. If the conditioning indicators on the ENDDO statement are not satisfied, control passes to the next calculation operation following the associated ENDDO statement (step 6). Otherwise, the ENDDO operation is processed (step 5).
  5. The ENDDO operation is processed by comparing factor 1 and factor 2 of the DOUxx operation or testing the condition specified by a combined operation. If the relationship xx exists between factor 1 and factor 2 or the specified condition exists, the DO group is finished and control passes to the next calculation operation after the ENDDO statement (step 6). If the relationship xx does not exist between factor 1 and factor 2 or the specified condition does not exist, the operations in the DO group are repeated (step 3).
  6. The statement after the ENDDO statement is processed when the conditioning indicators on the DOUxx or ENDDO statements are not satisfied (steps 1 or 4), or when the relationship xx between factor 1 and factor 2 or the specified condition exists at step 5.

See LEAVE (Leave a Do Group) and ITER (Iterate) for information on how those operations affect a DOUxx operation.

See DOUxx Examples.

DOUxx Examples

Figure 26. DOUxx Operations

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  The DOUEQ operation runs the operation within the DO group at
C*  least once.
C           FLDA      DOUEQFLDB
C*
C*  At the ENDDO operation, a test is processed to determine whether
C*  FLDA is equal to FLDB.  If FLDA does not equal FLDB, the
C*  preceding operations are processed again.  This loop continues
C*  processing until FLDA is equal to FLDB.  When FLDA is equal to
C*  FLDB, the program branches to the operation immediately
C*  following the ENDDO operation.
C                     SUB  1         FLDA
C                     ENDDO
C*
C*  The combined DOUEQ ANDEQ OREQ operation processes the operation
C*  within the DO group at least once.
C           FLDA      DOUEQFLDB
C           FLDC      ANDEQFLDD
C           FLDE      OREQ 100
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  At the ENDDO operation, a test is processed to determine whether
C*  the specified condition, FLDA equal to FLDB and FLDC equal to
C*  FLDD, exists.  If the condition exists, the program branches to
C*  the operation immediately following the ENDDO operation.  There
C*  is no need to test the OREQ condition, FLDE equal to 100, if the
C*  DOUEQ and ANDEQ conditions are met.  If the specified condition
C*  does not exist, the OREQ condition is tested.  If the OREQ
C*  condition is met, the program branches to the operation
C*  immediately following the ENDDO.  Otherwise, the operations
C*  following the OREQ operation are processed and then the program
C*  processes the conditional tests starting at the second DOUEQ
C*  operation.  If neither the DOUEQ and ANDEQ condition nor the
C*  OREQ condition is met, the operations following the OREQ
C*  operation are processed again.
C                     SUB  1         FLDA
C                     ADD  1         FLDC
C                     ADD  5         FLDE
C                     ENDDO


[ Top of Page | Previous Page | Next Page | Table of Contents ]