-
Copyrights 2010 - Online Training Oracle Applications. All Rights Reserved.
|
Create the following tables in the database create table bankmaster ( accno number(4) primary key, create table transaction ( accno number(4) references bankmaster (accno), Open the form builder tool and create a new form based on bankmaster table by using data block wizard and layout wizard. Save the form with the name BANKMASTER.fmb In the Object navigator, under BANKMASTER data block, create ON-ERROR trigger Provide the following code an compile. declare if errcode = 40508 then Save the form. Enter the following details Accno -- 1 Save. We get confirmation message " Transaction complete: 1 record applied and saved" Enter the following details Accno -- 2 Save. We get an message as "Account type can be "S" or "C" or "R" only" Note: Look at the screen shot By trapping -2290 error, we are able to give meaningful messages at the form level. Now, Go to Block , Clear the block and Enter the following details Accno -- 1 Save. We get an message as "Duplicate Account number is not allowed". Note: Look at the screen shot By trapping -00001 error, we are able to give meaningful messages at the form level.
Note
In the ON-ERROR trigger which we have created, we used the if condition based on the value 40508 FRM-40508 , is the error raised when insert statement is failed in forms. Now, let's create form based on transaction table using data block wizard and layout wizard. save the form with the name TRANSACTION.fmb Go to the layout editor and place to display items. Create KEY-NEXT-ITEM trigger for the item ACCNO, provide the following code and compile. begin next_item; The above trigger gets name and balance into the display items. The above trigger is fired when we insert the record. Let's create WHEN-VALIDATE-ITEM trigger for the item trandate The above trigger make sure that we enter today's date only. Before running the form, lets insert some more data in table bankmaster by using following commands. insert into bankmaster values ( 2,'vinay','C', 40000, '21-MAY-2013');
Look at the current status of bankmaster and transaction tables in our database. Now, let's Run the from. Enter the Accno as 2 and click on tab Continue entering the following details in the form Observe balance changes from 40000 to 47000 . ( ON-INSERT trigger will be executed.) Go to Block --> Clear Entering the following details in the form Acno - 3, Type - W Trandate -- todays date ( your current date ) , Amt -- 20000 Balance changes from 45000 to 25000 Transactional Triggers For the event INSERT 1) PRE-INSERT For the event UPDATE 1) PRE-UPDATE For the event DELETE 1) PRE-DELETE Note
|