Tuesday, May 19, 2009

Program in cobol : index sequential file from input records

What is index sequential file in Cobol? Suggest applications where indexed sequential file will be good use.
Create an Index sequential file from the following input records (Write a program and make suitable assumptions if needed).


INPUT FILE
FILE NAME: BOOK-DETAILS
ORGANIZATION: SEQUENTIAL
FILE FORMAT:
1-10 ISBN NUMBER OF THE BOOK
11-20 ACCESSION NUMBER
21-50 BOOK NAME
51-70 AUTHOR NAME
71-72 STATUS (AVAILABLE, ISSUED, GONE FOR BINDING, LONE , LOST ETC IN CODE OF TWO DIGITS)
73-80 NOT USED

The created Index file should be used in generating the following reports:
1) The number of total copies of all the books in the library.
2) The display of status of various books on searching through name of author
Write a program for generation of above reports.








Answer:

Indexed sequential file

In business data processing, files and records play the most important role. In indexed sequential file is one in which records are written only sequentially and in ascending order of the key. The file can be accessed sequentially and randomly.

Features of indexed sequential file

1. An indexed sequential file is always created on a direct access device such as disk.
2. Records can be only written only sequentially and in ascending order of the key.
3. When indexed file is accessed randomly the sequence in which the records are accessed is controlled by the individual by specifying the value of a data-item called record key.


So indexed sequential file will be of good use where ...

1. Direct access devices are used because file on such devices can be accessed sequentially and randomly.
2. Where data entry done sequentially in ascending order of the key.
3. there is need to access data sequentially as well as randomly.
4. there is need to access data Dynamically . The option dynamic implies that the records may be accessed sequentially or randomly in the same program.





Program Code:

IDENTIFICATION DIVISION
PROGRAM-ID BOOKS
ENVIRONMENT DIVISION
INPUT-OUTPUT SECTION
FILE-CONTROL
SELECT BOOKS-DETAILS ASSIGN TO OSR
ACCESS MODE IS INDEXED
RECORDING MODE IS ASCII

DATA DIVISION
FD BOOKS-DETAILS
VALUE OF IO IS “BOOKS.DAT”
DATA RECORD IS BK-RECORD
01 BK-RECORD USAGE DISPLAY-7
02 ISBN PIC 9(10)
03 ACNO PIC 9(10)
04 BNAME PIC X(30)
05 ANAME PIC X(20)
06 STATUS PIC XX
07 FILE PIC X(7)
WORKING-STORAGE SECTION
01 WS-BOOKS
02 WISBN PIC 9(10)
03 WANO PIC 9(10)
04 WBNAME PIC X(30)
05 WANAME PIC X(20)
06 WSTATUS PIC XX
07 MORENEED PIC Y
PROCEDURE DIVISION
BEGIN-WORK
OPEN OUTPUT BOOKS-DETAILS
READING DATA
DISPLAY “ENTER ISBN NUMBER”
ACCEPT WISBN
MOVE WISBN TO ISBN
DISPLAY “ENTER ACCESSARY NUMBER”
ACCEPT WANO
MOVE WANO TO ACNO
DISPLAY “ENTER BOOKS NAME”
ACCEPT WBNAME
MOVE WBNAME TO BNAME
DISPLAY “ENTER AUTHOR NAME”
ACCEPT WANAME
MOVE WANAME TO ANAME
DISPLAY STATUS
ACCEPT WSTATUS
MOVE WSTATUS TO STATUS
WRITE BK-RECORD

DISPLAY “ANY MORE (Y/N)”
ACCEPT MORENEED
IF MORENEED IS EQUAL TO “Y” THEN
GOTO READING DATA
ELSE
GOTO ENDING-SEG
ENDING-SEG
CLOSE BOOKS-DETAILS
STOP RUN

REPORT 1
FD-OUTFILE
VALUE OF FILE-ID “OUT.DAT”
01 OUT-REC
02 OZ OBNAME
03 OZ TOT

PROCEDURE DIVISION
MAIN-RTN
PERFORM OPEN-PARA
PROCESS-PARA
PERFORM COMPUTE PARA UNITS
EOF = 1
MOVE BNAME TO OBNAME
MOVE TOTC TOT
WRITS OUT-REC
DISPLAY OUT-REC
DISPLAY “PRESS ENTER TO CONTINUE”
COMPUTE PARA ACCEPT FLAG
MOVE 0 TO EOF
IF BNAME = OBNAME THEN
COMPUTE TOTC = TOTC + 1
ELSE
READ BOOK-DETAILS, OUTPUT OUTFILE
READ BOOK-DETAILS AT END MOVE 1 TO EOR
CLOSE PARA
CLOSE SALES OUTFILE

REPORT 2
PROCEDURE DIVISION
MAIN-WORK
OPEN INPUT BOOKS-DETAILS
MOVE 0 TO CHECK
DISPLAY “SEARCH BY AUTHOR OR NAME”
ACCEPT SEARCH KEY
DISPLAY “ENTER NAME TO SEARCH”
ACCEPT SEARCH NAME
SEARCH WORK
READ BOOKS-DETAILS AT END
MOVE TO CLOSE-WORK
IF SALARY KEY IS EQUAL TO “AUTHOR” THEN
MOVE NAME TO WNAME
IF WNAME = SEARCH NAME THEN
MOVE 1 TO CHECK
GO TO CLOSE-WORK
ELSE
MOVE BNAME TO WBNAME
IF WNAME = SEARCH NAME THEN
MOVE 1 TO CHECK
GOTO CLOSE-WORK
GOTO SEARCH-WORK
CLOSE-WORK
IF CHECK = 0 THEN
DISPLAY “NOT FOUND”
ELSE
DISPLAY ISBN
DISPLAY BNAME
DISPLAY ANAME
CLOSE BOOKS-DETAILS
STOP RUN

No comments:

Post a Comment

Post a Comment