COBOL OPEN AND CLOSED SUBROUTINES

来源:互联网 发布:阿里云ddos防护 编辑:程序博客网 时间:2024/06/06 10:06



COBOL supports open and closed subroutines.


  1. Open subroutinesThey are implemented using the first format of the PERFORM verb.
    For example:
    PERFORM SUBPREFORM.
    ...
    SUBPROFORM.
      COBOL-STATEMENTS
  2. 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)



0 0
原创粉丝点击