Monday, October 11, 2010

Trigger in D2kTrigger in D2kTrigger in D2k
















Trigger in D2k

1. Trigger in form builder are available at three level ie item level, Block level and form level.
2. The area of application of trigger is dependent on the level where it has been defined.
3. If the same trigger has been defined at more than one level than the execution of trigger depends on the value of the property of trigger i.e. ‘ execution hierarchy’.
Override
1. It will override the entire higher level trigger having same name.
before
1. Lower level will be executed before its immediate parent level
After
1. lower level trigger will be executed after its immediate parent.

The lower level trigger will be always available but reverse is not true.



you can help for more these two pic following link








Trigger in form builder is divided into five parts.

1. Pre
2. post
3. when
4. on
5. key

Pre – Trigger. This trigger is executed before the current event.
Some of the pre trigger event are
1. pre-commit
2. pre-form
3. pre-logon
4. pre-text-item
5. pre-block

Pre-Query:-
1. This trigger is executed before any query is send to the database for execution.
2. it is used to validate the user input before sending the user-input to db to remove unnecessary presence on DB.

Code for Pre Query.


If :emp.deptno not in (10,20,30) then message (:emp.deptno ’ does not exict’);
Message(‘’);
Raise form_trigger_failure;
Length(:emp.empno) <4>







Post – trigger :->
1. These trigger are executed after the corresponding event.
2. some of the post trigger
• post-logon
• post-block
• post-query
• post-insert/update/delete
• post-text-item

Post-query:- this trigger is executed after the execution of query in the block
3. pre-query is executed only once and post-query is executed that many no. of times records returned by the query submitted to DB.


Code for Post –Query Emp block

Declare
V_groeg_sal number;
V_grade char(1);
Begin
V_groeg_sal := :emp.T_gross_sal;
If v_gross_sal >= 50000 and v_gross_sal <= 7000 then v_grade := ‘a’; Else v_gross_sal >= 3000 and v_gross_sal <>
1. this is executed one the cursor/control goes from the item.
2. use this trigger to populate any value like grade on the basis of gross sal(sal + comm.)


When trigger ->

1. These trigger get executed when the corresponding event happens.
2. some of the when –trigger
when –button-pressed
when-validate-item
when-validate-record
when-new-item-instance
when-new-record-instance
when-new-block-instance
when-create-record


when-validate-item :-

it is executed when the control comes out of any item after making changes in th e value that item.


When-validate-record :- executed when the control goes out of the current record after making changes in the record.

When –create-record

This trigger is executed when a new record is created in the block.
This is the only trigger in form builder when the forms does not ask you to save changes if we have allocated some value to my field of the block.

Code for when –create-record at emp block

:emp.sal := 200;
:emp.comm := 100;

Code for when-validate-item of Sal field
If :emp.sal<2000> 2000’);
Raise form_trigger_failure;
End if;

Code at blk level
When-validate-record of emp block

If :emp.sal<:emp.comm Then Message(‘plz enter sal>comm’);
Message(‘’);
Raise form_trigger_failure;
Else if :emp.name is null or length(:emp.ename)<4> these trigger executed during corresponding event.

Some of the trigger are.

On-error
On-message
On-logon
On-insertupdatedelete

On-error:-> in this trigger is executed when any errors happens at run time which is a system defined error.
Some of the keyword are

Error-code
Error-type
Error-text

On-message

This is executed when any message comes at run time from form builder.

Keywords

Message-code
Message-type
Message-text
Code for on-error at form level

If error_code = 50016
Then message(‘plz enter only number’);
Message(‘’);
Else
Message(Error_code - ‘ error_type ’ ‘ error_text);
Message(‘’)


Key trigger :-> these trigger are executed whenever a corr. Runtime key is used

Key Trigger Bultin
F7 Key-enter Enter_query
F8 Key-executed Execute_query
F9 Key-listval List-values
F10 Key-commit Commit
F6 Key-crerec Create_record
Shift+f6 Key-delrec Delete_record

1. we can use key trigger to override the default functionality of run time keys.
2. we can use do_key (‘buil-in’) to call the corr/key trigger.
3. for example do_key(‘commit’) will made a call to key-commit trigger.
4. we can also use execute-trigger (‘any trigger name’) to execute the code of any trigger

execute_trigger(‘key-nxtrec’);

Code :-> for key-nexrec

If :system.last_record = ‘true’ then
Message (‘ you are already at last record’);
Message(‘’);
Raise form_trigger_failure;
Else
Next_record;
End if;

Code for next_record button

Button
D0-key(‘next_record’);
Execute_trigger(‘key-nxtrec’);



Code for key-up

If :system.cursor_record = ‘1’
Then message(‘ you are already at first record’);
Message(‘’);
Raise form_trigger_failure;
Else
Previous_record;
End if;

5 comments:

  1. good ankur
    this tutorial helps me to understand trigger

    ReplyDelete
  2. can u publish some developed new froms

    ReplyDelete
  3. Hello Sanjeev,

    I have many developed forms.

    what u want to do i will tell you here...

    just write me your problem ..

    Thanks

    Ankur Garg
    S.E

    ReplyDelete
  4. great tutorial to understand forms...thanks

    ReplyDelete