You are on page 1of 125

COBOL Programming DATE : 03/1/2008 PGM NO : 1

LARGEST OF THREE NUMBERS


AIM : TO FIND THE LARGEST OF THREE INPUT NUMBERS.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. LARGE. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 A PIC 9(4). 77 B PIC 9(4). 77 C PIC 9(4). 77 LARGE PIC 9(4). PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER THREE NUMBERS". ACCEPT A. ACCEPT B. ACCEPT C. COMPUTE-PARA. IF A>B AND A>C THEN MOVE A TO LARGE. IF B>C AND B>A THEN MOVE B TO LARGE. IF C>B AND C>A THEN MOVE C TO LARGE. DISPLAY-PARA. DISPLAY "LARGEST NUMBER=" LARGE. STOP RUN.

Department of Computer Applications

COBOL Programming

OUTPUT
ENTER THREE NUMBERS 15 6 19 LARGEST NUMBER=0019

Department of Computer Applications

COBOL Programming

DATE : 05/11/2008 PGM NO : 2

PAYSLIP-CALCULATION
AIM : TO CALCULATE TOTAL WAGE BASED ON RATE PER DAY AND NUMBER OF DAYS WORKED.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. PAYSLIP. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 EMPDET. 02 NAME PIC X(15). 02 NDAY PIC 999. 02 RATE PIC 9(7). 02 WAGE PIC 9(7). PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER THE NAME". ACCEPT NAME. DISPLAY "ENTER TOTAL DAYS WORKED". ACCEPT NDAY. DISPLAY "ENTER THE RATE PER DAY OF AN EMPLOYEE". ACCEPT RATE. COMPUTE-PARA. MULTIPLY NDAY BY RATE GIVING WAGE. DISPLAY-PARA. DISPLAY "*******PAY SLIP**********". DISPLAY "EMPLOYEE NAME :" NAME. DISPLAY "NO OF DAYS WORKED :" NDAY. DISPLAY "RATE PER DAY :" RATE. DISPLAY "WAGE :"WAGE. STOP RUN. Department of Computer Applications 3

COBOL Programming

OUTPUT ENTER THE NAME MAHESH ENTER TOTAL DAYS WORKED 25 ENTER THE RATE PER DAY OF AN EMPLOYEE 325 *******PAY SLIP********** EMPLOYEE NAME : MAHESH NO OF DAYS WORKED :025 RATE PER DAY : 0000325 WAGE : 0008125

Department of Computer Applications

COBOL Programming

DATE : 12/11/2008 PGM NO : 3

ARMSTRONG NO.
AIM : TO CHECK WHETHER THE GIVEN NO: IS ARMSTRONG OR NOT.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. AMSTRONG. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 AMS. 02 NUM PIC 9(4). 02 TEMP PIC 9(4). 02 REM PIC 9. 02 NUMB PIC 9(4). PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER THE NUMBER". ACCEPT NUM. MOVE NUM TO TEMP. PERFORM COMPUTE-PARA UNTIL NUM=0 COMPUTE-PARA. DIVIDE NUM BY 10 GIVING NUM REMAINDER REM. COMPUTE NUMB= NUMB + (REM * REM * REM). DISPLAY-PARA. IF NUMB=TEMP THEN DISPLAY "ARMSTRONG NUMBER" ELSE DISPLAY "NOT ARMSTRONG NUMBER". STOP RUN.

Department of Computer Applications

COBOL Programming

OUTPUT ENTER THE NUMBER 153 ARMSTRONG NUMBER ENTER THE NUMBER 123 NOT ARMSTRONG NUMBER

Department of Computer Applications

COBOL Programming

DATE : 13/11/2008 PGM NO : 4

PALINDROME NO.
AIM : TO CHECK WHETHER THE GIVEN NO: IS PALINDROME OR NOT.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. PALEND. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 PALIN. 02 N PIC 9(8) VALUE ZERO. 02 R PIC 9(8) VALUE ZERO. 02 Q PIC 9(8) VALUE ZERO. 02 REV PIC 9(8) VALUE ZERO. 02 TEMP PIC 9(8) VALUE ZERO. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER NUMBER". ACCEPT N. MOVE N TO TEMP. COMPUTE-PARA. IF N IS NOT EQUAL TO ZERO DIVIDE N BY 10 GIVING Q REMAINDER R MULTIPLY 10 BY REV ADD R TO REV MOVE Q TO N GO TO COMPUTE-PARA. DISPLAY-PARA. IF TEMP = REV DISPLAY " PALINDROME " ELSE DISPLAY " NOT PALINDROME ". STOP RUN. Department of Computer Applications 7

COBOL Programming

OUTPUT
ENTER NUMBER 121 PALINDROME ENTER NUMBER 546 NOT PALINDROME

Department of Computer Applications

COBOL Programming

DATE : 14/11/2008 PGM NO : 5

MATRIX MULTIPLICATION
AIM : TO FIND THE PRODUCT OF TWO MATRICES AND PRINT THE RESULT IN THE MATRIX FORM.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. MATRIXMUL. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 MAT. 02 R OCCURS 5 TIMES. 03 C OCCURS 5 TIMES. 04 A PIC 9(3). 04 B PIC 9(3). 04 M PIC 9(3). 01 Y. 05 F OCCURS 5 TIMES PIC Z(4)9. 77 I PIC 9. 77 J PIC 9. 77 K PIC 9. 77 M1 PIC 9. 77 M2 PIC 9. 77 N1 PIC 9. 77 N2 PIC 9. 77 SU PIC 9(4) VALUE 0. PROCEDURE DIVISION. P-1. DISPLAY "ENTER THE ORDER OF THE FIRST MATRIX". ACCEPT M1 ACCEPT N1. DISPLAY "ENTER THE ORDER OF THE SECOND MATRIX". ACCEPT M2 ACCEPT N2. Department of Computer Applications 9

COBOL Programming IF N1=M1 GO TO P-2 ELSE DISPLAY "ENTER A VALID MATRIX ORDER". P-2. DISPLAY "ENTER THE ELEMENTS OF THE FIRST MATRIX". PERFORM ACC-PARA1 VARYING I FROM 1 BY 1 UNTIL I > M1 AFTER J FROM 1 BY 1 UNTIL J > N1. DISPLAY "ENTER THE ELEMENTS OF THE SECOND MATRIX". PERFORM ACC-PARA2 VARYING I FROM 1 BY 1 UNTIL I > M2 AFTER J FROM 1 BY 1 UNTIL J > N2. PERFORM MUL-PARA VARYING I FROM 1 BY 1 UNTIL I >M1 AFTER J FROM 1 BY 1 UNTIL J>N2 AFTER K FROM 1 BY 1 UNTIL K>M2. DISPLAY "***MATRIX AFTER MULTIPLICATION****". PERFORM LIN-SET VARYING I FROM 1 BY 1 UNTIL I>M1. STOP RUN. ACC-PARA1. ACCEPT A(I J). ACC-PARA2. ACCEPT B(I J). MUL-PARA. COMPUTE M(I J)=M(I J)+( A(I K) * B(K J)). LIN-SET. PERFORM MOV-PARA VARYING J FROM 1 BY 1 UNTIL J>N1. DISPLAY Y. MOV-PARA. MOVE M(I J) TO F(J).

Department of Computer Applications

10

COBOL Programming

OUTPUT
ENTER THE ORDER OF THE FIRST MATRIX 2 2 ENTER THE ORDER OF THE SECOND MATRIX 2 2 ENTER THE ELEMENTS OF THE FIRST MATRIX 2 2 2 2 ENTER THE ELEMENTS OF THE SECOND MATRIX 2 2 2 2 ****MATRIX AFTER MULTIPLICATION**** 8 8 8 8

Department of Computer Applications

11

COBOL Programming

DATE :19/11/2008 PGM NO : 6

INTEREST CALCULATION USING SIMPLE PERFORM


AIM : TO CALCULATE THE INTEREST AFTER EACH YEAR USING SIMPLE PERFORM.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. AMOUNT. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 AMT PIC 9(6). 77 RATE PIC 99V9. 77 YR PIC 99. 77 INT PIC Z(6).99. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER AMOUNT AND RATE". ACCEPT AMT. ACCEPT RATE. MOVE 1 TO YR. PERFORM COMPUTE-PARA 15 TIMES. STOP RUN. COMPUTE-PARA. COMPUTE INT=AMT*YR*RATE/100. DISPLAY "INTEREST AT THE END" YR "YEAR" INT. ADD 1 TO YR.

Department of Computer Applications

12

COBOL Programming

OUTPUT
ENTER AMOUNT AND RATE 1450 6 INTEREST AT THE END 01YEAR INTEREST AT THE END 02YEAR INTEREST AT THE END 03YEAR INTEREST AT THE END 04YEAR INTEREST AT THE END 05YEAR INTEREST AT THE END 06YEAR INTEREST AT THE END 07YEAR INTEREST AT THE END 08YEAR INTEREST AT THE END 09YEAR INTEREST AT THE END 10YEAR INTEREST AT THE END 11YEAR INTEREST AT THE END 12YEAR INTEREST AT THE END 13YEAR INTEREST AT THE END 14YEAR INTEREST AT THE END 15YEAR

87.00 174.00 261.00 348.00 435.00 522.00 609.00 696.00 783.00 870.00 957.00 1044.00 1131.00 1218.00 1305.00

Department of Computer Applications

13

COBOL Programming

DATE : 21/11/2008 PGM NO : 7

INTEREST CALCULATION USING PERFORM-UNTIL


AIM : TO CALCULATE THE INTEREST AFTER EACH YEAR USING PERFORM-UNTIL.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. AMOUNT. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 AMT PIC 9(6). 77 RATE PIC 99V9. 77 YR PIC 99. 77 INT PIC Z(6).99. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER AMOUNT AND RATE". ACCEPT AMT. ACCEPT RATE. MOVE 1 TO YR. PERFORM COMPUTE-PARA. UNTIL YR>15. STOP RUN. COMPUTE-PARA. COMPUTE INT=AMT*YR*RATE/100. DISPLAY "INTEREST AT THE END" YR "YEAR" INT. ADD 1 TO YR.

Department of Computer Applications

14

COBOL Programming

OUTPUT
ENTER AMOUNT AND RATE 1450 6 INTEREST AT THE END 01YEAR INTEREST AT THE END 02YEAR INTEREST AT THE END 03YEAR INTEREST AT THE END 04YEAR INTEREST AT THE END 05YEAR INTEREST AT THE END 06YEAR INTEREST AT THE END 07YEAR INTEREST AT THE END 08YEAR INTEREST AT THE END 09YEAR INTEREST AT THE END 10YEAR INTEREST AT THE END 11YEAR INTEREST AT THE END 12YEAR INTEREST AT THE END 13YEAR INTEREST AT THE END 14YEAR INTEREST AT THE END 15YEAR

87.00 174.00 261.00 348.00 435.00 522.00 609.00 696.00 783.00 870.00 957.00 1044.00 1131.00 1218.00 1305.00

Department of Computer Applications

15

COBOL Programming

DATE :24/11/2008 PGM NO : 8

INTEREST CALCULATION USING PERFORM-VARYING


AIM : TO CALCULATE THE INTEREST AFTER EACH YEAR USING PERFORM-VARYING.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. AMOUNT. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 AMT PIC 9(6). 77 RATE PIC 99V9. 77 YR PIC 99. 77 INT PIC Z(6).99. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER AMOUNT AND RATE". ACCEPT AMT. ACCEPT RATE. PERFORM COMPUTE-PARA VARYING YR FROM 1 BY 1 UNTIL YR>15. STOP RUN. COMPUTE-PARA COMPUTE INT=AMT*YR*RATE/100. DISPLAY "INTEREST AT THE END" YR "YEAR" INT.

Department of Computer Applications

16

COBOL Programming

OUTPUT
ENTER AMOUNT AND RATE 1450 6 INTEREST AT THE END 01YEAR INTEREST AT THE END 02YEAR INTEREST AT THE END 03YEAR INTEREST AT THE END 04YEAR INTEREST AT THE END 05YEAR INTEREST AT THE END 06YEAR INTEREST AT THE END 07YEAR INTEREST AT THE END 08YEAR INTEREST AT THE END 09YEAR INTEREST AT THE END 10YEAR INTEREST AT THE END 11YEAR INTEREST AT THE END 12YEAR INTEREST AT THE END 13YEAR INTEREST AT THE END 14YEAR INTEREST AT THE END 15YEAR

87.00 174.00 261.00 348.00 435.00 522.00 609.00 696.00 783.00 870.00 957.00 1044.00 1131.00 1218.00 1305.00

Department of Computer Applications

17

COBOL Programming

DATE :28/11/2008 PGM NO : 9

MATRIX TRANSPOSE
AIM : TO ACCEPT A TABLE OF M*N MATRIX AND PRINT ITS TRANSPOSE IN MATRIX FORM.

PROGRAM
IDENTIFICATION DIVISION. PROGRAM-ID. TRANS. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 I PIC 99. 77 M PIC 99. 77 N PIC 99. 77 J PIC 99. 01 Y. 05 B OCCURS 3 TIMES PIC Z(4)9. 01 X. 05 R OCCURS 3 TIMES. 10 A PIC 99 OCCURS 3 TIMES. 10 C PIC Z(5) OCCURS 3 TIMES. PROCEDURE DIVISION. P1. DISPLAY "ENTER THE ORDER OF THE MATRIX" ACCEPT M ACCEPT N. DISPLAY "ENTER THE ELEMENTS IN THE MATRIX". PERFORM A-P VARYING I FROM 1 BY 1 UNTIL I>M AFTER J FROM 1 BY 1 UNTIL J>N. DISPLAY "THE TRANSPOSE MATRIX ". PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > N. STOP RUN A-P. ACCEPT A(I, J) MOVE A(I, J) TO C(J, I). LIN-SET. PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I>M. DISP-PARA. PERFORM MOV-PARA VARYING J FROM 1 BY 1 UNTIL J > M. DISPLAY Y.

Department of Computer Applications

18

COBOL Programming MOV-PARA. MOVE C(I J) TO B(J).

