INCLUDE Statement
INCLUDE Statement
INCLUDE statement used to insert a code block into a source program during the program compilation. The code block contains the PROCEDURE DIVISION code in it. These are called COBOL includes or PROCEDURE DIVISION copybooks.
The basic idea behind this concept is to place the common code in a member (like a program) and include it in the applicable programs with the help of an INCLUDE statement.
Syntax -
++INCLUDE member-name
Parameters -
- member-name - Refers to where the code is placed.
Uses -
- Increases the code readability and reduces the length of the code.
- Changes are done only in one place and can be reflected in multiple programs with a simple regeneration. This process reduces maintenance costs, time, and effort.
Practical Example -
Scenario - Including ACCINPUT (PROCEDURE DIVISION copybook) in the COBOL Program.
Code -
----+----1----+----2----+----3----+----4----+----5----+
...
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-NAME PIC X(20).
05 WS-GENDER PIC X(01).
...
PROCEDURE DIVISION.
PERFORM 1000-RECEIVE-INPUTS.
DISPLAY 'RECEIVED NAME: ' WS-NAME.
DISPLAY 'RECEIVED GENDER: ' WS-GENDER.
STOP RUN.
++INCLUDE ACCINPUT.
ACCINPUT code copybook -
1000-RECEIVE-INPUTS.
ACCEPT WS-NAME.
ACCEPT WS-GENDER.
Run JCL -
//MATEPKRJ JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID
//*
//STEP01 EXEC PGM=COBINC
//STEPLIB DD DSN=MATEPK.COBOL.LOADLIB,DISP=SHR
//SYSIN DD *
SRINIVAS
M
/*
//SYSOUT DD SYSOUT=*
Output -
RECEIVED NAME: SRINIVAS RECEIVED GENDER: M