Qur'an – Bible.

* Religion * Politics * News Networks * Mainstream Media Biased Reporting * Independent Analysis

Sample COBOL Program – Indexed File Creation.

Posted by QB on November 21, 2007

000010***********************************************************************
000020 IDENTIFICATION DIVISION.
000030 PROGRAM-ID. PRFOURA.
000040 AUTHOR. QB.
000050 DATE-WRITTEN. 10/19/2007.
000060 DATE-COMPILED.
000070
000080 ENVIRONMENT DIVISION.
000090 CONFIGURATION SECTION.
000100 SOURCE-COMPUTER. PC.
000110 OBJECT-COMPUTER. PC.
000120 INPUT-OUTPUT SECTION.
000130 FILE-CONTROL.
000140 SELECT ACCOUNT-FILE ASSIGN TO “A:\ACCOUNT.DAT”
000150 ORGANIZATION IS SEQUENTIAL.
000160
000170
000180 SELECT ACCOUNT-INDEXED-FILE ASSIGN TO “A:\ACCOUNTIDX.DAT”
000190 ORGANIZATION IS INDEXED
000200 ACCESS MODE IS DYNAMIC
000210 RECORD KEY IS ACCT-NO.
000220
000230 DATA DIVISION.
000240 FILE SECTION.
000250 FD ACCOUNT-FILE.
000260 01 ACCOUNT-RECORD.
000270 02 ACCOUNT-NO PIC X(7).
000280 02 ACCOUNT-NAME PIC X(15).
000290 02 ACCOUNT-BAL PIC S9(4)V99.
000300 02 TOTAL-DEPOSIT PIC S9(4)V99.
000310
000320 FD ACCOUNT-INDEXED-FILE.
000330 01 ACCOUNT-INDEXED-RECORD.
000340 02 ACCT-NO PIC X(7).
000350 02 ACCT-NAME PIC X(15).
000360 02 ACCT-BAL PIC S9(4)V99.
000370 02 TOT-DEPOSIT PIC S9(4)V99.
000380
000390 WORKING-STORAGE SECTION.
000400 77 EOF PIC X(3) VALUE “NO “.
000410
000420 PROCEDURE DIVISION.
000430 MAIN-PARAGRAPH.
000440 OPEN INPUT ACCOUNT-FILE.
000450 OPEN I-O ACCOUNT-INDEXED-FILE.
000460
000470 PERFORM READ-ROUTINE UNTIL EOF = “YES”.
000480 CLOSE ACCOUNT-FILE
000490 ACCOUNT-INDEXED-FILE.
000500 STOP RUN.
000510
000520 READ-ROUTINE.
000530 READ ACCOUNT-FILE AT END
000540 MOVE “YES” TO EOF.
000550 IF EOF NOT = “YES”
000560 PERFORM WRITE-RECORD.
000570
000580
000590 WRITE-RECORD.
000600 READ ACCOUNT-INDEXED-FILE INVALID KEY
000610 MOVE ACCOUNT-NO TO ACCT-NO
000620 MOVE ACCOUNT-NAME TO ACCT-NAME
000630 MOVE ACCOUNT-BAL TO ACCT-BAL
000640 MOVE TOTAL-DEPOSIT TO TOT-DEPOSIT
000650 WRITE ACCOUNT-INDEXED-RECORD INVALID KEY
000660 DISPLAY “Error occured writing indexed file”.
000670

The following is the input file ACCOUNT.DAT.

1000001W Sloan        120050000000
1001000R Gillespie    037523030254
2000312J McMordie     173281100012
3167592D Hughes       293553002481
3234577A Thompson     100000100000

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: