× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi,

Trigger programs have to be coded according to IBM's specs.  The spec that
IBM published in the first V3R1 manual (when trigger programs first came
out) was wrong, because the individual that coded the RPG example didn't
know RPG.  (Details, details...)

Here is an article that I wrote for the publication "Inside V3R1" many
years ago.  I chose to write it in RPG III, as RPG IV was not yet well
accepted.  I think that you can use this as a standard trigger shell.  Be
sure to view the code in a non-proportional font:

I started out on a quest to create a universal shell for a trigger program
for RPG.  I had a situation where there were two files, an order detail
file (named DETAIL) and a customer file (named CUSTFL with record format
CUSTFLR).  The order detail file contains price and a quantity field.  The
customer file contains the total amount on order for the customer.


    A trigger program was the ideal solution, because I my order entry
system allowed updates to the order detail file through several different
programs.  Either I would have to code my logic into each of these
different programs, or else write this logic once using the trigger
program.


    When a trigger program is called, two parameters are passed to it.  The
first parameter contains a data string containing all of the pertinent
information about the update to the file, and then contains the before and
after images and null byte maps of the file.  If you hard code the "to" and
"from" positions for the file length, the program would have to be modified
every time a field length were changed in the program.


    Instead, I used an image of the file in a data structure, and two other
"flat" data structures to hold the before and after images of the data.
You can access the data for either the before or after image by moving that
data structure into the externally defined data structure which specified
all the fields in the file.


    A representation of the actual program has been shown in the figure
below.  The "standard trigger shell" is shown bolded, and the custom code
for my application are shown in the lighter type.  Note that the externally
defined file name is inserted on the "I" spec on line 4300.The two
subroutines are what do the arithmetic, and have been omitted.


    Because the programs that update the order file do so repeatedly, I
have closed to not set LR on in the program.  This means that I have to
plan in the writing of the application that all variables will not be
initialized on each new CALL.




   100      H/TITLE  -- UPDATE CUSTFL WITH AMOUNTS FROM ORDER DETAIL RECORD
--
   200      F*

   300      F*     Copyright 1995, 2002 ? Barsa Consulting Group, LLC

   400      F*                            2900 Westchester Avenue

   500      F*                            Purchase, New York  10577

   600      F*

   700      F*                            (914) 251-1234

   800      F*

   900      FCUSTFL  UF  E           K        DISK

  1000      IQPARM1      DS                           9999

  1100      I* Physical file name/library/member

  1200      I                                        1  10 QFNAME

  1300      I                                       11  20 QLNAME

  1400      I                                       21  30 QMNAME

  1500      I* Trigger event     ('1'-Insert, '2'-Delete, '3'-Update)

  1600      I                                       31  31 QEVENT

  1700      I* Trigger time      ('1'-After, '2'-Before)

  1800      I                                       32  32 QTTIME

  1900      I* Commit lock level ('0'-*NONE, '1'-*CHG, '2'-*CS, '3'-*ALL)

  2000      I                                       33  33 QCOMIT

  2100      I* CCSID

  2200      I                                    B  37  400QCCSID

  2300      I* Offset to the original record

  2400      I                                    B  49  520Q1ROFF

  2500      I* Length of the original record

  2600      I                                    B  53  560Q1RLEN

  2700      I* Offset to the original record null byte map

  2800      I                                    B  57  600Q1NOFF

  2900      I* Length of the original null byte map

  3000      I                                    B  61  640Q1NLEN

  3100      I* Offset to the new record

  3200      I                                    B  65  680Q2ROFF

  3300      I* Length of the new record

  3400      I                                    B  69  720Q2RLEN

  3500      I* Offset to the new record null byte map

  3600      I                                    B  73  760Q2NOFF

  3700      I* Length of the new null byte map

  3800      I                                    B  77  800Q2NLEN

  3900      IQPARM2      DS

  4000      I                                    B   1   40QLENG

  4100      I/SPACE

  4200      I* Externally defined data structure with each field name
