• Aucun résultat trouvé

Relative Record Number

ln a direct file, a record is written and retrieved directly by specifying the location o f t h e r e c o r d in r e l a t i o n to t h e b e g i n n i n g of the file. This relative position is called t h e r e l a t i v e r e c o r d n u m b e r . T h e r e l a t i v e re c o r d n u m b e r is not a disk address, b u t i s a positive, whole number that is converted by disk system management to the disk address of the record to be accessed.

Deriving the Relative Record Number

A r e l a t i v e r e c o r d n u m b e r i s s i m i l a r to t h e k e y of an indexed file or the control infor-m a t i o n i n a s e q u e n t i a l f i l e ; i t i s d e p e n d e n t u p o n a s p e c i f i c fi e l d ( c o n t r o l field) in the r e c o r d . T h e c o n t r o r f i e r d c a n e i t h e r b e u s e d directry (without change) as a rerative record number or it can be mathematically converted to provide an acceptable re-lative record number.

Direct Method

An easy way to derive relative record numbers is to have them correspond directly to the control fields in the records. Because the control information need not be c o n v e r t e d i n t o a r e l a t i v e r e c o r d n u m b e r . m a n i p u l a t i o n a n d p r o g r a m m i n g a r e kept t o a m i n i m u m . F o r e x a m p l e . in F i g u r e g , the record with a 1 in the control f ield becomes relative record number one; the record with a 5 becomes relative record number five, and so forth. This method is practical where control numbers can be assigned on a sequential basis. such as employee numbers for payroll records, student numbers in a school. and customer numbers for customer files.

S u p p o s e a s m a l l c o l l e g e h a s a n e n r o l l m e n t o f 5 . 0 0 0 s t u d e n t s . A master student file is m a i n t a i n e d w h i c h i n c l u d e s c u r r e n t l y e n r o l l e d s t u d e n t s a n d g r a d u a t e s f o r t h e l a s t tw o years. The master file contains approximately 7,000 records. Each student is assigned a 6 - d i g i t fi l e n u m b e r a s f o l l o w s :

7\e3e7 i

Expected '7ear I

of graduation I

A u n i q u e i d e n t i f i c a t i o n n u m b e r f r o m 1 - 9 9 9 9

T h e i d e n t i f y i n g n u m b e r s a r e a s s i g n e d o n a s e q u e n t i a l b a s i s ; n u m b e r s re t i r e d fr o m t h e m a s t e r fi l e a r e a v a i l a b l e f o r r e a s s i g n m e n t .

A direct file with 10,000 record locations is used for the stuclent master file, satisfying a need for fast access to each student's record. Since the identifying numbers range between 1 and 9999 and there are no duplicates, the relative record n u m b e r is t a k e n d i r e c t l y f r o m t h e s t u d e n t fi l e n u m b e r . Figure 9 shows relative record numbers taken from the student file number being used to update student addresses.

' t 6

Student Addres F i l e

Control F i e l d

R E I I T J O H N H R R z

1 5 ' 6 r r a ' 9 t 0 r r 2 : r : r .

G L E N C O E r M I N N

a 2

l

B

2 l

a

I N N

! ! 5 . 5 t 5 6 t t

I H N S O N r J M A I N g T

3 l l r 3 ! ! G r ' , a J r . o L A K E T O

E L M S T U T L L V I O

R C E R I J A C Q U E S B I R O N C I T Y T M I N N

R B E R T F 3 1 6 E , u I N N

Diroct Student M a s t e r F i l e

i:*H)-'

8006 8007 8008

F i g u r e 9 . R e l a t i v e R e c o r d Numbers Corresponding Directly to a Control Field

Conversion Method

Conversion refers to any technique for obtaining a desirable range of relative record numbers from the control fields of the records. The conversion method must be used when the values in the control fields cannot be used directly as relative record numbers. For example, employee numbers in a factory range from 0001 to 1500, but only 450 numbers are in use since numbers belonging to employees who have retired or terminated have not been reused. A file large enough for 1500 records i s n o t n e e d e d ; t h e r e f o r e , a t e c h n i q u e m u s t b e f o u n d fo r c o n v e r t i n g t h e e m p l o y e e numbers to approximately a 1 through 500 range (which would provide 50 locations f o r f i l e e x p a n s i o n ) .

