Procedure Blocks

A procedure is a sequence of statements beginning with a PROCEDURE statement and ending with an END statement. The purpose of a procedure is to "package" a set of executable statements and declarations to form a block that can be executed from several places in the program simply by calling it. Because a procedure defines a block of statements, it is typically called a procedure block. The following example shows two procedure blocks, A and B:

A: PROCEDURE;
      .
      .
      .
   END A;
 
B: PROCEDURE;
      .
      .
      .
   END B;

Procedures contained within other procedures are called nested or internal procedures. Procedures not contained within other procedures are called external procedures. A program module consists of one or more external procedures. For example:

A: PROCEDURE;
      .
      .
      .
   B: PROCEDURE;
             .
             .
             .
   END B;
   C: PROCEDURE
      .
      .
      .
      D: PROCEDURE;
             .
             .
             .
      END D; 
   END C;
END A;

In this example, Procedure A is external, and procedures B and C are nested within it. Procedure D is nested within procedure C.