The &GOTO control statement can be coded wherever an executable
statement is permitted in an EXEC procedure. One of its common uses is
in conjunction with the &IF control statement. For example, in the
statement:
&IF &INDEX EQ 0 &GOTO -ERROR the branch to the statement labeled -ERROR is taken when the value of
the &INDEX special variable is zerOe Otherwise, control passes to the
next sequential statement in the EXEC proceduie.
An &GOTO statement can also stand alone as an EXEC control statement. When coded as such, it forces an unconditional branch to the specified
location. For example, you might create an EXEC that has several
execution paths, each of which terminates with an &GOTO state.ent
leading to a co.mon exit routine: -PATHl &CONTINUE &GOTO -EXIT -PATH2 &CONTINUE &GOTO -EXIT &PATH3 &CONTINUE -EXIT &CONTINUE Iou can use the &GOTO control statement to establish a loop. For
example: &GLOBALl = &GLOBAL1 + 1 &TIPE ENTER NUMBER: &READ VARS &NEXT SIF .&NEXT = &GOTO -FINIS
&IF &GLOBAL1 = 2 &TOTAL = 0 &TOTAL = &TOTAL &NEXT &GOTO TOP -FINIS STIPE TOTAL IS &TOTAL In this EXEC example, all of the statements, through the SGOTO TOP statement, are executed repeatedly until a null line is entered in
response to the prompting message. Then, the branch is taken to the
label -FINIS and the total is typed.
Note the use of
example. The &GLOBALn an initial value of 1.
the special variable &GLOBAL1 in the
special variables are self-initializing
preceding
and have When an EXEC procedure processes an &GOTO statement, and searches for a
given label or line number, the scan begins on the line following the &GOTO statement, proceeds to the botto. of the file, then wraps around
to the top of the file and continues to the line immediately preceding
278 IBM VM/370 CMS User's Guide
the &GOTO statement. If there are duplicate labels in an EIEC file, the
first label encountered during the search is the one that is branched
to.
If the label or line number is not found during the scan, EXEC terminates precessing and displays the .essage: ERROR IN EXEC FILE filename, LINE n - SSKIP or SGOTO ERROR
If the label or line number is found, control is passed to that location
and execution continues.
BRANCHING WITH THE SSKIP STATEMENT The SSKIP control statement provides you with a second method of passing
control to various points in an EXEC procedure. Instead of branching to
a named or numbered location in an EXEC procedure, SSKIP passes control
a specified number of lines forward or backward in the file.
Iou pass control forward in an EXEC by specifying how many lines to
skip. For example, to handle a conditional exit from an EXEC procedure,
you could code the following: SIF SRETCODE EQ 0 SSKIP SEXIT SRETCODE where the SEIIT statement is skipped whenever the value of SRETCODE equals zero. If the value of SRETCODE does not equal zero, control
passes out of the current EXEC procedure with a return code that is the
nonzero value in &RETCODE. Note that when no SSKIP operand is
specified, a value of 1 is assumed. A succession of SSKIP statements can be used to perform multiple
tests on a variable. For example, suppose an argument should contain a
value from 5 to 10 inclusive: SIF S1 LT 5 SSKIP SIF &1 LE 10 SSKIP STIPE &1 IS NOT WITHIN RANGE 5-10 If the value of &1 is less than 5. control passes to the &TIPE control
statement, which displays the erroneous value and an explanatory
message. If the value of S1 is greater than or equal to 5, the next
statement checks to see if it is less than or equal to 10. If this is
true, then the value is between 5 and 10 inclusive, and execution
continues following the STIPE statement. When you want to pass control to a statement that precedes the
current line, determine how many lines backward you want to go, and code SSKIP with the desired negative value: SVAL = 1 STIPE &VAL SVAL = &VAL + 1
&IF SVAL NE 10 SSKIP -2
In this EXEC, the STIPE statement is executed repeatedly until the value
of SVAL is 10, and then execution continues with the statement following
the &IP statement. Section 14. Building EXEC Procedures 279
Previous Page Next Page