RRN in trigger.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DB2newbie
    New Member
    • Sep 2013
    • 2

    RRN in trigger.

    Hi all,
    I am currently working in a scenario where, I had to write trigger(insert, update and delete) for a certain table in DB2 database(DB2 for i V5R4).
    The table have no primary key, but I need one to identify the records.
    The application is legacy and hence I cannot expect the client to change the DB structure.
    Hence I tried to use RRN( Relative Record Number) in my trigger.
    Here is the trigger I wrote.
    Code:
     
    CREATE TRIGGER "CMB"."CASPR_I" 
    	AFTER INSERT ON "CMB"."CASPR"
    	REFERENCING  NEW AS NEW_ROW
    	FOR EACH ROW MODE DB2SQL
    BEGIN ATOMIC
    DECLARE RID DECIMAL(15,0);
    SET RID=NEW_ROW.RRN("CMB"."CASPR");
    	 INSERT INTO "CMB"."AS400_CASPR" (ROW_ID,PREFIX,GEN_ACTION,GEN_DATE)
    		 VALUES(RID,NEW_ROW.PREFIX,'INSERT',CURRENT DATE);
    END
    I read that RRN is stored in static section of trigger buffer, but I couldn't figure out how to use it.
    I need some serious help.

    Regards.
  • Mr Kumar
    New Member
    • Sep 2013
    • 1

    #2
    I think this PDF could help to fix it http://publib.boulder.ibm.com/infoce.../dbp/rbafo.pdf

    Comment

    • DB2newbie
      New Member
      • Sep 2013
      • 2

      #3
      Mr. Kumar,
      Thanks for you reply.
      I had seen the document earlier, but it doesn't specify any way to access the RRN. Please share any examples,if any.
      Regards.

      Comment

      Working...