Hi all,
Quick question, is using lock statements (no-lock, exclusive-lock) when doing searches on temp tables considered bad coding standards? See example below. Now before anyone says anything note the below is a simple example for illustrative purposes only.
I know using locking with temp-tables is unnecessary, but I prefer to have them for two reasons.
1) It helps anyone re-reading the code at a later date determine quickly if a block or procedure is reading or updating a temp table.
2) I was told as a young developer that omitting no-lock and exclusive-lock when doing temp-table updates was a bad habit to get into. That it would lead to you forget them when it came to actual database tables. Whether right or wrong, I guess it is something that has stayed with me since then.
Where I work now a lot of the developers are completely against using locks with temp-tables. They say:
a) It looks terrible.
b) Using locks with temp-tables the below creates unnecessary locking entries in the system tables and uses unnecessary system resources which if they are omitted are not used.
Is b) above correct.
Are there any guidelines on use of locking and temp tables? As I'm beginning to wonder if I am in a minority of 1 here.
Quick question, is using lock statements (no-lock, exclusive-lock) when doing searches on temp tables considered bad coding standards? See example below. Now before anyone says anything note the below is a simple example for illustrative purposes only.
Code:
DEFINE TEMP-TABLE tt-customerReport NO-UNDO
LIKE customer
FIELD importantCustomer as logical.
FOR EACH customer NO-LOCK:
CREATE tt-customer.
BUFFER-COPY customer to tt-customerReport
END.
FOR EACH tt-customerReport [B]EXCLUSIVE-LOCK [/B]:
FOR EACH order WHERE order.customer-no = tt-customerReport
AND order.order-value > 1000000
NO-LOCK:
ASSIGN tt-customer.importantCustomer = TRUE.
END.
END.
I know using locking with temp-tables is unnecessary, but I prefer to have them for two reasons.
1) It helps anyone re-reading the code at a later date determine quickly if a block or procedure is reading or updating a temp table.
2) I was told as a young developer that omitting no-lock and exclusive-lock when doing temp-table updates was a bad habit to get into. That it would lead to you forget them when it came to actual database tables. Whether right or wrong, I guess it is something that has stayed with me since then.
Where I work now a lot of the developers are completely against using locks with temp-tables. They say:
a) It looks terrible.
b) Using locks with temp-tables the below creates unnecessary locking entries in the system tables and uses unnecessary system resources which if they are omitted are not used.
Is b) above correct.
Are there any guidelines on use of locking and temp tables? As I'm beginning to wonder if I am in a minority of 1 here.