iSelfSchooling.com  Since 1999     References  |  Search more  | Oracle Syntax  | Free Online Oracle Training

    Home      .Services     Login       Start Learning     Certification      .                 .Share your BELIEF(s)...

 

. Online Accounting        .Copyright & User Agreement   |
    .Vision      .Biography     .Acknowledgement

.Contact Us      .Comments/Suggestions       Email2aFriend    |

 

Online Oracle Training for beginners and advanced - The most comprehensive Oracle tutorial

The authors do not guarantee or take any responsibility for the accuracy, or completeness of the information.

Developers - FORMS

 

Lesson 01 | Lesson 02 | Lesson 03 | Lesson 04 | Lesson 05 | Lesson 06 | Lesson 07 | Lesson 08 | Lesson 09 | Lesson 10 | Lesson 11 | Lesson 12 | Lesson 13 | Lesson 14 | Lesson 15 | Lesson 16 | Lesson 17 | Lesson 18 | Lesson 19 | Lesson 20 | Lesson 21 | Lesson 22 | Lesson 23 |

 

Lesson 14

"Men show their characters in nothing more clearly than in what they think laughable." Johann Wolfgang von Goethe (1749 - 1832)

 

Read first then play the video:

   FRM-VIDEO -(Hands-On 12) How to use Global Variable and Trigger (WHEN-NEW-FORM-INSTANCE)

   

Global Variable, Trigger

 

Global Variable

A Global Variable is a binding variable that can be used by multiple Form Modules.

 

Form Trigger

A forms trigger is a block of PL/SQL code that adds functionality to your application. Triggers are attached to objects in your application. When a trigger is fired, it executes the code it contains. Each trigger"s name defines what event will fire it; for instance, a WHEN-BUTTON-PRESSED trigger executes its code each time you click on the button to which the trigger is attached. Or, we can say, a forms trigger is a set of PL/SQL actions that happen each time an event such as when-checkbox-changed, when-button-pressed, or when-new-record-instance occurs. You can attach several triggers to a data query. The most popular of them are the PRE-QUERY and POST-QUERY.

 

POST-QUERY trigger

The PRE-QUERY trigger fires before the select statement is finalized. The POST-QUERY trigger fires before selected records are presented to the user. It fires after records are retrieved but before they are displayed. So, you can use it to enhance a query"s records in a number of ways. Your Post-Query trigger can contain code to calculate or populate control items.

 

WHEN-NEW-FORM-INSTANCE trigger

Some other useful triggers are: PRE-INSERT and WHEN-NEW-FORM-INSTANCE.

A PRE-INSERT trigger fires once before each new record is inserted in a commit process. The "WHEN-NEW-FORM-INSTANCE" trigger will be used to prepare objects or an action when entering to a new form. It fires when the form is entered.

 

Hands-ON

Now, your client desires it would be better if they could get specific history of product price rather than entire product history prices table. They want you to add more functionality to their application to display only current history of product prices information.

Note: The current product would be defined by where the position of your cursor is.

You have been assigned to modify their application to query only history of product price information for a product rather than entire table.

See Figure 14.

 

Your tasks are:

1- Automate the "product history prices" application to query only a history of product prices.

2- Pass product ID as a parameter between these two Form applications.

3- Run and test all user functional requirements.

 

FYou will learn how to: use and assign global variable, pass global variable from one Form to another, use global variable to execute query base on its parameter, create and use the "WHEN-NEW-FORM-INSTANCE" trigger, use tab canvas, use "object navigator," use "Data Blocks," use "Layout Editor," use "Property Palette," use "Run Form," and "Execute Query."

 

Figure 14

 

Open a Module

In the "Object Navigator" window, highlight Forms. Go to the Main menu and choose "File," select "Open" to open an existing form (customer_orders_V11) in the "iself" folder.

 

Save Modules

Click on the "CUSTOMER_ORDERS_V11" form. The color changes to blue. Then change its name and save the Form name as version 12 (customer_orders_12). This way the original form is untouched.