OUTPUT
ENTER THE ORDER OF THE MATRIX 2 2 ENTER THE ELEMENTS IN THE MATRIX 4 6 8 9 THE TRANSPOSE MATRIX 4 8 6 9

Department of Computer Applications

19

COBOL Programming

DATE : 01/12/2008 PGM NO : 10

CALCULATION OF MODERATED MARKS


AIM : TO ACCEPT NAME AND TOTAL MARKS OF A STUDENT AND COMPUTE THE MODERATED MARKS OF THE STUDENT.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID.TOTAL. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 EMP. 02 NAM PIC X(15). 02 TMARK PIC 9(3). 02 TOT PIC Z(4). 77 M PIC 9. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER THE NAME AND TOTAL MARK." ACCEPT NAM. ACCEPT TMARK. COMPUTE-PARA. IF TMARK LESS THAN 31 THEN MOVE 0 TO M. IF TMARK > 30 AND TMARK < 41 THEN MOVE 2 TO M. IF TMARK > 40 AND TMARK < 51 THEN MOVE 5 TO M. IF TMARK > 50 THEN MOVE 7 TO M. COMPUTE TOT= TMARK + M. DISPLAY-PARA. DISPLAY "THE MODERATED MARK OF " NAM "IS" TOT. Department of Computer Applications 20

COBOL Programming STOP RUN.

OUTPUT
ENTER THE NAME AND TOTAL MARK. MAHESH 49 THE MODERATED MARK OF MAHESH IS 54 ENTER THE NAME AND TOTAL MARK. MAHESH 31 THE MODERATED MARK OF MAHESH

IS 33

Department of Computer Applications

21

COBOL Programming

DATE : 02/12/2008 PGM NO : 11

ILLUSTRATION REDEFINES CLAUSE


AIM : TO DISPLAY DATE OF BIRTH USING REDEFINES CLAUSE.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. REDEF. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 DATE-RECORD. 02 DOB. 03 DD PIC 9(2). 03 MM PIC 9(2). 03 YEAR PIC 9(4). 02 DOBI REDEFINES DOB. 03 DMY PIC 9(14). PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER DAY,MONTH & YEAR". ACCEPT DD. ACCEPT MM. ACCEPT YEAR. DISPLAY-PARA. DISPLAY "DMY=" DD "\" MM "\" YEAR. STOP RUN.

Department of Computer Applications

22

COBOL Programming

OUTPUT
ENTER DAY,MONTH & YEAR 16 02 1988 DMY=16\02\1988

Department of Computer Applications

23

COBOL Programming

DATE : 03/12/08 PGM NO : 12

ROW & COLUMN SUM OF A MATRIX


AIM : TO ACCEPT A MATRIX & TO DISPLAY ITS ROW & COLUMN TOTAL.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. ROWCOL. AUTHOR. MAHI. ENVIRONMENT DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 MAT. 02 R OCCURS 8 TIMES. 03 C OCCURS 8 TIMES. 05 A PIC 9(3). 01 Y. 05 F OCCURS 5 TIMES PIC Z(4)9. 77 I PIC 9(2). 77 J PIC 9(2). 77 RSUM PIC 9(3). 77 CSUM PIC 9(3). 77 M PIC 9. 77 N PIC 9. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER THE ORDER OF THE MATRIX". ACCEPT M ACCEPT N. DISPLAY "ENTER THE ELEMENTS". PERFORM ACC-PARA VARYING I FROM 1 BY 1 UNTIL I > M AFTER J FROM 1 BY 1 UNTIL J > N. DISPLAY "THE MATRIX U ENTERED IS". PERFORM LIN-SET VARYING I FROM 1 BY 1 UNTIL I>M. PERFORM COMPUTE-PARA VARYING I FROM 1 BY 1 UNTIL I > M. Department of Computer Applications 24

COBOL Programming STOP RUN. ACC-PARA. ACCEPT A(I J). LIN-SET. PERFORM MOV-PARA VARYING J FROM 1 BY 1 UNTIL J>N. DISPLAY Y. MOV-PARA. MOVE A(I J) TO F(J). COMPUTE-PARA. MOVE 0 TO RSUM CSUM. PERFORM RSUM-PARA VARYING J FROM 1 BY 1 UNTIL J > N. DISPLAY "THE SUM OF " I " ROW IS " RSUM. PERFORM CSUM-PARA VARYING J FROM 1 BY 1 UNTIL J > N. DISPLAY "THE SUM OF " I " COLUMN IS " CSUM. RSUM-PARA. COMPUTE RSUM = RSUM + A(I J). CSUM-PARA. COMPUTE CSUM = CSUM + A(J I).

Department of Computer Applications

25

COBOL Programming

OUTPUT
ENTER THE ORDER OF THE MATRIX 3 3 ENTER THE ELEMENTS 4 3 5 1 8 9 3 6 7 THE MATRIX U ENTERED IS 4 3 5 1 8 9 3 6 7 THE SUM OF 01 ROW IS 012 THE SUM OF 01 COLUMN IS 008 THE SUM OF 02 ROW IS 018 THE SUM OF 02 COLUMN IS 017 THE SUM OF 03 ROW IS 016 THE SUM OF 03 COLUMN IS 021

Department of Computer Applications

26

COBOL Programming

DATE : 09/12/2008 PGM NO : 13

COUNT OF MALE AND FEMALE STUDENTS


AIM : TO COUNT THE NUMBER OF MALES AND FEMALES IN A CLASS USING CONDTION NAME.

PROGRAM
IDENTIFICATION DIVISION. PROGRAM-ID. FEMSTUD. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 B PIC 99 VALUE 0. 77 G PIC 99 VALUE 0. 01 STUD-DET. 05 NAME PIC X(20). 05 CLAS PIC X(15). 05 SEX PIC A. 88 MALE VALUE "M" , "m". 88 FEMALE VALUE "F" , "f". 77 CHOICE PIC A. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER THE NAME" ACCEPT NAME. DISPLAY "ENTER THE CLASS". ACCEPT CLAS. DISPLAY "ENTER THE SEX". ACCEPT SEX. COMPUTE-PARA. IF MALE ADD 1 TO B. IF FEMALE ADD 1 TO G. DISPLAY "DO U WANT TO CONTINUE(Y/N)? ". ACCEPT CHOICE. IF CHOICE = "Y" OR "y" GO TO ACCEPT-PARA. DISPLAY-PARA. DISPLAY "NO OF MALE STUDENTS =" B.

Department of Computer Applications

27

COBOL Programming
DISPLAY "NO OF FEMALE STUDENTS =" G. STOP RUN.

OUTPUT
ENTER THE NAME MAHESH ENTER THE CLASS MCA ENTER THE SEX M DO U WANT TO CONTINUE(Y/N)? Y ENTER THE NAME VIJITH ENTER THE CLASS MCA ENTER THE SEX M DO U WANT TO CONTINUE(Y/N)? Y ENTER THE NAME SREEJA ENTER THE CLASS MCA ENTER THE SEX F DO U WANT TO CONTINUE(Y/N)? Y ENTER THE NAME ANUPAMA ENTER THE CLASS MCA ENTER THE SEX F DO U WANT TO CONTINUE(Y/N)? N NO OF MALE STUDENTS =02 NO OF FEMALE STUDENTS =02

Department of Computer Applications

28

COBOL Programming

DATE : 10/12/2008 PGM NO : 14

SUM OF DIAGONAL ELEMENTS


AIM : TO ACCEPT A MATRIX & FIND THE SUM OF THE ELEMENTS IN A LEADING DIAGONAL.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. DIAGSUM. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 MAT. 02 R OCCURS 5 TIMES. 03 C OCCURS 5 TIMES. 04 A PIC 9(3). 01 Y. 05 F OCCURS 5 TIMES PIC Z(4).9. 77 I PIC 9. 77 J PIC 9. 77 SU PIC 9(4) VALUE 0. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER A 5*5 MATRIX". DISPLAY "ENTER THE ELEMENTS". PERFORM ELEMENT-PARA VARYING I FROM 1 BY 1 UNTIL I>5 AFTER J FROM 1 BY 1 UNTIL J>5. PERFORM ADD-PARA VARYING I FROM 1 BY 1 UNTIL I>5. DISPLAY "**********THE ENTERED MATRIX***********". PERFORM LIN-SET VARYING I FROM 1 BY 1 UNTIL I>5. DISPLAY "THE DIAGONAL SUM="SU. STOP RUN.

Department of Computer Applications

29

COBOL Programming

ELEMENT-PARA. ACCEPT A(I J). LIN-SET. PERFORM MOV-PARA VARYING J FROM 1 BY 1 UNTIL J>5. DISPLAY Y. MOV-PARA. MOVE A(I J) TO F(J). ADD-PARA. ADD A(I I) TO SU.

Department of Computer Applications

30

COBOL Programming

OUTPUT
ENTER A 5*5 MATRIX ENTER THE ELEMENTS 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 **********THE ENTERED MATRIX*********** 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 THE DIAGONAL SUM=0065

Department of Computer Applications

31

COBOL Programming

DATE : 12/12/2008 PGM NO : 15

COMPUTATION OF GROSS PAY


AIM : TO ACCEPT NAME AND BASIC PAY OF AN EMPLOYEE ,THEN COMPUTE HIS DA,HRA AND DISPLAY THE GROSS PAY.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. EMPDET. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 EMP. 02 ENAME PIC X(20). 02 BP PIC 9(6)V99. 02 DA PIC 9(5). 02 HRA PIC 9(5). 02 GROS PIC 9(7)V99. 77 EBP PIC 9(6).99. 77 EGR PIC 9(7).99. PROCEDURE DIVISION. ACCEPT-PARA. DISPLAY "ENTER EMPLOYEE NAME ". ACCEPT ENAME. DISPLAY "ENTER THE BASIC PAY". ACCEPT BP. COMPUTE-PARA. COMPUTE DA ROUNDED = BP * (74 / 100). COMPUTE HRA ROUNDED = BP * (15 / 100). COMPUTE GROS = BP + DA + HRA. MOVE GROS TO EGR . MOVE BP TO EBP. DISPLAY (1 1) ERASE. DISPLAY-PARA. DISPLAY (5 5) "*********** SALARY DETAILS ***********". Department of Computer Applications 32

COBOL Programming DISPLAY (10 5) "NAME : "ENAME. DISPLAY (10 25) "BASIC PAY : " EBP. DISPLAY (14 5) "DA : "DA. DISPLAY (14 25) "HRA : "HRA. DISPLAY (18 10) "GROSS PAY : "EGR. STOP RUN.

Department of Computer Applications

33

COBOL Programming

OUTPUT
*********** SALARY DETAILS *********** NAME : MAHESH BASIC PAY : 008750.00 DA : 06475 HRA : 01313 GROSS PAY : 0016538.00

Department of Computer Applications

34

COBOL Programming

DATE : 16/12/2008 PGM NO : 16

ILLUSTRATION OF OCCURS CLAUSE


AIM : AN INTERACTIVE PROGRAM TO DISPLAY THE TELEPHONE NUMBER WHEN THE NAME IS GIVEN AND TO FIND THE NAME WHEN THE TELEPHONE NUMBER IS GIVEN.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. HOUSETEL. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 01 DET. 02 HNAM PIC X(20) OCCURS 5 TIMES. 02 TELNO PIC 9(10) OCCURS 5 TIMES. 77 NAM PIC X(20). 77 PNO PIC 9(10). 77 I PIC 9(4). 77 C PIC A. 77 S PIC 9. PROCEDURE DIVISION. P-1. PERFORM ACC-PARA VARYING I FROM 1 BY 1 UNTIL I > 2. P-6. DISPLAY (1 1) ERASE. DISPLAY "1.Search by House Name ". DISPLAY "2.Search by Phone No. ". DISPLAY "ENTER THE SEARCH OPTION(1/2):". ACCEPT S. IF S = 1 GO TO S1. IF S = 2 GO TO S2 ELSE DISPLAY "INVALID SEARCH OPTION" GO TO PS. Department of Computer Applications 35

COBOL Programming ACC-PARA. DISPLAY "ENTER THE " I " TH HOUSE NAME AND PHONE NO". ACCEPT HNAM(I). ACCEPT TELNO(I). S1. DISPLAY "ENTER THE HOUSE NAME". ACCEPT NAM. PERFORM H-PARA VARYING I FROM 1 BY 1 UNTIL I > 2. DISPLAY "THE HOUSE NAME NOT FOUND ". GO TO PS. H-PARA. IF NAM = HNAM(I) GO TO DISP-PARA. S2. DISPLAY "ENTER THE TELEPHONE NUMBER". ACCEPT PNO. PERFORM P-PARA VARYING I FROM 1 BY 1 UNTIL I > 2. DISPLAY " THE PHONE NO. NOT FOUND". GO TO PS. P-PARA. IF PNO = TELNO(I) GO TO DISP-PARA. DISP-PARA. IF S = 1 DISPLAY "THE PHONE NO.OF " NAM " IS " TELNO(I). IF S = 2 DISPLAY "THE PHONE NO. BELONGS TO " HNAM(I). PS. DISPLAY "DO U WISH TO CONTINUE(Y\N):". ACCEPT C. IF C = "y" OR = "Y" DISPLAY(1 1) ERASE GO TO P-6. STOP RUN.

Department of Computer Applications

36

COBOL Programming

OUTPUT

ENTER THE 0001 TH HOUSE NAME AND PHONE NO M.C SADANAM 9447427426 ENTER THE 0002 TH HOUSE NAME AND PHONE NO RAJI BHAVAN 9446789562 1.Search by House Name 2.Search by Phone No. ENTER THE SEARCH OPTION(1/2): 2 ENTER THE TELEPHONE NUMBER 9447427426 THE PHONE NO. BELONGS TO M.C SADANAM DO U WISH TO CONTINUE(Y\N): N

Department of Computer Applications

37

COBOL Programming

DATE : 05/01/2009 PGM NO : 17

