I need to know how to create a CL trigger program. I've already read many documents, but I can't find any "how...
to" information. A trigger program in CL is the same as a trigger program in RPG. It receives two parameters when it is called by the triggering event -- a parameter of variable length, and a 4-byte binary value giving the length of the first parameter.
You can determine the size of the first parameter by reference to the following structure, which is in RPG/IV -- it can be translated into substringed CL variables:
IP@TBUF DS 9999 * Trigger buffer definition * Name of triggering file I 1 10 TEPFNM * Library name of triggering file I 11 20 T@LIBR * Member name of triggering file I 21 30 T@MBR * Trigger event (1/2/3 = Insert/Update/Delete) I 31 31 T@EVNT * Trigger time (1/2 = After/Before) I 32 32 T@TIME * Trigger commitment level I 33 33 T@CMTL * Filler I 34 36 T@FIL1 * Coded Character Set ID I B 37 400T@CSID * Filler I 41 48 T@FIL2 * Offset to old record image I B 49 520T@ORIO * Length of old record image I B 53 560T@ORIL * Offset to old null field map I B 57 600T@ONMO * Length of old null field map I B 61 640T@ONML * Offset to new record image I B 65 680T@NRIO * Length of new record image I B 69 720T@NRIL * Offset to new null field map I B 73 760T@NNMO * Length of new null field map I B 77 800T@NNML * Reserved I 81 96 T@RES1 * *VAR Old record image * *VAR Old record null field map * *VAR New record image * *VAR New record null field map * Array over record images
The total length of the parameter will be 96 + (2 * record length of file), unless there are any null field maps involved. It's easy enough to create a test program and look at the parameter and its parts in debug.
So if you need the old and/or new record images in your CL program, you can hard-code their start positions and lengths. But you can also be flexible, and use the length supplied in the other parameter, in case the file's record length is changed in the future.
Also, note that there will NOT be an OLD image if the operation is *INSERT, or a NEW image if the operation is *DELETE.
For myself, I usually use a CL program to pass these parameters to an RPG program for more complex processing, but the CL is a useful harness, providing error management and reporting via return codes from the RPG.
Dig Deeper on iSeries ILE programming
Related Q&A from John Blenkinsop
When an error occurs on an IBM command, the diagnostic messages are sent first, then an escape message, which you can monitor. On AS/400 you see the ... Continue Reading
Learn how to 'append data to the file' with the FTP DIR command, and eliminate the hassle of having to end the FTP session and restart to view ... Continue Reading
RPGIV will 'think of' incoming integer fields as binary, and then will redefine them in the program structures as PACKED. So, when you chain a record... Continue Reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.