DO/DOEND

#### Search Results

Search

# DO/DOEND

`DO` `statement` `DOEND`

This document covers the following topics:

- DO/DOEND Usage

- DO/DOEND Restrictions

- DO/DOEND Example

For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.

Belongs to Function Group: Reporting Mode Statements

## DO/DOEND Usage

The `DO` and `DOEND` statements are used in reporting mode to specify a group of statements to be executed based on a logical condition as specified in any of the statements listed below.

- `AT BREAK`

- `AT END OF DATA`

- `AT END OF PAGE`

- `AT START OF DATA`

- `AT TOP OF PAGE`

- `BEFORE BREAK PROCESSING`

- `FIND ... IF NO RECORDS FOUND`

- `IF`

- `IF SELECTION`

- `ON ERROR`

- `READ WORK FILE ... AT END OF FILE`

Note
If you specify a only single statement to be executed based on a logical condition, you can omit the `DO` and `DOEND` statements. But with respect to good coding practice, you are not recommended to do so.

## DO/DOEND Restrictions

- The `DO` and `DOEND` statements are only valid in reporting mode.

- `WRITE TITLE`, `WRITE TRAILER`, and the `AT` condition statements `AT BREAK`, `AT END OF DATA`, `AT END OF PAGE`, `AT START OF DATA`, `AT TOP OF PAGE` are not permitted within a `DO`/`DOEND` statement group.

- A loop-initiating statement may be used within a `DO`/`DOEND` statement group provided that the loop is closed prior to the `DOEND` statement.

## DO/DOEND Example

    ** Example 'DOEEX1': DO/DOEND
    ************************************************************************
    *
    EMP. FIND EMPLOYEES WITH CITY = 'MILWAUKEE'
      VEH. FIND VEHICLES WITH PERSONNEL-ID = PERSONNEL-ID
        IF NO RECORDS FOUND DO
          ESCAPE
        DOEND
        DISPLAY PERSONNEL-ID (EMP.) NAME (EMP.)
                SALARY (EMP.,1)
                MAKE (VEH.) MAINT-COST (VEH.,1)
        AT END OF DATA DO
          WRITE NOTITLE
            / 10X 'AVG SALARY:'
                   T*SALARY (1) AVER(SALARY (1))
            / 10X 'AVG MAINTENANCE (ZERO VALUES EXCLUDED):'
                   T*MAINT-COST (1) NAVER(MAINT-COST (1))
        DOEND
        /*
      LOOP
    LOOP
    END

#### Output of Program DOEEX1:

    PERSONNEL         NAME           ANNUAL           MAKE         MAINT-COST
       ID                            SALARY
    --------- -------------------- ---------- -------------------- ----------

    20021100  JONES                     31000 GENERAL MOTORS            140
    20027800  LAWLER                    29000 GENERAL MOTORS              0
    20027800  LAWLER                    29000 TOYOTA                     86
    20030600  NORDYKE                   47000 FORD                      194

              AVG SALARY:               35666
              AVG MAINTENANCE (ZERO VALUES EXCLUDED):                   140

### On this page

- DO/DOEND Usage
- DO/DOEND Restrictions
- DO/DOEND Example