There is no need to convert everything into SQL.
If the identity column is generated always, the new identity value is
determined correctly when writing a new record.
If you perform an SQL SET statement, with IDENTITY_VAL_LOCAL, the identity
value of your write operation.
Exec SQL SET :LastId = Identity_Val_Local;

We use this conjunction WRITE in RPG and Identity_Columns and
IDENTITY_VAL_LOCAL since years without any problems

Determining the highest identity value in the table with SQL might not be
the best idea, because in between your write and determining the highest
value an other program or job could have been written an other row.
With Identity_Val_Local you'll really get the Identity value of your WRITE
(even if a trigger gets fired that writes an other row into the same table
with a new identity).

Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)

-----Ursprüngliche Nachricht-----
Von: RPG400-L [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im Auftrag von Peter
Gesendet: Wednesday, 31.8 2016 23:03
An: rpg400-l@xxxxxxxxxxxx
Betreff: Re: Identity columns and RLA

Thanks Vern. I'm thinking I'll change the program to just use SQL for
everything, since it's simpler. But I was curious about mixing RLA and SQL.

On 8/31/2016 1:16 PM, Vernon Hamberg wrote:
There's an IDENTITY_VAL_LOCAL function you can use to get the last
assigned - it'd be an SQL statement, like SET or VALUES


On 8/31/2016 3:05 PM, Peter Dow wrote:
What happens when writing a record with RLA to a table that has an
identity column?

Assuming it actually works, i.e. ignores the value in the identity
column on the WRITE, is there a way to get the value assigned to the
identity column?

*Peter Dow* /
Dow Software Services, Inc.
909 793-9050
petercdow@xxxxxxxxx <mailto:petercdow@xxxxxxxxx>
pdow@xxxxxxxxxxxxxx <mailto:pdow@xxxxxxxxxxxxxx> /

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2020 by 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].