&DISP = PRINT &COUNT = 2
&IF &INDEX GT 2 &EXIT 1
&IF &INDEX EQ 0 &GOTO -GO &COUNT = &1
&IF &INDEX = 2 &DISP = &2 -GO Default values are supplied for the variables&tISP and &COUNT. Then, &INDEX is tested, and the variables are reset if any arguments were
entered.
CHECKING ARGUMENTS There are a number an EXEC. In some
specific argument
numeric data. To
functions &LENGTH
of tests that you can perform on arguments passed to
cases, you may want to test for the length of a
or to test whether an argument is character data or
perform these tests, you can use the EXEC built-in
and &DATATYPE. To use either &LENGTH or &DATATYPE, you must first assign a variable
to receive the result of the function, and then test the variable. For example, to test whether an entered argument is five characters long,
you could use the statements: &LIMIT = &LENGTH &1
&IF &LIMIT GT 5 &EXIT &LIMIT When these statements are executed, if the first argument (&1) is
greater than five characters, the exit is taken, and the return code
indicates the length of &1.
If you wish to check whether a number was entered for an argument,
use the &DATATYPE function: &STRING = &DATATYPE &2
&IF &STRING ,= NUM &GOTO -ERR4
In this example, the second argument expected by the EXEC must be a
numeric quantity. If it is not, a branch is taken to an error exit
routine. Often, you may create an EXEC that tests for specific arguments and
then takes various paths, depending on the argument. For example:
&IF &2 = PRINT &GOTO -PR &IF &2 = TYPE &GOTO -TY &IF &2 = ERASE &GOTO -ER &EXIT In this EXEC, if the value of &2 is not PRINT, TIPE, or ERASE, or was
not entered, the EXEC terminates processing.
There are two special EXEC keywords that you may use to test arguments
passed in an EXEC. They are &* and &$, which can be used only in an &IF
or an &LOOP control statement. They test the entire range of numeric
variables &1 through &30, as follows:
274 IBM VM/370 eMS User's Guide
The special token &$ is interpreted as "any of the variables &1, &2, ••• , &30." That is, if the value of anyone of the numeric variables
satisfies the established condition, then the &IF statement is
considered to be true. The statement is false only when none of the
variables fulfills the specified requirements.
As an example, suppose you want to make sure that
value is passed to the EXEC. You can check to see
arguments satisfy this condition, as follows:
some particular
if any of the
&IF &$ EQ PRINT &SKIP 2 &TYPE PARM LIST MUST INCLUDE PRINT &EXIT In this example, the path to the &TYPE statement is taken only when none
of the arguments passed to the EXEC procedure equal the character string
PRINT. The special token &* is interpreted as "all of the variables &1, &2, ••• , &30." That is, if the value of each of the numeric variables
satisfies the established condition, then the &IF statement is
considered to be true. The statement is false when at least one of the
variables fails to meet the specified requirements. Use &* to test for the absence of an argument as follows:
&IF &* NE ASSEMBLE &EXIT 3
In this example, if an EXEC is invoked, and none of the arguments equals ASSEMBLE, the EXEC terminates with a return code of 3.
The tokens &* and &$ are set by arguments entered when an EXEC is
invoked and reset .hen you issue an SlRGS or &READ ARGS control
statement. If either &* or &$ is null because no arguments are entered,
the &IF statement is considered a null state.ent, and no error occurs.
Execution Paths In an EXEC You have already seen examples of the
control statements. A more detailed
statements and additional techniques for
an EXEC procedure follow.
LABELS IN AN EXEC PROCEDURE &IF, &GOTO, &SKIP, and &LOep discussion on each of these
controlling execution paths in
In many instances, an execution control statement in an EXEC procedure
causes a branch to a particular statement that is identified by a label.
The rules and conventions for creating syntactically correct EXEC labels
are: A label must begin with a hyphen (dash) and must have at least one
additional character following the hyphen. Up to seven additional alpha.eric characters may follow the hyphen
(with no intervening blanks). However, the sequence: &GOTO -PROBABLY -PROBABLY Section 14. Building EXEC Procedures 275
Previous Page Next Page