-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John,

Here's the source. If you'll send me your email privately, I'll forward
the document that goes with it.

- --
Pete Hall
pete@xxxxxxxxxxxxxx

/TITLE TRIGGER ** Trigger program shell **

* Replace <PFile> with physical file name

* If RPG record I/O is used to update ancillary files
* Replace <AFile> with ancillary file name. Otherwise,
* delete <AFile> and the *INZSR subroutine

* If embedded SQL is used to update ancillary tables in
* this trigger, compile the program with the
* COMMIT(*NONE) option. SQL will then adopt the
* commitment behavior of the job or activation level.
* See the DB2 UDB for AS/400 SQL Reference subsection
* titled "Notes" in the section covering "COMMIT"
* for an explanation of exactly how this works.

* ---------------------------------------------
* Ancillary files
* ---------------------------------------------
F<AFile> UF A E K DISK Commit(RunCommit) UsrOpn

* ---------------------------------------------
* Entry Parameters
* ---------------------------------------------
DBuffer DS 32767
D PFName 10
D PFLibrary 10
D PFMember 10
D TrgEvent 1
D TrgTime 1
D TrgCmtLvl 1
D 3
D TrgCCSID 10U 0
D 8
D OrOffset 10U 0
D OrRcdLen 10U 0
D OrNBMapOfs 10U 0
D OrNBMapLen 10U 0
D NwOffset 10U 0
D NwRcdLen 10U 0
D NwNBMapOfs 10U 0
D NwNBMapLen 10U 0

DBufferLen S 10U 0

* ---------------------------------------------
* Original Record
* ---------------------------------------------
D@OrRecord S * Inz(*Null)

DOrRecord E DS ExtName(<PFile>) Prefix(OR_)
D Based(@OrRecord)

* ---------------------------------------------
* New Record
* ---------------------------------------------
D@NwRecord S * Inz(*Null)

DNwRecord E DS ExtName(<PFile>) Prefix(NW_)
D Based(@NwRecord)

* ---------------------------------------------
* Constant Definitions
* ---------------------------------------------
* Commit Levels
DCL_NONE C '0'
DCL_CHG C '1'
DCL_CS C '2'
DCL_ALL C '3'

* Null byte status
DNB_NOTNULL C '0'
DNB_NULL C '1'

* Trigger events
DTE_INSERT C '1'
DTE_DELETE C '2'
DTE_UPDATE C '3'

* Trigger times
DTT_AFTER C '1'
DTT_BEFORE C '2'


C *ENTRY plist
C parm Buffer
C parm BufferLen


* ---------------------------------------------
* Main-line Procedure
* ---------------------------------------------

* Assign the record templates to their data space
C eval @OrRecord = %Addr(Buffer) + OrOffset
C eval @NwRecord = %Addr(Buffer) + NwOffset

* Execute the correct procedure based on trigger event
C TrgEvent caseq TE_INSERT DoInsert
C TrgEvent caseq TE_DELETE DoDelete
C TrgEvent caseq TE_UPDATE DoUpdate
C endcs

C return

* ---------------------------------------------
* Process a delete event
* ---------------------------------------------
CSR DoDelete BEGSR


CSR ENDSR

* ---------------------------------------------
* Process an insert event
* ---------------------------------------------
CSR DoInsert BEGSR


CSR ENDSR

* ---------------------------------------------
* Process an update event
* ---------------------------------------------
CSR DoUpdate BEGSR


CSR ENDSR

* ---------------------------------------------
* Program Initialization
* ---------------------------------------------
CSR *INZSR BEGSR

C eval RunCommit = (TrgCmtLvl > CL_NONE)
C open <AFile>

CSR ENDSR




On 2011-05-10 18:54, jmmckee wrote:
Seeing a working example would be helpful. Thanks.

John McKee
-----Original message-----
From: Pete Hall pete@xxxxxxxxxxxxxx
Date: Tue, 10 May 2011 18:09:13 -0500
To: midrange-l@xxxxxxxxxxxx
Subject: Re: Creating a trigger program

On 2011-05-09 21:56, jmmckee wrote:
We are looking into a process to notify doctors, via email, when one of their patients has been admitted. When a patient is admitted, a record is written to a log file. Current idea being tossed around is to read the log file from the previous day and srnd emails as needed. I thought this might be an ideal application for a trigger program. I could see the trigger getting fired on a write to the log file. All I would want to do is pass the data to be written to a program and the program would either send or not send an email. From looking at some documentation, I see that there is space for a before and an after image.

These sound like dumb questions to me: Is it as simple as referencing the log file as an external data structure? Then, moving the after image to that data structure?

John McKee


The old and new record images (for inserts, the old image is invalid)
are available in the trigger. I've got a (very old) RPG trigger template
you could have if you like. All you really need to do is name the data
structures for the trigger buffer and code the action you want to occur.
I've been using it for years with no issues. I've even got a document
somewhere that describes how it works. Let me know...

- --
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk3LIXsACgkQXczQcKdXKg7GqgCfcm18/SyK3WT5YAX05/Ie1Y42
TCgAnRWrwUBi9uxiq6t7/XwpWuR4VK3C
=tf8V
-----END PGP SIGNATURE-----

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2019 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].