Technical data
Example 6–5 (Cont.) FETCH NEXT Loop
000170 FREE CURRENT.
000180 ANALYZE-INVENTORY.
000190 FETCH NEXT INV_ITEMS
000200 AT END GO TO END-OF-PROGRAM.
000210 GO TO ANALYZE-INVENTORY.
.
.
.
You can also use FETCH NEXT and FIND NEXT loops to walk through a set
type. Assume you have to walk through the WAREHOUSE_SET and reduce the
reorder point quantity by 10 percent for all items with a cost greater than $500.
Furthermore, you also want to check the supplier’s credit terms for each of these
items. You could perform the task as shown in Example 6–6.
Example 6–6 Using a FETCH NEXT Loop to Walk Through a Set Type
.
.
.
000100 FETCH-WAREHOUSE.
000110 FETCH NEXT WHSE_REC
000120 AT END PERFORM END-OF-WAREHOUSE
000130 PERFORM WRAP-UP.
000140 ITEM-LOOP.
000150 FETCH NEXT INV_ITEM WITHIN WAREHOUSE_SET
000160 AT END
000170 FIND OWNER WITHIN WAREHOUSE_SET
000180 PERFORM FETCH-WAREHOUSE.
000190 IF INV_ITEM_COST IS GREATER THAN 500
000200 PERFORM SUPPLIER-ANALYSIS.
000210* Reduce reorder point quantity by 10%.
000220 MODIFY INV_ITEM.
000230 GO TO ITEM-LOOP.
000240 SUPPLIER-ANALYSIS.
000250 IF NOT SUPPLIER_SET MEMBER
000260 DISPLAY "NO SUPPLIER FOR THIS ITEM"
000270 EXIT.
000280 FETCH OWNER WITHIN SUPPLIER_SET.
000290* Check credit terms.
.
.
.
Notice the FIND OWNER WITHIN WAREHOUSE_SET statement on line
000170. At the end of a WAREHOUSE_SET collection, statement 000170 sets the
WAREHOUSE_SET type currency to the owner of the current occurrence. This
allows the next execution of FETCH NEXT WHSE_REC to use current of record
type WHSE_REC to find the next occurrence of WHSE_REC. Without statement
000170, a FETCH NEXT WHSE_REC would use the current of run unit, which is
an INV_ITEM record type.
6–16 DML Programming—Tips and Techniques