|
As Birgitta said, a before insert is what you want.
I do have to ask though. Why not use an identity column and have the
system autoincrement it for you?
Create table...
myKeyColumn int as identity,
...
Or perhaps a sequence object? Below is a tested example of sequence
created with "Run SQL Scripts":
set current schema rob;
create or replace sequence NextKey;
create table scuzz (
myKeyColumn int as identity,
SomeOtherColumn char(5),
CounterNumber int);
insert into scuzz
(SomeOtherColumn, CounterNumber)
values ('A', next value for NextKey);
insert into scuzz
(SomeOtherColumn, CounterNumber)
values ('B', next value for NextKey);
select * from scuzz;
you will see:
1, A, 1
2, B, 2
values previous value for NextKey;
You will see: 2
If you want to know what object it creates try DSPDTAARA. It's rather
complex though.
Data area . . . . . . . : NEXTKEY
Library . . . . . . . : ROB
Type . . . . . . . . . : *CHAR
Length . . . . . . . . : 2000
I think it uses all that space to keep track of last accessed information.
Rob Berendt
--
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to: 2505 Dekko Drive
Garrett, IN 46738
Ship to: Dock 108
6928N 400E
Kendallville, IN 46755
http://www.dekko.com
From: Steve Jones <sjones@xxxxxxxxxxxxxxx <javascript:;>>
To: rpg400-l@xxxxxxxxxxxx <javascript:;>
Date: 05/04/2017 09:13 AM
Subject: Trigger pgm to increment seq# in file
Sent by: "RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxx <javascript:;>>
We have a file that contains a sequence number for each unique key in the
file, file is defined like this:
Filea:
Field1 (key1)
Field2 (key2)
sequence number (starts at 1)
We want to have a trigger program fire when a record is added to set the
sequence number of the new record to be the next #.
So I tried adding a trigger with trigger time of *after & event *insert,
that fails because the record is still in use.
Seems like a simple idea, but we are missing something.
Thanks
--
Steve Jones
H-P Products, Inc
330-871-2054
--
NOTE: The information in this email is confidential and may be legally
privileged. If you are not the intended recipient, you must not read, use
or disseminate the information; please advise the sender immediately by
reply email and delete this message and any attachments without retaining
a
copy. Although this email and any attachments are believed to be free of
any virus or other defect that may affect any computer system into which
it
is received and opened, it is the responsibility of the recipient to
ensure
that it is virus free and no responsibility is accepted by H-P Products,
Inc. for any loss or damage arising in any way from its use.
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx <javascript:;>
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx <javascript:;>
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx <javascript:;> for any subscription
related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx <javascript:;>
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx <javascript:;>
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx <javascript:;> for any subscription
related questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD
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.