Also, you should save the "Product History Prices Data Entry" (PROD_DE) Form name as version 2 (PROD_DE_V02).

 

Now, we want to change the application to query all the product history prices for an item that the cursor is on.

 

Temporary Holder

In the PROD_DE_V02 form, expand the form, highlight the Data Blocks item and then click on the green "+" sign to create a data block.

 

New Data Block

In the "New Data Block" window, choose the "Build a new data block manually" option and click "OK."

 

Change a property palette sheet

Now, you have a new data block (Blockn). Right click on it and open its Property Palette. In its property palette, change its name to CONTROL_BLOCK. Change "Database Data Block" to "NO." Close the window.

 

Create an Item

In CONTROL_BLOCK, create a new item. Open its property palette. Change the "name" item to "TEMP_VALUE." Change its datatype to NUMBER with length 7 bytes. Change "database item" to "NO." Close the window.

 

Copy Value from Item

Select "Prodid" on the price data block; and open its property palette. For "Copy Value from Item" type "control_block.temp_value." Close the window.

 

Create a trigger

In the PROD_DE_V02 form, create a "WHEN-NEW-FORM-INSTANCE" trigger at Form level.

 

WHEN-NEW-FORM-INSTANCE trigger

In the Trigger window, type "W" and "N" and select the WHEN-NEW-FORM-INSTANCE trigger.

 

PL/SQL Editor

In the PL/SQL Editor, write a PL/SQL procedure to move the global prodid item value into the temp_value item. Then go to the "price" data block and execute the query function.

(PL/SQL Editor)

:temp_value := :global.prodid;

GO_BLOCK ("price");

EXECUTE_QUERY;

 

Compile a trigger

Compile the trigger and close the window.

 

Compile a module

Highlight the Form and save it. Then go to File > Administration > Compile file to compile it.

 

Create a Push Button

On the CUSTOMER_ORDERS_V12 Form, right click on the "Product History Data Entry" push button in the ITEM tap canvas to select "Smart Trigger" and select the "WHEN-BUTTON-PRESSED" trigger.

 

WHEN-BUTTON-PRESSED trigger

In the PL/SQL Editor, write a PL/SQL procedure to move the PRODID value into the global prodid item and call the Product History Price Data Entry form.

(PL/SQL Editor)

:GLOBAL.prodid := NAME_IN("item.prodid");

OPEN_FORM("c:_de_v02");

Compile the trigger and then close the window.

 

Run the Form

Run the application.

 

Execute Query

Click on the "Execute Query" icon.

 

Navigate the application

Navigate through the application.

 

Highlight a product id and then click on the "Product History Prices Data Entry" push button.

Now, you should only see information about that specific product id not all the products.

 

Repeat the process for some other items.

 

Then, close all the windows and save the changes.

 

"We all carry around so much pain in our hearts. Love and pain and beauty. They all seem to go together like one little tidy confusing package. It's a messy business, life. It's hard to figure--full of surprises. Some good. Some bad." Henry Bromel, Northern Exposure, The Big Kiss, 1991

 

Questions:

Q: How do you define a binding variable in a multiple forms?

Q: How do you assign a value to a global variable?

Q: How do you pass a global variable value from one form to another?

Q: How do you use a global variable to execute a query based on its parameter?

Q: Describe the "WHEN-NEW-FORM-INSTANCE" trigger.

Q: How do you create the "WHEN-NEW-FORM-INSTANCE" trigger?

Q: Now, your client desires it would be better if they could get specific history of product price rather than entire product history prices table. They want you to add more functionality to their application to display only current history of product prices information.

Note: The current product would be defined by where the position of your cursor is.

You have been assigned to modify their application to query only history of product price information for a product rather than entire table.

See Figure 14.

 

Your tasks are:

1- Automate the "product history prices" application to query only a history of product prices.

2- Pass product ID as a parameter between these two Form applications.

3- Run and test all user functional requirements.