A script-enabled browser is required for this page to function properly.

Creating a Calculated Item

To create a calculated item:

  1. In the Object Navigator, create a new interface item (make sure it is a control item).

    Tip: The item's datatype must be compatible with the calculation you wish to use to compute the item's value. For example, if you wish to compute an item's value with the Sum function, create an interface item of datatype Number.

  2. Double-click the item's object icon to display the Property Palette.
  3. Under the Calculation node, set the item's Calculation Mode property to Formula or Summary.
  4. If you set Calculation Mode to:

    Formula, click on the Formula property, click the More button to display the Formula dialog, and type a PL/SQL expression to define the formula. Click OK to compile the expression.

    Summary, use the Summary Function popList to select a summary type, then use the Summarized Block and Summarized Item popLists to select the block and item whose values will be summarized to compute a value for the calculated item.

Creating a calculated item Restrictions

The following item properties are defaulted to No at compilation time:

  The following item properties are ignored at compilation time:

Other restrictions to keep in mind when creating calculated items:  

Creating a calculated item Examples

Example

/* Example 1: Define a summary calculation to display the

** maximum salary of all employees. Create display item MAX_SAL
** in the EMP block, set its Calculation Mode property to
** Summary, set its Summary Function property to Max, set its
** Summarized Block property to EMP, and set its Summarized
** Item property to SAL.
**
** Example 2: Define a formula calculation to compute an
** employee's gross total compensation. Create display item
** TOTAL_COMP in the EMP block, set its Calculation Mode
** property to Formula, and set its Formula property to the
** following PL/SQL expression:

*/
:emp.sal + :emp.comm

/* Example 3: Define a Formula item to compute a different
** value for total compensation depending on the block where
** the cursor currently is positioned. Form has 3 blocks:
** 2 data blocks (EMP1 and EMP2), and one control block
** (COMP). Create a display item TOTAL_COMP in the COMP block
** that displays total compensation. Set the Formula property
** for COMP.TOTAL_COMP to an expression (a function call):
*/
total_comp_func


/* Function TOTAL_COMP_FUNC is defined as follows: */

FUNCTION total_comp_func RETURN number IS
BEGIN
IF :system.cursor_block = 'emp1' THEN
RETURN :emp1.sal + :emp1.comm;
END IF;
IF :system.cursor_block = 'emp2' THEN
RETURN :emp2.sal + :emp2.comm;
END IF;
RETURN null;
END;


/* Oracle Forms automatically recalculates COMP.TOTAL_COMP
** whenever a change occurs to the value of :EMP1.SAL,
** :EMP1.COMM, :EMP2.SAL, or :EMP2.COMM. Oracle Forms
** will not, however, recalculate COMP.TOTAL_COMP when an
** end user navigates between blocks, since changes to
** system variables don't automatically cause recalculation.
** To ensure that the correct value always is displayed,
** define a PRE-BLOCK trigger at the form level, containing
** the statement:
*/
RECALCULATE('comp.total_comp');


Defining a Button