Summary -
In this topic, we described about the INCLUDE Statement with detailed example.
INCLUDE statement used to inserts a piece of source code into a source program. INCLUDE can include part of actual code of application program.
Syntax -
++INCLUDE member-name
Member-name specifies the member name that contains the source code. member-name also called as a procedure division copybook.
During the pre-compilation process, INCLUDE statement replaces with the code in it. INCLUDE statement can be specified anywhere in the procedure division.
Uses: -
Reading master files are required in multiple programs and their reading procedure is same. If we code the same reading process in multiple programs, it increases the redundancy. INCLUDE statement resolves the issue by using a member-name that has the common code to read the master file. INCLUDE reduces coding and debugging time.
Practical Example - INCLUDE
Below example will explain about how the cobol code include will work
PERFCODE.INCLUDE will include to the main program during the pre-compilation process. So program will be compiled as a single piece of code
Include PERFCODE Code:
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 6 SET STD-INDEX TO 1 ACCEPT STD-MARKS (STD-INDEX) IF STD-MARKS (STD-INDEX) < 35 CONTINUE ELSE ADD STD-MARKS (STD-INDEX) TO TOTAL-MARKS SET STD-INDEX DOWN BY 1 COMPUTE J = J + 1 END-IF END-PERFORM.
Program Code:
IDENTIFICATION DIVISION. PROGRAM-ID. COBINCLD. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 STD-DET OCCURES 6 TIMES INDEXED BY STD-INDEX. 05 STD-MARKS PIC 9(03). 01 TOTAL-MARKS PIC 9(03) VALUE ZERO. 01 STD-PERCENT PIC 9(03).9(02). 01 I PIC 9(01). 01 J PIC 9(01) VALUE ZERO. PROCEDURE DIVISION. MOVE ZEROES TO TOTAL-MARKS. ++INCLUDE PERFCODE IF J < 6 DISPLAY 'STUDENT FAILED, NO PERCENTAGE CALCULATED' ELSE COMPUTE STD-PERCENT = TOTAL-MARKS/6 DISPLAY 'STUDENT PERCENTAGE : ' STD-PERCENT. END-IF. STOP RUN.