Try OpenEdge Now
skip to main content
Managing ABL Applications
R-code Features and Functions : R-code CRCs and procedure integrity : RCODE-INFO handle : Example: Deploying schema triggers
 
Example: Deploying schema triggers
The trload.p procedure installs new schema trigger definitions in an existing database. It reads dump files that contain the new data for table and field metaschema trigger records and updates these records with the new trigger procedure names and CRCs.

trload.p

/* trload.p */
DEFINE VARIABLE event      AS CHARACTER NO-UNDO FORMAT "x(6)".
DEFINE VARIABLE field-name AS CHARACTER NO-UNDO FORMAT "x(32)".
DEFINE VARIABLE iCRC       AS INTEGER   NO-UNDO.
DEFINE VARIABLE ix         AS INTEGER   NO-UNDO.
DEFINE VARIABLE proc-name  AS CHARACTER NO-UNDO FORMAT "x(32)".
DEFINE VARIABLE table-name AS CHARACTER NO-UNDO FORMAT "x(32)".
INPUT FROM "_file-tr.dat". /* Table trigger data */
_fl-loop:
REPEAT:
SET table-name event proc-name.
  ASSIGN
    RCODE-INFO:FILE-NAME = proc-name
    iCRC                 = RCODE-INFO:CRC-VALUE.
FIND _file WHERE _file._file-name = table-name.
FIND _file-trig WHERE _file-trig._file-recid = RECID(_file)
    AND _file-trig._event = event NO-ERROR.
IF AVAILABLE _file-trig THEN DO:
IF _file-trig._proc-name = proc-name
  AND _file-trig._trig-crc  = iCRC THEN NEXT _fl-loop.
ELSE DO:
/* ABL doesn't let you modify a trigger record, so delete and recreate. */
DELETE _file-trig.
CREATE _file-trig.
ASSIGN _file-trig._file-recid = RECID(_file)
_file-trig._event = event
_file-trig._override   = TRUE
_file-trig._proc-name = proc-name
_file-trig._trig-crc   = iCRC
ix                     = ix + 1.
END.
END.
END.
INPUT CLOSE.
MESSAGE ix "_file-trig records updated.".

INPUT CLOSE.
MESSAGE ix "_file-trig records updated.".
INPUT FROM "_field-t.dat". /* Field trigger data */
_fld-loop:
REPEAT:
SET table-name field-name event proc-name.
RCODE-INFO:FILE-NAME = proc-name.
  iCRC = RCODE-INFO:CRC-VALUE.
FIND _file WHERE _file._file-name = table-name.
FIND _field WHERE _field._file-recid = RECID(_file) AND
_field._field-name = field-name.
FIND _field-trig WHERE _field-trig._file-recid = RECID(_file) AND
_field-trig._field-recid = RECID(_field) AND
_event = event NO-ERROR.
IF AVAILABLE _field-trig
    AND _field-trig._proc-name = proc-name
    AND _field-trig._trig-crc = iCRC THEN NEXT _fld-loop.
ELSE DO:
DELETE _field-trig.
    CREATE _field-trig.
ASSIGN
_field-trig._file-recid = RECID(_file)
_field-trig._field-recid = RECID(_field)
_field-trig._event = event
_field-trig._override = TRUE
_field-trig._proc-name = proc-name
_field-trig._trig-crc    = iCRC
ix                       = ix + 1.
END.
END.
INPUT CLOSE.
MESSAGE ix "_field-trig records updated.".
Note: As this example shows, you must use the RECID function rather than the ROWID function to reference metaschema table record locations.