GOTO (Go To)
Free-Form Syntax | (not allowed - use other operation codes, such as LEAVE, LEAVESR, ITER, and RETURN) |
Code | Factor 1 | Factor 2 | Result Field | Indicators | ||
---|---|---|---|---|---|---|
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. The TAG can either precede or follow
the GOTO. Use a GOTO operation to specify a branch:
- From a detail calculation line to another detail calculation line
- From a total calculation line to another total calculation line
- From a detail calculation line to a total calculation line
- From a subroutine to a TAG or ENDSR within the same subroutine
- From a subroutine to a detail calculation line or to a total calculation line.
A GOTO within a subroutine in the cycle-main procedure can be issued to a TAG within the same subroutine, detail calculations or total calculations. A GOTO within a subroutine in a subprocedure can be issued to a TAG within the same subroutine, or within the body of the subprocedure.
Branching from one part of the RPG IV 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.
For more information, see Branching Operations.