Technical data
that a MODIFY to the PART record will not work even before you attempt the
MODIFY statement.
To correct the logic error, PART must be the current record type prior to execution
of the MODIFY PART_STATUS statement. One way to correct the logic error
is to execute a FETCH CURRENT PART statement before the MODIFY PART_
STATUS statement. Example 7–2 shows a corrected version of the sample
COBOL DML program statements in Example 7–1.
Example 7–2 Sample DML Program Statements
DATA DIVISION.
DB PARTSS3 WITHIN PARTS FOR NEW.
.
.
.
PROCEDURE DIVISION.
000-BEGIN.
READY PROTECTED UPDATE.
.
.
.
MOVE "AZ177311" TO PART_ID.
FETCH FIRST PART USING PART_ID.
MOVE "N" TO END-OF-COLLECTION.
PERFORM A100-LOOP THROUGH A100-LOOP-EXIT
UNTIL END-OF-COLLECTION = "Y".
.
.
.
STOP RUN.
A100-LOOP.
FETCH NEXT WITHIN PART_SUPPLY
AT END MOVE "Y" TO END-OF-COLLECTION
GO TO A100-LOOP-EXIT.
IF SUP_RATING = "0"
MOVE "5" TO SUP_RATING
MODIFY SUP_RATING
MOVE 1 TO MODIFY-COUNT
FETCH OWNER WITHIN VENDOR_SUPPLY
PERFORM PRINT-VENDOR.
IF MODIFY-COUNT = 1
MOVE "X" TO PART_STATUS
FETCH CURRENT PART RETAINING PART_SUPPLY
MODIFY PART_STATUS.
A100-LOOP-EXIT.
EXIT.
The FETCH CURRENT PART statement uses the RETAINING clause to keep
the current SUPPLY record as current of PART_SUPPLY.
Continue testing, starting with the new FETCH statement.
dbq> FETCH CURRENT PART RETAINING PART_SUPPLY
Figure 7–5 shows that executing FETCH CURRENT PART RETAINING PART_
SUPPLY makes PART the current record type, while the RETAINING clause
keeps SUPPLY current of PART_SUPPLY set. Retaining the current supply
record as current of PART_SUPPLY means the next execution of FETCH NEXT
WITHIN PART_SUPPLY uses the current SUPPLY record’s currency to locate the
next SUPPLY record. If you executed a FETCH CURRENT PART without the
Debugging and Testing HP COBOL DML Programs 7–7