MARKLIST PREPARATION
AIM : AN INTERACTIVE PROGRAM TO ACCEPT NAME & MARK THEN DISPLAY THE STUDENT IS PASSED OR FAILED.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. MARKLIST. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 M1 PIC 9(3). 77 M2 PIC 9(3). 77 M3 PIC 9(3). 77 REG PIC 9(5). 77 NAM PIC X(20). 77 RES PIC A(6). 77 TOT PIC 9(4). 77 C PIC A. PROCEDURE DIVISION. P-1. DISPLAY "ENTER THE STUDENT NAME AND REGISTER NO.". ACCEPT NAM ACCEPT REG. DISPLAY "ENTER THE MARKS FOR MATHS,PHYSICS & CHEMISTRY". ACCEPT M1 ACCEPT M2 ACCEPT M3. P-2. IF M1 > 35 AND M2 > 35 AND M3 > 35 MOVE "PASSED" TO RES ELSE MOVE "FAILED" TO RES. COMPUTE TOT = M1 + M2 + M3. PERFORM P-3. DISPLAY(22 10) "DO U WISH TO CONTINUE(Y/N):". Department of Computer Applications 38

COBOL Programming ACCEPT C. IF C = "Y" OR = "y" DISPLAY (1 1) ERASE GO TO P-1. STOP RUN. P-3. DISPLAY(1 1) ERASE. DISPLAY(5 30) "UNIVERSITY OF KERALA". DISPLAY(6 30) "********************". DISPLAY(8 38) "MARKLIST". DISPLAY(10 10) "NAME: "NAM. DISPLAY(10 35) "REG.NO.: "REG. DISPLAY(12 10) "1.MATHEMATICS : "M1. DISPLAY(14 10) "2.PHYSICS : "M2. DISPLAY(16 10) "3.CHEMISTRY : "M3. DISPLAY(17 10) "___________________________". DISPLAY(18 15) " TOTAL : "TOT. DISPLAY(19 10) "___________________________". DISPLAY(21 12) "RESULT : "RES.

Department of Computer Applications

39

COBOL Programming

OUTPUT
ENTER THE STUDENT NAME AND REGISTER NO. MAHESH 7031 ENTER THE MARKS FOR MATHS,PHYSICS & CHEMISTRY 75 80 70 UNIVERSITY OF KERALA ******************** MARKLIST NAME: MAHESH 1.MATHEMATICS 2.PHYSICS : 075 : 080 REG.NO.: 07058

3.CHEMISTRY : 070 ___________________________ TOTAL : 0225 ___________________________ RESULT : PASSED DO U WISH TO CONTINUE(Y/N):N

Department of Computer Applications

40

COBOL Programming DATE : 06/01/2009 PGM NO : 18

RANKLIST PREPARATION USING OCCURS CLAUSE


AIM : TO PREPARE RANKLIST CONSISTING OF ROLL NO & MARK.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. RANK. AUTHOR. MAHI. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. SYSTEM. OBJECT-COMPUTER. SYSTEM. DATA DIVISION. WORKING-STORAGE SECTION. 77 I PIC 9(2). 77 J PIC 9(2). 77 K PIC 9(2). 77 TEM1 PIC 9(5). 77 TEM2 PIC 9(3). 01 RAN. 02 ROLL PIC 9(5) OCCURS 60 TIMES. 02 MARK PIC 9(3) OCCURS 60 TIMES. PROCEDURE DIVISION. P-P1. DISPLAY "ENTER THE ROLL NO: AND TOT MARK OF 3 STUDENTS". PERFORM AC-PARA VARYING I FROM 1 BY 1 UNTIL I > 3. PERFORM SRT-PARA VARYING I FROM 1 BY 1 UNTIL I > 3 DISPLAY " RANK ROLLNO MARK ". PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > 3. STOP RUN. AC-PARA. DISPLAY I "TH RECORD". ACCEPT ROLL(I). ACCEPT MARK(I). SRT-PARA. COMPUTE K = I + 1. PERFORM SORT-PARA VARYING J FROM K Department of Computer Applications 41

COBOL Programming BY 1 UNTIL J > 3. SORT-PARA. IF MARK(I) < MARK(J) MOVE ROLL(J) TO TEM1 MOVE MARK(J) TO TEM2 MOVE ROLL(I) TO ROLL(J) MOVE MARK(I) TO MARK(J) MOVE TEM1 TO ROLL(I) MOVE TEM2 TO MARK(I). DISP-PARA. DISPLAY " " I " " ROLL(I) "

" MARK(I).

Department of Computer Applications

42

COBOL Programming

OUTPUT
01TH RECORD 1077 456 02TH RECORD 1078 565 03TH RECORD 1079 525 RANK ROLLNO MARK 01 01078 565 02 01079 525 03 01077 456

Department of Computer Applications

43

COBOL Programming

DATE : 07/01/2009 PGM NO : 19

EMPLOYEE DETAILS USING CONDITION NAME


AIM : AN INPUT FILE CONTAINS EMP NUMBER,NAME & CATEGORY TO COUNT THE NUMBER OF EMPLOYEES IN EACH CATEGORY USING CONDITION NAME IS DONE IN TH OUTPUT FILE.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. EMP1. AUTHOR. MAHI. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IP1 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IP1 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "IP" DATA RECORD IS EMP. 01 EMP. 02 ENO PIC 9(4). 02 ENAM PIC X(15). 02 ECAT PIC A. WORKING-STORAGE SECTION. 77 NM PIC 9(4). 77 N PIC 9(4). 77 I PIC 9(4). 77 NAM PIC X(15). 77 CAT PIC A. 88 EA VALUE "A" , "a". 88 EB VALUE "B" , "b". 88 EC VALUE "C" , "c". PROCEDURE DIVISION. Department of Computer Applications 44

COBOL Programming P1. OPEN OUTPUT IP1. DISPLAY "ENTER HOW MANY RECORDS TO ENTER ". ACCEPT N. PERFORM ACC-PARA VARYING I FROM 1 BY 1 UNTIL I>N. DISPLAY "THE RECORDS ARE WRITTEN". GO TO L-PARA. ACC-PARA. DISPLAY "ENTER EMPLOYEE NO: NAME & CTGY " I " RECORD". ACCEPT ENO ACCEPT ENAM ACCEPT ECAT. WRITE EMP. L-PARA. CLOSE IP1. STOP RUN.

Department of Computer Applications

45

COBOL Programming

OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. EMP. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IP1 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IP1 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "IP" DATA RECORD IS EMP. 01 EMP. 02 ENO PIC 9(4). 02 ENAM PIC X(15). 02 ECAT PIC A. WORKING-STORAGE SECTION. 77 NM PIC 9(4). 77 N PIC 9(4). 77 I PIC 9(4). 77 NAM PIC X(15). 77 NA PIC 9(2) VALUE 0. 77 NB PIC 9(2) VALUE 0. 77 NC PIC 9(2) VALUE 0. 77 CAT PIC A. 88 EA VALUE "A" , "a". 88 EB VALUE "B" , "b". 88 EC VALUE "C" , "c". PROCEDURE DIVISION. P1. OPEN INPUT IP1. P2. READ IP1 AT END GO TO L-PARA. MOVE ECAT TO CAT. IF EA ADD 1 TO NA. IF EB ADD 1 TO NB. IF EC ADD 1 TO NC. GO TO P2. L-PARA. DISPLAY " ". DISPLAY " ". DISPLAY "CATEGORY A : " NA. DISPLAY "CATEGORY B : " NB. DISPLAY "CATEGORY C : " NC. CLOSE IP1. Department of Computer Applications 46

COBOL Programming
STOP RUN.

OUTPUT
INPUT FILE(IP) 0101MAHESH 0102VIJITH 0103BEJOY 0104UNNI OUTPUT FILE CATEGORY A : 02 CATEGORY B : 01 CATEGORY C : 01 A B C A

Department of Computer Applications

47

COBOL Programming

DATE : 09/01/2009 PGM NO : 20

BUBBLE SORT
AIM : TO PERFORM BUBBLE SORT. IDENTIFICATION DIVISION. PROGRAM-ID. SORT. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 I PIC 9(3). 77 K PIC 9(3). 77 N PIC 9(2). 77 TEM PIC 9(3). 77 J PIC 9(3). 01 SRT. 02 AR PIC 9(3) OCCURS 20 TIMES. PROCEDURE DIVISION. P-1. DISPLAY "ENTER HOW MANY NUMBERS". ACCEPT N. DISPLAY "ENTER THE " N " ELEMENTS". PERFORM ACC-PARA VARYING I FROM 1 BY 1 UNTIL I > N. PERFORM SRT-PARA VARYING I FROM 1 BY 1 UNTIL I > N - 1. DISPLAY "THE SORTED ARRAY IS". PERFORM DISP-PARA VARYING I FROM 1 BY 1 UNTIL I > N. STOP RUN. ACC-PARA. ACCEPT AR(I). SRT-PARA. COMPUTE K = I + 1. PERFORM SORT-PARA VARYING J FROM K BY 1 UNTIL J > N. SORT-PARA. IF AR(I) < AR(J) MOVE AR(I) TO TEM MOVE AR(J) TO AR(I) MOVE TEM TO AR(J). DISP-PARA. Department of Computer Applications 48

PROGRAM

COBOL Programming DISPLAY AR(I).

OUTPUT
ENTER HOW MANY NUMBERS 8 ENTER THE 08 ELEMENTS 8 6 4 9 7 3 11 1 THE SORTED ARRAY IS 011 009 008 007 006 004 003 001

Department of Computer Applications

49

COBOL Programming

DATE : 13/01/2009 PGM NO : 21

CUSTOMER DETAILS USING LINEAR SEARCH


AIM : TO SEARCH THE DETAILS OF A CUSTOMER ON THE BASIS OF ACCOUNT NUMBER USING LINEAR SEARCH. IDENTIFICATION DIVISION. PROGRAM-ID. SRCHVB. AUTHOR. MAHI ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 77 AS-NO PIC 9(12). 01 SB. 02 TNO OCCURS 4 TIMES INDEXED BY M. 03 AMOUNT PIC 9(6). 03 ACNO PIC 9(5). 03 NAM PIC X(20). PROCEDURE DIVISION. P-1. SET M TO 1. PERFORM ACC-PARA 3 TIMES. DISPLAY(1 1) ERASE. DISPLAY "ENTER THE ACCOUNT NUMBER TO BE SEARCHED". ACCEPT AS-NO. SET M TO 1. SEARCH TNO AT END DISPLAY "NUMBER NOT FOUND" WHEN AS-NO=ACNO(M) DISPLAY "NAME IS :" NAM(M). DISPLAY "AMOUNT ON CREDIT:" AMOUNT(M). STOP RUN. ACC-PARA. DISPLAY "ENTER ACCOUNT NO, NAME AND AMOUNT". ACCEPT ACNO(M). ACCEPT NAM(M). ACCEPT AMOUNT(M). SET M UP BY 1. Department of Computer Applications 50

PROGRAM

COBOL Programming

OUTPUT
ENTER ACCOUNT NO, NAME AND AMOUNT 7503 MAHESH 25000 ENTER ACCOUNT NO, NAME AND AMOUNT 7504 LINU 30000 ENTER ACCOUNT NO, NAME AND AMOUNT 7505 KICHU 500000 ENTER THE ACCOUNT NUMBER TO BE SEARCHED 7505 NAME IS :KICHU AMOUNT ON CREDIT:500000

Department of Computer Applications

51

COBOL Programming

DATE : 14/01/2009 PGM NO : 22

CUSTOMER DETAILS USING BINARY SEARCH


AIM : TO SEARCH THE DETAILS OF A CUSTOMER ON THE BASIS OF ACCOUNT NUMBER USING BINARY SEARCH.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. STUDBIN. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 STUD. 02 ET OCCURS 4 TIMES ASCENDING KEY ACNO INDEXED BY I. 03 ACNO PIC 9(5). 03 NAM PIC X(20). 03 BRNAM PIC X(30). 03 AMOUNT PIC 9(6). 77 S-ACNO PIC 9(5). 77 C PIC A. PROCEDURE DIVISION. P-1. SET I TO 1. PERFORM ACC-PARA 4 TIMES. DISPLAY "ELEMENT ACCEPTED". P-2. DISPLAY (1 1) ERASE. SET I TO 1. DISPLAY "ENTER THE ACOUNT NO TO SEARCH". ACCEPT S-ACNO. SEARCH ALL ET AT END DISPLAY "NO. NOT FOUND" GO TO P-3 WHEN ACNO(I) = S-ACNO GO TO P-4. P-3. DISPLAY "DO U WISH TO CONTINUE(Y/N)". ACCEPT C. IF C="Y" OR ="y" GO TO P-2 ELSE Department of Computer Applications 52

COBOL Programming STOP RUN. P-4. DISPLAY "NAME : " NAM(I) DISPLAY "BRANCH NAME: " BRNAM(I) DISPLAY "AMOUNT :" AMOUNT(I). GO TO P-3. ACC-PARA. DISPLAY "ENTER ACOUNT NO,NAME, BRANCH NAME & AMOUNT". ACCEPT ACNO(I) ACCEPT NAM(I) ACCEPT BRNAM(I) ACCEPT AMOUNT(I). SET I UP BY 1.

Department of Computer Applications

53

COBOL Programming

OUTPUT
ENTER ACOUNT NO, NAME, BRANCH NAME & AMOUNT 5421 MAHESH TVM 1000 ENTER ACOUNT NO, NAME, BRANCH NAME & AMOUNT 5423 MANU KOTTAYAM 25000 ENTER ACOUNT NO, NAME, BRANCH NAME & AMOUNT 5422 KRISHNA KOLLAM 500 ENTER ACOUNT NO, NAME, BRANCH NAME & AMOUNT 5400 PRAVEEN NEDUMANGAD 75000 ENTER THE ACOUNT NO TO SEARCH 5423 NAME : MANU BRANCH NAME: KOTTAYAM AMOUNT :025000 DO U WISH TO CONTINUE(Y/N) N

Department of Computer Applications

54

COBOL Programming

DATE : 16/01/2009 PGM NO : 23

SEQUENTIAL FILE RELATING TO ADMISSION


AIM : GIVEN A SEQUENTIAL FILE RELATING TO ADMISSION INCLUDING ADMISSION NUMBER,NAME,MARKS.

