Compiler-directive Statements
Compiler directive statements (often called "directives") provide instructions to the COBOL compiler about how the program should compile and produce the desired object code.
Compiler-directive statements are not executable code, unlike other COBOL statements. These directives impact the behavior of the compiler during the compilation.
The important statements used in the COBOL program are -
COPY Statement
The COPY statement is used to include predefined copybooks (usually file record structures) from an external source into the current COBOL program.
COPY copybook-name
Example - Insert a copybook into the program.
Copybook - MATEPK.COBOL.COPYLIB(EMPREC)
----+----1----+----2----+----3----+----4----+----5----
05 EMP-NUM PIC 9(05).
05 EMP-NAME PIC X(10).
05 EMP-DESG PIC X(15).
05 EMP-SALARY PIC 9(10).
Code -
----+----1----+----2----+----3----+----4----+----5----
01 EMP-REC.
COPY EMPREC.
Listing after compilation -
----+----1----+----2----+----3----+----4----+----5----
01 EMP-REC.
* COPY EMPREC.
05 EMP-NUM PIC 9(05).
05 EMP-NAME PIC X(10).
05 EMP-DESG PIC X(15).
05 EMP-SALARY PIC 9(10).
EXIT Statement
The EXIT statement is a "do-nothing" statement mainly used for readability and structure, giving a logical endpoint for a section or paragraph.
EXIT
Example - EXIT usage in paragraph.
...
PROCEDURE DIVISION.
PERFORM 1000-DISPLAY
THRU 1000-EXIT.
STOP RUN.
1000-DISPLAY.
DISPLAY "PARAGRAPH EXIT EXAMPLE".
1000-EXIT.
EXIT.
Explaining Example -
1000-EXIT is the paragraph coded only with EXIT statement that acts as a exit paragraph for 1000-DISPLAY.
EJECT Statement
The EJECT statement specifies the next source statement should print as the first statement of the next page. It does not affect the compilation and execution of the program.
EJECT
Example - Coding EJECT statement in COBOL program.
Copybook - MATEPK.COBOL.COPYLIB(EMPREC)
----+----1----+----2----+----3----+----4----+
05 EMP-NUM PIC 9(05).
05 EMP-NAME PIC X(10).
05 EMP-DESG PIC X(15).
05 EMP-SALARY PIC 9(10).
Code -
----+----1----+----2----+----3----+----4----+
01 EMP-REC.
COPY EMPREC.
EJECT.
01 WS-VAR.
05 WS-INPUT1 PIC X(10).
Explaining Example -
The EJECT statement won't display in the program listing. It skips the current page listing, and WS-VAR starts displaying as the next page's first line of the program listing.
SKIP Statement
SKIP1, SKIP2, or SKIP3 statements specify the number of blank lines that should replace the SKIP statements while listing the COBOL source code.
SKIP1
SKIP2
SKIP3
Example - Coding SKIP1 statement in COBOL program.
----+----1----+----2----+----3----+----4----+----5----
01 EMP-REC.
COPY EMPREC.
SKIP1.
01 WS-VAR.
05 WS-INPUT1 PIC X(10).
Explaining Example -
The SKIP1 statement won't display in the program listing. It inserts one blank line before WS-VAR declaration line in the program listing.
Other Statements -
Statement | Usage |
---|---|
BASIS statement | It is an extended library statement and specifies the complete COBOL program as a source for compilation. |
CALLINTERFACE directive | Specifies the interface for CALL and SET statements. |
DELETE statement | It is an extended library statement that removes COBOL source statements from the BASIS source program. |
ENTER statement | Treats as a comment |
INSERT statement | Library statement adds COBOL statements to the source program. |
PROCESS (CBL) statement | Should code before IDENTIFICATION DIVISION and used to code compiler options that are to be used to compile the module. |
REPLACE statement | Used to replace the source program text. |
SERVICE LABEL statement | Generates by the CICS translator and used to specify the control flow. |
TITLE statement | Specifies the header that should print on top of each page. |
USE statement | Provides the declarative. |