Question Error in DB Trigger Program

Hi,

I have a scenario where the find statement in the db write trigger of a table fails with no records and the "IF NOT AVAIL" is having "RETURN NO-APPLY". At this condition will the records written to the db table will be saved or not? Kindly clarify. Thanks in advance.
 
That very much depends on your error handling. RETURN NO-APPLY might not be catched by the default error handlig - therefore you would need to roll your own mechanism. But, since you don't give any additional info it's hard to speculate.

First of all I have to admit that I don't like database triggers - not one bit. IMHO they are a concept dating back to the beginning of the '90s of the last century and I would not recommend their usage.

In general:
Database triggers fire:
  • The CREATE trigger immediately after the new record has been created and initial values have been assigned. Usually you would use it to assign a technical key automatically.
  • The WRITE and DELETE triggers at the end of the buffer scope ( or transaction scope - whichever comes first ).
Therefore you should take great care on buffer and transaction scope when you use database triggers because they might not fire when you expect them to fire.

Furthermore, I've never used RETURN NO-APPLY in database trigger. In order to have a transaction undone by the ABL automatically you need to raise an error - therefore, if, use RETURN ERROR instead. I would speculate that RETURN NO-APPLY wold not raise an error and depending on buffer and transaction scope it might go through. When you use RETURN ERROR you might append a string to the statement which you can check on the RETURN-VALUE. But, then again, the RETURN-VALUE is another thing that needs to be used with care because it might contain a value from a previous RETURN statement - therefore in order to be 100% positive you would need to clear it in calling a procedure that explicitely returns "".

Anyway you should also have a look into your error handling.

Heavy Regards, RealHeavyDude.
 
Thanks Dude. I too don't like db triggers. But this is an enhancement work and there are quiet a lot db triggers. Almost to all tables. I take care of the negatives you pointed out. I have another question too. Do we need to enable explicitly the db triggers if we disable them in the flow of the program?
 
You can disable database triggers with the DISABLE TRIGGERS statement - but there is no enable pendant. AFAIK the "disable" scope is the procedure in which the DISABLE TRIGGERS statement is executed.

Additionally you can override database triggers on any level.

Therefore you need to be cautious when you disable or override database triggers so that they are not disabled or overriden when you need them to fire.

Why would you disable database triggers in the application? If you want the logic they contain to fire only in certain places then you should better define the triggers "ON CREATE OF ..." where you need them instead of having to cope with issue of them being disabled with no straight forward possibility to enable them.

Heavy Regards, RealHeavyDude.
 
Back
Top