PROGRAM IDENTIFICATION DIVISION PROGRAM-ID. TSTFILE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDREC ASSIGN TO DISK ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD STUDREC LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "STUD.DAT" DATA RECORD IS STUDR. 01 STUDR. 05 ADMNO PIC 9(5). 05 SNAM PIC X(30). 05 SADD PIC X(30). 05 AGE PIC 9(2). WORKING-STORAGE SECTION. 77 C PIC A. PROCEDURE DIVISION. P-1. OPEN OUTPUT STUDREC. P-2. DISPLAY(1 1) ERASE. DISPLAY(5 1) "1.Admission No:". ACCEPT(5 20) ADMNO. DISPLAY(7 1) "2.Name: ". ACCEPT(7 20) SNAM. DISPLAY(9 1) "3.Address: ". ACCEPT(9 20) SADD. DISPLAY(11 1) "4.Age: ". Department of Computer Applications 55

COBOL Programming ACCEPT(11 20) AGE. WRITE STUDR. DISPLAY(13 1) "DO U WISH TO CONTINUE(Y\N)". ACCEPT(13 30) C. IF C="Y" OR ="y" GO TO P-2. CLOSE STUDREC. STOP RUN.

Department of Computer Applications

56

COBOL Programming

OUTPUT
1.Admission No: 1159 2.Name: MAHESH 3.Address: M.C SADANAM 4.Age: 21 DO U WISH TO CONTINUE(Y\N) Y 1.Admission No: 1129 2.Name: REJU 3.Address: KRIPA 4.Age: 22 DO U WISH TO CONTINUE(Y\N) N OUTFILE(STUD.DAT) 1159MAHESH M.C SADANAM 1129REJU KRIPA 22

Department of Computer Applications

57

COBOL Programming

DATE : 19/01/2009 PGM NO : 24

EXAM DETAIL USING SEQUENTIAL FILE


AIM : TO PREPARE A LIST OF TABULATION CONTAINING GIVEN DETAILS ALONG WITH TOTAL MARK & AVERAGE MARK.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. RESULT. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EXAM ASSIGN TO DISK ORGANIZATION IS SEQUENTIAL SELECT OPTFILE ASSIGN TO DISK ORGANIZATION IS SEQUENTIAL. DATA DIVISION. FILE SECTION. FD EXAM LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "IP1" DATA RECORD IS EDET1. 01 EDET1. 02 REGNO PIC 9(5). 02 SNAM PIC X(15). 02 M1 PIC 9(3). 02 M2 PIC 9(3). 02 M3 PIC 9(3). FD OPTFILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "OP1" DATA RECORD IS EDET2. 01 EDET2. 02 ORNO PIC 9(5). 02 ONAM PIC X(15). 02 OM1 PIC Z(3). 02 OM2 PIC Z(3). 02 OM3 PIC Z(3). 02 TOT PIC 9(5). Department of Computer Applications 58

COBOL Programming 02 AVG PIC Z(4).99. WORKING-STORAGE SECTION. 77 C PIC A. PROCEDURE DIVISION. P-1. OPEN OUTPUT EXAM. P-2. DISPLAY "ENTER THE REGISTER NO.". ACCEPT REGNO. DISPLAY "ENTER THE NAME". ACCEPT SNAM. DISPLAY "ENTER THE 3 MARKS". ACCEPT M1 ACCEPT M2 ACCEPT M3. WRITE EDET1. P-3. DISPLAY "DO U WISH TO CONTINUE(Y\N)". ACCEPT C. IF C="Y" OR ="y" DISPLAY (1 1) ERASE GO TO P-2. GO TO P-4. P-4. CLOSE EXAM .

Department of Computer Applications

59

COBOL Programming

OUTPUT
ENTER THE REGISTER NO. 7031 ENTER THE NAME MAHESH ENTER THE 3 MARKS 65 75 55 DO U WISH TO CONTINUE(Y\N) Y ENTER THE REGISTER NO. 7032 ENTER THE NAME MATHEW ENTER THE 3 MARKS 56 89 75 DO U WISH TO CONTINUE(Y\N) N INPUT FILE(IP1) 07031MAHESH 06507505507032MATHEW 056089075

OUTPUT FILE(OP1) 07031MAHESH 73.33 65 75 5500195 65.0007032MATHEW 56 89 7500220

Department of Computer Applications

60

COBOL Programming DATE : 22/01/2009 PGM NO : 25

HIGHEST TOTAL USING SEQUENTIAL FILE


AIM : GIVEN A INPUT FILE CONTAINING NAME,REG NO,MARKS THEN FIND THE TOTAL MARK & HIGHEST TOTAL STORE IT IN AN OUT FILE.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. HIGHEST. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "MT" DATA RECORDS ARE STUD. 01 STUD. 02 REGNO PIC 9(5). 02 SNAM PIC X(12). 02 M1 PIC 9(3). 02 M2 PIC 9(3). 02 M3 PIC 9(3). WORKING-STORAGE SECTION. 77 N PIC 9(2). 77 I PIC 9(2). PROCEDURE DIVISION. P1. OPEN OUTPUT IP. P2. DISPLAY "ENTER HOW MANY RECORDS". ACCEPT N. PERFORM P3 VARYING I FROM 1 BY 1 UNTIL I>N. STOP RUN. P3. Department of Computer Applications 61

COBOL Programming DISPLAY "REG NO.,NAME & 3 MARKS OF " I "RECORD". ACCEPT REGNO ACCEPT SNAM ACCEPT M1. ACCEPT M2 ACCEPT M3. WRITE STUD. OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. HIGHEST. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT OP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "MT" DATA RECORDS ARE STUD. 01 STUD. 02 REGNO PIC 9(5). 02 SNAM PIC X(12). 02 M1 PIC 9(3). 02 M2 PIC 9(3). 02 M3 PIC 9(3). FD OP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "OP" DATA RECORDS ARE STUD1. 01 STUD1. 02 ORNO PIC Z(5). 02 OSM PIC X(12). 02 O1 PIC Z(3). 02 O2 PIC Z(3). 02 O3 PIC Z(3). 02 TOT PIC Z(3). 02 RS PIC X(6). WORKING-STORAGE SECTION. 77 BIG PIC 9(3) VALUE IS 0. 77 I PIC 9(2). 77 T PIC 9(3).

Department of Computer Applications

62

COBOL Programming PROCEDURE DIVISION. P1. OPEN INPUT IP OUTPUT OP. P2. READ IP AT END GO TO L-PARA. COMPUTE T = M1 + M2 + M3. IF M1 > 40 AND M2 > 40 AND M3 > 40 MOVE "PASSED" TO RS ELSE MOVE "FAILED" TO RS. MOVE REGNO TO ORNO. MOVE SNAM TO OSM. MOVE M1 TO O1. MOVE M2 TO O2. MOVE M3 TO O3. MOVE T TO TOT. IF BIG < TOT MOVE TOT TO BIG. WRITE STUD1. GO TO P2. L-PARA. CLOSE OP IP. OPEN INPUT OP. DISPLAY(1 1) ERASE. DISPLAY "********MAHATMA GANDHI UNIVERSITY**********". DISPLAY "-------------------------------------------". DISPLAY "REGNO NAME M1 M2 M3 TOTAL RESULT". DISPLAY "-------------------------------------------". P3. READ OP AT END GO TO S-PARA. DISPLAY ORNO " " OSM O1 " " O2 O3 " " TOT " " RS. GO TO P3. S-PARA. DISPLAY "THE HIGHEST TOTAL IS " BIG. CLOSE OP. STOP RUN.

Department of Computer Applications

63

COBOL Programming

OUTPUT
INPUT FILE(MT) ENTER HOW MANY RECORDS 3 REG NO.,NAME & 3 MARKS OF 01RECORD 1077 MAHESH 89 75 65 REG NO.,NAME & 3 MARKS OF 02RECORD 1078 MATHEW 63 31 55 REG NO.,NAME & 3 MARKS OF 03RECORD 1079 PRADEEP 95 78 96 TYPE MT 01077MAHESH 01078MATHEW 01079PRADEEP OUTPUT FILE ****************MAHATMA GANDHI UNIVERSITY************* --------------------------------------------------------------------------------------------REGNO NAME M1 M2 M3 TOTAL RESULT ---------------------------------------------------------------------------------------------------1077 MAHESH 89 75 65 229 PASSED 1078 MATHEW 63 31 55 149 FAILED 1079 PRADEEP 95 78 96 269 PASSED THE HIGHEST TOTAL IS 269

089075065 063031055 095078096

Department of Computer Applications

64

COBOL Programming

DATE : 23/01/2009 PGM NO : 26

TELEPHONE BILL
AIM : TO PREAPRE TELEPHONE BILL.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. TELE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TELIP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD TELIP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TIP" DATA RECORDS ARE TEL. 01 TEL. 02 SNAM PIC X(10). 02 SADD PIC X(10). 02 TPH PIC 9(10). 02 MN PIC 99. 02 YR PIC 9(4). 02 MTR PIC 9(5). WORKING-STORAGE SECTION. 77 N PIC 9(2). 77 I PIC 9(2). PROCEDURE DIVISION. P0. OPEN OUTPUT TELIP. P1. DISPLAY "ENTER HOW MANY RECORDS ". ACCEPT N. PERFORM P2 VARYING I FROM 1 BY 1 UNTIL I>N. GO TO L-PARA. P2. Department of Computer Applications 65

COBOL Programming DISPLAY "ENTER NAME,ADDRESS,PHONE NO, MONTH&YEAR & READING " I. ACCEPT SNAM ACCEPT SADD ACCEPT TPH. ACCEPT MN ACCEPT YR ACCEPT MTR. WRITE TEL. L-PARA. CLOSE TELIP. STOP RUN. OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. TELE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TELIP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT TELOP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD TELIP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TIP" DATA RECORDS ARE TEL. 01 TEL. 02 SNAM PIC X(10). 02 SADD PIC X(10). 02 TPH PIC 9(10). 02 MN PIC 99. 02 YR PIC 9(4). 02 MTR PIC 9(5). FD TELOP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TOP" DATA RECORDS ARE TEL1. 01 TEL1 PIC X(65). WORKING-STORAGE SECTION. 77 N PIC 9(2). 77 I PIC 9(2). 77 A PIC 9(6). 77 AMT PIC 9(6). 77 S PIC A. 01 L1 PIC X(65) VALUE ALL "-". 01 L2. 02 FILLER PIC X(22) VALUE SPACE. Department of Computer Applications 66

COBOL Programming 02 FILLER PIC X(25) VALUE "BHARAT SANCHAR NIGAM LTD". 02 FILLER PIC X(22) VALUE SPACE. 01 L3. 02 FILLER PIC X(5) VALUE SPACE. 02 FILLER PIC X(15) VALUE "CONSUMER NAME: ". 02 ONM PIC X(10). 02 FILLER PIC X(10) VALUE SPACE. 02 FILLER PIC X(9) VALUE "ADDRESS:". 02 OAD PIC X(10). 01 L4. 02 FILLER PIC X(5) VALUE SPACE. 02 FILLER PIC X(15) VALUE "TELEPHONE NO :". 02 OT PIC Z(9)9. 02 FILLER PIC X(5) VALUE SPACE. 01 L6. 02 FILLER PIC X(5) VALUE SPACE. 02 FILLER PIC X(15) VALUE "METER READING :". 02 OMTR PIC Z(5). 02 FILLER PIC X(10) VALUE SPACE. 02 FILLER PIC X(15) VALUE "MONTH & YEAR :". 02 OM PIC 99. 02 FILLER PIC X VALUE "\". 02 OY PIC 9(4). 01 L5. 02 FILLER PIC X(15) VALUE SPACE. 02 FILLER PIC X(13) VALUE "BILL AMOUNT :". 02 OAT PIC Z(5)9.99. PROCEDURE DIVISION. P0. OPEN INPUT TELIP OUTPUT TELOP. P1. READ TELIP AT END GO TO L-PARA. WRITE TEL1 FROM L1. WRITE TEL1 FROM L2. WRITE TEL1 FROM L1. SUBTRACT 150 FROM MTR GIVING A. IF A<0 MOVE 0 TO AMT. IF A > 150 AND < 600 COMPUTE AMT = 400 + (150 * A). IF A > 600 AND < 1200 COMPUTE AMT = 400 + (300 * A). IF A > 1200 COMPUTE AMT = 400 + (500 * A). MOVE SNAM TO ONM. MOVE SADD TO OAD. Department of Computer Applications 67

COBOL Programming MOVE TPH TO OT. MOVE MN TO OM. MOVE YR TO OY. MOVE MTR TO OMTR. MOVE AMT TO OAT. WRITE TEL1 FROM L3. WRITE TEL1 FROM L4. WRITE TEL1 FROM L6. WRITE TEL1 FROM L1. WRITE TEL1 FROM L5. WRITE TEL1 FROM L1. GO TO P1. L-PARA. CLOSE TELIP TELOP. STOP RUN.

Department of Computer Applications

68

COBOL Programming

OUTPUT
ENTER HOW MANY RECORDS 1 ENTER NAME,ADDRESS,PHONE NO, MONTH&YEAR & READING ANIL ANILBHAVAN 9496806481 02 2007 650 INPUT FILE(TIP) ANIL ANILBHAVAN949680648102200700650 OUTPUT FILE(TOP) ---------------------------------------------------------------------------------BHARAT SANCHAR NIGAM LTD ---------------------------------------------------------------------------------CONSUMER NAME: ANIL ADDRESS: ANILBHAVAN TELEPHONE NO : 9496806481 METER READING : 650 MONTH & YEAR : 02\2007 ---------------------------------------------------------------------------------BILL AMOUNT : 75400.00 -----------------------------------------------------------------------------------

Department of Computer Applications

69

COBOL Programming

DATE : 03/02/2009 PGM NO : 27

