Technical data

Example 5–4 Using the RETAINING Clause
000100 PROCEDURE DIVISION.
.
.
.
000400 100-VENDOR-SUPPLY-WALKTHRU.
000410 FETCH NEXT VENDOR WITHIN MARKET
000420 AT END GO TO 900-ALL-DONE.
.
.
.
************************
* VENDOR PRINT ROUTINE *
************************
.
.
.
000500 300-GET-VENDORS-SUPPLY.
000510 FETCH NEXT SUPPLY WITHIN VENDOR_SUPPLY
000520 RETAINING REALM
000530 AT END
000540 GO TO 100-VENDOR-SUPPLY-WALKTHRU.
.
.
.
************************
* SUPPLY PRINT ROUTINE *
************************
.
.
.
000550 GO TO 300-GET-VENDORS-SUPPLY.
Statement 000410 fetches the vendors. Statement 000510 fetches the supply
records owned by their respective vendors. Statement 000510 also uses the
RETAINING clause to save the realm currency.
A FETCH NEXT SUPPLY (statement 000510) without the RETAINING clause
makes SUPPLY current for the run unit, its record type, all sets in which it
participates, and its realm. When SUPPLY record 2-WEEKS in Figure 5–29 is
current of run unit, a FETCH NEXT VENDOR statement fetches the vendor
whose physical location in the database follows the 2-WEEKS record. As shown
in Figure 5–29, MUSICO would be the next vendor and the program would be in
an infinite loop.
Figure 5–29 Physical Representation of a Realm Without a RETAINING Clause
4−DAYS 2−WEEKS 2−DAYS MUSICO SOUND−OFF(start walkthrough)
without retaining
ZK−1389−GE
A FETCH NEXT SUPPLY with the RETAINING clause makes SUPPLY current
for the run unit and the set types but keeps the vendor record current for
the realm shown in Figure 5–30. By retaining the realm currency when you
fetch supply records, the last accessed vendor record remains current of realm.
A FETCH NEXT VENDOR WITHIN MARKET statement uses the realm
Database Programming with HP COBOL 5–31