Open In App

COBOL – Include Statement

The INCLUDE statement refers to the file or the directory mentioned after it and inserts the command present inside that member in the pre-compilation state. Basically, it is used to insert a code block onto a source program.

Syntax:



INCLUDE member-name

Where,

Advantages of using Include:

Following are the advantages of using the INCLUDE statement:



Let’s take an example of the INCLUDE statement in Cobol.

Example:




IDENTIFICATION DIVISION.
PROGRAM-ID. DEMO2.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
    01 NUM  PIC 9(5) VALUE ZERO.
    01 REM  PIC 9(5) VALUE ZERO.
    01 DIV  PIC 9(5) VALUE ZERO.
    01 FLAG PIC A(1) VALUE 'Y'.
PROCEDURE DIVISION.
MAIN-PROCEDURE.
 
    A-PARA.
    INCLUDE ODDEVE.
    EXIT.
 
    PERFORM A-PARA UNTIL FLAG EQUAL 'N'
 
    STOP RUN.

Explanation:

The program DEMO2 is using a member ODDEVE with the help of Include syntax in COBOL, when the program executes instead of line INCLUDE ODDEVE  the actual code present inside the member ODDEVE(shown below) is inserted which is logically written to check whether the number is odd or even.




DISPLAY 'ENTER NUMBER:'
ACCEPT NUM
 
DIVIDE NUM BY 2 GIVING DIV REMAINDER REM.
 
IF REM = 0
    DISPLAY 'EVEN NUMBER'
    DISPLAY 'DO YOU WANT TO CONTINUE? (Y/N):'
    ACCEPT FLAG
 
ELSE
    DISPLAY 'ODD NUMBER'
    DISPLAY 'DO YOU WANT TO CONTINUE? (Y/N):'
    ACCEPT FLAG
END-IF.

Output:

 


Article Tags :