Previous Topic: ProcedureNext Topic: QUIT Statement


PROCESS NEXT Statement

The PROCESS NEXT statement terminates the current iteration and initiates the next iteration of a repetitive construct (LOOP, FOR EACH/FIRST n/ANY). If the current construct is a FOR, any data record acquired for update is released and no updates take place. The process continues with the next record, if any.

This statement has the following format:

PROCESS NEXT [label]
PROCESS NEXT

Without a label, PROCESS NEXT must appear only in the lexical scope of a LOOP or FOR EACH construct. With a label, PROCESS NEXT must appear in the logical scope of a LOOP or FOR EACH construct.

When a PROCESS NEXT statement appears in the scope of a FOR EACH, any updates to the current dataview record are abandoned, even for fields whose values already were changed.

label

The label of the LOOP or FOR construct for which the current iteration is terminated. The PROCESS NEXT label statement must be in the logical scope of the construct identified by label, that is, PROCESS NEXT must reference the current construct or one at a higher logical level.

When constructs are nested, for example, A invokes B (with a DO B statement), B invokes C, C invokes D, and so on, all procedures in the series of invocations down to the most recently invoked procedure are active. In the above series of invocations, a QUIT B issued from B, C, or D makes B, C, and D inactive and returns control to A. This also applies to nested LOOP or FOR.

The PROCESS NEXT statement, without a label, must appear physically in the program text between FOR/ENDFOR or LOOP/ENDLOOP construct where the statement applies. The FOR or LOOP construct so referenced need not have an explicit label. PROCESS NEXT, without a label, should never appear in a WHEN NONE clause of a FOR construct.

You can always code the PROCESS NEXT statement with a label, regardless of where it appears.

When the PROCESS NEXT statement is executed, the construct where its label refers must be undergoing active iteration. If more than one iterative process can execute a common procedure, take care when specifying PROCESS NEXT to ensure that only the iterative process currently executing is processed.

When PROCESS NEXT executes, the ENDLOOP or ENDFOR statements are not executed.

A PROCESS NEXT in the scope of a FOR construct abandons any modifications to the file caused by the FOR construct, since no modifications are applied until the ENDFOR, with one exception: A DELETE is performed immediately and is not aborted by a PROCESS NEXT.

Example

<<EMP>>
    FOR EACH EMPLOYEE
      WHERE DEPT = 'D' AND JOB_CODE = 'J'
        DO NOTE_DJ_EMP
      <<DEP>>
          FOR EACH DEPENDENT
             DO NOTE_DEP
             IF DEP_AGE > 21
              DO TOO_OLD
              PROCESS NEXT DEP
             ENDIF
             DO ANAL_DEP
         ENDFOR
      IF FOUND_ENOUGH_EMP	QUIT EMP
      ENDIF
ENDFOR

Example

<<MAIN>> PROCEDURE
    SET EMPLOYEE_CO = 0
    <<EMP>>
        FOR EACH EMPLOYEE
          SET FOURTH_QTR_SALES = SALES (10)
            + SALES (11) + SALES (12)
          IF FOURTH_QTR_SALES < 1000
            PROCESS NEXT EMP
          ENDIF
          MOVE 0 TO TOTAL_SALES
          MOVE 1 TO LOW_SUB
          MOVE 1 TO HIGH_SUB
          LOOP VARYING SEARCH_SUB FROM 1 BY 1 THRU 12
            ADD SALES (SEARCH_SUB) TO TOTAL_SALES
            IF SALES (LOW_SUB) > SALES (SEARCH_SUB)
              MOVE SEARCH_SUB TO LOW_SUB
            ENDIF
            IF SALES (HIGH_SUB) < SALES (SEARCH_SUB)
              MOVE SEARCH_SUB TO HIGH_SUB
            ENDIF
          ENDLOOP
          LIST EMPLOYEE.NAME  SALES (LOW_SUB)
            SALES (HIGH_SUB)  TOTAL_SALES
          ADD 1 TO EMPLOYEE_COUNT
          IF EMPLOYEE_COUNT > 99 :illustration only,
             QUIT EMP             :could have been done
          ENDIF                  :with
       ENDFOR                    :FOR FIRST 99 EMPLOYEE
                                 :at beginning
                                  :of EMP PROCEDURE
ENDPROC

PRODUCE Statement

The PRODUCE statement generates a report that must be previously defined with the Report Definition Facility. The PRODUCE statement usually is contained in a FOR or LOOP structure. Each execution of the PRODUCE statement generates one detail group comprising one or more physical lines. (For more information, see the Generating Reports Guide.) The PRODUCE command (see the Command Reference Guide) generates a report facsimile.

This statement has the following format:

PRODUCE report_name[group_name]
report_name

The one‑ to eight‑character name of the report definition for which output is generated.

group_name

The three‑ to eight‑character name of a group in the detail section of the report. If omitted, the primary group is assumed.

Note: Producing a secondary group before its primary group can cause unpredictable results.

Page breaks, control breaks, headings, summaries, and so on, are produced automatically according to the report specification (see the Generating Reports Guide).

In batch, each eight‑character report‑name corresponds to the name of a DD statement and, therefore, must be unique in the run. If the report‑name contains hyphens (‑) or underscores (_), you must use an ASSIGN statement to provide a legal DD name to the operating system.

All fields in the detail group must have values at the time the PRODUCE statement is issued or a runtime error is produced.

A PRODUCE statement can reference only reports that were specified in the program's resource table.

A PRODUCE statement activates a report and it remains active until the application terminates or until the program or the report is released. For more information, see the RELEASE statement topic in this chapter.

A maximum of 15 reports can be active simultaneously.

Example

   FOR EACH EMPLOYEE
      WHERE STATE_ADDRESS = 'TX' AND CITY_ADDRESS = 'DALLAS'
      PRODUCE EMPRPT
   ENDFOR