Previous Topic: Storing RecordsNext Topic: Erasing Records


Modifying Records

To change a record occurrence in the database, perform the following steps:

  1. Ready all affected areas in one of the update usage modes (for more information, see Area Usage Modes).

    Areas should be readied whether they are affected explicitly or implicitly (for example, as owner or member of a set whose members' sort keys are being modified).

  2. Establish the specified record as current of run unit by issuing either a FIND or an OBTAIN statement.
  3. Change the variable-storage fields of the record to be modified.

    When using FIND, be sure to initialize all the appropriate values of the record to be modified. The best practice, however, is to use the OBTAIN statement to ensure that all the elements in the modified record are present in variable storage.

  4. Issue the MODIFY command.
  5. Perform the IDMS-STATUS routine if the DBMS returns a nonzero value.

CALC and Sort Key Considerations

The following special considerations apply to the modification of CALC- and sort-keys:

Native VSAM Considerations

The length of a record in an entry-sequenced data set (ESDS) cannot be changed even in the case of variable-length records.

The prime key for a key-sequenced data set (KSDS) cannot be modified.

Example of Modifying Records

The program excerpt below modifies records in the database.

The program retrieves the specified EMPLOYEE record and modifies the address and phone number. This program issues a COMMIT statement after every 100 updates. COMMIT releases all implicit exclusive locks and writes a checkpoint to the journal file.

 WORKING-STORAGE SECTION.
 01  COMMIT-COUNTER              PIC S9(4) COMP VALUE +0.
 PROCEDURE DIVISION.
          .
     READ NEW-EMP-ADDRESS-FILE-IN.
          AT END MOVE 'Y' TO EOF-SW.
     PERFORM A300-CHANGE-ADDRESS THRU A300-EXIT
                        UNTIL END-OF-FILE.
     FINISH.
     GOBACK.
 A300-CHANGE-ADDRESS.
     MOVE EMP-ID-IN TO EMP-ID-0415.
*** RETRIEVE EMPLOYEE RECORD ***
     OBTAIN CALC EMPLOYEE.
*** CHECK FOR ERROR-STATUS = 0326 ***
     IF DB-REC-NOT-FOUND
        THEN DISPLAY
        'EMPLOYEE ' EMP-ID-IN ' NOT FOUND'
        GO TO A300-GET-NEXT
     ELSE IF DB-STATUS-OK
        NEXT SENTENCE
     ELSE
        PERFORM IDMS-STATUS.
     PERFORM U500-WRITE-OLD-ADDRESS.
*** CHANGE DATA AND ISSUE THE MODIFY STATEMENT ***
     MOVE NEW-ADDRESS-IN TO EMP-ADDRESS-0415.
     MOVE NEW-PHONE-IN   TO EMP-PHONE-0415.
     MODIFY EMPLOYEE.
     PERFORM IDMS-STATUS.
     ADD 1 TO COMMIT-COUNTER.
     IF COMMIT-COUNTER > 100 THEN
        COMMIT
        PERFORM IDMS-STATUS
        MOVE 0 TO COMMIT-COUNTER.
     PERFORM U0510-WRITE-NEW-ADDRESS.
 A300-GET-NEXT.
     READ NEW-EMP-ADDRESS-FILE-IN
          AT END MOVE 'Y' TO EOF-SW.
 A300-EXIT.
     EXIT.