Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File trigger

Status
Not open for further replies.

WP

Programmer
Nov 30, 1999
463
0
0
CH
I want to prevent a file from being updated if a certain condition is met.

I only have the file's *UPDATE trigger event to work with as the program that does the update is from a vendor and a program change would just be too long.

Is there a way to suppress the update using the BEFORE update event trigger?

Bill Paton


Check out
 
I don't think so.

A trigger program gets a copy of the record in the DS block. You cannot do any further updates for the record that activated the trigger. And I do not know of any call or setting you can make to prevent the original action being completed.

If there is something you can set to stop the update taking place, I guess this would only work if the trigger time is set as *BEFORE anyway. If it's *AFTER then the update would already have been done before your trigger program is running.

You can't do anything else with the record inside the trigger (sort of like a lock condition), but perhaps you could code your trigger program to pass the *BEFORE and *AFTER images out to a separate process, which must run after the trigger program has completed, which could then do an undo of the trigger change after the original event. But that will generate another trigger action! So you'd need to somehow prevent this or somehow recognise the undo action and not call the undo for an undo (!)

If nobody else knows of a cancel-trigger-action method then I'm afraid you've got some work ahead of you...
 
Woah! Why do I always remember stuff AFTER I've hit the 'Send' button?!

I just remembered the ALWREPCHG parameter. If you set this to *YES then you can make further changes to the record.

So if the trigger event is *AFTER then you can presumably do a second update to the record writing out the *BEFORE image you extracted from the trigger data. I am not sure if this would generate another trigger request though, if it did you'd need to code for this so you don't undo the undo.

The trigger event must be *AFTER though, not *BEFORE.
 
Hi Bill, how's it hangin' ? Long time no see!

If you were doing the change under commitment control you could do a roll back, but I suppose that still means mod'ing the other program. krg400s idea about using the ALWREPCHG parameter sounds good. Since the *AFTER *UPDATE trigger has both the before and after images of the record you would be able to put it back to it's previous values.

Shame it's not like VB - the Record_BeforeUpdate event has a Cancel parameter which will stop the update just by setting it to false.

PeteJ
(Contract Code-monkey)

It's amazing how many ways there are to skin a cat
(apologies to the veggies)
 
Thanks for the responses.

Good to here form you Pete. Yeah, things are going good - heavily into RPG ILE at the moment, all backend file processing for web stuff and still in London. Drop me a mail and let me know what's happening with you.

I solved my problem by forcing the the trigger to fail. Within the *BEFORE *UPDATE trigger program when my condition is met I send a program message. The severity of the message causes the trigger program and the internal database update to fail. Perfect.

WP

Bill Paton


Check out
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top