I have pgmA which calling by 50 programs.pgmA has detail file in input mode..some of the 50 calling programs has detail file in update mode .as per new requirement, I will get the detail file records in PGMA in XML format..that needs to be breaked and updated..parsing is fine but I am worrying about updating detail file in PgmA because calling programs may locks record and further I may get issue with locked by same job ! Analayzing those programs also bit difficult because they are calling PgmA multiple times and code is vast and old..any suggestion how to update detail file with out having lock...suggest me any solution..
-
2are you using commitment control? That complicates record locks since the locks are held until the entire transaction is committed. Run `DSPRCDLCK` periodically to see how frequently records are locked. You can even run that command in batch and print the output. Then you could get some idea of how long record locks are held. Theoretically, many jobs can update the same file at the same time. Default wait time is 15 seconds to read a locked record. Which is plenty of time as long as other jobs are not retaining their locks. – RockBoro Oct 11 '21 at 16:26
1 Answers
The short answer is: You can't update a record without locking it first.
But you can adjust your locking scheme to minimize the effect of locking. You may need to do this in the 50 programs that call pgmA. The approach is to read the record to be updated without a lock, do your processing, then just before updating, read it again, this time with the lock. That way if your processing is long running (usually something with user input) the lock time is minimized.
Often an update id is stored in each record which is just a sequential number to help detect changes made to the record by another process between the first and second read of the record. Another way to detect these changes is to store the record in a data structure with the first read, and then compare the initial read to the second read before updating.
So with RLA processing it looks something like this:
chain(n) (key:fields) file old;
if %found(file);
// process record
chain (key:fields) file new;
if %found(file);
if new <> old;
// record changed between reads - reprocess
else;
// apply changes to new
update record new;
endif;
else;
// record deleted between reads - reprocess
endif;
endif;

- 11,030
- 31
- 59