INCOME TAX
AIM : TO PREAPRE INCOME TAX.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. TAX. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IT ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IT LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TAX" DATA RECORDS ARE TA. 01 TA. 02 ENO PIC 9(5). 02 ENAM PIC X(10). 02 DESI PIC X(10). 02 EBP PIC 9(6)V99. 02 LIC PIC 9(4)V99. 02 MSS PIC 9(4)V99. 02 NCC PIC 9(4)V99. 02 TOT PIC 9(7)V99. WORKING-STORAGE SECTION. 77 C PIC A. PROCEDURE DIVISION. P1. OPEN OUTPUT IT. P2. DISPLAY "ENTER THE EMPLOYEE NO:,NAME, DESI & BASICPAY". ACCEPT ENO ACCEPT ENAM ACCEPT DESI ACCEPT EBP. DISPLAY "CONTRIBUTIONS TO LIC,MSS,NCC & TOTAL INCOME:". Department of Computer Applications 70

COBOL Programming ACCEPT LIC ACCEPT MSS ACCEPT NCC ACCEPT TOT. IF TOT< EBP DISPLAY "ENTER THE TOTAL INCOME GREATER THAN BASIC" ACCEPT TOT. WRITE TA. P3. DISPLAY "WANT TO ENTER MORE RECORDS(Y/N)". ACCEPT C. IF C = "Y" OR = "y" DISPLAY(1 1) ERASE GO TO P2. CLOSE IT. STOP RUN. OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. TAX. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IT ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT OT ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IT LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TAX" DATA RECORDS ARE TA. 01 TA. 02 ENO PIC 9(5). 02 ENAM PIC X(10). 02 DESI PIC X(10). 02 EBP PIC 9(6)V99. 02 LIC PIC 9(4)V99. 02 MSS PIC 9(4)V99. 02 NCC PIC 9(4)V99. 02 TOT PIC 9(7)V99. FD OT LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TAX1" DATA RECORDS ARE TA1. 01 TA1 PIC X(80). Department of Computer Applications 71

COBOL Programming WORKING-STORAGE SECTION. 01 L1. 02 FILLER PIC X(80) VALUE ALL "-". 01 L2. 02 FILLER PIC X(30) VALUE ALL "*". 02 FILLER PIC X(20) VALUE "INCOME TAX STATEMENT". 02 FILLER PIC X(30) VALUE ALL "*". 01 L3. 02 FILLER PIC X(8) VALUE SPACE. 02 FILLER PIC X(14) VALUE "EMPLOYEE CODE: ". 02 ONO PIC Z(4)9. 02 FILLER PIC X(4) VALUE SPACE. 02 FILLER PIC X(14) VALUE "EMPLOYEE NAME: ". 02 ONM PIC X(10). 01 L4. 02 FILLER PIC X(8) VALUE SPACE. 02 FILLER PIC X(14) VALUE "DESIGNATION: ". 02 OD PIC X(10). 02 FILLER PIC X(4) VALUE SPACE. 02 FILLER PIC X(14) VALUE "BASIC PAY: ". 02 OBP PIC Z(5)9.99. 01 L5. 02 FILLER PIC X(8) VALUE SPACE. 02 FILLER PIC X(14) VALUE "CONTRIBUTIONS ". 02 FILLER PIC X(4) VALUE SPACE. 01 L6. 02 FILLER PIC X(8) VALUE SPACE. 02 FILLER PIC X(6) VALUE "LIC: ". 02 OL PIC Z(3)9.99. 02 FILLER PIC X(4) VALUE SPACE. 02 FILLER PIC X(6) VALUE "MSS: ". 02 OM PIC Z(3)9.99. 02 FILLER PIC X(4) VALUE SPACE. 02 FILLER PIC X(6) VALUE "NCC: ". 02 ONCC PIC Z(3)9.99. 02 FILLER PIC X(4) VALUE SPACE. 01 L7. 02 FILLER PIC X(8) VALUE SPACE. 02 FILLER PIC X(14) VALUE "TOTAL INCOME: ". 02 OTOT PIC Z(6)9.99. 02 FILLER PIC X(4) VALUE SPACE. 02 FILLER PIC X(14) VALUE "TAXABLE INCOME: ". 02 OTI PIC Z(6)9.99. 01 L8. 02 FILLER PIC X(25) VALUE SPACE. Department of Computer Applications 72

COBOL Programming 02 FILLER PIC X(14) VALUE "TAX TO BE PAID: ". 02 OTAX PIC Z(4)9.99. 02 FILLER PIC X(4) VALUE SPACE. 77 CNT PIC 9(5)V99. 77 TAM PIC 9(5)V99. 77 AMT PIC 9(5)V99. PROCEDURE DIVISION. P1. OPEN INPUT IT OUTPUT OT. P2. READ IT AT END GO TO L-PARA. WRITE TA1 FROM L1. WRITE TA1 FROM L2. WRITE TA1 FROM L1. COMPUTE CNT = LIC + MSS + NCC. IF CNT > 60000 MOVE 60000 TO CNT. COMPUTE TAM = TOT - CNT - 20000 . IF TAM < 40001 MOVE 0 TO AMT. IF TAM > 40000 AND < 100001 COMPUTE AMT = .20 * TAM. IF TAM > 100000 COMPUTE AMT = 20000 + (.30 * (TAM - 100000)). MOVE ENO TO ONO. MOVE ENAM TO ONM. MOVE DESI TO OD. MOVE EBP TO OBP. MOVE LIC TO OL. MOVE MSS TO OM. MOVE NCC TO ONCC. MOVE TOT TO OTOT. MOVE TAM TO OTI. MOVE AMT TO OTAX. WRITE TA1 FROM L3. WRITE TA1 FROM L4. WRITE TA1 FROM L5. WRITE TA1 FROM L6. WRITE TA1 FROM L7. WRITE TA1 FROM L1. WRITE TA1 FROM L8. WRITE TA1 FROM L1. GO TO P2. L-PARA. CLOSE IT OT. STOP RUN. Department of Computer Applications 73

COBOL Programming

OUTPUT
ENTER THE EMPLOYEE NO:,NAME, DESI & BASICPAY 15258 MAHESH MANAGER 15000 CONTRIBUTIONS TO LIC,MSS,NCC & TOTAL INCOME: 4500 5500 3300 28000 WANT TO ENTER MORE RECORDS(Y/N) Y -------------------------------------------------------------------------------------------******************INCOME TAX STATEMENT***************** -------------------------------------------------------------------------------------------EMPLOYEE CODE:15258 EMPLOYEE NAME:MAHESH DESIGNATION: MANAGER BASIC PAY: 15000.00 CONTRIBUTIONS LIC: 4500.00 MSS: 5500.00 NCC: 3300.00 TOTAL INCOME: 28000.00 TAXABLE INCOME 5300.00 ------------------------------------------------------------------------------------------TAX TO BE PAID 0.00 -------------------------------------------------------------------------------------------

Department of Computer Applications

74

COBOL Programming

DATE : 05/02/2009 PGM NO : 28

MARKSHEET USING SEQUENTIAL FILE


AIM : TO PREAPRE MARKSHEET OF A STUDENT FOR FIVE DIFFERENT SUBJECTS.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID.MSHEET. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MARK-FILE ASSIGN TO DISK ORGANIZATION LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD MARK-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "T.DAT" DATA RECORDS ARE SREC. 01 SREC. 05 NAME PIC X(15). 05 REGN PIC 9999. 05 INT1 PIC 99. 05 EXT1 PIC 99. 05 INT2 PIC 99. 05 EXT2 PIC 99. 05 INT3 PIC 99. 05 EXT3 PIC 99. 05 INT4 PIC 99. 05 EXT4 PIC 99. 05 INT5 PIC 99. 05 EXT5 PIC 99. WORKING-STORAGE SECTION. 77 C PIC A. PROCEDURE DIVISION. S1. Department of Computer Applications 75

COBOL Programming OPEN OUTPUT MARK-FILE. S2. DISPLAY "ENTER THE NAME AND REGISTER NUMBER". ACCEPT NAME. ACCEPT REGN. DISPLAY "ENTER THE INTERNAL EXTERNAL FOR FIVE SUBJECT". ACCEPT INT1. ACCEPT EXT1. ACCEPT INT2. ACCEPT EXT2. ACCEPT INT3. ACCEPT EXT3. ACCEPT INT4. ACCEPT EXT4. ACCEPT INT5. ACCEPT EXT5. WRITE SREC. DISPLAY "DO YOU WISH TO CONTINUE(Y/y)". ACCEPT C. IF C = 'Y' OR = 'y' GO TO S2 ELSE GO TO ST-PARA. ST-PARA. CLOSE MARK-FILE. STOP RUN. OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID.MOUT. ENVIRONMENT DIVISION. CONFIGURATION SECTION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MARK-FILE ASSIGN TO DISK ORGANIZATION LINE SEQUENTIAL. SELECT TAB-FILE ASSIGN TO DISK ORGANIZATION LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD MARK-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "T.DAT". 01 SREC. 05 NAME PIC X(15). Department of Computer Applications 76

COBOL Programming 05 REGN PIC 9999. 05 INT1 PIC 99. 05 EXT1 PIC 99. 05 INT2 PIC 99. 05 EXT2 PIC 99. 05 INT3 PIC 99. 05 EXT3 PIC 99. 05 INT4 PIC 99. 05 EXT4 PIC 99. 05 INT5 PIC 99. 05 EXT5 PIC 99. FD TAB-FILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "T1.DAT" DATA RECORD IS TREC. 01 TREC PIC X(75). WORKING-STORAGE SECTION. 01 L0. 02 PIC X(30) VALUE ALL "*". 02 PIC X(15) VALUE "PROGRESS REPORT". 02 PIC X(30) VALUE ALL "*". 01 L1. 02 PIC X(75) VALUE ALL "-". 01 L2. 05 FILLER PIC X(15) VALUE "NAME". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(10) VALUE "REGNO:". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "I1". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "E1". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "I2". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "E2". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "I3". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "E3". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "I4". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "E4". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE "I5". 05 FILLER PIC X(2) VALUE SPACE. Department of Computer Applications 77

COBOL Programming 05 FILLER PIC X(2) VALUE "E5". 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(6) VALUE "RESULT". 01 L3. 05 ONAM PIC X(15). 05 FILLER PIC X(2) VALUE SPACE. 05 OREG PIC 9(4). 05 FILLER PIC X(2) VALUE SPACE. 05 ODESI PIC 9(4). 05 FILLER PIC X(2) VALUE SPACE. 05 I1 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 E1 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 I2 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 E2 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 I3 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 E3 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 I4 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 FILLER PIC X(2) VALUE SPACE. 05 E4 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 I5 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 E5 PIC 99. 05 FILLER PIC X(2) VALUE SPACE. 05 RES PIC A(6). 77 K PIC 9(3). PROCEDURE DIVISION. P1. OPEN INPUT MARK-FILE OUTPUT TAB-FILE. WRITE TREC FROM L0. WRITE TREC FROM L1. WRITE TREC FROM L2. WRITE TREC FROM L1. P2. READ MARK-FILE AT END GO TO L-PARA. COMPUTE K = INT1 + EXT1. IF K > 49 AND EXT1 > 25 MOVE "PASSED" TO RES ELSE Department of Computer Applications 78

COBOL Programming MOVE "FAILED" TO RES. COMPUTE K = INT2 + EXT2. IF K > 49 AND EXT2 > 25 MOVE "PASSED" TO RES ELSE MOVE "FAILED" TO RES. COMPUTE K = INT3 + EXT3. IF K > 49 AND EXT3 > 25 MOVE "PASSED" TO RES ELSE MOVE "FAILED" TO RES. COMPUTE K = INT4 + EXT4. IF K > 49 AND EXT4 > 25 MOVE "PASSED" TO RES ELSE MOVE "FAILED" TO RES. COMPUTE K = INT5 + EXT5. IF K > 49 AND EXT5 > 25 MOVE "PASSED" TO RES ELSE MOVE "FAILED" TO RES. MOVE NAME TO ONAM. MOVE REGN TO OREG. MOVE INT1 TO I1. MOVE INT1 TO I2. MOVE INT1 TO I3. MOVE INT1 TO I4. MOVE INT1 TO I5. MOVE EXT1 TO E1. MOVE EXT1 TO E2. MOVE EXT1 TO E3. MOVE EXT1 TO E4. MOVE EXT1 TO E5. WRITE TREC FROM L3. GO TO P2. L-PARA. WRITE TREC FROM L1. CLOSE MARK-FILE TAB-FILE. STOP RUN.

Department of Computer Applications

79

COBOL Programming

OUTPUT
**********************PROGRESS REPORT******************** -------------------------------------------------------------------------------------------NAME REGNO: I1 E1 I2 E2 I3 E3 I4 E4 I5 E5 RESULT -----------------------------------------------------------------------------------------MAHESH 1234 21 20 21 20 21 20 21 20 21 20 FAIL REJEESH 1235 21 22 21 22 21 22 21 22 21 22 FAIL VIJITH 1136 34 23 34 23 34 23 34 23 34 23 FAIL ABHILASH 1102 23 45 23 45 23 45 23 45 23 45 PASS ------------------------------------------------------------------------------------------

Department of Computer Applications

80

COBOL Programming

DATE : 06/02/2009 PGM NO : 29

SALARY STATMENT - SEQUENTIAL FILE


AIM : TO COMPUTE THE SALARY STATEMENT IN PROPER FORMAT WHICH CONTAINS NAME,BP,HRA,GP.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. SALSTMT. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMP1 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT EMP2 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD EMP1 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "E1" DATA RECORD IS EP1. 01 EP1. 02 NAM PIC X(25). 02 BP PIC 9(5). FD EMP2 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "E2" DATA RECORD IS EP2. 01 EP2 PIC X(70). WORKING-STORAGE SECTION. 01 L1. 02 FILLER PIC X(35) VALUE SPACE. 02 FILLER PIC X(16) VALUE " SALARY STATEMENT". 01 L2. 02 FILLER PIC X(51) VALUE ALL "*". 01 L3. 02 FILLER PIC X(3) VALUE SPACE. 02 FILLER PIC X(4) VALUE "SLNO". Department of Computer Applications 81

