GOTO – Continue execution from an in scope label

Use the GOTO command to allow the process to skip to a named line of code, as long as it is in scope.

GOTO <label>

Where <label> is the name of the line to which the process is to skip (the colon sign must not be included).

Workload Automation Programming Language labels can be up to 16 characters in length, contain alpha, numeric or the underscore character. A label is indicated by the colon sign (:) at the end (for example, MYLABEL: ). The colon is not included in the length.

The label to which you want to jump must be in scope. This means that:

  • You can jump only to a label in the same input stream. For example, you cannot jump from a statement in EQQOPTS to one in SYSIN.
  • You can jump forward or backward.
  • You cannot jump into a loop or other DO|END structure.
  • You can jump out of a loop or other DO|END structure, including jumping out into a DO|END structure that contains the current one.
  • You cannot jump into a SUBROUTINE.
  • You cannot jump out of a SUBROUTINE.

Using GOTO could cause an uncontrolled loop. The OPTIONS LIMIT keyword sets the number of times that any single GOTO statement can run; when the limit is reached RC=12 is issued. The default limit is 100.

Because the GOTOcommand runs in an uncontrolled way, consider first the following alternatives:

  • ITERATE escapes the running of the current loop and continues from the top of the loop on the next iteration.
  • LEAVE exits the current loop and resumes processing after the END statement at the bottom of the loop.
  • CALL SUB allows a subroutine to be called and returns processing to the line following the CALL when the end of the subroutine is reached.
The following example shows a GOTO command used within SYSIN, loops, and subroutines:
VARSUB SCAN                    
PART1: DISPLAY "PART1"         
VARSET COUNT = 0               
PART2: DISPLAY "PART2"         
GOTO PART9                     
PART3: DISPLAY "PART3"         
VARSET COUNT DELTA(1)          
PART4: DISPLAY "PART4"         
PART5: DISPLAY "PART"          
DO 5                           
   PART5A: DISPLAY "PART5A"    
   GOTO PART5E                 
   PART5B: DISPLAY "PART5B"    
   PART5C: DISPLAY "PART5C"    
   PART5D: DISPLAY "PART5D"    
   PART5E: DISPLAY "PART5E"    
END                            
CALL SUB(BLK_SUBROUTINE1)      
PART6: DISPLAY "PART6"         
PART7: DISPLAY "PART7"         
PART8: DISPLAY "PART8"      
PART9: DISPLAY "PART9"      
IF !COUNT < 4 THEN DO       
   GOTO PART3:              
END                         
PART10: DISPLAY "PART10"    
EXIT                        
                            
BLK_SUBROUTINE1: SUBROUTINE 
SUB2: DISPLAY "SUB2"        
GOTO SUB8                   
SUB3: DISPLAY "SUB3"        
SUB4: DISPLAY "SUB4"        
SUB5: DISPLAY "SUB5"        
SUB6: DISPLAY "SUB6"        
SUB7: DISPLAY "SUB7"        
SUB8: DISPLAY "SUB8"        
SUB9: RETURN      

Example of use of GOTO within SYSIN, loops and subroutines