Network (CODASYL) Data Model (Course Library)
1. H.Maurer and N.Scherbakov "Network (CODASYL) Data Model"

6. C O D A S Y L D M L (Part 1)

6.1. Introduction

In the network data model the process of data retrieving can be seen as step-by-step reading of record occurrences from a database to UWA.

Reading a record occurrence is a two stage process

The GET command always copies the current of run-unit into a template for whatever record type which is the current of run-unit.

The form of the GET command is:
GET [record name]

Thus, for debugging purposes, we can append the record type to the GET command. For example, the command GET R2 will copy the current of run-unit into the R2 template, if the current of run-unit is a R2 record. Otherwise, the system will warn the user of an error when the GET R2 command is executed (i.e. the DBMS returns a nonzero value of the error status).

The FIND command in the Codasyl proposals is really a collection of different commands, distinguished by the keywords following FIND. These commands have the common purpose of locating a particular record occurrence by some designated strategy.

Note that the term "locate a record occurrence" in the Codasyl proposals is perceived as "make a record occurrence the current record of the run-unit and area in which it resides; make it also the current record of its record type and of all sets in which it participates as either owner or member".

The variety of FIND statements is extensive, and here we shall consider only the following useful subset of the possibilities:

6.2. Finding a Record Directly


The first two kinds of FIND statements access record occurrences by a "key", either the database key or the CALC-key.

To access by the database key we write:
Find [record name] Record by Database Key [variable]
where the [variable] is a program's variable that has previously been given a database key as value.
For example,
X=11; Find R1 Record by Database Key X;
Get R1;


Obviously, we have to be careful with this command and check if the FIND operator was successfully executed. Perhaps, there is no such a record occurrence having that database key.
For example,
X=10; Find R2 Record by Database Key X;
If Error_Status=0 then Get R2;
Else Print "Not Found !";

In order to find a record directly using known values of its fields, such fields should be defined as so-called CALC - keys in the database schema.


To find a record given values for its CALC-key fields, we "pass" these values in the corresponding fields of the template.

Then we issue the command:
FIND [record name] RECORD BY CALC-KEY.
For example,
R1.i1="A";
Find R1 Record by Calc-Key


Note that there can be more than one record occurrence with the same value of the fields in the CALC-key, if the record type was defined with the option DUPLICATES ARE ALLOWED.

To find all the record occurrences of a given type (say, R1) with a given value for the CALC-key we can find the first such record occurrence as in the previous case.
R1.i1="A"; Find R1 Record by Calc-Key;

And then we can find additional record occurrences with the same CALC-key by executing, in a loop,
FIND DUPLICATE [record type] RECORD BY CALC-KEY.
For example,
R1.i1="A"; Find R1 Record by Calc-Key;
Find Duplicate R1 Record by Calc-Key;

When performing any sort of scan, we must be prepared to find no record occurrences matching the specification:
For example,
R1.i1="A"; Find R1 Record by Calc-Key;
Loop: Find Duplicate R1 Record by Calc-Key;
If Error_Status=0 then begin;
. . . Go to Loop; end;

6.3. Scanning a Set Occurrence

To begin, suppose we have a current set occurrence for some Codasyl set (say, S1). Recall that the set occurrence can be viewed as a ring consisting of the owner (DBK=11) and each of the members (DBK=21, DBK=22 and DBK=23).

The statement:
Find Next [record name] Record In [set name] Set
goes one position around the ring from the current of [set name].

For example,
Find Next R2 Record In S1 Set;


The FIND NEXT command can be repeated as many times as we like, taking us around the ring for the set occurrence.
For example,
Loop: Find Next R2 Record In S1 Set;
If Error_Status=0 then goto Loop;

The operator FIND NEXT returns a non-zero value to the error status if the next record is not of the [record type], so we fail when we try to get back to the owner.

We may also issue the command:
Find First [record name] Record In [set name] Set
to get the first member record of the current [set name] set.

For example,
Find First R2 Record In S1 Set; The operator FIND FIRST returns a non-zero value to the error status if there are no members of the current set occurrence. Otherwise, we can continue around the ring with a loop containing a FIND NEXT command, as above.
For example,
Find First R2 Record In S1 Set;
Find Next R2 Record In S1 Set;

We can also scan a set occurrence in the "reverse" direction (i.e. backwards from the last member up to the first member).

The statement
Find Prior [record name] Record In [set name] Set
goes one position back from the current of [set name].

For example,
Find Prior R2 Record In S1 Set;

The statement FIND PRIOR returns a nonzero value to the error status if the prior member is not of the [record type], i.e., when we get back to the owner.

The statement
Find Last [record name] Record In [set name] Set
goes to the last member record of the current of [set name].
For example,
Find Last R2 Record In S1 Set;

The statement FIND LAST returns a nonzero value to the error status if there are no members of this set occurrence.

Note that the statements FIND LAST and FIND PRIOR can be efficiently used if the set type is defined with the option
SET IS RRIOR PROCESSABLE

The next type of FIND statement also scans the members of a set occurrence, but it allows us to look at records only with specified values in certain fields (so-called, search keys).

The values for these fields (search keys) are stored in the template for the member record type before using the statement FIND.

For example,
R2.i2="a.1";

To find the first member record having the desired values we write:
Find [record type] Record In [set name] Set Using [field list]

For example,
R2.i2="a.1";
Find R2 Record In S1 Set Using i2;

To find subsequent records in the same set occurrence with the same values of selected fields we can say:
Find Duplicate [record type] Record In [set name] Set Using [field list]

For example,
R2.i2="a.1";
Find R2 Record In S1 Set Using i2;
Find Duplicate R2 Record In S1 Set Using i2;

This operator FIND returns nonzero value to the error status if the current of set is the last member of the current set occurrence having the specified values.

6.4. Finding an Owner

Normally, the statement FIND OWNER is used if a record occurrence can be accessed through two or more different set occurrences.

Note that the record type R2 is declared as a member of two set types (S1 and S2).

The statement:
Find Owner Of [set name] Set;
locates an owner of the current set.
For example,


Find Next R2 Member of S1 Set;
Find Owner of S2 Set;

Note, the operator FIND OWNER can be efficiently used if the set type is defined with the option:
LINKED TO OWNER