× 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.



Are you at V5R2?  Lose the trigger and use either:

        1. ROWID data type.
        2. IDENTITY column attribute.

If not use the age old proven method of the data area to handle the
sequence assignment.


-----Original Message-----
From: Mark Adkins [mailto:adkinsm@xxxxxxxxxx] 
Sent: Wednesday, April 30, 2003 3:12 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: SQL "SERIAL" field work around with a trigger.


I want to set up a serial field that auto-increments when you insert a
new
record.  For a table that has two fields SEQUENCE BIGINT, DATTIM
TIMESTAMP.
If I insert/write the values (0, CURDATE) and the last sequence number
was
100, it would insert a record as 101.  I would then use my timestamp to
chain the record to get the sequence number created.  I didn't readily
find
a way to alter the record buffer on an RPG trigger, but an SQL trigger
did
the trick.

CREATE TRIGGER TransactionBeforeTrigger BEFORE INSERT ON TEST
REFERENCING NEW AS new_row
FOR EACH ROW MODE DB2ROW
BEGIN
  IF NEW_ROW.SEQ = 0 THEN
   SET NEW_ROW.SEQ =
       (SELECT IFNULL(MAX(SEQ),0) + 1 FROM TEST);
  END IF;
END

The problem I have is locking the table so only one process tries to
write
a seqence number at a time.  If I add, "LOCK TABLE TEST IN EXCLUSIVE
MODE
ALLOW READ;", it never releases the lock and eventually crashes.  Any
ideas?

Regards,

Mark

_______________________________________________
This is the RPG programming on the AS400 / 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.cgi/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.



As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.