Summary -

In this topic, we described about the Subroutines with detailed example.

Subroutines are one of the below -

  • A paragraph separated from procedure division.
  • A piece of code that is executed from more than one program.
  • A subprogram called from main program.

Subroutines that are a paragraph compiled along with program compilation. Subroutines that are procedure division code can't be compiled independently and compiled along with program compilation where it is included. For example, B is a procedure division subroutine and included in program A. B can't be compiled independently. However, B gets compiled while A is compiling.

Subroutines that are subprograms compiled independently and can't be executed individually. Subroutine Types - There are two types of subroutines -

  • Internal subroutines - Called by using Outline PERFORM statement
  • External subroutines - These are two types
    • Subprograms - called by using CALL statement.
    • Procedure division code modules - included in the program by using INCLUDE statement and called by using PERFORM statement.