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)
本文介绍了COBOL语言中两种子程序的概念:开放式子程序和封闭式子程序。开放式子程序通过PERFORM语句定义,其内的GOBACK、STOP RUN和EXIT PROGRAM指令与主程序相同。封闭式子程序则使用CALL语句调用,并可以是内嵌或外部子程序。
4414

被折叠的 条评论
为什么被折叠?



