Technical data

currency pointer, which points to MUSICO to fetch the next vendor, SOUND-
OFF. Therefore, retaining the realm currency allows you to fetch the next logical
vendor record.
Figure 5–30 Physical Representation of a Realm with a RETAINING Clause
4−DAYS 2−WEEKS 2−DAYS MUSICO SOUND−OFF(start walkthrough)
with retaining
ZK−1507−GE
5.14.2 Using Keeplists
A keeplist is a stack of database key values (see the description of KEEPLIST in
LD (Keeplist Description)). The KEEP and FIND ALL statements build a stack
of keys that lets you retrieve Oracle CODASYL DBMS records using the ordinal
position of the stack entries. Oracle CODASYL DBMS calls the table of entries
a keeplist. Each execution of the KEEP or FIND ALL statement adds a record’s
database key (dbkey) value to the end of a keeplist and places a retrieval lock on
the record. Therefore, other users cannot change a record while its database key
is in your keeplist.
You can use a keeplist to retain the database key of a record after that record is
no longer current. That is, by inserting a database key into a keeplist, you can
continue to reference that record by specifying the keeplist name and database
key value in your DML statement. This is especially useful when you want
to remember a record during a long sequence of DML commands that affect
currency, or when you want to remember a list of records.
A keeplist can contain zero, one, or several database key values. To activate a
keeplist, use the KEEP statement. To empty a keeplist, use the FREE statement.
All keeplists are deallocated when you execute a COMMIT or ROLLBACK unless
COMMIT RETAINING is used.
The following example adds database keys to a keeplist.
000100 PROCEDURE DIVISION.
.
.
.
000140 100-KEEPLIST-EXAMPLE.
000150 FETCH FIRST VENDOR.
000160 KEEP CURRENT USING KEEPLIST-1.
000170 FETCH FIRST SUPPLY WITHIN VENDOR_SUPPLY.
000180 FETCH OWNER WITHIN PART_INFO.
000190 IF PART_STATUS = "M"
000200 KEEP CURRENT WITHIN VENDOR_SUPPLY USING KEEPLIST-1.
Statement 000160 adds the vendor record’s dbkey value (the current of run unit)
to KEEPLIST-1. Figure 5–31 shows the contents of KEEPLIST-1 after execution
of statement 000160. Adding a record’s database key to a keeplist also prevents
record updating by other concurrent users. Statements 000190 and 000200 add
a supply record’s database key to KEEPLIST-1 whenever its PART_INFO owner
has a status of M. Figure 5–32 shows the contents of KEEPLIST-1 after the
execution of statements 000190 and 000200.
5–32 Database Programming with HP COBOL