COBOL Include Statement

COBOL Copy Statement COBOL Array/Table

Advertisements


INCLUDE statement used to inserts declarations (DCLGEN) or statements into a source program.

INCLUDE statement can add the code to the programs but not an executable statement.

INCLUDE can include DCLGEN (which are usually copybook layouts to the tables) and part of actual code of application program.


Syntax:

INCLUDE SQLCA/SQLDA/member-name

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


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.

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.                                                   


COBOL Copy Statement COBOL Array/Table

Advertisements