|
Let me try a different example and you tell me if we're thinking the same
thing now.
create table ordhead (
Ordernumber int as identity,
customernumber int,
primary key(ordernumber))
;
insert into ordhead (customernumber) values(2);
Now you're thinking "Hey I need to know that new order number!". So you
do this instead
select ordernumber
from final table (insert into ordhead (customernumber) values(27));
And now you'll back the newly generated order number. In our case, a 2.
Basically you just wrap your insert with this "select ... from final
table" stuff.
Now, let's add a line to this order.
create table ordline (
ordernumber int not null,
orderline int not null,
itemNumber int,
ordqty dec (15,5),
constraint ordline_ordheadFK foreign key (ordernumber) references ordhead
(ordernumber)
);
insert into ordline (
ordernumber,
orderline
itemNumber,
ordqty)
values (
:NumberRetrievedFromSelectFromFinalTable,
1,
4,
2.3);
And, since you could have
ordernumber orderline
1, 1
1, 2
1, 3
2, 1
2, 2
You want to know how you can get this order line sequence to auto
increment?
Good luck with that...
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>
To: "RPG programming on the IBM i (AS/400 and iSeries)"
<rpg400-l@xxxxxxxxxxxx>
Date: 05/04/2017 11:18 AM
Subject: Re: Trigger pgm to increment seq# in file
Sent by: "RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxx>
The sequence is based on a field in the file, so there could be multiple
records with same seq# Example file would be FieldA, Seq
File:
FieldA = "TEST" Seq = 1
FieldA = "TEST" Seq = 2
FieldA = 'ROB' Seq = 1
FieldA = 'STEVE' Seq = 1
On Thu, May 4, 2017 at 11:12 AM, Rob Berendt <rob@xxxxxxxxx> wrote:
I don't understand your question.the
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>
To: "RPG programming on the IBM i (AS/400 and iSeries)"
<rpg400-l@xxxxxxxxxxxx>
Date: 05/04/2017 11:05 AM
Subject: Re: Trigger pgm to increment seq# in file
Sent by: "RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxx>
Never saw a identity column before, that would be perfect.
Can the number be based on like key field? In your example:
1, A, 1
1, A, 2
2, B, 1
On Thu, May 4, 2017 at 10:18 AM, Rob Berendt <rob@xxxxxxxxx> wrote:
As Birgitta said, a before insert is what you want.information.
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
the
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>
To: rpg400-l@xxxxxxxxxxxx
Date: 05/04/2017 09:13 AM
Subject: Trigger pgm to increment seq# in file
Sent by: "RPG400-L" <rpg400-l-bounces@xxxxxxxxxxxx>
We have a file that contains a sequence number for each unique key in
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
*insert,sequence number of the new record to be the next #.
So I tried adding a trigger with trigger time of *after & event
legallythat 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
byprivileged. If you are not the intended recipient, you must not read,use
or disseminate the information; please advise the sender immediately
whichreply email and delete this message and any attachments withoutretaining
aof
copy. Although this email and any attachments are believed to be free
any virus or other defect that may affect any computer system into
Products,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
(RPG400-L)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
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx 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)
usemailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD
--
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,
or disseminate the information; please advise the sender immediately byretaining
reply email and delete this message and any attachments without
aof
copy. Although this email and any attachments are believed to be free
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
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx 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
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx for any subscription related
questions.
Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD
--
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
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx 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
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.
Please contact support@xxxxxxxxxxxx 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.