Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Creating an auto-increment trigger

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating an auto-increment trigger

    Add the trigger program with a "Trigger Time" of *BEFORE on a "Trigger Event of *INSERT" and "Allow Repeated Change" is *YES. Then have the trigger program modify the RECNO field position in the "NEW RECORD BUFFER". Hope this helps, Jerry Hensley Farm Credit Bank

  • #2
    Creating an auto-increment trigger

    Thanks so much. I failed to use "Allow Repeated Change" = *yes. That's what I needed and now it works! Thanks again!

    Comment


    • #3
      Creating an auto-increment trigger

      I'm trying to do the same exact thing here. Does anyone have any code examples of this kind of trigger?

      Comment


      • #4
        Creating an auto-increment trigger

        Here is a sample program for this type of trigger. It uses a data area rather than a file to track the next sequential number.
         *----------------------------------------------------------- * Data Area EmployeeDA contains the last employee number * used. *----------------------------------------------------------- DEmployeeDA DS Dtaara(EmployeeDA) D Last# 9S 0 * DpBefore S * DpAfter S * * DBefore E DS ExtName(EMPLOYEE) Prefix(B_) D Based(pBefore) DAfter E DS ExtName(EMPLOYEE) Prefix(A_) D Based(pAfter) D* *----------------------------------------------------------- * Trigger Buffer and Trigger Buffer Length Declarations *----------------------------------------------------------- DBufferLen S 10I 0 DTrigBuff DS D TrigFile 10A File Name D TrigLib 10A File Library D TrigMbr 10A File Member D TrigEvent 1A Trigger Event D TrigTime 1A Trigger Time D TrigCommit 1A Commit Control Lvl D TrigRes1 3A Reserved 1 D TrigCCSID 10I 0 CCSID D TrigRRN 10I 0 Current RRN D TrigRes2 4A Reserved 2 D TrigB4OS 10I 0 Before Image Offset D TrigB4Len 10I 0 Before Image Offset D TrigB4NBM 10I 0 Before Null Byte Map D TrigB4NBL 10I 0 Before Null Byte Len D TrigAftOS 10I 0 After Image Offset D TrigAftLen 10I 0 After Image Offset D TrigAfNBM 10I 0 After Null Byte Map D TrigAfNBL 10I 0 After Null Byte Len *----------------------------------------------------------- * Trigger Constants *----------------------------------------------------------- D@Insert C '1' D@Delete C '2' D@Update C '3' D@Before C '2' D@After C '1' *------------------------------------------------------------ * Input parameters are passed automatically when the trigger * fires. Passed are the trigger buffer and trigger buffer length. *------------------------------------------------------------ C *Entry PList C Parm TrigBuff C Parm BufferLen * *------------------------------------------------------------ * Map the data structures for the before and after images to * the offset location in the trigger buffer using pointers. *------------------------------------------------------------ C Eval pBefore = %Addr(TrigBuff) + TrigB4OS C Eval pAfter = %Addr(TrigBuff) + TrigAftOS * *------------------------------------------------------------ * Only assign employee number on inserts. *------------------------------------------------------------ C If TrigEvent = @Insert *------------------------------------------------------------ * Get the last employee number from the data area. Increment * it and update data area and trigger buffer with new number. *------------------------------------------------------------ C *Lock In EmployeeDA C Eval Last# = Last# + 1 C Out EmployeeDA C Eval A_EMEMP# = Last# C Endif * C Return 

        Comment


        • #5
          Creating an auto-increment trigger

          I would like to create a trigger program that automatically assigns the next sequential number to a field called RECNO just prior to adding the record to a file. RECNO will be the primary key. I will store the last recno used in another file. I've used trigger programs before but not to change the data in the record that caused the program to be triggered. How do I do this? Thanks, Tom Tufankjian

          Comment

          Working...
          X