× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Charles,

I think that, if you need to retrieve the IDENTITY_VAL_LOCAL value BEFORE
the record is really inserted, you could be opening the proverbial can of
worms. From the V5R3 SQL Reference Manual, page 260 :
----------------------------------
<SNIP>

The value returned is the value that was assigned to the identity column of
the table identified in the most recent INSERT statement for a table
containing an identity column. The INSERT statement has to be issued at the
same level; that is, the value has to be available locally within the level
at which it was assigned until replaced by the next assigned value. A new
level is initiated when a trigger, function, or stored procedure is invoked.
A trigger condition is at the same level as the associated triggered action.


The assigned value can be a value supplied by the user (if the identity
column is defined as GENERATED BY DEFAULT) or an identity value that was
generated by the database manager.

The result can be null. The result is null if an INSERT statement has not
been issued for a table containing an identity column at the current
processing level. This includes invoking the function in a before or after
insert trigger.
*

Invoking the function within the trigger condition of an insert trigger

*The result of invoking the IDENTITY_VAL_LOCAL function from within the
condition of an insert trigger is the null value.

---------------------------------------------
So, at best, it seems to me that *maybe* your result would be null... (At
least as I can best interpret the manual)

Regards,


Luis Rodriguez
IBM Certified Systems Expert — eServer i5 iSeries


On Thu, Mar 11, 2010 at 9:59 AM, Charles Wilt <charles.wilt@xxxxxxxxx>wrote:

Luis,

I could do that, or I could simply do the trigger as an RPG program.
Thought it'd need to be SQLRPGLE in order to use the
Identity_value_local() function.

Charles

On Thu, Mar 11, 2010 at 8:47 AM, Luis Rodriguez <luisro58@xxxxxxxxx>
wrote:
Charles,

Just a wild guess but, What happens if, inside your SQL trigger, you call
a
RPG program with the required writes/updates?

Regards,

Luis Rodriguez
IBM Certified Systems Expert — eServer i5 iSeries


On Thu, Mar 11, 2010 at 8:40 AM, Charles Wilt <charles.wilt@xxxxxxxxx
wrote:

All,

I was putting together a Before Insert SQL Trigger and was suprised to
learn that it can't use the INSERT or UPDATE statements...you get an
SQL0751 error:

-- Statements not allowed in an SQL BEFORE trigger are INSERT, UPDATE,
DELETE, ALTER TABLE, COMMENT ON, CREATE, DROP, GRANT, LABEL ON, RENAME,
REVOKE, REFRESH TABLE, and ALTER PROCEDURE.

What I was trying to do (error handling omitted, also note FILEB has
an identity column FILEB_ID)

create trigger FILEA_BEFORE_INSERT
before insert on FILEA
referencing NEW ROW as new_row
for each row mode DB2ROW

begin
if new_row.fileb_id = 0 then
insert into FILEB (fld1, fl2, fld3)
values (new_row.fld1, new_row.fld2, new_row.fld3);
new_row.fileb_id = indentity_val_local();
else
update FILEB
set (fld1, fld2, fld3) = (new_row.fld1, new_row.fld2, new_row.fld3)
where FILEB_ID = new_row.FILEB_ID;
end if;
end

I guess I'm going to have to use RPG for the trigger?

Charles
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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

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.