COBOL Programming 02 FILLER PIC X(5) VALUE SPACE. 02 FILLER PIC X(25) VALUE "NAME". 02 FILLER PIC X(10) VALUE "BASIC". 02 FILLER PIC X(8) VALUE "DA". 02 FILLER PIC X(8) VALUE "HRA". 02 FILLER PIC X(8) VALUE "GROSS". 01 DEP2. 02 DSNO PIC Z(3)9. 02 FILLER PIC X(3) VALUE SPACE. 02 ONAM PIC X(30). 02 OBP PIC Z(8). 02 ODA PIC Z(8). 02 OHRA PIC Z(8). 02 OGR PIC Z(8). 77 SNO PIC 9(4) VALUE 0. 77 DA PIC 9(5). 77 HRA PIC 9(5). 77 TOT PIC 9(5). PROCEDURE DIVISION. P-1. OPEN INPUT EMP1 OUTPUT EMP2. WRITE EP2 FROM L1. WRITE EP2 FROM L2. WRITE EP2 FROM L3. WRITE EP2 FROM L2. P-2. READ EMP1 AT END GO TO L-PARA. ADD 1 TO SNO. COMPUTE DA ROUNDED = .05 * BP. IF DA < 1000 MOVE 1000 TO DA. IF DA > 5000 MOVE 5000 TO DA. COMPUTE HRA ROUNDED = .02 * BP. COMPUTE TOT = BP + DA + HRA. MOVE SNO TO DSNO. MOVE NAM TO ONAM. MOVE BP TO OBP. MOVE DA TO ODA. MOVE HRA TO OHRA. MOVE TOT TO OGR. WRITE EP2 FROM DEP2. GO TO P-2. L-PARA. WRITE EP2 FROM L2. CLOSE EMP1 EMP2. Department of Computer Applications 82

COBOL Programming STOP RUN.

OUTPUT
MAHESH PRIYA LINU PRAVEEN 7500 10000 8500 5500

Department of Computer Applications

83

COBOL Programming

DATE : 11/02/2009 PGM NO : 30

STUDENT FILE PREPARATION


AIM : TO PREPARE A STUDENT FILE USING INPUT FILE CONTAIN NAME AND MARK.THE FORMATTED OUTPUT CONTAIN SERIAL NO,NAME AND MARK.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. ETSTFILE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT OP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "I" DATA RECORD IS S-REC. 01 S-REC. 02 NAME PIC X(15). 02 I-MARK PIC 9(4). FD OP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "O" DATA RECORD IS R-REC. 01 R-REC PIC X(40). WORKING-STORAGE SECTION. 77 SLNO PIC 9(3) VALUE 0. 01 L1 PIC X(40) VALUE ALL "-". 01 L2. 02 FILLER PIC X(2) VALUE SPACE. 02 FILLER PIC X(4) VALUE "SLNO". 02 FILLER PIC X(2) VALUE SPACE. 02 FILLER PIC X(4) VALUE "NAME". 02 FILLER PIC X(11) VALUE SPACE. Department of Computer Applications 84

COBOL Programming 02 FILLER PIC X(9) VALUE "INDEXMARK". 01 L3. 02 FILLER PIC X(2) VALUE SPACE. 02 D-SL PIC Z(3). 02 FILLER PIC X(2) VALUE SPACE. 02 D-NAME PIC X(15). 02 FILLER PIC X(5) VALUE SPACE. 02 D-MARK PIC Z(3)9. PROCEDURE DIVISION. P-1. OPEN INPUT IP OUTPUT OP. WRITE R-REC FROM L1. WRITE R-REC FROM L2. WRITE R-REC FROM L1. P-2. READ IP AT END GO TO P-3. ADD 1 TO SLNO. MOVE SLNO TO D-SL. MOVE NAME TO D-NAME. MOVE I-MARK T WRITE R-REC FROM L3. GO TO P-2. P-3. WRITE R-REC FROM L1. CLOSE IP OP. STOP RUN.

Department of Computer Applications

85

COBOL Programming

OUTPUT
INPUT FILE MAHESH 0622 LINU 0465 SHARU 0490 SHINCY 0465 OUTPUT FILE -----------------------------------------------SLNO NAME INDEXMARK -----------------------------------------------1 MAHESH 622 2 LINU 465 3 SHARU 490 4 SHINCY 465 -------------------------------------------------

Department of Computer Applications

86

COBOL Programming

DATE : 17/02/2009 PGM NO : 31

INDEXED FILE
AIM : TO CREATE AN INDEXED FILE FROM SEQUENTIAL FILE.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. INDEXE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT SEQF ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT ISAM ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS MODE IS SEQUENTIAL RECORD KEY IS I-NO. DATA DIVISION. FILE SECTION. FD ISAM LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "IND.DAT". 01 IREC. 02 I-NO PIC X(4). 02 I-NAM PIC X(10). 02 I-ADD PIC X(10). 02 I-AMT PIC 9(3). FD SEQF LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "SEQ.DAT". 01 SREC. 02 S-NO PIC X(4). 02 S-NAM PIC X(10). 02 S-ADD PIC X(10). 02 S-AMT PIC 9(3). PROCEDURE DIVISION. S1. OPEN INPUT SEQF OUTPUT ISAM. R-PARA. Department of Computer Applications 87

COBOL Programming DISPLAY "THE RECORDS ARE MOVING". READ SEQF AT END GO TO CC-PARA. MOVE S-NO TO I-NO. MOVE S-NAM TO I-NAM. MOVE S-ADD TO I-ADD. WRITE IREC INVALID KEY GO TO NOT-WRITTEN. DISPLAY "THE RECORDS ARE MOVED". GO TO R-PARA. CC-PARA. CLOSE SEQF ISAM. STOP RUN. NOT-WRITTEN. DISPLAY "RECORD NOT WRITTEN". GO TO R-PARA.

Department of Computer Applications

88

COBOL Programming

OUTPUT
INPUT FILE (SEQ.DAT) 1136 PRIJITH SHEELALAYM500 1132 ANUPAMA ANILVILA 750 OUTPUT FILE (IND.DAT) 1136PRIJITH SHEELALAYM 1132ANUPAMA ANILVILA

Department of Computer Applications

89

COBOL Programming

DATE : 20/02/2009 PGM NO : 32

BANK TRANSACTION USING INDEXED FILE


AIM : TO IMPLEMENT ALL BANKING TRANSACTIONS ON A SALES ACCOUNT OF A BANK.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. INDBANK. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ISAM ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS IACNO. DATA DIVISION. FILE SECTION. FD ISAM LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "SB1.DAT". 01 IREC. 02 IACNO PIC 9(5). 02 INAM PIC X(10). 02 IADD PIC X(15). 02 IAMT PIC 9(6)V99. WORKING-STORAGE SECTION. 77 C PIC A. 77 TR PIC A. 88 WITHDRAWAL VALUE "W". 88 DEPOSIT VALUE "D". 88 OPENING VALUE "O". 88 EXT VALUE "X". 88 CLOSING VALUE "C". 77 AMT PIC 9(6)V99. PROCEDURE DIVISION. P1. OPEN I-O ISAM. P2. DISPLAY "ENTER ANY TRANSACTION(D/W/O/C/X)". ACCEPT TR. Department of Computer Applications 90

COBOL Programming
IF DEPOSIT GO TO S1. IF WITHDRAWAL GO TO S2. IF OPENING GO TO S3. IF CLOSING GO TO S4. IF EXT GO TO S5. GO TO P2. S1. DISPLAY "ENTER THE ACCOUNT NUMBER". ACCEPT IACNO. DISPLAY "AMOUNT TO BE DEPOSITED". ACCEPT AMT. READ ISAM RECORD INVALID KEY GO TO N-FOUND. ADD AMT TO IAMT. REWRITE IREC INVALID KEY GO TO N-WRITE. GO TO P2.

S2. DISPLAY "ENTER THE ACCOUNT NUMBER". ACCEPT IACNO. DISPLAY "AMOUNT TO BE WITHDRAWN". ACCEPT AMT. READ ISAM RECORD INVALID KEY GO TO N-FOUND. IF IAMT > AMT SUBTRACT AMT FROM IAMT ELSE DISPLAY "WITHDRAWAL NOT POSSIBLE". REWRITE IREC INVALID KEY GO TO N-WRITE. GO TO P2.
S3. DISPLAY "ENTER A/C NO.,NAME,ADDRESS AND AMOUNT". ACCEPT IACNO ACCEPT INAM. ACCEPT IADD ACCEPT IAMT. WRITE IREC INVALID KEY GO TO N-WRITE. GO TO P2. S4. DISPLAY "ENTER THE ACCCOUNT NUMBER". ACCEPT IACNO. READ ISAM RECORD INVALID KEY GO TO N-FOUND. DELETE ISAM RECORD INVALID KEY GO TO N-WRITE. GO TO P2.

S5. CLOSE ISAM. STOP RUN. N-FOUND. DISPLAY "RECORD NOT FOUND " IACNO. GO TO P2. N-WRITE. DISPLAY "RECORD NOT WRITTEN". Department of Computer Applications 91

COBOL Programming GO TO P2.

OUTPUT
ENTER ANY TRANSACTION(D/W/O/C/X) O ENTER A/C NO.,NAME,ADDRESS AND AMOUNT 78960 DINIL CHITHRAM 500000 ENTER ANY TRANSACTION(D/W/O/C/X) O ENTER A/C NO.,NAME,ADDRESS AND AMOUNT 78692 DEEPU KAILASAM 95000 ENTER ANY TRANSACTION(D/W/O/C/X) W ENTER THE ACCOUNT NUMBER 78960 AMOUNT TO BE WITHDRAWN 4000 ENTER ANY TRANSACTION(D/W/O/C/X) X

Department of Computer Applications

92

COBOL Programming

DATE : 25/02/2009 PGM NO : 33

CUSTOMER DETAILS USING INDEXED FILE


AIM : TO DISPLAY THE NAME OF THE CUSTOMER ,IF THE TELEPHONE NUMBER IS GIVEN.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. INDTEL. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ISAM ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS I-TEL. DATA DIVISION. FILE SECTION. FD ISAM LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TELE1.DAT". 01 I-REC. 05 I-TEL PIC 9(10). 05 I-NAM PIC X(10). WORKING-STORAGE SECTION. 77 C PIC A. PROCEDURE DIVISION. P1. OPEN OUTPUT ISAM. P2. DISPLAY "ENTER THE TELPHONE NO AND NAME". ACCEPT I-TEL ACCEPT I-NAM. WRITE I-REC INVALID KEY GO TO N-WRITEN. DISPLAY "RECORD ADDED". GO TO L-PARA. L-PARA. DISPLAY "DO U WANT TO ENTER MORE RECORDS". ACCEPT C. Department of Computer Applications 93

COBOL Programming IF C="Y" OR ="y" DISPLAY (1 1) ERASE GO TO P2. CLOSE ISAM. STOP RUN. N-WRITEN. DISPLAY "RECORDS NOT WRITTEN TO THE FILE". GO TO L-PARA. OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. INDTEL. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ISAM ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS I-TEL. DATA DIVISION. FILE SECTION. FD ISAM LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "TELE1.DAT". 01 I-REC. 05 I-TEL PIC 9(10). 05 I-NAM PIC X(10). WORKING-STORAGE SECTION. 77 C PIC A. PROCEDURE DIVISION. P1. OPEN INPUT ISAM. P2. DISPLAY "ENTER THE TELEPHONE NO.". ACCEPT I-TEL. READ ISAM RECORD INVALID KEY GO TO N-FOUND. DISPLAY "THE CORRESPONDING NAME= " I-NAM. DISP-PARA. DISPLAY "DO U WISH TO CONTINUE(Y\N)". ACCEPT C. IF C="Y" OR ="y" DISPLAY(1 1) ERASE GO TO P2. CLOSE ISAM . STOP RUN. N-FOUND. DISPLAY "THE RECORD DOES NOT EXISTS". GO TO DISP-PARA. Department of Computer Applications 94

COBOL Programming

OUTPUT
INPUT FILE ENTER THE TELPHONE NO AND NAME 9447897676 MAHESH RECORD ADDED DO U WANT TO ENTER MORE RECORDS Y ENTER THE TELPHONE NO AND NAME 9745223247 KUMAR RECORD ADDED DO U WANT TO ENTER MORE RECORDS N OUT PUT FILE ENTER THE TELEPHONE NO. 9447897676 THE CORRESPONDING NAME= MAHESH DO U WISH TO CONTINUE(Y\N) N

Department of Computer Applications

95

COBOL Programming

DATE : 27/02/2009 PGM NO : 34

ENTRANCE EXAM USING SEQUENTIAL FILE


AIM : TO SORT A SEQUENTIAL FILE RELATING TO ENTRANCE EXAMINATION.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. SORTVB. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INFILE ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT OUTFILE ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT PROFILE ASSIGN TO DISK. DATA DIVISION. FILE SECTION. FD INFILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "STUD1.DAT" DATA RECORD IS INREC. 01 INREC PIC X(22). FD OUTFILE LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "RANK.LST" DATA RECORDS ARE OUTREC. 01 OUTREC PIC X(22). SD PROFILE 01 SREC. 02 S-NO PIC 9(3). 02 S-NAM PIC X(10). 02 S-TOT PIC 9(3). 02 S-MAT PIC 9(2). 02 S-PHY PIC 9(2). 02 S-CHE PIC 9(2). PROCEDURE DIVISION. S1. SORT PROFILE ON DESCENDING KEY S-TOT ON DESCENDING KEY S-MAT ON DESCENDING KEY S-PHY USING INFILE GIVING OUTFILE. Department of Computer Applications 96

COBOL Programming STOP RUN.

OUTPUT
INPUT FILE(STUD1.DAT) 100ANITHA 101VINITHA 103PRIYANKA 104VARNA 105RAMESH 522859378 465708975 555909585 365806555 520457889

OUT FILE AFTER SORTING 103 PRIYANKA 555909585 100 ANITHA 522859378 105RAMESH 520457889 101 VINITHA 465708975 104VARNA 365806555

Department of Computer Applications

97

COBOL Programming

DATE : 04/03/2009 PGM NO : 35

