Department of Mca, Dsce Cobollaboratory 1
Department of Mca, Dsce Cobollaboratory 1
Department of Mca, Dsce Cobollaboratory 1
Program:1A
Problem Statement:
Write a program to evaluate the following using COMPUTE verb. Z=(A-B)*C.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID.P1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 A PIC S9(2).
77 B PIC S9(2).
77 C PIC S9(2).
77 Z1 PIC -ZZZZZ9.
PROCEDURE DIVISION.
ACCEPT-PARA.
DISPLAY "ENTER THE VALUE OF A".
ACCEPT A.
DISPLAY "ENTER THE VALUE OF B".
ACCEPT B.
DISPLAY "ENTER THE VALUE OF C".
ACCEPT C.
DISPLAY-PARA.
COMPUTE Z1=( A - B )*C.
DISPLAY "VALUE OF EXPRESSION IS" Z1.
STOP RUN.
Output:
4
ENTER THE VALUE OF B
2
ENTER THE VALUE OF C
9
VALUE OF EXPRESSION IS 18
Program:1B
Problem Statement:
Write a program to find the sum of individual digits in the given ‘n’ digit decimal
number
Source Code:
2
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
IDENTIFICATION DIVISION.
PROGRAM-ID.P2.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 NUM PIC S9(8).
77 R PIC S9(2).
77 SUM2 PIC 9(4) VALUE 0.
77 SUM1 PIC Z(5).
PROCEDURE DIVISION.
ACCEPT-PARA.
DISPLAY "ENTER THE NUMBER".
ACCEPT NUM.
PERFORM REV-PARA UNTIL NUM=0.
DISPLAY "SUM OF THE DIGITS IS"SUM1.
STOP RUN.
REV-PARA.
DIVIDE NUM BY 10 GIVING NUM REMAINDER R.
ADD R TO SUM2.
MOVE SUM2 TO SUM1.
Output:
Program:2A
Problem Statement:
Write a program for generating odd and even numbers between the given limits by using
PERFORM statement.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID.P2A.
ENVIRONMENT DIVISION.
DATA DIVISION.
3
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
WORKING-STORAGE SECTION.
01 NUM1 PIC 9(3).
01 NUM2 PIC 9(3).
01 R PIC 9(2).
01 N PIC 9(2).
01 I PIC 9(2).
01 J PIC 9(2).
01 M PIC Z(3).
PROCEDURE DIVISION.
DISPLAY-PARA.
DISPLAY "ENTER THE LOWER LIMIT:".
DISPLAY "_____________________".
ACCEPT NUM1.
DISPLAY "ENTER THE UPPER LIMIT:".
DISPLAY "_____________________".
ACCEPT NUM2.
IF NUM1>NUM2
DISPLAY "INVALID INPUT"
STOP RUN.
DISPLAY "_____________________".
DISPLAY "LIST OF EVEN NUMBERS".
DISPLAY "_____________________".
PERFORM CAL-PARA VARYING I FROM NUM1 BY 1 UNTIL I>NUM2.
DISPLAY "______________________".
DISPLAY "LIST OF ODD NUMBERS".
DISPLAY "_____________________".
PERFORM CAL1-PARA VARYING I FROM NUM1 BY 1 UNTIL I>NUM2.
STOP RUN.
CAL-PARA.
DIVIDE I BY 2 GIVING N REMAINDER R.
IF R=0
MOVE I TO J
DISPLAY SPACES "|" J "|".
CAL1-PARA.
DIVIDE I BY 2 GIVING N REMAINDER R.
IF R NOT = 0
MOVE I TO M
DISPLAY SPACES "|" M "|".
Output:
_____________________
1
ENTER THE UPPER LIMIT:
_____________________
10
_____________________
LIST OF EVEN NUMBERS
_____________________
|02|
|04|
|06|
|08|
|10|
______________________
LIST OF ODD NUMBERS
_____________________
| 1|
| 3|
| 5|
| 7|
| 9|
Program:2B
Problem Statement:
Write a program for sorting numeric numbers.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID.P2B.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A1-TABLE.
02 A1 PIC S9(4)V99 OCCURS 10 TIMES.
77 I PIC 9(3).
77 J PIC 9(3).
77 K PIC 9(3).
77 N PIC 9(3).
77 NUM PIC 9(3).
5
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Output:
- 1.00
0.00
4.00
9.00
Program:4A
Problem Statement:
By using table handling concepts, write a program for Sorting alphanumeric data.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. 3A.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A-TAB.
02 A PIC X(10) OCCURS 10 TIMES.
77 I PIC 99.
77 J PIC 99.
77 N PIC S999.
77 T PIC X(10).
77 C PIC XX.
PROCEDURE DIVISION.
PARA-1.
DISPLAY "ENTER THE NUMBER OF TERMS".
ACCEPT N.
IF N < 1
GO TO END-PARA.
DISPLAY "ENTER THE ELEMENTS".
PERFORM READ-PARA VARYING I FROM 1 BY 1 UNTIL I > N.
7
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
READ-PARA.
ACCEPT A(I).
B-PARA.
PERFORM SORT-PARA VARYING J FROM 1 BY 1 UNTIL J > N - 1.
SORT-PARA.
IF A(J) > A(J + 1)
MOVE A(J) TO T
MOVE A(J + 1) TO A(J)
MOVE T TO A(J + 1).
DISPLAY-PARA.
DISPLAY A(I).
END-PARA.
DISPLAY "INVALID INPUT".
DISPLAY "DO YOU WANT TO CONTINUE,IF YES PRESS Y OTHERWISE
N".
ACCEPT C.
IF C='N' OR 'n'
STOP RUN.
IF C='Y' OR 'y'
GO TO PARA-1
STOP RUN.
8
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Output:
9
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Program:4B
Problem Statement:
By using table handling concepts, write a program for Searching a numeric number using
SEARCH verb.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. 3B.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 N PIC S9(5).
01 ARRAY.
03 A PIC S9(2) OCCURS 10 TIMES INDEXED BY I.
77 I1 PIC Z(3)9.
77 N1 PIC S9(5).
77 F PIC -Z(2).
77 C PIC XX.
PROCEDURE DIVISION.
A-PARA.
DISPLAY "ENTER THE SIZE OF THE ARRAY".
ACCEPT N.
IF N < 1
GO TO END-PARA.
DISPLAY "ENTER THE ARRAY ELEMENTS".
PERFORM READ-ARRAY VARYING I FROM 1 BY 1 UNTIL I > N.
DISPLAY "ENTER THE NUMBER TO SEARCH".
ACCEPT N1.
PERFORM SEARCH-PARA.
DISPLAY "DO YOU WISH TO CONTINUE(Y/N)?".
ACCEPT C.
IF C= 'N' OR 'n'
STOP RUN.
IF C= 'Y' OR 'y'
GO TO A-PARA
STOP RUN.
10
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
READ-ARRAY.
ACCEPT A(I).
SEARCH-PARA.
SET I TO 1.
SEARCH A AT END
DISPLAY "ELEMENT NOT FOUND"
WHEN N1=A(I)
MOVE I TO I1
MOVE A(I) TO F
DISPLAY "ELEMENT " F " FOUND AT POSTION " I1.
END-PARA.
DISPLAY "INVLAID INPUT".
DISPLAY "DO YOU WISH TO CONTINUE(Y/N)?".
ACCEPT C.
IF C= 'N' OR 'n'
STOP RUN.
IF C= 'Y' OR 'y'
GO TO A-PARA
STOP RUN.
Output:
Program:5
Problem Statement:
By using table handling concepts, write a program for matrix addition and matrix
subtraction.
Source Code:
12
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
IDENTIFICATION DIVISION.
PROGRAM-ID. MAT4.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MAT.
02 ROW OCCURS 20 TIMES.
03 COLM OCCURS 20 TIMES.
04 A PIC S9(4).
04 B PIC S9(4).
04 SUM1 PIC S9(4).
04 DIFF1 PIC S9(4).
01 T PIC -ZZZ9.
01 I PIC 9(2).
01 J PIC 9(2).
01 P PIC S9(2).
01 Q PIC S9(2).
01 M PIC S9(2).
01 N PIC S9(2).
PROCEDURE DIVISION.
PARA-1.
DISPLAY "ENTER ORDER OF MATRIX A:".
ACCEPT M.
ACCEPT N.
14
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Output:
Program:6
Problem Statement:
By using table handling concepts, write a program for matrix multiplication.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID.MUL.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 MATRIX1.
02 A1 OCCURS 10 TIMES.
03 A PIC S9(3) OCCURS 10 TIMES.
01 MATRIX2.
02 B1 OCCURS 10 TIMES.
03 B PIC S9(3) OCCURS 10 TIMES.
01 MATRIX3.
02 C1 OCCURS 10 TIMES.
03 C PIC S9(3) OCCURS 10 TIMES.
01 MATRIX4.
02 D1 OCCURS 10 TIMES.
03 D PIC -Z(3)9 OCCURS 10 TIMES.
77 I PIC 9.
77 J PIC 9.
77 K PIC 9.
77 M PIC S99.
17
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
77 N PIC S99.
77 P PIC S99.
77 Q PIC S99.
77 LIN PIC 9(2).
77 COLM PIC 9(2).
PROCEDURE DIVISION.
MAINPARA-1.
DISPLAY " ENTER THE ORDER OF MATRIX 1:".
ACCEPT M.
ACCEPT N.
ACCEPT-PARA1.
ACCEPT A(I J).
ACCEPT-PARA2.
ACCEPT B(I J).
DISPLAY-PARA1.
MOVE A(I J) TO D(I J).
DISPLAY(LIN COLM) D(I J).
ADD 5 TO COLM.
IF(J = N)
ADD 1 TO LIN
MOVE 5 TO COLM.
DISPLAY-PARA2.
MOVE B(I J) TO D(I J).
DISPLAY(LIN COLM) D(I J).
ADD 5 TO COLM.
IF(J = Q)
ADD 1 TO LIN
MOVE 30 TO COLM.
MUL-PARA.
MOVE 0 TO C(I J).
PERFORM MUL-PARA1 VARYING K FROM 1 BY 1 UNTIL K > N.
MUL-PARA1.
COMPUTE C(I,J) = C(I,J) + (( A(I,K) * B(K,J)).
MUL-DISPLAY.
MOVE C(I J) TO D(I J).
DISPLAY( LIN COLM) D(I J).
ADD 5 TO COLM.
19
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
IF(J = M)
ADD 1 TO LIN
MOVE 50 TO COLM.
Output:
46
82
6
-8
95
16
43
28
92
Program:7A
Problem Statement:
Write a program to sort records in the file using SORT verb.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID.6A.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SOL ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT SOR ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT WORKFILE ASSIGN TO DISK.
DATA DIVISION.
21
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
FILE SECTION.
FD SOL
LABEL RECORDS ARE STANDRAD
VALUE OF FILE-ID IS "SOL.DAT"
DATA RECORD IS SO-REC.
01 SO-REC.
02 NAME PIC X(10).
02 REGNO PIC 9(10).
FD SOR
LABEL RECORDS ARE STANDRAD
VALUE OF FILE-ID IS "SOR.DAT"
DATA RECORD IS SORTE.
01 SORTE.
02 NAME PIC X(10).
02 REGNO PIC 9(10).
SD WORKFILE
01 W-REC.
02 NAME1 PIC X(10).
02 REGNO1 PIC 9(10).
PROCEDURE DIVISION.
MAIN.
SORT WORKFILE ON ASCENDING
KEY NAME1 USING SOL GIVING SOR.
STOP RUN.
Output:
C:\Cobol>TYPE SOL.DAT
MANJU IP09MCA32
RAGHU IP09MCA70
ROHIT IP09MCA72
PRAVEEN IP09MCA69
AMBRISH IP09MCA05
RAJA IP09MCA76
C:\Cobol>TYPE SOR.DAT
AMBRISHIP09MCA05
MANJU IP09MCA32
PRAVEENIP09MCA69
RAGHU IP09MCA70
22
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
RAJA IP09MCA76
ROHIT IP09MCA72
Program:7B
Problem Statement:
Write a program to merge files using MERGE verb.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID.6B.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MYFILE1 ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT MYFILE2 ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT OFILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
SELECT WFILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD MYFILE1
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID "FILE1.DAT"
DATA RECORD IS AREC.
01 AREC.
02 NAME PIC X(10).
02 REG PIC 9(10).
FD MYFILE2
VALUE OF FILE-ID IS "FILE2.DAT"
DATA RECORD IS BREC.
01 BREC.
02 NAME PIC X(10).
02 REG PIC 9(10).
FD OFILE
VALUE OF FILE-ID IS "FILE3.DAT"
DATA RECORD IS OREC.
23
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
01 OREC.
02 NAME PIC X(10).
02 REG PIC 9(10).
SD WFILE
01 WREC.
02 WNAME PIC X(10).
02 WREG PIC 9(10).
PROCEDURE DIVISION.
MAIN-PARA.
MERGE WFILE ON ASCENDING KEY WREG
USING MYFILE1,MYFILE2 GIVING OFILE.
STOP RUN.
Output:
C:\Cobol>TYPE FILE1.DAT
MANJU IP09MCA32
RAGHU IP09MCA70
ROHIT IP09MCA72
C:\Cobol>TYPE FILE2.DAT
PRAVEEN IP09MCA69
AMBRISH IP09MCA05
RAJA IP09MCA76
C:\Cobol>TYPE FILE3.DAT
AMBRISHIP09MCA05
MANJU IP09MCA32
PRAVEENIP09MCA69
RAGHU IP09MCA70
RAJA IP09MCA76
ROHIT IP09MCA72
24
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Program:8
Problem Statement:
Write a program to read employee file as sequential file and calculate Gross Pay and Net
pay for employees in the organization.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. EMP.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMP-FILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD EMP-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "EMP.DAT".
01 EMP-REC.
02 EMP-ID PIC X(15).
02 NAME PIC X(15).
02 BS PIC 9(5).
02 DA PIC 9(5).
02 HRA PIC 9(5).
02 TA PIC 9(5).
02 TAX PIC 9(5).
02 PFND PIC 9(5).
WORKING-STORAGE SECTION.
01 GP PIC 9(7).
01 NP PIC 9(7).
01 OPTION PIC X VALUE IS "Y".
01 EGP PIC Z(6)9.
01 ENP PIC Z(6)9.
PROCEDURE DIVISION.
MAIN-PARA.
OPEN OUTPUT EMP-FILE.
PERFORM WRITE-PARA UNTIL OPTION NOT = "Y".
CLOSE EMP-FILE.
25
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Output:
1P109MCA68
ENTER EMPLOYEE'S NAME:
RAGHUVEER
ENTER EMPLOYEE'S BASIC PAY:
80000
PRESS Y/y TO ADD MORE EMPLOYEE RECORDS:
Y
ENTER THE EMPLOYEE DETAILS
===========================================================
ENTER EMPLOYEE-ID:
1PI09MCA69
ENTER EMPLOYEE'S NAME:
VIKAS
ENTER EMPLOYEE'S BASIC PAY:
75000
PRESS Y/y TO ADD MORE EMPLOYEE RECORDS:
N
----------------------------------------------------------------------------------------------------
EMP-ID EMP-NAME BASIC-PAY GROSS-PAY NET-PAY
----------------------------------------------------------------------------------------------------
1PI09MCA68 RAGHUVEER 80000 108000 92000
1PI09MCA69 VIKAS 75000 101250 86250
Program:9
Problem Statement:
Write a program to store student’s details with results in a file with sequential file
handling techniques.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. 8A.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL
SELECT STFILE ASSIGN TO DISK
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD STFILE
LABEL RECORDS ARE STANDARD
27
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
ACCEPT SUB3.
DISPLAY "ENTER MARKS IN SUB4" .
ACCEPT SUB4.
DISPLAY "ENTER MARKS IN SUB5" .
ACCEPT SUB5.
COMPUTE TOTAL = SUB1 + SUB2 + SUB3 + SUB4 + SUB5.
IF( SUB1 < 35 OR SUB2 < 35 OR SUB3 < 35 OR
SUB4 < 35 OR SUB5 < 35 )
MOVE "FAIL" TO REMARKS
ELSE IF TOTAL > 200 AND TOTAL < 251
MOVE "THIRD" TO REMARKS
ELSE IF TOTAL > 250 AND TOTAL < 301
MOVE "SECOND" TO REMARKS
ELSE IF TOTAL > 300
MOVE "FIRST" TO REMARKS.
COMPUTE PRCNT = TOTAL / MAX * 100.
WRITE AREC.
DISPLAY "ANY MORE RECORD (Y/N)?".
ACCEPT ANS1.
READ-PARA.
READ STFILE AT END MOVE "N" TO ANS1.
IF ANS1 = "N"
STOP RUN.
MOVE-PARA.
MOVE REGNO TO EREGNO.
MOVE NAME TO ENAME.
MOVE SUB1 TO ESUB1.
MOVE SUB2 TO ESUB2.
MOVE SUB3 TO ESUB3.
MOVE SUB4 TO ESUB4.
MOVE SUB5 TO ESUB5.
DISP-PARA.
DISPLAY "REGNO:" EREGNO.
DISPLAY "NAME OF THE STUDENT:" ENAME.
DISPLAY "SUB1:" ESUB1.
DISPLAY "SUB2:" ESUB2.
DISPLAY "SUB3:" ESUB3.
DISPLAY "SUB4:" ESUB4.
DISPLAY "SUB5:" ESUB5.
DISPLAY "TOTAL:" TOTAL.
DISPLAY "PERCENT:" PRCNT.
DISPLAY "REMARKS:" REMARKS.
29
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
Output:
-------STUDENT RECORD------
REGISTER NUMBER IS : 001
NAME OF THE STUDENT IS :ABHISHEK
MARKS IN SUB1 IS : 34
MARKS IN SUB2 IS : 78
MARKS IN SUB3 IS : 87
MARKS IN SUB4 IS : 95
MARKS IN SUB5 IS : 70
TOTAL MARKS IS : 364
PERCENTAGE IS : 72.80
REMARKS : FAIL
PERCENTAGE IS : 85.60
REMARKS : FIRST
Program:10
Problem Statement:
Using the index file organization,
a)write a program to store employee details.
b)To delete a record in the index file.
c)To search a record in the index file.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. PRO12.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPINFILE ASSIGN TO DISK
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EMP-ID.
DATA DIVISION.
FILE SECTION.
FD EMPINFILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "EMP12.DAT"
DATA RECORDS ARE EMPREC.
01 EMPREC.
02 EMP-ID PIC 9(3).
02 EMP-NAME PIC A(10).
02 EMP-BASIC PIC 9(5).
WORKING-STORAGE SECTION.
01 I PIC 9 VALUE 1.
01 J PIC 9 VALUE 1.
01 EXIS PIC 9 VALUE 1.
01 FLAG PIC 9.
01 C PIC 9 VALUE 1.
01 CH1 PIC 9 VALUE 1.
01 EOF PIC 9 VALUE 0.
31
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
PROCEDURE DIVISION.
MAIN.
DISPLAY "-------------------------------".
DISPLAY "SEARCH & DELETE THE RECORDS IN THE INDEX
FILE".
DISPLAY "----------------------------------------".
MAIN-PARA.
OPEN OUTPUT EMPINFILE.
PERFORM D-PARA UNTIL C=5.
D-PARA.
DISPLAY " "
DISPLAY "1. INSERT 2. SEARCH 3.DELETE 4.DISPLAY
5.EXIT"
DISPLAY "ENTER YOUR CHOICE: ".
ACCEPT C.
IF C=1
PERFORM WRITE-PARA
ELSE IF C=2
CLOSE EMPINFILE
OPEN I-O EMPINFILE
PERFORM UPDATE-PARA
GO TO CHOICE-PARA
ELSE IF C=3
CLOSE EMPINFILE
OPEN I-O EMPINFILE
PERFORM DEL-PARA
GO TO CHOICE-PARA
ELSE IF C=4
CLOSE EMPINFILE
OPEN INPUT EMPINFILE
MOVE 0 TO EOF
DISPLAY "--------------------------"
DISPLAY "EMP-ID NAME SALARY"
DISPLAY "--------------------------"
PERFORM DISPLAY-PARA UNTIL EOF=1
ELSE IF C=5
GO TO EXIT-PARA
ELSE
DISPLAY "WRONG CHOICE!!!".
CHOICE-PARA.
PERFORM NEXT-PARA UNTIL CH1=5.
32
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
NEXT-PARA.
DISPLAY " "
DISPLAY "2.SEARCH 3. DELETE 4. DISPLAY 5. EXIT"
DISPLAY "ENTER YOUR CHOICE: ".
ACCEPT CH1.
IF CH1=2
CLOSE EMPINFILE
OPEN I-O EMPINFILE
PERFORM UPDATE-PARA
ELSE IF CH1=3
CLOSE EMPINFILE
OPEN I-O EMPINFILE
PERFORM DEL-PARA
ELSE IF CH1=4
MOVE 0 TO EOF
CLOSE EMPINFILE
OPEN INPUT EMPINFILE
DISPLAY "--------------------------"
DISPLAY "EMP ID NAME SALARY"
DISPLAY "---------------------------"
PERFORM DISPLAY-PARA UNTIL EOF=1
ELSE IF CH1=5
GO TO EXIT-PARA
ELSE
DISPLAY "INVALID INPUT!!!".
DISPLAY-PARA.
READ EMPINFILE NEXT RECORD AT END MOVE 1 TO EOF.
IF EOF=0
DISPLAY EMP-ID " " EMP-NAME " " EMP-BASIC.
WRITE-PARA.
DISPLAY " ".
DISPLAY "ENTER EMPLOYEE ID: ".
ACCEPT EMP-ID.
DISPLAY "ENTER EMPLOYEE NAME: ".
ACCEPT EMP-NAME.
DISPLAY "ENTER BASIC SALARY: ".
ACCEPT EMP-BASIC.
WRITE EMPREC INVALID KEY DISPLAY " DUPLICATE
ENTRY ".
33
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
UPDATE-PARA.
MOVE 1 TO EXIS.
DISPLAY "ENTER THE EMP ID TO SEARCH: ".
ACCEPT EMP-ID.
READ EMPINFILE RECORD KEY IS EMP-ID
INVALID KEY MOVE 0 TO EXIS.
IF EXIS = 0
DISPLAY "RECORD IS NOT EXISTS"
ELSE
DISPLAY "EMPLOYEE ID : " EMP-ID
DISPLAY "EMPLOYEE NAME : " EMP-NAME
DISPLAY "BASIC SALARY : " EMP-BASIC.
DEL-PARA.
MOVE 1 TO EXIS.
DISPLAY "ENTER EMP ID TO DELETE: ".
ACCEPT EMP-ID.
DELETE EMPINFILE INVALID KEY MOVE 0 TO EXIS.
IF EXIS = 1
DISPLAY "RECORD DELETED"
ELSE
DISPLAY "RECORD NOT FOUND".
EXIT-PARA.
CLOSE EMPINFILE.
STOP RUN.
Output:
------------------------------------------------------------------------------
SEARCH & DELETE THE RECORDS IN THE INDEX FILE
------------------------------------------------------------------------------
34
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
---------------------------------------
EMP ID NAME SALARY
---------------------------------------
012 RAGHUVEER 25000
Program:11
Problem Statement:
Using the index file organization, write a program to update employee salary (increase
DA of 3%)
Source Code:
35
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
IDENTIFICATION DIVISION.
PROGRAM-ID. INDEXD11.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMP-FILE ASSIGN TO DISK
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EMP-NO.
DATA DIVISION.
FILE SECTION.
FD EMP-FILE
LABEL RECORDS ARE STANDARD
VALUE OF FILE-ID IS "EMP.TXT".
01 EMP-REC.
02 EMP-NO PIC X(8).
02 EMP-NAME PIC X(10).
WORKING-STORAGE SECTION.
01 DA PIC Z(4)9.99.
01 SALARY PIC Z(4)9.99.
01 BASIC PIC Z(4)9.99.
01 DAP PIC Z9.99.
PROCEDURE DIVISION.
MAIN.
OPEN OUTPUT EMP-FILE.
PERFORM CREATE-PARA UNTIL CHOICE1 = "N" OR
CHOICE1 = "n".
CLOSE EMP-FILE.
36
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
CREATE-PARA.
DISPLAY "UPDATE EMPLOYEE SALARY(INDEX FILE
ORGANIZATION)".
DISPLAY "_____________________________________________".
DISPLAY "ENTER EMPLOYEE ID: ".
ACCEPT EMP-NO.
DISPLAY "ENTER THE NAME OF THE EMPLOYEE: ".
ACCEPT EMP-NAME.
DISPLAY "ENTER THE BASIC SALARY OF THE EMPLOYEE:
".
ACCEPT EMP-BASIC.
DISPLAY "ENTER THE PERCENTAGE(%) OF DA".
ACCEPT EMP-DAP.
PROCESS-PARA.
DISPLAY "ENTER EMPLOYEE ID, OF THE RECORD TO BE
MODIFIED".
ACCEPT EMP-NO.
DISPLAY
"=============================================".
DISPLAY "BEFORE INCREMENTING".
37
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
DISPLAY
"=============================================".
DISPLAY " NO NAME BASIC DA% EDA SALARY".
DISPLAY " ---------------------------------------------".
DISPLAY EMP-NO EMP-NAME BASIC DAP DA SALARY.
DISPLAY "_____________________________________________".
DISPLAY " ".
DISPLAY "=======================================".
DISPLAY "AFTER INCREMENTING".
DISPLAY
"==========================================".
DISPLAY "NO NAME BASIC DA% EDA SALARY".
DISPLAY "------------------------------------------".
DISPLAY EMP-NO EMP-NAME BASIC DAP DA SALARY.
DISPLAY "___________________________________________".
DISPLAY "DO U WANT TO MODIFY MORE RECORDS ?
(Y/N) :".
ACCEPT CHOICE2.
NOT-FOUND.
DISPLAY "EMPLOYEE RECORD DOESN'T EXIST".
STOP RUN.
Output:
2
ENTER MORE RECORDS ? (Y/N)
Y
UPDATE EMPLOYEE SALARY(INDEX FILE ORGANIZATION)
_____________________________________________
ENTER EMPLOYEE ID:
1
ENTER THE NAME OF THE EMPLOYEE:
ROSHAN
ENTER THE BASIC SALARY OF THE EMPLOYEE:
20000
ENTER THE PERCENTAGE(%) OF DA
2
INVALID KEY
ENTER MORE RECORDS ? (Y/N)
Y
UPDATE EMPLOYEE SALARY(INDEX FILE ORGANIZATION)
_____________________________________________
ENTER EMPLOYEE ID:
2
ENTER THE NAME OF THE EMPLOYEE:
ANIL
ENTER THE BASIC SALARY OF THE EMPLOYEE:
2000
ENTER THE PERCENTAGE(%) OF DA
2
ENTER MORE RECORDS ? (Y/N)
N
=========================================================
AFTER INCREMENTING
=========================================================
NO NAME BASIC DA% EDA SALARY
39
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
-------------------------------------------------------------------------------------------------
1 RAGHUVEER 1000.00 5.00 50.00 1050.00
________________________________________________________________
DO U WANT TO MODIFY MORE RECORDS ? (Y/N) :
N
Program:12
Problem Statement:
Write a program to calculate Net Pay and Gross Pay by reading relative file containing
records emp-no, emp-name, basic-pay. Store the output in relative file.
Source Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. 13P.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMP-FILE ASSIGN TO DISK
ORGANIZATION IS RELATIVE
RELATIVE KEY IS POS
ACCESS MODE DYNAMIC.
DATA DIVISION.
FILE SECTION.
FD EMP-FILE
40
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
READ-PARA.
DISPLAY "ENTER RELATIVE POSITION(1-100)".
ACCEPT POS.
COMP-PARA.
READ EMP-FILE NEXT AT END GO TO TITLE-PARA.
COMPUTE EMP-DA = EMP-BASIC * 0.15.
COMPUTE EMP-HRA = EMP-BASIC * 0.10.
COMPUTE EMP-TAX = EMP-BASIC * 0.12.
COMPUTE GPAY = EMP-BASIC + EMP-DA + EMP-HRA.
COMPUTE NETPAY = GPAY - EMP-TAX.
REWRITE EMPREC.
GO TO COMP-PARA.
TITLE-PARA.
CLOSE EMP-FILE
OPEN INPUT EMP-FILE.
DISPLAY
"=================================================".
DISPLAY " EMPLOYEE INFORMATION".
DISPLAY
"=================================================".
DISPLAY "EMP-NO EMP-NAME EMP-BASIC GROSSPAY
NETPAY".
DISPLAY
"____________________________________________________".
PERFORM DISP-PARA.
DISP-PARA.
READ EMP-FILE NEXT AT END GO TO CLOSE-PARA.
DISPLAY ENO " " EMP-NAME " " EBASIC " " EGPAY " "
ENETPAY.
42
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
GO TO DISP-PARA.
CLOSE-PARA.
DISPLAY
"____________________________________________________".
CLOSE EMP-FILE.
Output:
Program:13
Problem Statement:
Write a program to find simple interest and compound interest using subroutine concept.
Main:
IDENTIFICATION DIVISION.
PROGRAM-ID. PRO13.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 P PIC 9(5).
77 T PIC 9(2).
77 R PIC 9(2)V99.
77 SI PIC 9(4)V99.
77 CI PIC 9(4)V99.
77 S PIC Z(3)9.99.
77 C PIC Z(3)9.99.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY "ENTER THE PRINCIPLE:".
ACCEPT P.
DISPLAY "ENTER THE TIME:".
ACCEPT T.
DISPLAY "ENTER THE RATE:".
ACCEPT R.
MOVE SI TO S.
MOVE CI TO C.
44
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
IDENTIFICATION DIVISION.
PROGRAM-ID.SUBPROG.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 P1 PIC 9(5).
01 T1 PIC 9(2).
01 R1 PIC 9(2)V99.
01 SI PIC 9(4)V99.
01 CI PIC 9(4)V99.
PROCEDURE DIVISION USING P1,T1,R1,SI,CI.
MAIN-PARA.
COMPUTE R1 = R1 / 100 .
COMPUTE SI = P1 * T1 * R1.
COMPUTE CI = P1 * ( ( 1 + R1 ) ** T1 ) - P1.
EXIT PROGRAM.
Output:
45
Department of MCA, DSCE COBOLLaboratory
COBOL PROGRAMMING LAB
46
Department of MCA, DSCE COBOLLaboratory