[U2] UniData Update Triggers

2011-10-09 Thread David Wolverton
During an Update Trigger, I'd like to alter the 'Current Record' as passed
into the trigger so the 'effective written' record is different with changes
I want to make, but it appears the change is not allowed.

I have some logic that would be easy to add into a trigger to modify a few
fields that otherwise I get to hunt through every relevant 'write' in BASIC
-- worse, I will miss the ability to do this field update if the records is
AE edited.

Is just a 'too bad, so sad' thing?  I am guessing I could write a whole
bunch of 'phantom' that monitors a log record, and have the trigger record
the needed data into the 'log' and have the phantom 'update' the record in a
second pass, but that seemed extreme, and possibly a problem if the record
received several sequential changes.






___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


Re: [U2] UniData Update Triggers

2011-10-09 Thread Jeff Butera

On 10/09/2011 08:46 PM, David Wolverton wrote:

During an Update Trigger, I'd like to alter the 'Current Record' as passed
into the trigger so the 'effective written' record is different with changes
I want to make, but it appears the change is not allowed.


I'm not sure I understand not allowed - are you getting an errors?


I have some logic that would be easy to add into a trigger to modify a few
fields that otherwise I get to hunt through every relevant 'write' in BASIC
-- worse, I will miss the ability to do this field update if the records is
AE edited.


That's the whole point of EXECSTAT:

0 = don't write the record
1 = write record as passed in, ignoring any changes made in trigger
2 = write record as edited by trigger

This example will overwrite field 1:

SUBROUTINE MY_TRIGGER_SUB(X.EXECSTAT,X.DICT,X.FILE,X.ID,X.REC)
X.EXECSTAT=2
X.REC1 = 'Happily overwriting fields in this record'
RETURN

I use this for stored computed columns and other things that sound 
similar to what you want.  Here's a real example that sets a slew of 
default values anytime a record is written:


SUBROUTINE H08.T.H08.JA.SEARCH(X.EXECSTAT,X.DICT,X.FILE,X.ID,X.REC)
X.EXECSTAT=2
IF X.DICT = '' THEN
* record changed who/date/time
  X.REC5 =UPCASE(@LOGNAME)
  X.REC3 =DATE()
  X.REC4 =TIME()
  IF X.REC17 = THEN
* record added who/date/time
X.REC17 =X.REC5
X.REC1 =X.REC3
X.REC2 =X.REC4
  END
* Default values...
* Next Question=1
  IF X.REC25 = '' THEN
X.REC25 = 1
  END
* Num apps
  IF X.REC46 = '' THEN
X.REC46 = 0
  END
* Status=Search Creation
  IF X.REC10 = '' THEN
X.REC10 = 'SC'
X.REC11 = DATE()
  END
* Accept Resumes=NO
  IF X.REC20 = '' THEN
X.REC20 = 'N'
  END
* Cull method=view all apps
  IF X.REC23 = '' THEN
X.REC23 = 'A'
  END
END
RETURN


--
Jeff Butera, PhD
Manager of ERP Systems
Hampshire College
413-559-5556

___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users


Re: [U2] UniData Update Triggers

2011-10-09 Thread David Wolverton
Ah!!  By 'not allowed' I meant that it was not using my record change -- but
I was using EXECSTAT = 1 as well!

I missed the EXECSTAT = 2 ...  I only had 0 (fail) and 1 (write) as valid
choices -- I missed the 2.

Let me try my code with a 2 and see -- that's likely my whole issue ... 

Thanks Jeff!


-Original Message-
From: Jeff Butera [mailto:jbut...@hampshire.edu] 
Sent: Sunday, October 09, 2011 10:41 PM
To: u2-users@listserver.u2ug.org; dwolv...@flash.net
Subject: Re: [U2] UniData Update Triggers

On 10/09/2011 08:46 PM, David Wolverton wrote:
 During an Update Trigger, I'd like to alter the 'Current Record' as passed
 into the trigger so the 'effective written' record is different with
changes
 I want to make, but it appears the change is not allowed.

I'm not sure I understand not allowed - are you getting an errors?

 I have some logic that would be easy to add into a trigger to modify a
few
 fields that otherwise I get to hunt through every relevant 'write' in
BASIC
 -- worse, I will miss the ability to do this field update if the records
is
 AE edited.

That's the whole point of EXECSTAT:

0 = don't write the record
1 = write record as passed in, ignoring any changes made in trigger
2 = write record as edited by trigger

This example will overwrite field 1:

SUBROUTINE MY_TRIGGER_SUB(X.EXECSTAT,X.DICT,X.FILE,X.ID,X.REC)
X.EXECSTAT=2
X.REC1 = 'Happily overwriting fields in this record'
RETURN

I use this for stored computed columns and other things that sound 
similar to what you want.  Here's a real example that sets a slew of 
default values anytime a record is written:

SUBROUTINE H08.T.H08.JA.SEARCH(X.EXECSTAT,X.DICT,X.FILE,X.ID,X.REC)
X.EXECSTAT=2
IF X.DICT = '' THEN
* record changed who/date/time
   X.REC5 =UPCASE(@LOGNAME)
   X.REC3 =DATE()
   X.REC4 =TIME()
   IF X.REC17 = THEN
* record added who/date/time
 X.REC17 =X.REC5
 X.REC1 =X.REC3
 X.REC2 =X.REC4
   END
* Default values...
* Next Question=1
   IF X.REC25 = '' THEN
 X.REC25 = 1
   END
* Num apps
   IF X.REC46 = '' THEN
 X.REC46 = 0
   END
* Status=Search Creation
   IF X.REC10 = '' THEN
 X.REC10 = 'SC'
 X.REC11 = DATE()
   END
* Accept Resumes=NO
   IF X.REC20 = '' THEN
 X.REC20 = 'N'
   END
* Cull method=view all apps
   IF X.REC23 = '' THEN
 X.REC23 = 'A'
   END
END
RETURN


-- 
Jeff Butera, PhD
Manager of ERP Systems
Hampshire College
413-559-5556



___
U2-Users mailing list
U2-Users@listserver.u2ug.org
http://listserver.u2ug.org/mailman/listinfo/u2-users