Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Nesting S procedures

&pagelevel(3)&pagelevel

When a procedure is called within another procedure, this type of procedure call is also referred to as a nested call. By extension, the resulting procedure link is called procedure nesting.

Note that, although nested procedures can be called, one procedure cannot be “written” inside another. This means that each procedure container can contain one procedure only.

If nested procedures are called, the “inner” (=called) procedure is completely processed before control is returned to the calling (= superordinate) procedure. The called procedure is subordinate to the calling procedure.

There are three commands for procedure nesting:

  • CALL-PROCEDURE and INCLUDE-PROCEDURE for the procedure call

  • EXIT-PROCEDURE for procedure termination

The diagram below shows an example of procedure nesting.

In this example, PROC1 is called on the system level; PROC1 is the superordinate procedure for PROC2, PROC3 and PROC4. PROC2, PROC3 and PROC4 are called from within a procedure, i.e. they are subordinate procedures; PROC2 and PROC4 are subordinate to PROC1 only and PROC3 is subordinate to PROC2 and PROC1. PROC2 contains PROC3.

Nested procedures are always called in the foreground. Hence the same rules apply for the call (or start), execution and termination as for foreground procedures which are called on the system level.

Nested procedures may call background procedures. However, these procedures are not nested within the caller hierarchy, but instead initiate a new job with its own independent procedure nesting.

It is important when executing nested procedures that there be mutual access to variables (i.e. to variables that are declared in the superordinate or in the subordinate procedure).

Whether variables can be accessed in nested procedures, i.e. are visible, depends on the declaration of the variable scope and on the command used to call the procedure.

SDF-P provides the following options for accessing variables from superordinate procedures:

  • Passing a variable name as a procedure parameter with the procedure call.

  • Redeclaring task-global variables that are not visible. This means that each of these variables must be declared using a DECLARE-VARIABLE command and with exactly the same attributes as in the superordinate procedure.

  • Importing task-global variables using the IMPORT-VARIABLE command.

For a detailed description of the relationship between the visibility of variables and the procedure call command, as well as the “redeclaration” and importation of variables, see section “Scope of variables”.

For a description of how variable names are passed as procedure parameters, see section“Passing procedure parameters”.