############################################################################## ###!
C###jfffffffffffffffffffffffffffffffffffffffffffffffffffff"###pyr```�� � � � � � �f f f f f f f f f f f f f f f f f f f f f f f f f f ```ld
� � � � � � � � � � � � � � � � � � � �
###����####�����������������������������������������������������������������������
Gallery#####MS_ClipArt_Gallery#####MS_ClipArt_Gallery# 9 q############� � ��#ࡱ# #######� #############��#ࡱ# ################>###� �� #############R#o#o#t#
#E#n#t#r#y###������������������������������������������####��������############### #########��������##�� �< ##### ###� ����O#b#j#e#c#t#1###������������������������������
#######&####### ######F####` q < #` q < #� � � � � � � ������������##O#l#e###������������������� ffffffffo��oo���� ��o oo��offffffffffffffffff
######bf` f f f f f f f f f f� � � � � � � � � � ������� ������� � � � � � � � �o f f f f f f f f f```g######jfffffffffff ffffffo��fofff o f offffffffffffffffffffff"######fbf� � � �� � � � � � � � � � � � � � �f f f f f f f f f f f f f f f f f f f f f f f f f f ```d######hfffffffffffffffffffffffffffffffffffffffffffffffff � � � � � � � � � � � �
ffff
######`fb f f f f f f f f f f f f� � � � � � � � � � � � �� � � � � � � � � � � � � �f f f f f f f f f f f f f f```d######jffffffffff ffffffffff���oo����offfffffffffffffffffff ##
###fff�� � � � � � � � � � �� ������� � � � � � � � � � �f f f f f f f f f f o f f f f f f f f f f ```h######hfffffffffffffff fffff��fffffff��ffffffffffffffffffffff
#(#bff f f f f f f f� � � � � � � ���������� � ��� ���� � � � � � � �o f f o f f f f f f f```f######jfffffffffffoo of� ofo f o o ffffffffffff
� �������� � ��� ��
######fff�� � � � � � ��� � � � � � � � � �� � � � � � � � � �f f f f f f f f o f f f f f f f f f f f f f f f ```d###f#&hffffffffff ffffffffffffffffffffffffff ffffffffffffffff �
######fff f f f f f f f f f f f f f f f f f f f f f f f f f f f````� � � � � � � � � � � � � � � � � � � � � � � � � � � ���#&#jfffffffff fffffffff���ooof�� ������o ffffffffffffffffff"##
#`#fff�� � � � � � � � � � ����� ������ � � � � � � � � �f f f f f f f f f o f f f f f f f f f f ```h###&#fhfffffffffffffff fff�� �f ffofo o� ��ffffffffffffffffffffff
######fff f f f f f f f f f f f f f f f f f f f f f f f f f f f````####&#jfffffffff� � � � � � � � � � � � � � � � � � � � � � � � � � � f f f f f f f f f ```l#_=f&fhffffffffffffffffffff ffffffffffffffffffffffffffffffff
� � � � � � � � � � �
####
fff f f f f f f f f f f f f f f f f f f f f f f f f f f f```o � � � � � � � � � � � � � � � � � � � � � � � � � � � � �
&f&jffffffffffffffffffff o f o oooffffffffffffffffffff ####
# ff� �� � � � � � � � � � ����� ��� � � � � � � � � � � �f f f f f f f f f f f o f f f f f f f f f f ```gC##fffhffffffffffffffff ffffoofffffo��fffffffffffffffffffffff
#_=ff��� � � � � � � � � � � � � � � � � � � � � � � � � � �f f f f f f f f f f f f f f f f f f f f f f f f f f ````#��fffhffffffffffff ffffffffo fffffffffffffffffffffffffffffff �
#fffjffffffffffffffffffoo������� ���o fffffffffffffffffff ####8# f f f f f f f ffffffffffffffffffbfff`f`f`b`b```````````` �������������������� � � � � � � � �
#########AG����� ��############ ## # 2# A� � � ��� �0 ## ############ #### 2##`# � � � P#`#p############# ##d
(##a# ###
� �
############# ##D# = ### ##### #####3## ##Z # # #� � � � � � � � � ��
###��#####�� ��# d#########d#2#######r### Copyright 1997 John Wiley & Sons, Inc. � � All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express written permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or
#r#########r#####
###########r#########r##### #��d#########d#2#######r## ##�
#################$##########################�� ��# d######3##d#########2## ##� �� �M F#�� #### ####T # K######0##d#########Z### Eighth edition Nancy Stern
� �� � ��
#Z#########################################>###############################A####### ########b###############1############### #################Z#############T#
###K######0##d#######R###T# ###K######0##d#######Z###T# ###K######0##d####### ###T#� ###K######0##d############################################## A��� �p 0#�
############ ## # CA###` p # ############ ######################2## ##� � � � � � � � #s
####################### #############��############, ######## # 2########� �
#########AGp #� � �############ ## #_M################r## ##� � � �� �- V
,### ##### # d#########d#########9###CHAPTER 15##Indexed and Relative
��� �� �� ��
#
#########
#####,########### #########
####�� ��# d#########d#########2## ##� ���M s#��####��####U �
# ######### ################# #############U# ###K#########d#######&###U# � � �
###K#########d#######$###U# ###K#########d#######9###U# ###K#########d#######5###U# ###K#########d#######.###U#
#########AGg S� � # ############ ## # 2# A� � � � ����
############# ##T#'>#### ###########r## ## p M
� � � � �� �
#################,##########################�� ��# d#########d#########2## ##� ���} # #### ####U l# K#########d#########X###Systems Considerations for
� �� �� � ��
#X#########################Q#################X#####
#################,##########################�� ��# d#########d#########2## ##� �� �= } ##��####��####U l#� ��K#########d#########b###Processing Indexed Disk Files (continued)Accessing or Reading from an Indexed File for Reporting PurposesThe FILE STATUS ClauseProcessing Relative Disk FilesWhat is a Relative File?Creating
#b#########*###############X############### #################b#####�
###*###U#l###K#########d#######A###U#l###K#########d###########U#l###K#########d### ########U#l###K#########d###########U#l###K#########d###########U#l###K#########d## #####%###U#l###K#########d#######!
###U#l###K#########d#######"###U#l###K#########d#######(###U#l###K#########d####### %###"#############################$### # 2!� �
#########AG�� �S # ############ ## #/######### #######r## ##� � � � � �� �p }
#0#########0#####,###########0#########0####�� ��# d#########d#######,###)########### #R####ive Fi*###+### # 2(###-############### ################# ####
#########AGg #� � ��############ ##4#_=# A g p� � � � ############# ## #_=#### ###########r## ## 0 M
� � � � � �� �
,### ##### # d#########d#############Sequential File Organization
#################,##########################�� ��# d#########d#########2## ##� ���M s#��####��####U l#� ��K#########d#########W###The simplest type of disk file organization is sequential. Sequential files are processed in the same way
regardless of the type if magnetic media on wehich they are stored. Typically, the records to be stored in a sequential file are first sorted into sequence by a key field such as customer number, part number, or employee number. It is then
#########AGg #� � ��############ ##L�
_=# A g p� � ��############# ## #_=#### ###########r## ##� � � � �� �0 M
,### ##### # d#########d#############Indexed File Organization
# ######### ################# ######### ###U#l###K#########d#######|� � � � ###U#l###K#########d#######?
###U#l###K#########d#######l###U#l###K#########d####### ###U#l###K#########d#######� :###7################### ### #8###9#####_=6###;############### #################� � � ���
#########AGg S� � # ############ ##,#gC# A g� � � ��� ############## ## #_=#### ###########r## ##� � � � �� �p M
#################,##########################�� ��# d#########d#########2## ##� ���M # #### ####U l# K#########d#########a###Relative files also permit random
� �� �� � ��
#########AGg #� � ��############ ## # 2# A g p� � � � � � �############# ##d#?�
###2## ##� ���M s#��####��####U l#� ��K#########d######### ###Magnetic disk is a �
#########AG7��W s ############ ## #/## A 7� � � � ���W ############## ##� � i#### ###########r## ##q #
� � � ��� V��####��####U �
#n#########n#################n#############U# ###K#########d###########U# ###K#########d#######J###U#
#########AGg #� � ��############ ## #?e################r## ##� � � �� �@ M
$### ##### # d#########d#############Processing Indexed Disk Fileso
#################,##########################�� ��# d#########d#######V###S########### ############T###U###4#?4R###W############### ################# ####
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ## # 2#### ###########r## ## 0 M
� � � � � � �� �
,### ##### # d#########d#############Creating an Indexed File
#################,##########################�� ��# d#########d#########2## ##� ���M s#��####��####U l#� ��K#########d#########*###Indexed files are created in
#*#########*#################*######### ###U#l###K#########d#######R###U#l###K#####� ####d#######]###Z#########################[###\### #?4Y###^###############�
#########AGg #� � ��############ ## # 2# A g � � � � � �� @############# ## #gC#### ###########r## ##� � � � �� �0 M
#### ##### # d#########d#########-###CREATING AN INDEXED FILE#The SELECT
��� �� �� ��
#-###############$###############,###########################-#########-####�� ��# d#########d#########2## ##� �� �= M ##��####��####U �
# #########(############### ################# #########(###U#l###K#########d#######� � � 1###U# ###K#########d###########U# ###K#########d####### ###U#
###K#########d###########U#
#########AGg #� � ��############ ## # 2# A g p� � � � � � �############# ##d#?�
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ## #gC#### ###########r## ## 0 M
� � � � � �� �
#### ##### # d#########d#########,###CREATING AN INDEXED FILE #The ACCESS
��� �� �� ��
#########AGg #� � ��############ ## # 2# A g p� � � � � � �############# ##d#?�
#*#########*#################*#########g###U#l###K#########d#######J###U#l###K##### ####d#######!
#########AG����� ��############ #### =# A� � ����� ############# ## # =#### ###########r## ### #
� � � � � � � �
$### ##### # d#########d#########+###DEBUGGING TIP - #GUIDELINES FOR
��� �� �� ��
#+#########+#####$###########+#########+####�� ��# d#########d#########2## ###� ��� # #### ####U # K#########d######### ###1. COBOL 85 states that the RECORD
� �� �� � �� �
KEY should be defined with a PIC of X's. Most compilers also allow a PIC of 9's as an enhancement. Regardless of whether the record key is defined with X's or 9's, it is best to use a RECORD KEY that has a numeric value. Fields such as ACCT- NO in an accounts receivable record, SOC-SEC-NO in a payroll record, or PART-NO in an
# ######### ################# #############U# ###K#########d####### ###U# � � � � ###K#########d#######'###U#
#########AGg #� � ��############ #### =# A g p� � � � � ############# ## #'>#### ###(#######r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########+###DEBUGGING TIP - #GUIDELINES FOR
��� �� �� ��
# ######### ################# ######### ###U# ###K#########d#######W###U# � � � � ###K#########d####### ### ############# ###### ### ### ###\#?� � � � � �
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ##\#_=#### ###########r## ## 0 M
� � � � �� �
$### ##### # d#########d#############The INVALID KEY Clause
#T################################################################################# ##########################################T#############U#
###K#########d#######)###U# ###K#########d#######$###U#
#########AGg #� � ��############ ## # 2# A g p� � � � � � �############# ## #?� �
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ## #_=#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########!###Updating an Indexed File Randomly#
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ##D#',#### ###########r## ## 0 M
� � � � �� �
$### ##### # d#########d#########!###Updating an Indexed File Randomly#
# #########H############### ################# #########I###U#l###K#########d#######� � � Q###U# ###K#########d#######C###U# ###K#########d####### ###U# �
#########AGg #� � ��############ ## # ## A g p� � � � � � �############# ##� �
###########I############### ###########################J###U# � ###K#########d####### ###U# �
###K#########d####### ### ######################### ### ### #', ### ###############� � � � � � � ################# ####
#########AGg #� � ��############ ## ?e# A g p� � � � �
############# ## #WO#### ###########r## ## 0 M
� � � � � �� � ���####��####U �
# ######### ################# #############U# ###K#########d#######0###U# � � �
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ## #_=#### ###########r## ## 0 M
� � � � � �� �
#### ##### # d#########d#########@###Updating an Indexed File Randomly
��� �� �� ��
#@#########!
#####$###########################@#########@####�� ��# d#########d#########2## ##� ���M s#��####��####T l#� ��K#########d#########
###When updating an indexed file, we open it as I-O, for input-output, because it will be read from and written to. That is, (1) it is used as input [I] for reading or accessing disk records(2) it is also used as output [O] for rewriting or
#
#########
#################
#########{###U#l###K#########d#######B###T#l###K#########d#######M###T#l###K####### ##d####### ### ######################### ### ### #?� � � � �
#########AGg�� S ############ ## # 2# A g P� � � � � � � p############# ##,# 2#### ###########r## ##� � � � ���M
#4#########"#####$###########################4#########4####�� ��# d#########d####### ##2## ##� �� �m M S#��####��####U #� ��K#########d######### ###We read in the �
# ######### ################# ######### ###U#l###K#########d###########U#l###K#####� � � � ####d###########U# ###K#########d#######/###U# ###K#########d###########U#
###K#########d#######!###U# ###K#########d###########U# ###K#########d#######+###U# ###K#########d#######.###U# ###K#########d###########U# ###K#########d###########U# ###K#########d####### ### ######################### ### ###$#?� � � �
#########AGg #� � ��############ ## # 2# A g� � � � ��� ############# ##d#gC#### ###########r## ## M
� � � � �� �
#### ##### # d#########d#########^###Updating an Indexed File Randomly
��� �� �� ��
#^#########!
#########AGg�� S ############ ## # 2# A g P� � � � � � � p############# ##d#?�
#D#########!
#####$###########################D#########D####�� ��# d#########d#########2## ##� �� �m M S#��####��####U l#� ��K#########d######### ###Once a master indexed record has � been accessed, transaction data is used to updatethe master record.We code a
# ######################### ###############P################# #########e###U#l###K#� � � ########d#######}###U#l###K#########d#######;###U#l###K#########d#######(###U# ###K#########d#######]###U#
###K#########d#######P###U#l###K#########d####### ### ######################### ###� � � ###L
#########AGg�� ��############ ## # 2# A 7� � � � ��W �############# ##,#?�
#D#########!
#####$###########################D#########D####�� ��# d#########d#########2## ##q� ��# # #### ####U # K#########d#########E###Updating an indexed master file
� �� �� � ��
(continued)3. When the READ (master file) instruction is executed, the
#E#########,#################################E#########,###U#l###K#########d####### ###U# ###K#########d#######l###U# ###K#########d###########U#
�
#########AGg #� � ��############ ## # 2# A g p� � � � � � ############# ## #',#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########"### Updating an Indexed File Randomly
# ######################### ################# #############U#l###K#########d#######� � � *###U# ###K#########d#######)###U# ###K#########d#######/###U#
###K#########d###########U# ###K#########d#######'###U#
#########AG��� S ############ ##d#?4# A 7 # W� � � � � 0############# ##\#_=#### ###########r## ##� � � ���}
#!#########!#################!#########6###U# ###K#########d####### ###U# � ###K#########d#######g###U#
#########AGg #� � ��############ ##d#?4# A g p� � � � ############# ## #_=#### ###########r## ## 0 M
� � � � � �� �
#### ##### # d#########d#########L###Updating an Indexed File
��� �� �� ��
#L#########!
#####$#########+#################L#########L####�� ��# d#########d#########2## ##� ���M s#############U# ###K#########d#########~###2. Creating new records. For
#~#########~#################~#############U# ###K#########d#######9###U# ###K#########d####### ###U# ###K#########d####### ###U# � �
#########AGg #� � ��############ ##d#?4# A g p� � � � �############# ##$#?�
#L#########!
#######################################$###U# ###K#########d#######^###U# ###K#########d####### ###U# �
###K#########d####### ### ############# #####X#a#b# ### ### #_= ### ###############� � � � � � � � ################# ####
#########AG���� ��############ ##d#?4# A # # '� � � � ############# ####_=#### ###########r## ##� � � �� �# }
#### ##### # d#########d#########L###Updating an Indexed File
��� �� �� ��
#L#########!
#####$#########+#################L#########L####�� ��# d#########d#####"###2## ##A #� � � ### #### ####U # K#########d#############The format for the DELETE statement
� �� �� � ��
is as follows:DELETE indexed-file-name-1 RECORD [INVALID KEY
###########3############### ###########################3###U# �
###K#########d#######"###U# ###K#########d#######)###U# ###K#########d#######+###U# ###K#########d###########U# ###K#########d#######\###U#
#########AG�� �s C ############ ##d#?4# A� � ������ ############## ## #gC#### ###########r## ##� � � � ���}
#Q#########Q#####$###########Q#########Q####�� ��# d#########d#########2## ###� ��� # #### ####U l# K#########d######### ###We illustrated two separate types
� �� �� � �� �
of updates for sequential master files when:(1) only one transaction per master is permitted or when (2) multiple transactions per master are permitted. With indexed master files, the same procedure can be used regardless of the number of
# ######### ################# #########O###U#l###K#########d#######:###U# � � � ###K#########d#######5###U#
#########AG�� �C # ############ ##d#?4# A� � ����� ############# ## #_=################r## ## ` }
� � � � �� �
#### ##### # d#########d#########l###Accessing or Reading from an Indexed
��� �� �� ��
#l#########@#####$#########,#################l#########l####�� ��# d#########d#####$# ##2## ##� ����} � ��# ####��####U l#� ��K#########d######### ###Suppose we have an �
######## A 7 ` W� � � �############# ##d#?4##AGg s� � � C ############ ##4#gC################r## ##� � � ���M
#0#########0#################0#####
###U# ###K#########d###########U# ###K#########d###########U#
### #########################
#########AG����� ��############ ##d#?4# A� ��� ��
@############# ##D#gC################r## ###� � ��� ���
# #########A#####$#########?##### �
########### ######### ####� � �� ��# d#########d#####&###2## ##� �� �= }
#V#########V#################V#########?
###U#l###K#########d####### ###U#l###K#########d#######|�
#########AGg #� � ��############ ##d#?4# A g p� � � � �############# ##4�
# ######### ################# ######### ###U#l###K#########d#######W###U#l###K#####� � � � ####d###########U# ###K#########d###########U# ###K#########d#######a###U#
#########AG@ `� � ############ ##D� �
L#### P# ############# ########A p # ############# ####oT#### ### #######r##
� ��� � � ��� �� � � � � �
#
#########
#####,########### #########
#########AGg #� � ��############ #### =# A g p� � � � � ############# ## # 2#### ###########r## ## 0 M
� � � � � � �� �
$### ##### # d#########d#########
# ######### ################# #########k###U# ###K#########d#######*###U# � � � ###K#########d#######(###%#########################&###'###$#?
2#### ###########r## ## 0 M
#n#########n#################n#########T###U# ###K#########d###########U# ###K#########d#######/###,#########################-###.###D#',
#########AGg #� � ��############ #### =# A g p� � � � � ############# #### 2#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########
# ######### ################# #########;###U# ###K#########d#######T###U# � � � ###K#########d#######6###3#########################4###5### #?�
#########AGg #� � ��############ #### =# A g p� � � � � ############# ##l# 2#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########
#O#########O#################O#########?###U# ###K#########d###########U# ###K#########d#######=###:#########################;###<### #?�
#########AGg #� � ��############ #### =# A g p� � � � � ############# ##T####### ###########r## ## 0 M
� � � � �� �
$### ##### # d#########d#########
# ######### ################# #########g###U# ###K#########d#######J###U# � � � ###K#########d#######D###A#########################B###C###|#?
#########AGg #� � ��############ #### =# A g p� � � � � ############# ##D# 2#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########
#V#########V#################V#########K###U# ###K#########d###########U#
#########AGg #� � ��############ #### =# A g p� � � � � �############# ##� � 2#### ###########r## ## 0 M
#c#########c#################c#########T###U# ###K#########d###########U# ###K#########d#######R###O#########################P###Q### #?�
#########AG��� c ############ ##d#?:################r## ##� � � ���}
#################,##########################�� ��# d#########d#####0#Y###V########### ######
#########AGg #� � ��############ ##d#?4# A g p� � � � ############# ## #_=#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#############What Is a Relative File?
#########AGg #� � ��############ ##d#?4# A� ����� ############# ##D#gC#### ###########r## ## 0 M
� � � � �� �
$### ##### # d#########d#############What Is a Relative File?
#################$##########################�� ��# d#########d#####2###2## ##� ��� # #### ####U # K#########d######### ###FORMATSELECT file-name-1 ASSIGN TO
� �� �� � �� �
#########AGg #� � ��############ ##d#?4# A g p� � � � �############# ##� � 2#### ###########r## ## 0 M
#################$##########################�� ��# d#########d#####3###2## ##� ���M s#��####��####U l#� ��K#########d######### ###Relative files are created � sequentially, and either the computer or the user can supply the key. When a relative file's SELECT statement includes ACCESS IS SEQUENTIAL, the RELATIVE KEY clause can be omitted. If the RELATIVE KEY clause is omitted, the computer writes the records with keys designated as 1 to n. That is, the first record is placed in relative record location 1 (RELATIVE KEY = 1), the second in relative record
#########AGg S� � # ############ ##d#?4# A # '� � � � � @############# ## #gC#### ###########r## ##� � � � �� �p M
#################$##########################�� ��# d#########d#####4###2## ##A =� � ��### #### ####U l# K#########d######### ###Suppose the programmer designates CUST-NO
�� �� � �� �
as the RELATIVE KEY when creating the file. The record with CUST-NO 001 will be the first record on disk, the record with CUST-NO 002 will be the second record etc. If there is no CUST-NO 003, then a blank record will automatically be inserted by the computer. Similarly, suppose a CUST-NO field that also serves as a RELATIVE KEY is entered in sequence as 10, 20, 30, and so on; blank records would be inserted in disk locations 1 to 9, 11 to 19, 21 to 29, . . . . This allows records to be added later between the records originally created. That is, if a CUST-NO of 09 is
#########AGg #� � ��############ ##d#?4# A g p� � � � ############# ##D#gC#### ###########r## ## 0 M
� � � � �� �
$### ##### # d#########d#########$###Sequential Reading of Relative Files
#########AGg #� � ��############ ##d#?4# A g p� � � � ############# ## #_=#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d######### ###Random Reading of Relative Files
#########AGg #� � ��############ ##d#?4# A g p� � � � ############# ## #gC#### ###########r## ## 0 M
� � � � � �� �
$### ##### # d#########d#########!###Random Updating of Relative Files#
#########AGg #� �
############ ## #OO####( ##[############# ######################r## ## 0 M
�� � � �� � � �� �
$### ##### # d#########d#####9#######MORE QUESTIONS?e
#################,##########################�� ��# d#########d#####8# ### ###########� � ######
#########AGg #� � ��############ #### =# A g p� � � � � ############# ## # 2#### ###########r## ## 0 M
� � � � � � �� �
$### ##### # d#########d#########
# ######### ################# #########y###U# ###K#########d#######5###U# � � � ###K#########d####### ### ######################### ### ####� � � � ?
#########AGg #� � ��############ #### =# A g p� � � � � �############# ##T#?