f+t

tril

D i r e c t F i l e s 1 7

when the conversion method is used, every possible control field in the f ile must convert to a relative record number in the allotted range (in this case, I through b00), and the resulting relative record numbers should be distributed evenly across the af lotted range so that there are few synonym records. synonym records are rwo or more records whose control fields yield the same relative record number, but contain different data (see the next section, synonym Recordsl. your program must allow for synonyms if they are generated.

A way to convert the range of employee numbers from 1500 to b00 is to divide the employee number by 3 and drop the remainder (thus 3 becomes 1; 6 becomes 2;

1500 becomes 500). However, there is a possibility of having synonym records. For example, if the numbers 6, 7, and 8 are present, all three become relative record number 2 .

Another technique that may produce fewer synonyms is to divide the employee number by 2 and drop the remainder. This compresses 1500 numbers to 7s0. There are 300 unused locations in this case, rather than 50.

A third method would be to divide the employee number by 499 (500 - 1). and use the remainder + 1 as the relative record nUmber,

lf there is no sequence to numbers in a control field (such as part numbers), a conversion technique that produces random numbers can be used. The resulting numbers should be distributed evenly within the selected range (depending upon the number of record locations needed), and should be suitable as relative record numbers (positive, whole numbers). one such technique is squaring the number in the control field and selecting certain digits from the resulting number as the relative record number. The calculation must be performed every time the program must seek a record, For example, suppose you have part numbers that consist of six d i g i t s . w i t h c e r t a i n d i g i t s h a v i n g a s p e c i a l m e a n i n g . N o t w o p a r t n u m b e r s a r e a l i k e . The part number is squared and, of the resulting digits, only four are used as the relative record number for the parts inventory file.

Part number = 4681 52 4€81 52 x 4681 52 = 21 91166-t6ls1 04

Relative record number = 6629

Since four digits are selected. random numbers from 1 to gggg could be developed.

Therefore, a file containing 10,000 record locations should be provided for the parts inventory.

Even the technique used in the example above is likely to produce synonym records, since the selected four digits of the square of two different part numbers can be

identical. lf a conversion technique produces too many synonyms, it may be necessary to f ind a different technique.

1 8

Synonym Records

Two or more records whose control f ields yield the same relative record number are called synonym records. Synonyms have the same relative record numbers, but con-tain different data. Since only one synonym record can be stored in the record location for its relative record number. a different method must be found to store and retrieve the other synonym records.

Chain Technique

O n e w a y t o h a n d l e s y n o n y m s i s to c h a i n (l i n k ) th e m to g e t h e r s o th a t a l l c a n b e f o u n d b y locating the first. The first record is stored in the record location indicated by its relative record number. That location is called the home location; the record placed there is called the home record. The first synonym (second record) is stored in the first unoccu-pied record location in the file (a location for which no relative record number had been d e v e l o p e d ) . T h e r e l a t i v e r e c o r d n u m b e r o f t h e s e c o n d l o c a t i o n i s th e n s t o r e d i n t h e h o m e r e c o r d ; t h a t i s , th e f i r s t s y n o n y m i s li n k e d to t h e h o m e re c o r d . T h e s e c o n d s y n o n y m , i f present. would be stored in the next unoccupied record location and would be linked to t h e f i r s t s y n o n y m , a n d s o fo r t h . I n F i g u r e 1 0 , a l l r e c o r d s t h a t a r e s y n o n y m s a r e lo a d e d into the file after records that can be stored in their home location have been loaded.

L o a d i n g t h e r e c o r d s i n t h i s m a n n e r s i m p l i f i e s t h e p r o g r a m m i n g b e c a u s e t h e c o d i n g f o r l o a d i n g s y n o n y m r e c o r d s c a n b e d o n e i n a s e p a r a t e p r o g r a m . T h e c h a i n t e c h n i q u e i s useful when a file is created, but tends to be of less value as records are added to or de-l e t e d f r o m a f i l e .

U n o c c u p i e d L o c a t i o n s

l \

S y n o n y m I , A d d e d

S y n o n y m B, Added

Record I contains location o f s y n o n y m 8 r .

S y n o n y m I , c o n t a i n s lo c a t i o n o f s y n o n y m I , Home

Location

A B 3

8 1

I

l u

D

B z

G H

I

1 2 3 4 5 6 7 8 I 1 0

F i g u r e 1 0 . S t o r i n g S y n o n y m R e c o r d s i n a D i r e c t F i l e

D i r e c t F i l e s 1 9

l f a n e w r e c o r d is a d d e d to t h e f i l e , but its home location is already occupied by a s y n o n y m , f o r a d i f f e r e n t r e c o r d lo c a t i o n , the new record must be treated as a syno-n y m f o r i t s h o m e l o c a t i o syno-n . F i g u r e 1 1 shows the file that resulted from the additiosyno-n o f s y n o n y m s in F i g u r e 1 0 . T h e h o m e l o c a t i o n fo r r e c o r d c is occupied by a synonym f o r r e c o r d B , s o r e c o r d c i s p l a c e d in the first unoccupied location. Since record B1 i s a l r e a d y li n k e d t o r e c o r d B 2 , r e c o r d c must be linked through 82 to its home loca-t r o n .

Record C is relative record number 3, but location 3 is already occupied. Therefore, record C must be placed in the first avail-a b l e l o c avail-a t i o n .

Figure 11. Storing a Record When lts Home Location ls Occupied

W h e n y o u p r o c e s s a d i r e c t f i l e c o n t a i n i n g s y n o n y m s , y o u m u s t v e r i f y e v e r y r e c o r d r e t r i e v e d . F o r e x a m p l e , w h e n y o u r e t r i e v e re l a t i v e record 3 from the file in Figure 11.

y o u g e t r e c o r d 8 1 , w h i c h i s a synonym for relative record2, which is not the rer:ord you w a n t . H o w e v e r , if y o u c h e c k t h e r e c o r d r e t r i e v e d , y o u f i n d t h a t i t i s a s y n o n y m r . Y o u c a n n o w c h a i n th e r e l a t i v e re c o r d lo c a t i o n , if a n y , i n d i c a t e d b y the first record:rnd re-t r i e v e re-th e s e c o n d re c o r d . Y o u c a n c o n re-t i n u e re-th i s p r o c e s s u n t i l y o u f i n d t h e r e c o r d y o u w a n t o r u n t i l t h e c h a i n o f s y n o n y m s e n d s . I n t h i s c a s e , y o u c o u l d e v e n t u a l l v h a v e a n e r r o r c o n d i t i o n b e c a u s e t h e r e q u e s t e d r e c o r d is n o t i n t h e f i l e .

A s i m i l a r m e t h o d f o r h a n d l i n g s y n o n y m s is t o s e t a s i d e a p o r t i o n of the f ile for synonym records' Suppose, for example, a f ile for 8500 records is set up to provide relative record n u m b e r s b e t w e e n 0 a n d 9 9 9 9 . B y a c t u a l l y s e t t i n g a s i d e e n o u g h area for 1 1,000 records, a n y s y n o n y m s d e v e l o p e d c a n b e s t o r e d in r e c o r d lo c a t i o n s f r o m 1 0 , 0 0 0 t o 1 0 , 9 9 9 .

Relative record numbers G9999 S y n o n y m

records

9999 10,000 10,999

1 0

\

A

I

B 1 3 I

I

B t 5 D

I

p l A

- 2 l "

I

c

G H J

D i r e c t F i l e

20

The relative record number of a synonym is stored in the home location, and a c h a i n o f s y n o n y m s i s b u i l t a s in t h e p r e v i o u s m e t h o d .

)

