D M L (Part 1)Reading a record occurrence is a two stage process
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:
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;

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

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;

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;

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";
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.

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