Sign in

docs ILE Concepts

Call Stack Example

Call Stack Example

Figure 1 contains a segment of a call stack with two programs: an OPM program (Program A) and an ILE program (Program B). Program B contains three procedures: its program entry procedure, its user entry procedure, and another procedure (P1). The concepts of program entry procedure (PEP) and user entry procedure (UEP) are defined in Module Object. The call flow includes the following steps:

  1. A dynamic program call to Program A.
  2. Program A calls Program B, passing control to its PEP. This call to Program B is a dynamic program call.
  3. The PEP calls the UEP. This is a static procedure call.
  4. The UEP calls procedure P1. This is a static procedure call.

Figure 1. Dynamic Program Calls and Static Procedure Calls on the Call Stack

Figure 1 illustrates the call stack for this example. The most recently called entry on the stack is depicted at the bottom of the stack. It is the entry for the program or procedure that is currently processing. The current program or procedure may do either of the following:

  • Call another procedure or program, which adds another entry to the bottom of the stack.
  • Return control to its caller after it is done processing, which causes its call stack entry to be removed from the stack.

Assume that, after procedure P1 is done, no more processing is needed from Program B. Procedure P1 returns control to the UEP, and the entry for P1 is removed from the stack. Then the UEP returns control to the PEP, and the UEP entry is removed from the stack. Finally, the PEP returns control to Program A, and the PEP entry is removed from the stack. Only Program A’s entry is left on this segment of the call stack. Program A continues processing from the point where it made the dynamic program call to Program B.