A

B

I

110000 ,1111;1..r.1.i1i1111ifi+.'+fl " i.ro-'[$ ]Hfl Bl

D l

10,000 10,001

-Synonyrrs Processing by this method is faster when records must be added to a file because

a home location is kept free for every relative record number; only one seek operation is required for records without synonyms. However, this method wastes more file space, because 11,000 locations are used for 8500 records.

Spill Technique

A n o t h e r m e t h o d o f h a n d l i n g s y n o n y m r e c o r d s , t h e s p i l l t e c h n i q u e . u s e s t h e h o m e l o c a t i o n a s a s t a r t i n g p o i n t . W h e n t h e f i l e i s f i r s t l o a d e d , a c o u n t e r i s s e t t o i n d i c a t e t h e m a x i m u m n u m b e r o f r e a d s w h i c h w o u l d b e n e c e s s a r y f o r l o c a t i n g a g i v e n s y n o n y m r e c o r d . ( F o r e x a m p l e , t h e c o u n t e r w o u l d b e s e t t o 3 i f t h e m a x i m u m number of synonyms for a given home address were 3.) To retrieve a record from t h e f i l e , y o u w o u l d f i r s t n e e d to d e t e r m i n e th e h o m e r e c o r d lo c a t i o n a n d r e a d th e record from that address. lf it isn't the record you want. you read the record in the n e x t l o c a t i o n in t h e f i l e . T h i s o r o c e s s c o n t i n u e s u n t i l t h e c o r r e c t r e c o r d i s s e l e c t e d f r o m t h e f i l e . l f t h e m a x i m u m n u m b e r o f r e a d s (3 i n t h e e x a m p l e , a b o v e ) is r e a c h e d . a record-not-found condition exists.