defined
  4300      IQFILE     E DSDETAIL

  4400      I* "Before image" of the file

  4500      IQFILEB      DS                           4500

  4600      I* "After image" of the file

  4700      IQFILEA      DS                           4500

  4800      C/SPACE

  4900      C* Parameter list required for every trigger program

  5000      C           *ENTRY    PLIST

  5100      C                     PARM           QPARM1           See DS
above.
  5200      C                     PARM           QPARM2           Not used
in pgm
  5300      C* Using offsets and lengths provided get the before & after
images.
  5400      C           Q1ROFF    ADD  1         Q       50       Before
offset
  5500      C           Q1RLEN    SUBSTQPARM1:Q  QFILEB           Get befor
image
  5600      C           Q2ROFF    ADD  1         Q                After
offset
  5700      C           Q2RLEN    SUBSTQPARM1:Q  QFILEA           Get after
image
  5800      C/SPACE

  5900      C           QKEY      KLIST                           Customer
file
  6000      C                     KFLD           CUST#            key list.

  6100      C/SPACE

  6200      C           QEVENT    IFEQ '2'                        Delete
Record
  6300      C           QEVENT    OREQ '3'                        Update
Record
  6400      C                     MOVELQFILEB    QFILE            Get befor
image
  6500      C           QKEY      CHAINCUSTFLR              05      Get
customer
  6600      C           *IN05     IFEQ *OFF                         record
& sub
  6700      C                     EXSR SUB                          out
order
  6800      C                     UPDATCUSTFLR
amounts.
  6900      C                     ENDIF                           *IN05
IFEQ *OFF
  7000      C                     ENDIF                           QEVENT
IFEQ '1'
  7100      C/SPACE

  7200      C           QEVENT    IFEQ '1'                        Insert
Record
  7300      C           QEVENT    OREQ '3'                        Update
Record
  7400      C                     MOVELQFILEA    QFILE            Get after
image
  7500      C           QKEY      CHAINCUSTFLR              05      Get
customer
  7600      C           *IN05     IFEQ *OFF                         record
& add
  7700      C                     EXSR ADD                          in
order
  7800      C                     UPDATCUSTFLR
amounts.
  7900      C                     ENDIF                           *IN05
IFEQ *OFF
  8000      C                     ENDIF                           QEVENT
IFEQ '1'
  8100      C/SPACE

  8200      C                     RETRN                           Return

  8300      C/SPACE 2

  8400      C           ADD       BEGSR






    To start the trigger function the following three commands have to be
executed:

             ADDPFTRG   FILE(DETAIL) TRGTIME(*AFTER) +
             ADDPFTRG   FILE(DETAIL) TRGTIME(*AFTER) +
                          TRGEVENT(*DELETE) PGM(program-name)
                          TRGEVENT(*INSERT) PGM(program-name)
             ADDPFTRG   FILE(DETAIL) TRGTIME(*AFTER) +
                          TRGEVENT(*UPDATE) PGM(program-name)
                          TRGUPDCND(*CHANGE)


Al

Al Barsa, Jr.
Barsa Consulting Group, LLC

400>390

914-251-1234
914-251-9406 fax

http://www.barsaconsulting.com
http://www.taatool.com






                      Bill Erhardt
                      <ERHARDT@BaldwinHQ        To:       "'Mid Range list - 
Questions'" <MIDRANGE-L@midrange.com>
                      .com>                     cc:
                      Sent by:                  Subject:  V5R1 - and Trigger 
Programs
                      midrange-l-admin@m
                      idrange.com


                      11/08/2002 10:12
                      AM
                      Please respond to
                      midrange-l






This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
--
[ Picked text/plain from multipart/alternative ]
We've just installed V5R1 and now have problems with trigger programs.
I've
heard that the parameter has changed but how?  I've gone to the infocenter
and found the trigger buffer section but this doesn't seem correct.
Bill Erhardt
Baldwin hardware
_______________________________________________
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@midrange.com
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/cgi-bin/listinfo/midrange-l
or email: MIDRANGE-L-request@midrange.com
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.








As an Amazon Associate we earn from qualifying purchases.

This thread ...


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

This mailing list archive is Copyright 1997-2024 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].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.