Trigger Question - IBM AS400

This is a discussion on Trigger Question - IBM AS400 ; Hi all I have some new totals that I wish to add to a record and as it is added/updated in a number of places I thought it might be a good time to start using triggers. If I add ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Trigger Question

  1. Trigger Question

    Hi all

    I have some new totals that I wish to add to a record and as it is
    added/updated in a number of places I thought it might be a good time
    to start using triggers.

    If I add record A to SODET the trigger "add" program will update the
    new fields in record A. As an update has taken place to record A will
    this cause the SODET trigger "update" program to be called? I'm
    concerned about looping.

    Thanks, in advance, for your help.

    Cheers,
    Neil


  2. Re: Trigger Question

    On Jun 20, 9:18 am, Newbie_Neil wrote:
    > Hi all
    >
    > I have some new totals that I wish to add to a record and as it is
    > added/updated in a number of places I thought it might be a good time
    > to start using triggers.
    >
    > If I add record A to SODET the trigger "add" program will update the
    > new fields in record A. As an update has taken place to record A will
    > this cause the SODET trigger "update" program to be called? I'm
    > concerned about looping.
    >
    > Thanks, in advance, for your help.
    >
    > Cheers,
    > Neil


    I cant comment on sql triggers but the addpftrg command can run a
    program in any of 6 situations: before or after any of add,update or
    delete. So if your program is adding a record & you need to make
    adjustments before its added to the db you can run your trigger before
    add. In this case sending a cpf message back to the calling program
    vetoes the add to database so you can also use it for verification. If
    your program updates other records in the same file when a record is
    written then the trigger would run after add & updates to the file
    should not call the trigger. If you need to make upadtes to a file
    based on updates then yes the trigger will fire recursively - however
    there is a parameter which I think prevents that in the addpftrg
    commend. I would think you can in any case determine if this is the
    result of a trigger by examining the before & after images unless your
    logic is too convoluted. In that case I would write a record off to a
    transaction file of some sort which must be read by a batch job which
    could set a data area in qtemp which the trigger picks up & reads to
    indicate no further processing. If yuor programs are likely to
    rollback at any point you can pick up the current comit control status
    of the file & open any other files in the same transaction so they all
    commit/rollback together. We have a number of files using triggers.
    Its impossible to remove the trigger program to update it with a
    bugfixed version if its called by a trigger until the user closes &
    unlocks the file. Our cunning plan was to intorduce a higher level
    general trigger program which figured out which program to call &
    passed the appropriate parameters. This has the advantage of hiding
    the pointer maths in one place.

    HTH
    Jonathan


  3. Re: Trigger Question

    On Jun 20, 4:18 am, Newbie_Neil wrote:
    > Hi all
    >
    > I have some new totals that I wish to add to a record and as it is
    > added/updated in a number of places I thought it might be a good time
    > to start using triggers.
    >
    > If I add record A to SODET the trigger "add" program will update the
    > new fields in record A. As an update has taken place to record A will
    > this cause the SODET trigger "update" program to be called? I'm
    > concerned about looping.
    >
    > Thanks, in advance, for your help.
    >
    > Cheers,
    > Neil


    If you are updating the record just written using a trigger, adding
    ALWREPCHG(*YES) to ADDPFTRG command will solve your problem.


  4. Re: Trigger Question

    Hi both

    Thank you for your replies. We're writing rpg triggers.

    > If you are updating the record just written using a trigger, adding
    > ALWREPCHG(*YES) to ADDPFTRG command will solve your problem.


    Problem solved.

    Thanks again,
    Neil


+ Reply to Thread