TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Include Statement


The INCLUDE statement inserts application code, including declarations and statements, into a source program.

Rules:

  1. INCLUDE must specified in DATA DIVISION and PROCEDURE DIVISION.

  2. INCLUDE should contain source language statements or any SQL statements.

  3. Identifies a member to be included only in the configured include library.

Syntax:

INCLUDE [SQLCA / SQLDA / member-name]

Example: Include an SQL communications area

EXEC SQL
  INCLUDE SQLCA
END-EXEC; 

During the Pre-compilation process, INCLUDE statement replaces by the statements in member.

We will see another use of include.

The ++INCLUDE statement is used to include all of the data records of one source file in another source file at compilation time.

Syntax:

++INCLUDE member-name

Rules:

  • ++INCLUDE must begin in column 8, must be in upper case and must be followed by one or more spaces.

  • Text-name defines a unique external file-name which conforms to the rules for user-defined words.

  • This special statement is not part of the COBOL language. It must, in its entirety, be contained on a single line and must be in upper case.

  • member-name determines the COBOL source file to be included at this place in the source code.

  • Any other text appearing on the line is treated as a comment.

Example:

Below example will explain about how the cobol code include will work.

INCLCODE.INCLUDE will include to the main program during the pre-compilation process. So program will be compiled as a single piece of code

Below example will explain about how the cobol code include will work.

MOVE SPACES TO NAME.
ACCEPT NAME.

COBOL Main Program:

IDENTIFICATION DIVISION.
PROGRAM-ID. COBINCLD.

ENVIRONMENT DIVISION.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 NAME PIC X(10) VALUE SPACES.

PROCEDURE DIVISION.

++INCLUDE INCLCODE 

    DISPLAY 'ENTERED NAME : ' NAME.
    STOP RUN.

This is simple COBOL program. you can add any number of line in include library member.


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal