Kbase 6030: SAMPLE CODE Getting the "next" batch number LOCK
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
SAMPLE CODE Getting the "next" batch number LOCK
920116-elp01/* This sample program can be used when you have a file
in the database which is being used as a control number
to single thread the incremental numbering of records,
such as for sequentially numbered invoices. It manages
record contention gracefully when there are two users
trying each to get "the next" invoice or batch number. */
define buffer bbuf for batchfile.
/* Add a file BATCHFILE to the demo database.
Add the field "b-num" as integer to BATCHFILE.
Add the field "b-desc" as char to BATCHFILE.
Add the primary index "batch-i1" on b-num to BATCHFILE.
INSERT some BATCHFILE records.
for each batchfile:
display batchfile.
end. */
do for batchfile transaction:
create batchfile.
assign b-num = -1 * int(recid(batchfile)).
/* insert batchfile processing here */
assign b-desc = "NEW REC".
GET-NUM:
do for bbuf while not available bbuf:
find last bbuf exclusive-lock where recid(bbuf) NE recid(batchfile)
USE-INDEX batch-i1 no-wait no-error.
if not available bbuf
then do:
if locked bbuf
then do:
message "Getting batch number. Please wait.".
next GET-NUM.
end.
else do: /* batchfile record isn't locked and can't be ambiguous,
so it must not be there yet. */
assign batchfile.b-num = 1. /* first time through */
leave get-num.
end.
end.
else do:
batchfile.b-num = bbuf.b-num + 1.
leave get-num.
end.
end.
end.
Progress Software Technical Support Note # 6030