TAL Programmer's Guide

Declaring Subprocedures
Structuring Programs
3–10 096254 Tandem Computers Incorporated
Declaring
Subprocedures
You declare subprocedures to specify discrete portions of source code within a
procedure. You can call subprocedures only from within the encompassing
procedure. You can declare any number of subprocedures within a procedure, but
you cannot declare subprocedures within subprocedures.
Place any subprocedure declarations following the procedure’s local declarations. In a
subprocedure declaration, you normally specify a heading and a body.
Subprocedure Heading In the subprocedure heading, include:
The keyword SUBPROC
The subprocedure identifier
Identifiers of formal parameters, if any
The attribute VARIABLE, if needed
Declarations of formal parameters, if any
For example, a subprocedure heading with no formal parameters or attributes looks
like this:
SUBPROC my_heading;
A subprocedure heading with one parameter (named PARAM) and the VARIABLE
attribute looks like this:
SUBPROC my_heading (param) VARIABLE;
INT param;
Subprocedure Body For the subprocedure body, specify a BEGIN-END construct that can contain sublocal
data declarations and statements. For example, within the procedure named
MYPROC you can declare a subprocedure named MYSUB, declare sublocal data
VAR1 and VAR2, and assign a value to VAR1 in a sublocal assignment statement:
PROC myproc; !Declare MYPROC
BEGIN
!Local data declarations
SUBPROC mysub; !Declare MYSUB
BEGIN
INT var1;
INT var2;
var1 := var1 - var2;
END; !End MYSUB
!Local statements
END; !End MYPROC
FORWARD Subprocedures If you need to call a subprocedure before you declare its body, declare a FORWARD
subprocedure. You can then call it from anywhere in the encompassing procedure.
SUBPROC to_come;
FORWARD;