COBOL supports open and closed subroutines.
- Open subroutinesThey are implemented using the first format of the PERFORM verb.
For example:
PERFORM SUBPREFORM.
...
SUBPROFORM.
COBOL-STATEMENTS - Closed subroutines They are implemented using the CALL verb and contained or external subprograms.
For example:
CALL "SUBPROG"
Open subroutine is not a real routine, it's in fact a instructions block, so instructions GOBACK/STOP RUN/EXIT PROGRAM on a open subroutines work like on main program.
For example: (RED instructions will not be executed)
STOP RUN
IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. DISPLAY "MAIN ENTRY". PERFORM PERFORM-SUB. DISPLAY "MAIN EXIT". STOP RUN. PERFORM-SUB. DISPLAY 'SUB ENTRY'. STOP RUN. *> PROGRAM STOP HERE DISPLAY 'SUB EXIT'.
EXIT PROGRAM
IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. DISPLAY "MAIN ENTRY". PERFORM PERFORM-SUB. DISPLAY "MAIN EXIT". STOP RUN. PERFORM-SUB. DISPLAY 'SUB ENTRY'. EXIT PROGRAM. *> STATEMENT IS IGNORED DISPLAY 'SUB EXIT'.
(EXIT PROGRAM is ignored)
GOBACK
IDENTIFICATION DIVISION. PROGRAM-ID. MAINPROG. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. DISPLAY "MAIN ENTRY". PERFORM PERFORM-SUB. DISPLAY "MAIN EXIT". STOP RUN. PERFORM-SUB. DISPLAY 'SUB ENTRY'. GOBACK. *> PROGRAM STOP HERE DISPLAY 'SUB EXIT'.
(GOBACK works as STOP RUN)