When a record is to be added to a file, you first check the location at the home a d d r e s s . lf t h i s l o c a t i o n in d i c a t e s t h a t t h e h o m e r e c o r d h a s a s y n o n y m , y o u i n c r e -m e l t t h e r e l a t i v e r e c o r d n u m b e r b y o n e . a n d c o n t i n u e to c h e c k f o r s y n o n y m s , u n t i l a n a v a i l a b l e s p a c e i s f o u n d . A t t h a t p o i n t y o u w o u l d a d d t h e n e w r e c o r d t o t h e file. lf the number of times you incremented the relative record number exceeds t h e c o u n t y o u s e t u p f o r t h e m a x i m u m n u m b e r o f r e a d s , t h e c o u n t w o u l d b e i n c r e -m e n t e d b y o n e ( i n t h e e x a -m p l e , th e c o u n t w o u l d b e s e t t o 4 ) .

O t h e r m e t h o d s fo r h a n d l i n g s y n o n y m s c a n b e d e v i s e d . W h a t e v e r t h e m e t h o d u s e d , plan on extra accesses for synonym records and extra coding in order to verify the recoros.

C r e a t i n g a D i r e c t F i l e

T o c r e a t e a d i r e c t f i l e , y o u m u s t d e f i n e a d i s k f i l e a s : a c h a i n e d o u t p u t f i l e ( f o r R P G l l ) ; a r a n d o m o u t p u t f i l e ( f o r C O B O L ) ; o r , a d i r e c t a c c e s s f i l e ( f o r F O R T R A N ) . I n t h i s w a y , t h e f i l e i s u n i q u e l y id e n t i f i e d to d i s k s y s t e m m a n a g e m e n t a s a d i r e c t f i l e . D i s k s y s t e m m a n a g e m e n t t h e n a l l o c a t e s d i s k s p a c e f o r t h e f i l e , a n d t h e e n t i r e f i l e s p a c e i s e r a s e d t o b l a n k s . T h i s a c t i o n , in e f f e c t , c r e a t e s d u m m y r e c o r d s w h o s e length is determined by the creating program- Once the file has been cleared, one o r m o r e s u b s e q u e n t j o b s c a n b e r u n t o r e a d r e c o r d lo c a t i o n s w h i l e l o a d i n g th e f i l e . The method you use to write data records on the file depends on whether or not y o u m u s t c h e c k fo r s y n o n y m s a m o n g th o s e r e c o r d s .

D i r e c t F i l e s 2 1

whether or not you must check for synonyms. relative record numbers are used in your program to make the corresponding record locations available for loading. Re-cords are loaded into the file in an update mode by f irst chaining the record to a given record location according to its relative record number, and then by ourput-ting the new record into that record space. The relative record number is the sequence number of that record within the file. The data used as a relative record number can come from a field in the input record, or it can be created in your pro-gram.

Creating a Direst File Without Synonyms

lf you do not have synonyms, you can load records into a direct file in a single pass. In this case, record locations are not inspected before they are filled with data. lf a synonym is encountered, it is written over the previous record and the previous record is lost.

Creating a Direct File With Synonyms

lf you have synonyms, you can create a direct file by using more tnan one pass to load records into the file. The exact method you use depends on your scheme for handling synonym records (see Synonym Recordsl.

Documents relatifs