|
On Thu, 18 Sep 2003, Michael Naughton wrote: > > I have a file that has a numeric field that I want to use as a unique key > -- like an auto-increment field, but we're still at V5R1 :-(. I thought I > could do this with a trigger - simply set up a data area with the > last-used number, add the trigger program before the insert, and it could > read the data area, update the number, and put it in the field before the > record is stored. Yep, that's doable. > This seemed simple enough, but I can't get it to work. I've got a trigger > program, and I know it's running because I can see it in debug. I know > it's finding the data area because the counter there is getting updated. I > can even see in debug that the (new image of the ) field in the file is > getting the new value. But it's not being stored in the file -- all the > new records are showing up with zeros. I hope you're not actually issuing an UPDATE op-code to that file in a trigger program? (That would cause the trigger to, basically, call itself) > > Can this be done? If so, would someone give me a hint as to what I might > be doing wrong and/or point me to somewhere where I can learn more about > how this works? I haven't done this since we did our Y2K conversion (at the time I was on V3R2) so I'm a bit rusty, but this is what pops into my head: 1) the trigger must be a *BEFORE trigger. Otherwise, the record is already written before your trigger gets called. 2) You must specify ALWREPCHG(*YES) when adding the trigger to the file, otherwise it will not allow the trigger to change the data. 3) You need to make your changes in the "after" buffer that's passed to you as a parm. (don't use actual file op-codes in the trigger program)
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.