Code for Program to create a Attendence Report of Employees in Cobol
IDENTIFICATION DIVISION.
PROGRAM-ID. EMPLOYEE.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMP-IN-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT EMP-OUT-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
* Input file description.
FD EMP-IN-FILE LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS 'EMPL2001.DAT'.
01 EMP-REC.
05 ENO PIC 9(5).
05 ENAME PIC X(25).
05 EBASIC PIC 9(4)V99.
05 EMY.
10 MM PIC 99.
10 YY PIC 99.
* Attendence of the 31 days.
05 EATTEN OCCURS 31 TIMES PIC A.
FD EMP-OUT-FILE LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS 'EMPREC.RPT'.
01 OUT-REC PIC X(120).
WORKING-STORAGE SECTION.
* Structure of the header to be printed.
01 HEAD1.
05 FILLER PIC X(35) VALUE SPACES.
05 TEXT1 PIC X(25) VALUE
'RCC INFO TECH LTD'.
01 HEAD2.
05 FILLER PIC X(4) VALUE SPACES.
05 COL1 PIC X(5) VALUE 'EMP.'.
05 FILLER PIC X(2) VALUE SPACES.
05 COL2 PIC X(25) VALUE 'EMP.'.
05 FILLER PIC X(2) VALUE SPACES.
05 COL3 PIC X(7) VALUE 'DAILY'.
05 FILLER PIC X(4) VALUE SPACES.
05 COL4 PIC X(8) VALUE SPACES.
05 COL5 PIC X(10) VALUE 'ATTENDANCE'.
05 COL6 PIC X(7) VALUE 'DAYS'.
05 COL7 PIC X(5) VALUE SPACES.
05 FILLER PIC X(2) VALUE SPACES.
05 COL8 PIC X(6) VALUE SPACES.
05 FILLER PIC X(2) VALUE SPACES.
05 COL9 PIC X(8) VALUE SPACES.
05 FILLER PIC X(5) VALUE SPACES.
05 COL10 PIC X(15) VALUE 'SALARY'.
* Structure of the actual record to be printed in report.
01 REC.
05 FILLER PIC X(1) VALUE SPACES.
05 REC1 PIC Z(5).
05 FILLER PIC X(2) VALUE SPACES.
05 REC2 PIC X(25).
05 FILLER PIC X(4) VALUE SPACES.
05 REC3 PIC ZZZZ.ZZ.
05 REC-ATTEN OCCURS 6 TIMES PIC Z(7)9.
05 FILLER PIC X(5) VALUE SPACES.
05 REC5 PIC ZZ,ZZ,ZZ9.99.
* Attendence count of the 6 type of employees.
01 EMP-ATTEN.
05 ATTEN OCCURS 6 TIMES PIC 9(7).
77 D-LINE PIC X(120) VALUE ALL '-'.
77 AMT PIC 9(9)V99.
77 TSAL PIC 9(9)V99 VALUE ZERO.
77 ECOUNT PIC 99 VALUE ZERO.
77 I PIC 99 VALUE ZERO.
77 EOF PIC X VALUE 'N'.
PROCEDURE DIVISION.
* Main procedure to open files and perform operations.
MAIN-PARA.
OPEN INPUT EMP-IN-FILE
OUTPUT EMP-OUT-FILE.
PERFORM HEAD-PARA.
READ EMP-IN-FILE.
PERFORM READ-PARA UNTIL EOF = 'Y'.
PERFORM FOOTER-PARA.
PERFORM CLOSE-PARA.
* Intialise the total variables by zero.
INIT-PARA.
MOVE ZERO TO ATTEN(I).
* Para to print the header in the output file.
HEAD-PARA.
WRITE OUT-REC FROM HEAD1.
MOVE 'SALARY STATEMENT' TO TEXT1.
WRITE OUT-REC FROM HEAD1.
WRITE OUT-REC FROM D-LINE.
WRITE OUT-REC FROM HEAD2.
MOVE 'NO.' TO COL1.
MOVE 'NAME' TO COL2.
MOVE 'RATE' TO COL3.
MOVE 'PRE' TO COL4.
MOVE 'ABS' TO COL5.
MOVE 'HDAY' TO COL6.
MOVE 'LWP' TO COL7.
MOVE 'SICK' TO COL8.
MOVE 'LEAVE' TO COL9.
MOVE SPACES TO COL10.
WRITE OUT-REC FROM HEAD2.
WRITE OUT-REC FROM D-LINE.
* Para to read the record and calculate his attendence.
READ-PARA.
ADD 1 TO ECOUNT.
PERFORM INIT-PARA VARYING I FROM 1 BY 1 UNTIL I > 6.
PERFORM CALC-PARA VARYING I FROM 1 BY 1 UNTIL I > 31.
PERFORM WRITE-PARA.
READ EMP-IN-FILE AT END MOVE 'Y' TO EOF.
* Depending upon the input value increment the attendence type.
CALC-PARA.
IF EATTEN(I) = 'P'
ADD 1 TO ATTEN(1)
ELSE IF EATTEN(I) = 'A'
ADD 1 TO ATTEN(2)
ELSE IF EATTEN(I) = 'H'
ADD 1 TO ATTEN(3)
ELSE IF EATTEN(I) = 'W'
ADD 1 TO ATTEN(4)
ELSE IF EATTEN(I) = 'S'
ADD 1 TO ATTEN(5)
ELSE IF EATTEN(I) = 'E'
ADD 1 TO ATTEN(6).
* Write the output record to the file.
WRITE-PARA.
MOVE ENO TO REC1.
MOVE ENAME TO REC2.
MOVE EBASIC TO REC3.
PERFORM MOVE-PARA VARYING I FROM 1 BY 1 UNTIL I > 6.
IF ATTEN(1) > 26
COMPUTE AMT = (EBASIC * 26) +
((1.5 * EBASIC) * (ATTEN(1) - 26))
ELSE
COMPUTE AMT = (EBASIC * 26).
ADD AMT TO TSAL.
MOVE AMT TO REC5.
WRITE OUT-REC FROM REC.
* Move unedited attendence to edited one.
MOVE-PARA.
MOVE ATTEN(I) TO REC-ATTEN(I).
* Para to print the footer report in the output file.
FOOTER-PARA.
WRITE OUT-REC FROM D-LINE.
MOVE SPACES TO REC.
MOVE 'TOTAL SALARY' TO REC2.
MOVE TSAL TO REC5.
WRITE OUT-REC FROM REC.
MOVE SPACES TO REC.
MOVE 'NO. OF EMPLOYEES :=> ' TO REC2.
MOVE ECOUNT TO REC-ATTEN(1).
WRITE OUT-REC FROM REC.
WRITE OUT-REC FROM D-LINE.
* Para to close all files and end the program.
CLOSE-PARA.
CLOSE EMP-IN-FILE EMP-OUT-FILE.
STOP RUN.