Write trigger with condition

lchlee

New Member
Hi all fellows!

I have the feeling sorry for all folks because I posted new
thread whenever I had some problems.

However, I think you may understand me because you underwent this kind of experience.
CREATE TABLE test1 (f1 CHAR(100)).
CREATE TABLE test2 (f1 CHAR(100), f2 INTEGER, f3 DATE, f4 CHAR(1)).

TRIGGER PROCEDURE FOR WRITE OF test1 NEW BUFFER new-test1 OLD BUFFER old-test1.

CREATE test2.

IF test2.f1=old-test1.f1 THEN DO:
test2.f4="I".
END.

ELSE DO:
test2.f4="U".
END.
ASSIGN
test2.f1=new-test1.f1
test2.f2=NEXT-VALUE(NEXT-Test1-Num)
test2.f3=TODAY.

I make two table test1, test2. Above code snippets are write trigger for test1. I want to give the condition on this trigger.

If "insert" event occurs, I want to put test2.f4 "I".
In case of "update" event, test2.f4="U".
"delete" event ¡æ test2.f4="D".

I heard that write trigger will fire on the event of insert, update, delete.
Actually, I made delete trigger for "delete" event.
I read that write trigger would be fired in the case of "delete" event.
Should I change or use delete trigger?
What kind of condition should I give trigger procedure?

Anyway, thanks for reading this thread.
I wish anybody give me the answer which can solve my problem.
 
Hope this helps.

The Write trigger does not fire when a Delete occurs. You need a separate Delete trigger.

You can test in the Write trigger whether you are inserting or updating using the test

NEW(new-test1)

If you are inserting, this will return TRUE. If you are updating, this will return FALSE.
 

lchlee

New Member
That was exactly what i needed
Thank you very much Norman.

Today, I feel so happy. You help me solve my problem.
Our soccer team won yesterday in World-cup.
After 48 years, we got 1 win in World-cup.

Again, I really appreciate for your help.
 
Top