RPG/400 Help

GOTO (Go To)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| GOTO    |               | Label           |                |               |
*---------*---------------*-----------------*----------------*---------------*

The GOTO operation allows calculation operations to be skipped by instructing the program to go to (or branch to) another calculation operation in the program. A TAG (Tag) operation names the destination of a GOTO operation. Use a GOTO operation to specify a branch:

A GOTO operation outside a subroutine cannot specify a branch to a TAG or ENDSR operation within that subroutine.

A branch cannot be made from a total calculation line to a detail calculation line. (A total calculation line is defined as one that is conditioned by a control level indicator in positions 7 and 8 of the calculation specifications.)

Branching from one part of the RPG/400 logic cycle to another may result in an endless loop. You are responsible for ensuring that the logic of your program does not produce undesirable results.

Factor 2 must contain the label to which the program is to branch. This label is entered in factor 1 of a TAG or ENDSR operation. The label must be a unique symbolic name.

See Figure "GOTO and TAG Operations" for examples of the GOTO operation.

GOTO Examples

Figure 31. GOTO and TAG Operations

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  If indicator 10, 15, or 20 is on, the program branches to
C*  the TAG label specified in the GOTO operations.
C*  A branch within detail calculations.
C   10                GOTO RTN1
C*
C*  A branch from detail to total calculations.
C   15                GOTO RTN2
C*
C           RTN1      TAG
C*
C                      :         Calculations
C                      :
C
C   20                GOTO END
C*
C                      :
C                      :         Calculations
C                      :
C           END       TAG
C*  A branch within total calculations.
CL1                   GOTO RTN2
CL1
CL1         RTN2      TAG


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