Can AS/400 trigger program read the file of the trigger itself?

Tags:
AS 400
AS/400 triggers
I wrote a trigger program on a file. Can this program read/use this file itself? In case of an ADD in the file I have to read the last record of the file, is this possible?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Short answer: Yes, the trigger can gain access to every record in the file except the one that caused it to be invoked.

Longer answer: This is because that record is still locked by the application that is updating it. I suspect on ADD you want to generate the key value by adding 1 to the last record, am I correct? Something like *HiVal SetLL, ReadP, Key +=1. ? Be aware that the ‘current’ last record might be locked by another application so you will need to do ReadP(N) for read-only access.
I have written dozens of triggers, including some that do a BoM explosion of components back into the same file. Never bothered with a read trigger though…

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Splat
    Why do you need to access the last record in the file?
    12,915 pointsBadges:
    report
  • ToddN2000
    Strange request. How is the file set up, is it last record by RRN or by key? Is the trigger fired on a before or after? More specific details would help us understand the task.
    134,585 pointsBadges:
    report
  • azohawk
    I would need to understand why the trigger program would need to access the file record. If the trigger program fires on a read, then reads the file; I would expect an endless loop situation with potential for record lock issues against itself. Haven't worked a lot with trigger programs, but this seems like a recipe for disaster.
    4,055 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: