Sequential Part Number Generator...with a twist
Darren Reely
darren_reely@latticesemi.com
Fri, 18 Feb 2000 10:59:04 -0800
Chris,
If you have a relational database then you could adapt the following code.
It works for me. It does how ever allow for gaps in your actual records
because after the user fetches the number, they could exit the screen.
As for allowing the user to append to a field. I think if you display your
generated value, then the user could use control-B to bring it up to allow
them to tac on something to the end of it. Another solution might be to
display the two halfs separately, and if they don't want to enter the first
value, they could just hit return with confidence that a proper value will
be generated. A third silent field could be used to combine the first two
into your end result.
; Begin Code sample ------------------------------------------------------
;; We need an exclusive lock so we don't get confusing code conflicts or a
;; faulty attempt at using the same sequence number for a given lot prefix.
transaction mylock &
commit on update &
reserving for exclusive write last_seq_num in mfg &
wait
file last_seq_num in mfg designer transaction mylock for update
access via lot_prefix using TRUNC(received_lot_prefix) OPT ;optional
so we can
;get though
cleanly
file lot_step_summ in mfg designer ;Make sure new lot doesn't exist
.......
;;lock last_seq_num exclusive happening
get last_seq_num OPT
if ACCESSOK
then let t_seq_num = ilf_seq_num + 1
else begin
let lot_prefix of last_seq_num = trunc(received_lot_prefix)
let t_seq_num = 1
end
; We PUT the record back immediately so we don't end up with
; duplicate ILF numbers between different processes.
let ilf_seq_num of last_seq_num = t_seq_num
put last_seq_num reset
commit ;I think the put will also commit, just want to be sure
; End Code sample ------------------------------------------------------
Darren
P.S. I haven't yet used the above code in production. But running multiple
instances of a test screen show it all worked out fine. I guess I'm
saying: Use at your own risk.
Chris Gassett wrote:
>
> The users would like a sequentially generated field. The field is split
> into two sections XXXXX-XXX (Ex. 000012, 000013-001, 000014, 000014-001,
> etc.) and is handled with three variables. The first 5 characters is the
> field that is generated sequentially. In entry mode the user would hit the
> enter key and the next number would be generated automatically and the
> cursor would move to the last three digits and the dash in between would be
> displayed or the user can enter up to 5 digits of a previous record to
> append to the end of it with three additional characters. The user has the
> option to enter up to three characters or hit the enter key. If the enter
> key is pressed without entering data the dash disappears and the second
> field is left blank. My problem is if two people are accesssing this screen
> at one time two or more users can grab the same sequentially generated
> number. What I need to do is do commit the record after the second field of
> three characters is passed. If anyone knows of something remotely close to
> what I am attempting to do I would greatly appreciate the feedback. Thanks,
> Chris
> = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
> Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
> Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
> This list is closed, thus to post to the list, you must be a subscriber.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.