RPG/400 Help

DOWxx (Do While)

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

The DOWxx operation begins a group of operations you want to process while the relationship xx exists between factor 1 and factor 2. To specify a more complex condition, immediately follow the DOWxx statement with ANDxx or ORxx statements. 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 figurative constant, a field name, a table name, an array element, or a data structure name. Factor 1 and factor 2 must be either both character or both numeric. The comparison of factor 1 and factor 2 follows the same rules as those given for the compare operations. See Compare Operations.

In addition to the DOWxx operation itself, the conditioning indicators on the DOWxx and ENDDO statements control the DO group. The conditioning indicators on the DOWxx statement control whether or not the DOWxx operation is begun. The conditioning indicators on the associated ENDDO statement control whether the DO group is repeated another time.

The DOWxx operation follows these steps:

  1. If the conditioning indicators on the DOWxx statement line are satisfied, the DOWxx operation is processed (step 2). If the indicators are not satisfied, control passes to the next operation to be processed following the associated ENDDO statement (step 6).
  2. The DOWxx operation is processed by comparing factor 1 and factor 2 or testing the condition specified by a combined DOWxx, ANDxx, or ORxx operation. If the relationship xx between factor 1 and factor 2 or the condition specified by a combined operation does not exist, the DO group is finished and control passes to the next calculation operation after the ENDDO statement (step 6). If the relationship xx between factor 1 and factor 2 or the condition specified by a combined operation exists, the operations in the DO group are repeated (step 3).
  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 operation to run following the associated ENDDO statement (step 6). Otherwise, the ENDDO operation is processed (step 5).
  5. The ENDDO operation is processed by passing control to the DOWxx operation (step 2). (Note that the conditioning indicators on the DOWxx statement are not tested again at step 1.)
  6. The statement after the ENDDO statement is processed when the conditioning indicators on the DOWxx or ENDDO statements are not satisfied (steps 1 or 4), or when the relationship xx between factor 1 and factor 2 of the specified condition does not exist at step 2.

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

See DOWxx Examples.

DOWxx Examples

Figure 27. DOWxx Operations

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  The DOWLT operation allows the operation within the DO group
C*  to be processed only if FLDA is less than FLDB.  If FLDA is
C*  not less than FLDB, the program branches to the operation
C*  immediately following the ENDDO operation.  If FLDA is less
C*  than FLDB, the operation within the DO group is processed.
C           FLDA      DOWLTFLDB
C*
C*  The ENDDO operation causes the program to branch to the first
C*  DOWLT operation where a test is made to determine whether FLDA
C*  is less than FLDB.  This loop continues processing until FLDA
C*  is equal to or greater than FLDB; then the program branches
C*  to the operation immediately following the ENDDO operation.
C                     MULT 2.08      FLDA
C                     ENDDO
C*  In this example, multiple conditions are tested.  The combined
C*  DOWLT ORLT operation allows the operation within the DO group
C*  to be processed only while FLDA is less than FLDB or FLDC. If
C*  neither specified condition exists, the program branches to
C*  the operation immediately following the ENDDO operation. If
C*  either of the specified conditions exists, the operation after
C*  the ORLT operation is processed.
C           FLDA      DOWLTFLDB
C           FLDA      ORLT FLDC
C*  The ENDDO operation causes the program to branch to the second
C*  DOWLT operation where a test determines whether specified
C*  conditions exist.  This loop continues until FLDA is equal to
C*  or greater than FLDB and FLDC; then the program branches to the
C*  operation immediately following the ENDDO operation.
C                     MULT 2.08      FLDA
C                     ENDDO


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