Previous Topic: Setting Longterm Explicit LocksNext Topic: Managing Tables


Monitoring Concurrent Database Access

You can monitor concurrent database access associated with a specific record during a pseudoconverse, instead of locking the record. In most cases, monitoring is preferable to locking because it allows other run units unrestricted access to the specified database record.

'Pageable map applications'. Because you cannot predict the number of occurrences that will be accessed and displayed on a pageable map, it is especially useful to monitor, rather than lock, such records.

Steps Before the Pseudoconverse

To monitor concurrent database access across a pseudoconverse, perform the following steps:

  1. Request DC to begin monitoring database concurrent access for the specified record occurrence by issuing a KEEP LONGTERM statement that includes the NOTIFY parameter.
  2. Begin the pseudoconverse by issuing a DC RETURN statement.

Steps After the Pseudoconverse

In subsequent tasks, perform the following steps:

  1. Determine if the record has been accessed by another run unit by issuing a KEEP LONGTERM statement with the TEST parameter. The components of the value returned as a result of the KEEP LONGTERM TEST statement are as follows:

    For example, a value of 9 means that the record was obtained and logically deleted; the highest possible value is 31, which indicates that all the above actions were performed. You should proceed according to the effect that other run units' processing has on your application and the extent of the other run units' processing.

    Typically, you should require the user to resubmit any transaction in which another run unit has modified a record's data.

    'Pageable map applications'. You should be aware of the effect modified detail occurrences have on each other when using longterm notify locks. For example, if you are modifying a series of records that participate in the same occurrence of a sorted set, a value of 5 (obtained and modified by DISCONNECT/CONNECT) is returned beginning with the second modified detail occurrence.

  2. If necessary, issue a KEEP LONGTERM statement with the UPGRADE parameter to place a longterm explicit lock on the specified record.
  3. Access the database, as required.
  4. Finish longterm monitoring and release longterm locks by issuing a KEEP LONGTERM statement with the RELEASE parameter.

Data Sharing Considerations

A data sharing environment allows programs executing on more than one CA IDMS system to concurrently access and update data in the same areas of the data base. In order to do this, such systems must be members of a data sharing group.

KEEP LONGTERM DML statements will control or monitor data access across members of a data sharing group just as they do within a single CA IDMS system. Programs do not need to be concerned with whether or not the data is being shared between members, with one exception: the retrieval of data is not monitored between members. This means that if a program executing on one member issues a KEEP LONGTERM NOTIFY statement and a program on another member subsequently obtains (but does not update) the affected record, then no indication of the retrieval will be returned to the monitoring program when it checks to see what access has taken place using the KEEP LONGTERM TEST statement. If the accessing program updates the record, the notification value returned to the monitoring program will be an even number greater than 1.

Example of Establishing Longterm Monitoring

The first program excerpt below uses the NOTIFY option of the KEEP LONGTERM statement to monitor concurrent database access across a pseudoconverse. (The second program excerpt performs processing based on the result of database monitoring.)

The first program excerpt uses the NOTIFY option of the KEEP LONGTERM statement to establish monitoring of other run units' access to the specified EMPLOYEE record. It uses the employee's CALC key as the longterm ID.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  EMPMOD                     PIC X(8)   VALUE 'EMPMOD'.
 01  KEEP-INFO.
     05 KEEP-LNGTRM-ID          PIC X(4).
 01  MAP-WORK-REC.
     05 WORK-EMP-ID             PIC 9(4).
     05 WORK-FIRST              PIC X(10).
     05 WORK-LAST               PIC X(15).
     05 WORK-ADDRESS            PIC X(42).
 PROCEDURE DIVISION.
     BIND MAP DCTEST03.
     BIND MAP DCTEST03 RECORD MAP-WORK-REC.
 .
 .
 .
     OBTAIN CALC EMPLOYEE
        ON DB-REC-NOT-FOUND GO TO ERR-NO-EMP.
*** USE EMPLOYEE'S CALC KEY FOR THE LONGTERM ID ***
     MOVE EMP-ID-0415 TO KEEP-LNGTRM-ID.
*** BEGIN MONITORING ***
     KEEP LONGTERM KEEP-LNGTRM-ID
         NOTIFY CURRENT EMPLOYEE.
     MOVE EMP-ID-0415 TO WORK-EMP-ID.
     MOVE EMP-LAST-NAME-0415 TO WORK-LAST.
     MOVE EMP-FIRST-NAME-0415 TO WORK-FIRST.
     MOVE EMP-ADDRESS-0415 TO WORK-ADDRESS.
     MAP OUT USING DCTEST03.
     DC RETURN NEXT TASK CODE EMPMOD.

Monitoring Concurrent Database Access

The program excerpt below checks to determine if any other run units have accessed the specified record. If any modifications have been made, the program issues a ROLLBACK and informs the user. If no modifications have been made, the program locks the record by issuing a KEEP LONGTERM UPGRADE statement before performing database access and modification.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  REDISP                     PIC X(8)   VALUE 'REDISPLY'.
 01  KEEP-INFO.
     05 KEEP-LNGTRM-ID          PIC X(4)   VALUE 'KPID'.
     05 KL-STAT                 PIC S9(8)  COMP.
 01  MAP-WORK-REC.
     05 WORK-EMP-ID             PIC 9(4).
     05 WORK-FIRST              PIC X(10).
     05 WORK-LAST               PIC X(15).
     05 WORK-ADDRESS            PIC X(42).
 PROCEDURE DIVISION.
     BIND MAP DCTEST03.
     BIND MAP DCTEST03 RECORD MAP-WORK-REC.
     MAP IN USING DCTEST03.
     MOVE WORK-EMP-ID TO EMP-ID-0415.
     OBTAIN CALC EMPLOYEE
        ON DB-REC-NOT-FOUND GO TO ERR-NO-EMP.
     MOVE EMP-ID-0415 TO KEEP-LNGTRM-ID.
*** TEST TO SEE IF OTHER RUN UNITS HAVE ACCESSED THE RECORD ***
     KEEP LONGTERM KEEP-LNGTRM-ID
         TEST RETURN NOTIFICATION INTO KL-STAT.
*** A RETURNED VALUE THAT IS GREATER THAN 1 MEANS ***
*** THAT THE RECORD WAS MODIFIED IN SOME WAY.     ***
*** ROLLBACK AND REQUIRE THE OPERATOR TO RESUBMIT ***
***    NOTE: THE SIGNIFICANCE OF THE RETURNED     ***
***          VALUE IS APPLICATION-SPECIFIC.       ***
***          FOR EXAMPLE, FOR SOME APPLICATIONS   ***
***          A RETURNED VALUE > 1 MAY BE          ***
***          ACCEPTABLE, FOR OTHERS, IT MAY NOT.  ***
     IF KL-STAT > 1
        ROLLBACK TASK CONTINUE
        MAP OUT USING DCTEST03 DATA IS ATTRIBUTE
            MESSAGE IS EMPMOD-MESS LENGTH 40
        DC RETURN DEXT TASK CODE REDISP
*** OTHERWISE UPGRADE THE LOCK TO SHARED          ***
     ELSE
        KEEP LONGTERM KEEP-LNGTRM-ID
            UPGRADE SHARE.
*** DATABASE UPDATE PROCESSING ***