Maintaining Data Integrity in the Online Environment
To maintain database integrity in the online environment, DC allows you to perform the following functions:
idmscu19
To maintain database integrity in the online environment, DC allows you to perform the following functions:
- Place an explicit lock on a database record-You can restrict other run units' access to a specified database record occurrence.
- Monitor concurrent database access across a pseudoconverse-You can determine if other run units have accessed a certain database record during a pseudoconverse.
This article describes the following information:
2
2
Setting Longterm Explicit Locks
In pseudoconversational programming, you may be required to lock records across run units for the duration of a transaction. For example, a high-priority update application may lock record occurrences as they are retrieved in order to prevent other run units from accessing data that is about to be modified.
Steps to Set Longterm Locks
To lock a database record explicitly across a pseudoconverse, perform the following steps:
- Retrieve the database record.
- Issue a KEEP LONGTERM statement that specifies either the SHARE CURRENT or the EXCLUSIVE CURRENT parameter:
- SHARE CURRENTplaces a shared lock on the specified record occurrence; other run units can access the record but not update it.
- EXCLUSIVE CURRENTplaces an exclusive lock on the specified record occurrence; other run units cannot access the record in any way.
- Perform pseudoconversational processing, as required.
- As soon as possible, release the explicit lock by issuing a KEEP LONGTERM statement with the RELEASE parameter.
Release longterm locks as soon as possible to provide availability to other run units.
Interaction of Longterm Locks
Locks in effect
| Locks allowed for other run units
| Locks disallowed for other run units
|
Shared | Shared and longterm shared | Exclusive and longterm exclusive |
Exclusive | None | Shared, exclusive, longterm shared, and longterm exclusive |
Longterm shared | For all run units: shared and longterm shared .sp For run units on the same terminal: exclusive and longterm exclusive | For run units on other terminals: exclusive and longterm exclusive |
Longterm exclusive | For run units on the same terminal: shared, exclusive, longterm shared, and longterm exclusive | For run units on other terminals: shared, exclusive, longterm shared, and longterm exclusive |
Example of Setting Longterm Exclusive Locks
The first program excerpt below sets longterm exclusive locks in order to ensure that other programs cannot access any data. (The second program excerpt performs database modifications and releases the locks as soon as possible.)
The first program excerpt locks the EMPLOYEE and DEPARTMENT records in order to prevent other run units from modifying them during the pseudoconverse.
DATA DIVISION. WORKING-STORAGE SECTION. 01 CHNGDEPT PIC X(8) VALUE 'CHNGDEPT'. 01 KEEP-INFO. 05 DEPT-LNGTRM-ID PIC X(4) VALUE 'DEPT'. 05 EMPL-LNGTRM-ID PIC X(4) VALUE 'EMPL'. 01 MAP-WORK-REC. 05 WORK-OLD-DEPT-ID PIC 9(4). 05 WORK-NEW-DEPT-ID PIC 9(4). 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. *** SET AN EXCLUSIVE LOCK ON THE CURRENT EMPLOYEE RECORD *** KEEP LONGTERM EMPL-LNGTRM-ID EXCLUSIVE 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. IF DEPT-EMPLOYEE IS NOT EMPTY OBTAIN OWNER IN DEPT-EMPLOYEE ELSE GO TO NO-DEPT. *** SET AN EXCLUSIVE LOCK ON THE CURRENT DEPARTMENT RECORD *** KEEP LONGTERM DEPT-LNGTRM-ID EXCLUSIVE CURRENT DEPARTMENT. MOVE DEPT-ID-0410 TO WORK-OLD-DEPT-ID. *** ALLOW INPUT IN THE NEW DEPARTMENT FIELD ONLY *** MODIFY MAP DCTEST03 FOR ALL EXCEPT DFLD WORK-NEW-DEPT-ID ATTRIBUTES PROTECTED. MAP OUT USING DCTEST03. DC RETURN NEXT TASK CODE CHNGDEPT.
Example of Releasing Longterm Exclusive Locks
This program excerpt maps in the new department ID, disconnects the employee from the old department, and connects the record to the new department.
DATA DIVISION. WORKING-STORAGE SECTION. 01 CHNGSHOW PIC X(8) VALUE 'CHNGSHOW'. 01 TEMP-DEPT-DBKEY PIC S9(8) COMP. 01 KEEP-INFO. 05 DEPT-LNGTRM-ID PIC X(4) VALUE 'DEPT'. 05 EMPL-LNGTRM-ID PIC X(4) VALUE 'EMPL'. 01 MAP-WORK-REC. 05 WORK-OLD-DEPT-ID PIC 9(4). 05 WORK-NEW-DEPT-ID PIC 9(4). 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. IF WORK-NEW-DEPT-ID IS NOT NUMERIC GO TO ERR-NONNUMERIC-DEPT-ID. *** OBTAIN NEW DEPARTMENT RECORD TO ENSURE IT EXISTS *** MOVE WORK-NEW-DEPT-ID TO DEPT-ID-0410. FIND CALC DEPARTMENT ON DB-REC-NOT-FOUND GO TO ERR-NO-NEW-DEPT. MOVE DBKEY TO TEMP-DEPT-DBKEY. *** REOBTAIN OLD DEPARTMENT *** MOVE WORK-OLD-DEPT-ID TO DEPT-ID-0410. FIND CALC DEPARTMENT. *** REOBTAIN EMPLOYEE RECORD *** MOVE WORK-EMP-ID TO EMP-ID-0415. FIND CALC EMPLOYEE. DISCONNECT EMPLOYEE FROM DEPT-EMPLOYEE. *** REOBTAIN NEW DEPARTMENT USING SAVED DB-KEY *** FIND DEPARTMENT USING TEMP-DEPT-DBKEY. CONNECT EMPLOYEE TO DEPT-EMPLOYEE. *** RELEASE ALL LONGTERM LOCKS *** KEEP LONGTERM ALL RELEASE. MAP OUT USING DCTEST03 OUTPUT DATA IS ATTRIBUTE MESSAGE IS EMP-CONNECTED-MESS LENGTH 80. DC RETURN NEXT TASK CODE CHNGSHOW.
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:
- Request DC to begin monitoring database concurrent access for the specified record occurrence by issuing a KEEP LONGTERM statement that includes the NOTIFY parameter.
- Begin the pseudoconverse by issuing a DC RETURN statement.
Steps After the Pseudoconverse
In subsequent tasks, perform the following steps:
- 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:
- 0- The record was not accessed.
- 1- The record was obtained.
- 2- The record was modified.
- 4- The record's prefix was modified by a CONNECT or DISCONNECT operation.
- 8- The record was logically deleted.
- 16- The record was physically deleted.
- 32- The status of the record is uncertain.
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. - If necessary, issue a KEEP LONGTERM statement with the UPGRADE parameter to place a longterm explicit lock on the specified record.
- Access the database, as required.
- 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 ***