官术网_书友最值得收藏!


Creating a computation>

Computations are events that will prepare items with data. As the name implies, computations can "compute" how data is to be shown on screen or how data is handled after submitting. Computations can be triggered during page rendering, but they can also be used in the After Submit process.

This example will show an implementation of a computation, but there are many more possible uses for computations.

How to do it...

Start by creating a normal text item on the form that was created in the second recipe of the first chapter. This is a normal form based on the EMP table. Normally, a user would have to manually enter the commission. What we are going to do is to create a computation that will automatically enter an amount into this field, based on a percentage of the salary and a bonus for people that work in the Sales department.

First, identify the item that holds the commission column.

The next step is to find the moment when we want to execute the computation. In this case, before the page is submitted but after the Save button is pressed. So in this case we will create the computation After Submit.

  1. Right-click on the Computations under After Submit in the Page Processing component and click on Create:
  2. Choose Item on this page and press Next.
  3. Select P5_COMM from the Compute Item select list, select PL/SQL Function Body from the Computation Type select list and click on Next.
  4. The next step is to enter the PL/SQL code for this computation:
    declare
      l_comm number;
    begin
      if :P5_DEPTNO = 30
      then
        l_comm := :P5_SAL * 1.10;
      else
        l_comm := :P5_SAL * 1.05;
      end if;
      return l_comm;
    end;
    [9672_01_15.txt]
  5. Click on Create.

The computation is now done. It can be tested by selecting an existing record from the list of employees and altering its salary and then saving the data. Another option is to create a completely new employee. You will see that an employee under the Sales department with dept no. 30 will receive a 10 percent commission whilst employees from all other departments will receive 5 percent.

There's more...

Computations can be used for far more situations than preparing an item before saving it to the database.

An example of another implementation can be an item that will show the current date when the page loads, or an item that will show a total amount when certain other amount items are entered. Used with dynamic actions, computations can be very powerful.

主站蜘蛛池模板: 海伦市| 双峰县| 布拖县| 香港| 阳西县| 霍城县| 滨海县| 建阳市| 绩溪县| 鹤庆县| 河源市| 南陵县| 桃源县| 小金县| 延津县| 棋牌| 紫云| 玉环县| 栾川县| 伊金霍洛旗| 茶陵县| 宾阳县| 大余县| 渝北区| 定远县| 夏河县| 富源县| 稻城县| 高台县| 朝阳县| 苍南县| 上犹县| 定襄县| 兴和县| 威海市| 策勒县| 毕节市| 阳泉市| 祥云县| 大新县| 塔城市|