Another example of a conditional loop is: &Y = &LITERAL A&B &LOOP 2 .&X EQ &LITERAL .& &X = &SUBSTR &Y 2 1 &TYPE &X These statements are interpreted and executed as follows:
1. The variable &Y is set to the literal value A&B.
2. The two statements following the &LOOP statement are to be executed
until the value of &X is &.
3. The &SUBSTR built-in function is used to set the variable &X to the
value of the second character in the variable &Y, which is a
literal ampersand (&).
4. The ampersand is typed once, and the loop does not execute again
because the condition that the value of &X be a literal ampersand
is met. NESTING EXEC PROCEDURES If you want to use an EXEC procedure within another EXEC, you must use
the EXEC command to execute it. For example, if you have the statement: EXEC TEST in an EXEC procedure, it invokes the EXEC procedure TEST. The procedure TEST EXEC executes independently of the other EXEC; the variables &1, &2
and so on are assigned values and the default settings for control
statements such as &CONTROL and &HEX are reset. When TEST EXEC completes execution, control returns to the next line in the calling EXEC, where the values for variable symbols and EXEC settings are the
same as when the TEST EXEC was invoked. Variables in an EXEC file have meaning only within the particular
procedure in which they are defined. There are two methods you can use
to pass variable information to nested EXECs. One way is to pass
arguments on the EXEC command line. For examFle, if the CHECK EXEC contains the line: EXEC COUNTEft SWUM then the current values of and are assigned to the variable
symbols &1 and &2 in COUNTEft EXEC. (The values of &1 and &2 in CBECK EXEC do not change.) You can also use the ten special variables &GLOBALO through &GLOB1L9. These variables can only contain integral numeric values; you cannot
assign them character-string values. These variables can be used to set
up arguments to pass to nested procedures, or to communicate between EXEC files at different recursion levels.
282 IBM VM/370 User's Guide
Thus, if CHECK EXEC contains:
&GLOBAL1 = 100 EXEC COUNTEM The variable &GLOBAL1 has a value of 100 in COUNTEM EXEC, which may also
test and modify it.
The EXEC interpreter can handle up to 19 levels of recursion at one
time, that is, up to 19 EXECs may be active, one nested within another.
An EXEC may also call itself.
Iou can test the &GLOBAL special variable to see if an EXEC is
executing within another procedure and if so, at what level of recursion
it is executing. For example, if the file RECOMP EXEC contained the
lines: &IP &GLOBAL EQ 2 &GOTO -2NDPASS EXEC RECOMP -2NDPASS &TIPE SECOND PASS BEGINS then when the line "EXEC RECOMP" is executed, control passes to the
beginning of the EXEC; the value of &GLOBAL changes from 1 to 2; and
control is passed to the &TIPE statement at the label 2NDPASS. EXITING FROM EXEC PROCEDURES Execution in an EXEC procedure proceeds sequentially through a file,
line by line. When a statement causes control to be passed to another
statement, execution continues at the second statement, and again
proceeds sequentially through the file. When the end of the file is
reached, the EXEC terminates processing. Frequently, however, you may not want processing to continue to the end of the file. Iou can use the &EXIT statement to cause an immediate exit from EXEC processing and a
return to the CMS environment. If the EXEC has been invoked from
another EXEC, control is returned to the calling EXEC file. For
example, the statement:
&IF &RETCODE 0 &EXIT would cause an immediate exit from the EXEC if the return code from the
last issued CMS command was not zero.
Iou can use the
execution paths in
statements, &EXIT statement to
an EXEC. For
terminate each
example, using
of a
the
series of
following
Section 14. Building EXEC Procedures 283
Previous Page Next Page