FILE MERGE
AIM : TO MERGE TWO FILES BASED ON MARK.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. MERGEVB. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INP1 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT INP2 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT OUP ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT TEMP ASSIGN TO DISK. DATA DIVISION. FILE SECTION. FD INP1 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "ST1" DATA RECORD IS SREC. 01 SREC PIC X(30). FD INP2 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "ST2" DATA RECORD IS INREC. 01 INREC PIC X(30). FD OUP LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "OUT" DATA RECORD IS OUTREC. 01 OUTREC PIC X(30). SD TEMP 01 TREC. 02 ADNO PIC 9(15). Department of Computer Applications 98

COBOL Programming 02 NAM PIC X(15). 02 MARK PIC 9(5). PROCEDURE DIVISION. S1. MERGE TEMP ON DESCENDING KEY MARK USING INP1 INP2 GIVING OUP. STOP RUN.

Department of Computer Applications

99

COBOL Programming

OUTPUT
INPUT FILE 1 15258KIRAN 15272MANOJ INPUT FILE 2 15246VINOD 360 522 465

AFTER MERGING OUT PUTFILE 15258KIRAN 15272MANOJ 15246 VINOD 522 465 360

Department of Computer Applications

100

COBOL Programming

DATE : 11/03/2009 PGM NO : 36

TICKET RESERVATION
AIM : TO CREATE RESERVATION FILE CONTAINING TICKET NO, SEAT NO,NAME,ROUTE AND CHECK WHETHER TICKETS ARE CONFIRMED OR NOT.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. LAB34. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT RES ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD RES LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "RESERVE" DATA RECORD IS RS. 01 RS. 02 TNO PIC Z(5). 02 SNO PIC Z(2). 02 NAM PIC X(10). 02 ROU PIC X(10). WORKING-STORAGE SECTION. 77 T PIC 9(5). 77 I PIC 9(2). 77 N PIC 9(2). 77 C PIC A. 77 S PIC 9. 77 J PIC 9(2). 77 SN PIC 9(2). 77 NM PIC X(10). 77 R PIC X(10). PROCEDURE DIVISION. P2. DISPLAY "*********MENU DRIVEN PROGRAMMING*********". Department of Computer Applications 101

COBOL Programming DISPLAY " ". DISPLAY "------------------------------------------". DISPLAY "1.RESERVATION". DISPLAY "2.TICKET CONFIRMATION". DISPLAY "3.DISPLAY". DISPLAY "ENTER YOUR CHOICE". ACCEPT S. GO TO P6 L-PARA P8 DEPENDING ON S. DISPLAY "WRONG CHOICE" GO TO P5. P6. OPEN I-O RES. DISPLAY "ENTER HOW MANY RECORDS". ACCEPT N. PERFORM P3 VARYING I FROM 1 BY 1 UNTIL I>N. GO TO P5. P3. DISPLAY "THE TCKTNO,STNO,NAM,ROUTE TO B " I " RESERVED". ACCEPT T ACCEPT SN ACCEPT NM ACCEPT R. PERFORM C-PARA . P7. MOVE T TO TNO. MOVE SN TO SNO. MOVE NM TO NAM. MOVE R TO ROU. WRITE RS. DISPLAY "THE TICKET IS BOOKED". CLOSE RES. GO TO P5. L-PARA. OPEN INPUT RES. DISPLAY "ENTER THE TICKET NO. TO BE CONFIRMED". ACCEPT T. PERFORM P4 . P4. READ RES AT END GO TO NF. IF TNO = T DISPLAY "THE TICKET NO: " T " IS CONFIRMED" GO TO P5. GO TO P4. NF. DISPLAY "THE TICKET NO: " T " IS NOT CONFIRMED". GO TO P5. P5. CLOSE RES. Department of Computer Applications 102

COBOL Programming DISPLAY "DO U WISH TO CONTINUE". ACCEPT C. IF C = "y" OR ="Y" DISPLAY (1 1) ERASE GO TO P2. STOP RUN. C-PARA. READ RES AT END GO TO P7. IF TNO = T DISPLAY "THE TICKET IS ALREADY BOOKED ". GO TO C-PARA. P8. OPEN INPUT RES. DISPLAY "TKTNO SEATNO NAME ROUTE ". DISPLAY "--------------------------------------------". GO TO P9. P9. READ RES AT END GO TO P5. DISPLAY TNO " " SNO " " NAM " " ROU . GO TO P9.

Department of Computer Applications

103

COBOL Programming

OUTPUT
*********RAILWAY TICKET RESERVATION*********

---------------------------------------------------------------------------1.RESERVATION 2.TICKET CONFIRMATION 3.DISPLAY ENTER YOUR CHOICE 1 ENTER HOW MANY RECORDS 1 THE TCKTNO,STNO,NAM,ROUTE TO B 01 RESERVED 105 45 MAHI TVM DO U WISH TO CONTINUE Y *********RAILWAY TICKET RESERVATION********* -----------------------------------------------------------------------------1.RESERVATION 2.TICKET CONFIRMATION 3.DISPLAY ENTER YOUR CHOICE 2 ENTER THE TICKET NO. TO BE CONFIRMED 101 THE TICKET NO: 00101 IS CONFIRMED DO U WISH TO CONTINUE Y *********RAILWAY TICKET RESERVATION********* ------------------------------------------------------------------------1.RESERVATION 2.TICKET CONFIRMATION 3.DISPLAY ENTER YOUR CHOICE 3 TKTNO SEATNO NAME ROUTE -------------------------------------------------------------------------00102 01 PRADEEP PANDALAM Department of Computer Applications 104

COBOL Programming 00101 03 PRIJIL PATHANAMTH 00104 05 REJEESH KOTTAYAM ------------------------------------------------------------------------------DO U WISH TO CONTINUE Y *********RAILWAY TICKET RESERVATION********* -----------------------------------------1.RESERVATION 2.TICKET CONFIRMATION 3.DISPLAY ENTER YOUR CHOICE 1 ENTER HOW MANY RECORDS 1 THE TCKTNO,STNO,NAM,ROUTE TO B 01 RESERVED 101 4 MAHESH BANGLORE THE TICKET IS ALREADY BOOKED DO U WISH TO CONTINUE N

Department of Computer Applications

105

COBOL Programming

DATE : 25/03/2009 PGM NO : 37

MENU DRIVEN-OPERATIOS ON FILE


AIM : MENU DRIVEN PROGRAM TO ADD,DELET, AND MODIFY RECORDS IN AN INDEXED FILE.

PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. INDEMP. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ISAM ASSIGN TO DISK ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS ENO. DATA DIVISION. FILE SECTION. FD ISAM LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "IEMP" DATA RECORDS ARE EMP. 01 EMP. 02 ENO PIC 9(5). 02 ENAM PIC X(15). 02 EBP PIC 9(4)V99. WORKING-STORAGE SECTION. 77 E PIC 9(5). 77 C PIC 9. 77 R PIC 9(5). 77 S PIC A. PROCEDURE DIVISION. P1. OPEN I-O ISAM. P2. DISPLAY(1 1) ERASE DISPLAY "*********** MENU DRIVEN PROGRAMMING**********". DISPLAY "--------------------------------------------". DISPLAY " ". DISPLAY "1.ADD". Department of Computer Applications 106

COBOL Programming DISPLAY "2.DELETE". DISPLAY "3.DISPLAY". DISPLAY "4.MODIFY". DISPLAY "5.EXIT". DISPLAY "--------------------------------------------". DISPLAY " ". DISPLAY "ENTER UR CHOICE(1\2\3\4\5)". ACCEPT C. GO TO C1 C2 C3 C4 C5 DEPENDING ON C. DISPLAY "ENTERED THE CHOICE WRONGLY". GO TO ASK-PARA. C1. DISPLAY "ENTER THE EMPLOYEE NO.,NAME & BASIC PAY". ACCEPT ENO ACCEPT ENAM ACCEPT EBP. WRITE EMP INVALID KEY GO TO NW. DISPLAY "RECORD IS ADDED". GO TO ASK-PARA. C2. DISPLAY "ENTER THE EMPLOYEE NUMBER TO BE DELETED". ACCEPT ENO. READ ISAM RECORD INVALID KEY GO TO NF. DELETE ISAM RECORD INVALID KEY GO TO ND. DISPLAY "RECORD DELETED". GO TO ASK-PARA. C4. DISPLAY "ENTER THE EMPLOYEE NO. TO BE MODIFIED". ACCEPT ENO. READ ISAM RECORD INVALID KEY GO TO NF. DISPLAY "NAME " ENAM. DISPLAY "AMOUNT " EBP. DISPLAY "ENTER THE NEW EMPLOYEE NAME & BASIC PAY". ACCEPT ENAM. ACCEPT EBP. REWRITE EMP INVALID KEY GO TO NW. DISPLAY "RECORD IS UPDATED". GO TO ASK-PARA. C3. DISPLAY "ENTER THE EMPLOYEE NO. TO BE SEARCHED". ACCEPT ENO. READ ISAM INVALID KEY GO TO NF. DISPLAY "NAME : " ENAM. Department of Computer Applications 107

COBOL Programming DISPLAY "BASIC PAY : " EBP. GO TO ASK-PARA. C5. GO TO ASK-PARA. NW. DISPLAY ENO " RECORD NOT WRITTEN". GO TO ASK-PARA. NF. DISPLAY ENO " RECORD NOT FOUND". GO TO ASK-PARA. ND. DISPLAY ENO " RECORD NOT DELETED". GO TO ASK-PARA. ASK-PARA. DISPLAY "DO U WISH TO CONTINUE(Y\N)". ACCEPT S. IF S="Y" OR ="y" GO TO P2. CLOSE ISAM. STOP RUN.

Department of Computer Applications

108

COBOL Programming

OUTPUT ***********MENU DRIVEN PROGRAMMING********** ----------------------------------------------------------------------------1.ADD 2.DELETE 3.DISPLAY 4.MODIFY 5.EXIT --------------------------------------------------------------------------------ENTER UR CHOICE(1\2\3\4\5) 1 ENTER THE EMPLOYEE NO.,NAME & BASIC PAY 109 MAHI 5250 RECORD IS ADDED DO U WISH TO CONTINUE(Y\N) Y ENTER UR CHOICE(1\2\3\4\5) 3 ENTER THE EMPLOYEE NO. TO BE SEARCHED 109 NAME : MAHI BASIC PAY : 5250 DO U WISH TO CONTINUE(Y\N) N

Department of Computer Applications

109

COBOL Programming

DATE : 26/03/2009 PGM NO : 38

MASTER FILE-TRANSACTION FILE


AIM : TO CREATE A RELATIVE FILE WITH SPNO AS THE KEY. USE THE DIVISION REMAINDER METHOD TO COMPUTE THE RELATIVE ADDRESS

PROGRAM MASTER FILE IDENTIFICATION DIVISION. PROGRAM-ID. MASTER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MAS ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS SPNO. DATA DIVISION. FILE SECTION. FD MAS LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "M" DATA RECORD IS MT. 01 MT. 02 SNO PIC 9(5). 02 SPNAM PIC X(15). 02 SPADD PIC X(15). 02 SAMT PIC 9(6)V99. WORKING-STORAGE SECTION. 77 SPNO PIC 9(5). 77 X PIC 9(5). 77 C PIC A. PROCEDURE DIVISION. P1. OPEN OUTPUT MAS. ACC-PARA. DISPLAY "ENTER NO:,NAME,ADDRESS & AMT ". ACCEPT SNO ACCEPT SPNAM ACCEPT SPADD ACCEPT SAMT. Department of Computer Applications 110

COBOL Programming DIVIDE SNO BY 888 GIVING X REMAINDER SPNO. WRITE MT INVALID KEY GO TO NW. DISPLAY "THE RECORD IS WRITTEN". GO TO DIS-PARA. NW. DISPLAY SNO " NOT WRITTEN". GO TO DIS-PARA. DIS-PARA. DISPLAY "DO U WISH TO CONTINUE(Y/N)". ACCEPT C. IF C = "Y" OR ="y" DISPLAY(1 1) ERASE GO TO ACC-PARA. CLOSE MAS. STOP RUN. TRANSACTION FILE IDENTIFICATION DIVISION. PROGRAM-ID. TRANS. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TRANS ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS SPNO. DATA DIVISION. FILE SECTION. FD TRANS LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "T" DATA RECORD IS TR. 01 TR. 02 SNO PIC 9(5). 02 TCOD PIC 9(5). 02 ODATA PIC X(25). WORKING-STORAGE SECTION. 77 SPNO PIC 9(5). 77 X PIC 9(5). 77 C PIC A. PROCEDURE DIVISION. P1. OPEN OUTPUT TRANS. ACC-PARA. DISPLAY "ENTER SPNO:,TRANSACTION CODE & OTHER INFO.". Department of Computer Applications 111

COBOL Programming ACCEPT SNO ACCEPT TCOD ACCEPT ODATA. DIVIDE SNO BY 888 GIVING X REMAINDER SPNO. WRITE TR INVALID KEY GO TO NW. DISPLAY "THE RECORD IS WRITTEN". GO TO DIS-PARA. NW. DISPLAY SNO " NOT WRITTEN". GO TO DIS-PARA. DIS-PARA. DISPLAY "DO U WISH TO CONTINUE(Y/N)". ACCEPT C. IF C = "Y" OR ="y" DISPLAY(1 1) ERASE GO TO ACC-PARA. CLOSE TRANS. STOP RUN. OUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. LABM36. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT MAS ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS SPNO SELECT TRANS ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS SPNO. DATA DIVISION. FILE SECTION. FD MAS LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "M" DATA RECORD IS MT. 01 MT. 02 SNO PIC 9(5). 02 SPNAM PIC X(15). 02 SPADD PIC X(15). 02 SAMT PIC 9(6)V99. FD TRANS LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "T" DATA RECORD IS TR. Department of Computer Applications 112

