Hi,
I am looking for a method to implements transaction management (as in the DO TRANSACTION block keyword) in many programs.
I need to do this because there some table lock wait issue on some programs.
I have already found some technics to implements the locking, for example this kind of code block :
What I want to do here is to put this kind of code (or better, if you have any suggestion ) around the code where there are the Table update (typically : ASSIGN Table.field = value).
Basically I have 2 parts : lock and unlock
The thing is that I have many pieces of code where I should add TRANSACTION management.
I don't want to repeat the code itself everywhere (it will complexify the code reading), but want to put some kind of "generic" code call before and after Table update (multiple different tables are concerned by this).
What I have thought about :
- Procedures to achieve this :
=> But it implies to split the DO TRANSACTION block in 2 parts, which is not possible (???)
- Put some preprocessor constant to hold the lock and unlock code :
&GLOBAL-DEFINE lock-{&table} r-rowid = ROWID(Table). ~
DEFINE BUFFER Table FOR Table. ~
TRANS_LOCK: ~
...
In calling code :
But it seems that this is not possible to have preprocessor values on multiples lines and with spaces... each time when my preprocessor definition is executed before it is referenced in the calling, whcih result in errors.
Any suggestions is welcome.
For information : Progress 11.5.1, OS : Windows 7 .
Thanks in advance.
I am looking for a method to implements transaction management (as in the DO TRANSACTION block keyword) in many programs.
I need to do this because there some table lock wait issue on some programs.
I have already found some technics to implements the locking, for example this kind of code block :
Code:
/*lock part : */
r-rowid = ROWID(Table).
DEFINE BUFFER Table FOR Table.
TRANS_LOCK:
DO TRANSACTION ON ERROR UNDO, RETRY :
FIND CURRENT Table EXCLUSIVE-LOCK NO-WAIT.
FIND Table EXCLUSIVE-LOCK WHERE ROWID(Table) = r-rowid NO-WAIT.
IF NOT AVAILABLE(Table)
THEN DO:
IF LOCKED(Table)
THEN DO:
IF ( i-Retries >= i-Max-Nb-Retries-Lock )
THEN DO:
c-message = c-message + '[ERROR] Attempt To Retry Block [ TRANS_LOCK ] - ' + STRING(i-Max-Nb-Retries-Lock) + ' times - Leave [ TRANS_LOCK ] ' + CHR(13) + CHR(10).
UNDO TRANS_LOCK, LEAVE TRANS_LOCK.
END.
ASSIGN
c-message = c-message + '[ERROR] Table Record already locked !' + CHR(13) + CHR(10)
i-Retries = i-Retries + 1
c-message = c-message + '[WARNING] Table Record Locked - Retry Block [ TRANS_LOCK ] - Wait ' + STRING(de-Max-nb-seconds-waiting-Lock) + ' Sec - Nb Retry : ' + STRING(i-Max-Nb-Retries-Lock) + CHR(13) + CHR(10)
.
ETIME(YES).
DO WHILE(ETIME) < de-Max-nb-seconds-waiting-Lock :
READKEY PAUSE(0).
END.
ETIME(NO).
UNDO TRANS_LOCK, RETRY TRANS_LOCK.
END.
ELSE DO:
c-message = c-message + '[ERROR] Table Record not found !' + CHR(13) + CHR(10).
UNDO TRANS_LOCK, RETRY TRANS_LOCK.
END.
END.
/*end lock part.*/
/*DO SOME Table UPDATES*/
/*unlock part : */
FIND CURRENT Table NO-LOCK NO-WAIT.
END. /*TRANS_LOCK: DO TRANSACTION*/
/*end unlock part.*/
What I want to do here is to put this kind of code (or better, if you have any suggestion ) around the code where there are the Table update (typically : ASSIGN Table.field = value).
Basically I have 2 parts : lock and unlock
The thing is that I have many pieces of code where I should add TRANSACTION management.
I don't want to repeat the code itself everywhere (it will complexify the code reading), but want to put some kind of "generic" code call before and after Table update (multiple different tables are concerned by this).
What I have thought about :
- Procedures to achieve this :
Code:
RUN lock(BUFFER Table)
ASSIGN Table.field = value
RUN unlock(BUFFER Table).
- Put some preprocessor constant to hold the lock and unlock code :
&GLOBAL-DEFINE lock-{&table} r-rowid = ROWID(Table). ~
DEFINE BUFFER Table FOR Table. ~
TRANS_LOCK: ~
...
In calling code :
Code:
{&lock-Table}
ASSIGN Table.field = value
{&unlock-Table}
Any suggestions is welcome.
For information : Progress 11.5.1, OS : Windows 7 .
Thanks in advance.