COBOL Programming 01 TR. 02 SNO PIC 9(5). 02 TCOD PIC 9(5). 02 ODATA PIC X(25). WORKING-STORAGE SECTION. 77 SPNO PIC 9(5). 77 N PIC 9(5). 77 X PIC 9(5). 77 C PIC A. 77 S PIC 9. PROCEDURE DIVISION. P1. OPEN I-O MAS TRANS. P2. DISPLAY "**********MENU DRIVEN PROGRAMMING**********". DISPLAY " ". DISPLAY " ". DISPLAY " 1.CHANGE ADDRESS.". DISPLAY " ". DISPLAY " 2.CHANGE TRANSACTION CODE". DISPLAY " ". DISPLAY " 3.DELETE RECORD". DISPLAY " ". DISPLAY " ". DISPLAY "ENTER YOUR CHOICE (1\2\3\4)". ACCEPT S. GO TO P3 P4 P5 DEPENDING ON S. DISPLAY "ENTERED WRONG CHOICE ". GO TO ASK-PARA. P3. DISPLAY "ENTER THE SPNO: OF ADDRESS TO B MODIFIED". ACCEPT N. DIVIDE N BY 888 GIVING X REMAINDER SPNO. READ MAS RECORD INVALID KEY GO TO NF. DISPLAY "ENTER THE NEW ADDRESS ". ACCEPT SPADD. REWRITE MT INVALID KEY GO TO NRW. DISPLAY "THE RECORD IS MODIFIED". GO TO ASK-PARA. P4. DISPLAY "ENTER THE SPNO: OF THE TRNCODE TO B MODIFIED". ACCEPT N. DIVIDE N BY 888 GIVING X REMAINDER SPNO. READ TRANS RECORD INVALID KEY GO TO NF. 113

Department of Computer Applications

COBOL Programming DISPLAY "ENTER THE NEW TRANSACTION CODE". ACCEPT TCOD. REWRITE TR INVALID KEY GO TO NRW. DISPLAY "THE RECORD IS MODIFIED". GO TO ASK-PARA. P5. DISPLAY "ENTER THE SPNO:OF THE RECORD TO B DELETED". ACCEPT N. DIVIDE N BY 888 GIVING X REMAINDER SPNO. READ MAS RECORD INVALID KEY GO TO NF. DELETE MAS RECORD INVALID KEY GO TO ND. DISPLAY "THE RECORD IS DELETED" DISPLAY "THE RECORD IS DELETED FROM THE MASTER FILE". READ TRANS RECORD INVALID KEY GO TO NF. DELETE TRANS RECORD INVALID KEY GO TO ND. DISPLAY "THE RECORD IS DELETED" DISPLAY "THE RECORD IS DELETED FROM THE TRANSACTION FILE". GO TO ASK-PARA. NF. DISPLAY "THE RECORD " N " NOT FOUND". GO TO ASK-PARA. NRW. DISPLAY "THE RECORD " N " NOT MODIFIED". GO TO ASK-PARA. ND. DISPLAY "THE RECORD " N " IS NOT DELETED" GO TO ASK-PARA. ASK-PARA. DISPLAY "DO U WISH TO CONTINUE(Y/N)". ACCEPT C. IF C="Y" OR ="y" DISPLAY(1 1) ERASE GO TO P2. CLOSE MAS TRANS. STOP RUN.

Department of Computer Applications

114

COBOL Programming

OUTPUT
MASTER FILE ENTER NO:,NAME,ADDRESS & AMT 125 MAHESH M C SADANAM 15000 THE RECORD IS WRITTEN DO U WISH TO CONTINUE(Y/N) Y ENTER NO:,NAME,ADDRESS & AMT 154 NIMMI SUKRITHAM 25000 THE RECORD IS WRITTEN DO U WISH TO CONTINUE(Y/N) N TRANSACTION FILE ENTER SPNO:,TRANSACTION CODE &OTHER INFO. 125 256 SALE THE RECORD IS WRITTEN DO U WISH TO CONTINUE(Y/N) N OUT FILE **********MENU DRIVEN PROGRAMMING********** 1.CHANGE ADDRESS. 2.CHANGE TRANSACTION CODE 3.DELETE RECORD ENTER YOUR CHOICE (1\2\3\4) 1 ENTER THE SPNO: OF ADDRESS TO B MODIFIED Department of Computer Applications 115

COBOL Programming 154 ENTER THE NEW ADDRESS CHITHRAM THE RECORD IS MODIFIED DO U WISH TO CONTINUE(Y/N) Y **********MENU DRIVEN PROGRAMMING********** 1.CHANGE ADDRESS. 2.CHANGE TRANSACTION CODE 3.DELETE RECORD ENTER YOUR CHOICE (1\2\3\4) 3 ENTER THE SPNO:OF THE RECORD TO B DELETED 125 THE RECORD IS DELETED THE RECORD IS DELETED FROM THE MASTER FILE THE RECORD IS DELETED THE RECORD IS DELETED FROM THE TRANSACTION FILE DO U WISH TO CONTINUE(Y/N) N OUT FILE 00154NIMMI CHITHRAM 02500000

Department of Computer Applications

116

COBOL Programming

DATE : 27/03/2009 PGM NO : 39

PAYROLL USING RELATIVE FILE


AIM : TO PREPARE PAYROLL USING REALTIVE FILE.

PROGRAM INPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. RELSALIP. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IPSAL ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS RELNO. DATA DIVISION. FILE SECTION. FD IPSAL LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "RSALIP" DATA RECORDS ARE SAL. 01 SAL. 02 ENO PIC 9(5). 02 ENAM PIC X(20). 02 EBP PIC 9(5)V99. WORKING-STORAGE SECTION. 77 N PIC 99. 77 RELNO PIC 9(5) VALUE IS 0. PROCEDURE DIVISION. P1. OPEN OUTPUT IPSAL. P2. DISPLAY "HOW MANY RECORDS TO ENTER". ACCEPT N. PERFORM P3 N TIMES. DISPLAY N " RECORDS ENTERED". GO TO P4. P3. DISPLAY "ENTER THE EMPLOYEE NO.,NAME & BASIC PAY". Department of Computer Applications 117

COBOL Programming ACCEPT ENO ACCEPT ENAM ACCEPT EBP. ADD 1 TO RELNO. WRITE SAL INVALID KEY GO TO NOT-WRITTEN. NOT-WRITTEN. DISPLAY ENO " RECORD NOT WRITTEN". P4. CLOSE IPSAL. STOP RUN. OUTPUT FILE IDENTIFICATION DIVISION. PROGRAM-ID. RELSAL. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IPSAL ASSIGN TO DISK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS RELNO SELECT OPSAL ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD IPSAL LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "RSALIP" DATA RECORDS ARE SAL. 01 SAL. 02 ENO PIC 9(5). 02 ENAM PIC X(20). 02 EBP PIC 9(5)V99. FD OPSAL LABEL RECORDS ARE STANDARD VALUE OF FILE-ID IS "RSALOP" DATA RECORDS ARE SAL2. 01 SAL2 PIC X(75). WORKING-STORAGE SECTION. 01 L1 PIC X(75) VALUE ALL "-". 01 L2. 02 FILLER PIC X(20) VALUE ALL SPACE. 02 FILLER PIC X(75) VALUE "RELATIVE FILE PROGRAM". 01 L3. 02 FILLER PIC X(7) VALUE " NUMBER". 02 FILLER PIC X(15) VALUE " NAME". 02 FILLER PIC X(7) VALUE " BASIC". 02 FILLER PIC X(6) VALUE " DA". 02 FILLER PIC X(6) VALUE " HRA". Department of Computer Applications 118

COBOL Programming 02 FILLER PIC X(6) VALUE " PF". 02 FILLER PIC X(6) VALUE " LOAN". 02 FILLER PIC X(7) VALUE " NET". 77 RELNO PIC 9(5) VALUE IS 0. 77 L PIC 9(6)V99. 77 DA PIC 9(4)V99. 77 HRA PIC 9(4)V99. 77 PF1 PIC 9(4)V99. 01 SAL1. 02 OENO PIC 9(5). 02 FILLER PIC X(2) VALUE SPACE. 02 OENAM PIC X(20). 02 FILLER PIC X(2) VALUE SPACE. 02 OEBP PIC 9(5).99. 02 FILLER PIC X(2) VALUE SPACE. 02 ODA PIC 9(4).99. 02 FILLER PIC X(2) VALUE SPACE. 02 OHRA PIC 9(4).99. 02 FILLER PIC X(2) VALUE SPACE. 02 OPF PIC 9(4).99. 02 FILLER PIC X(2) VALUE SPACE. 02 LN PIC 9(4).99. 02 FILLER PIC X(2) VALUE SPACE. 02 NP PIC 9(6).99. PROCEDURE DIVISION. P1. OPEN INPUT IPSAL OUTPUT OPSAL. WRITE SAL2 FROM L1. WRITE SAL2 FROM L2. WRITE SAL2 FROM L1. WRITE SAL2 FROM L3. WRITE SAL2 FROM L1. P2. ADD 1 TO RELNO. READ IPSAL RECORD INVALID KEY GO TO P3. COMPUTE DA = 0.25 * EBP. COMPUTE HRA = 0.20 * EBP. COMPUTE PF1 = 0.1 * EBP. MOVE EBP TO OEBP. DISPLAY "ENTER THE LOAN AMOUNT ". ACCEPT L. IF L < EBP DISPLAY "LOAN GRANTED" COMPUTE NP = (EBP + DA + HRA ) - (PF1 + L ) ELSE Department of Computer Applications 119

COBOL Programming DISPLAY "LOAN REJECTED BCOZ OF INSUFFICIENT BALANCE" COMPUTE NP = (EBP + DA + HRA ) - PF1 MOVE 0 TO L. MOVE ENO TO OENO. MOVE ENAM TO OENAM. MOVE L TO LN. MOVE DA TO ODA . MOVE HRA TO OHRA. MOVE PF1 TO OPF. WRITE SAL2 FROM SAL1. GO TO P2. P3. WRITE SAL2 FROM L1. CLOSE IPSAL OPSAL. STOP RUN.

Department of Computer Applications

120

COBOL Programming

OUTPUT
INPUT FILE(RSALIP) HOW MANY RECORDS TO ENTER 2 ENTER THE EMPLOYEE NO.,NAME & BASIC PAY 145 MAHESH 8500 ENTER THE EMPLOYEE NO.,NAME & BASIC PAY 135 GAYATHRI 15000 02 RECORDS ENTERED TYPE RSALIP 00145MAHESH 00135GAYATHRI OUT PUT FILE ENTER THE LOAN AMOUNT 5000 LOAN GRANTED ENTER THE LOAN AMOUNT 500 LOAN GRANTED TYPE RSALOP --------------------------------------------------------------------------------------------------RELATIVE FILE PROGRAM --------------------------------------------------------------------------------------------------NUMBER NAME BASIC DA HRA PF LOAN NET --------------------------------------------------------------------------------------------------00145 MAHESH 08500.00 2125.00 1700.00 0850.00 5000.00 00135 GAYATHRI 15000.00 3750.00 3000.00 1500.00 0500.00 --------------------------------------------------------------------------------------------------0850000 1500000

Department of Computer Applications

121

COBOL Programming

DATE : 30/03/2009 PGM NO : 40

ILLUSTRATION OF SUBPROGRAMMING
AIM : MENU DRIVEN PROGRAM TO ADD,DELET, AND MODIFY RECORDS IN AN INDEXED FILE.

PROGRAM MAIN PROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. EMPSAL. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMP1 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL SELECT EMP2 ASSIGN TO DISK ORGANIZATION IS LINE SEQUENTIAL DATA DIVISION. FILE SECTION. FD EMP1 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "EM1" DATA RECORD IS EREC1. 01 EREC1. 02 ECODE PIC 9(2). 02 ENAM PIC X(5). 02 EBP PIC 9(5). FD EMP2 LABEL RECORDS ARE STANDARD VALUE OF FILE-ID "EM2" DATA RECORD IS EREC2. 01 EREC2. 02 OECODE PIC 9(2). 02 OENAM PIC X(5). 02 OEBP PIC Z(5). 02 OHRA PIC Z(4). 02 ODA PIC Z(4). 02 OGP PIC Z(7). WORKING-STORAGE SECTION. 77 DA PIC 9(4). 77 HRA PIC 9(4). 77 GP PIC 9(7). Department of Computer Applications 122

COBOL Programming PROCEDURE DIVISION. P1. OPEN INPUT EMP1 OUTPUT EMP2 P2. READ EMP1 AT END GO TO L-PARA. CALL "DAPGM1" USING EBP DA. CALL "HRAPGM1" USING EBP HRA. COMPUTE GP = EBP + DA + HRA. MOVE ECODE TO OECODE. MOVE ENAM TO OENAM. MOVE EBP TO OEBP. MOVE DA TO ODA. MOVE HRA TO OHRA. MOVE GP TO OGP. WRITE EREC2. GO TO P2. L-PARA. CLOSE EMP1 EMP2. STOP RUN. SUBPROGRAM 1 IDENTIFICATION DIVISION. PROGRAM-ID. DAPGM. ENVIRONMENT DIVISION. DATA DIVISION. LINKAGE SECTION. 77 D PIC 9(4). 77 B PIC 9(5). PROCEDURE DIVISION USING B D. P1. OMPUTE D ROUNDED = .65 * B. IF D < 1000 MOVE 1000 TO D. IF D > 5000 MOVE 5000 TO D. P2. EXIT PROGRAM. SUBPROGRAM 2 IDENTIFICATION DIVISION. PROGRAM-ID. HRAPGM. ENVIRONMENT DIVISION. DATA DIVISION. LINKAGE SECTION. 77 H PIC 9(4). Department of Computer Applications 123

COBOL Programming 77 B PIC 9(5). PROCEDURE DIVISION USING B H. P1. COMPUTE H ROUNDED = .15 * B. IF H > 1500 MOVE 1500 TO H. IF H < 500 MOVE 500 TO H. P2. EXIT PROGRAM.

Department of Computer Applications

124

COBOL Programming

OUTPUT
INPUT FILE
TYPE EM1

15SURESH66000 12SACHU70000 56KUMAR35000 10MOHAN30000 OUTPUT FILE


TYPE EM2

15SURESH6600015002900 12SACHU70000 5005000 56KUMAR3500015002750 10MOHAN3000015005000

70400 75500 39250 36500

Department of Computer Applications

125