Top Banner
....................................................................................... 44112GC10 Production 1.0 May 1999 M08751 Oracle Developer: Build Forms II Volume 1 • Instructor Guide
446

Build Forms II Volume 1 Instructor Guide 7196298

Oct 26, 2014

Download

Documents

fa99999
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Build Forms II Volume 1 Instructor Guide 7196298

.......................................................................................

44112GC10

Production 1.0

May 1999

M08751

Oracle Developer: Build Forms II

Volume 1 • Instructor Guide

Page 2: Build Forms II Volume 1 Instructor Guide 7196298

Author

Mark Sullivan

Technical Contributors and Reviewers

Louise Barnfield

Gunnar Boehrs

Jacquelyn Bruce

Phyllis Chan

Bulent Cinarkaya

Laurent Dereac

Mark Doran

Gillian Elias

Tushar Gadhia

Stephen Gramann

Nancy Greenberg

Ursula Hovy

Uwe Jentzsch

Leta A. Johnson

Jan Keuben

Steve Lirette

Jayne Marlow

Rita Morin

Daphne Nougier

Christin Nowakowski

Bryan Roberts

Bert Salyga

Helene Schwann

Hiroyuki Sugiyama

Pal Tarcsay

Bart Van der Laar

Jack Walsh

Publisher

Kelly Lee

Sherry Polm

Copyright Oracle Corporation, 1999. All rights reserved.

This documentation contains proprietary information of Oracle Corporation. It isprovided under a license agreement containing restrictions on use and disclosureand is also protected by copyright law. Reverse engineering of the software isprohibited. If this documentation is delivered to a U.S. Government Agency of theDepartment of Defense, then it is delivered with Restricted Rights and thefollowing legend is applicable:

Restricted Rights LegendUse, duplication or disclosure by the Government is subject to restrictions forcommercial computer software and shall be deemed to be Restricted Rightssoftware under Federal law, as set forth in subparagraph (c) (1) (ii) of DFARS252.227-7013, Rights in Technical Data and Computer Software (October 1988).

This material or any portion of it may not be copied in any form or by any meanswithout the express prior written permission of the Worldwide Education Servicesgroup of Oracle Corporation. Any other copying is a violation of copyright law andmay result in civil and/or criminal penalties.

If this documentation is delivered to a U.S. Government Agency not within theDepartment of Defense, then it is delivered with “Restricted Rights,” as defined inFAR 52.227-14, Rights in Data-General, including Alternate III (June 1987).

The information in this document is subject to change without notice. If you findany problems in the documentation, please report them in writing to EducationProducts, Oracle Corporation, 500 Oracle Parkway, Box 659806, RedwoodShores, CA 94065. Oracle Corporation does not warrant that this document iserror-free.

Oracle Developer, Oracle Server, and PL/SQL are trademarks or registeredtrademarks of Oracle Corporation.

All other products or company names are used for identification purposes only,and may be trademarks of their respective owners.

Page 3: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II iii

.....................................................................................................................................................Contents

PrefaceProfile xv

Related Publications xvi

Typographic Conventions xvii

Lesson 1: Managing Projects with Project BuilderIntroduction 1-3

Introducing Project Builder 1-5

Project Builder Terminology 1-7

Project Builder Benefits 1-9

Project Builder User Interface 1-11

Project Builder User Interface 1-13

Creating Projects and Subprojects 1-15

Adding Project Files 1-17

Subdirectories Added as Subprojects 1-19

Creating Connections 1-21

Working with Project Files 1-23

Establishing Dependencies 1-25

Building Projects 1-27

Delivering Projects 1-29

Summary 1-33

Practice Session Overview: Lesson 1 1-35

Practice 1 1-36

Lesson 2: Creating a Menu ModuleIntroduction 2-3

Components of the Menu Module 2-5

The Default Menu 2-7

The Menu Editor 2-9

Creating a Menu Module 2-11

Module Properties 2-13

Menu Properties 2-15

Menu Item Properties 2-17

Menu Item Types 2-19

Page 4: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................iv Oracle Developer: Build Forms II

.....................................................................................................................................................Contents

Menu Item Command Types 2-21

Implementing Menu Toolbars 2-23

Storing the Menu Module 2-25

Attaching the Menu Module 2-27

Pop-up Menus 2-29

Summary 2-31

Practice Session Overview: Lesson 2 2-33

Practice 2 2-34

Lesson 3: Managing Menu ModulesIntroduction 3-3

Using PL/SQL in Menu Item Code 3-5

Useful Built-in Menu Subprograms 3-7

Showing and Hiding the Current Menu 3-9

Managing Menu Security 3-11

Defining Security Roles 3-13

Assigning Access to Menu Items 3-15

Summary 3-17

Practice Session Overview: Lesson 3 3-19

Practice 3 3-20

Lesson 4: Programming Function KeysIntroduction 4-3

Key Triggers 4-5

Defining Key Triggers 4-7

Characteristics of Key Triggers 4-9

Classification of Key Triggers 4-11

Using Key Triggers 4-15

Association with Other Interface Controls 4-17

Summary 4-19

Practice Session Overview: Lesson 4 4-21

Practice 4 4-22

Page 5: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II v

.....................................................................................................................................................Contents

Lesson 5: Responding to Mouse EventsIntroduction 5-3

What Are Mouse Events? 5-5

Responding to Mouse Movement 5-7

Responding to Mouse Button Actions 5-11

Summary 5-17

Practice Session Overview: Lesson 5 5-19

Practice 5 5-20

Lesson 6: Controlling Windows and Canvases ProgrammaticallyIntroduction 6-3

Using Window-Interaction Triggers 6-5

Built-ins for Manipulating Windows 6-7

Built-ins for Manipulating Canvases 6-9

Working with Tab-Style Canvases 6-11

Windows and Blocks 6-15

Manipulating Window Properties Programmatically 6-17

Showing Multiple Windows 6-19

Closing Windows 6-21

Blocks with Many Items 6-23

Summary 6-25

Practice Session Overview: Lesson 6 6-27

Practice 6 6-28

Lesson 7: Defining Data SourcesIntroduction 7-3

Data Source Types 7-5

Basing a Data Block on a FROM Clause Query 7-7

Basing a Data Block on a Stored Procedure 7-9

Example of a Query Using a REF Cursor Procedure 7-11

Example of Query Using a Table of Records Procedure 7-13

Example of DML Using a Stored Procedure 7-15

Deciding Whether to Use a REF Cursor or a Tableof Records 7-17

Page 6: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................vi Oracle Developer: Build Forms II

.....................................................................................................................................................Contents

Data Block Wizard 7-19

Data Block Properties 7-21

Data Source Guidelines 7-23

Summary 7-27

Practice Session Overview: Lesson 7 7-29

Practice 7 7-30

Lesson 8: Working with Oracle8 Objects in Form BuilderIntroduction 8-3

What Are Object Types? 8-5

Review of Objects 8-7

Object REFs 8-9

Supported Oracle8 Features 8-11

How Oracle Developer Treats Objects 8-13

Object Type Displays 8-15

Creating Data Blocks Based on Oracle8 Objects 8-17

Selecting Object Table Columns 8-19

Selecting Object Column Attributes 8-21

Blocks with REF Lookups 8-23

The REF Column Value 8-25

LOVs for REFs 8-27

Summary 8-29

Practice Session Overview: Lesson 8 8-31

Practice 8 8-32

Lesson 9: Controlling Data Block RelationshipsIntroduction 9-3

Creating a Relation 9-5

Block Coordination 9-7

Coordinate Blocks Using REFs 9-9

Characteristics of Relation-Handling Triggers 9-11

Principles of Relation-Handling Code 9-13

Obtaining Relation-Handling Information 9-15

Implementing a Coordination-Type Toggle 9-17

Page 7: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II vii

.....................................................................................................................................................Contents

Forcing a Commit Per Master 9-19

Summary 9-21

Practice Session Overview: Lesson 9 9-23

Practice 9 9-24

Lesson 10: Building Multiple Form ApplicationsIntroduction 10-3

OPEN_FORM to Invoke Additional Forms 10-5

Closing Forms 10-7

Navigating Between Forms 10-9

Transaction Processing for Opened Forms 10-11

CALL_FORM to Invoke Additional Forms 10-13

Transaction Processing for Called Forms 10-15

NEW_FORM to Invoke Additional Forms 10-19

Controlling Open Forms and Called Forms Together 10-21

Different Ways of Invoking Forms 10-23

Using Form Parameters 10-25

Parameter Lists 10-29

Creating and Manipulating Parameter Lists 10-31

Passing Data Between Forms 10-33

Summary 10-35

Practice Session Overview: Lesson 10 10-37

Practice 10 10-38

Lesson 11: Working with Record GroupsIntroduction 11-3

Record Groups 11-5

Using Record Groups 11-7

Defining Record Groups at Design Time 11-9

Built-in Functions for Controlling Record Groups 11-11

Defining Query Record Groups Programmatically 11-17

Defining Nonquery Record Groups Programmatically 11-19

Manipulating Record Group Rows 11-21

Manipulating Selected Record Group Rows 11-23

Page 8: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................viii Oracle Developer: Build Forms II

.....................................................................................................................................................Contents

Defining Global Record Groups 11-25

Manipulating List Items Programmatically 11-27

Implementing Dynamic List Items 11-29

Adding Values to Combo Boxes 11-31

Summary 11-33

Practice Session Overview: Lesson 11 11-35

Practice 11 11-36

Lesson 12: Including Charts and ReportsIntroduction 12-3

Including Charts by Using the Chart Wizard 12-5

Chart Item Properties 12-11

Reporting Within Form Builder 12-13

Report Object Properties 12-15

Working with Reports 12-17

Summary 12-21

Practice Session Overview: Lesson 12 12-23

Practice 12 12-24

Lesson 13: Applying TimersIntroduction 13-3

Timers 13-5

Handling Timer Expiration 13-7

Creating a Timer 13-9

Modifying a Timer 13-11

Deleting a Timer 13-13

Summary 13-15

Practice Session Overview: Lesson 13 13-17

Practice 13 13-18

Lesson 14: Using Server Features in Form BuilderIntroduction 14-3

Using Oracle Server Functionality in Forms 14-5

Dealing with PL/SQL Code 14-7

Page 9: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II ix

.....................................................................................................................................................Contents

PL/SQL8 Support 14-9

New PL/SQL8 Scalar Data Types 14-11

Unsupported Client-Side PL/SQL8 Features 14-13

Handling Errors Raised by the Oracle Server 14-15

Performing DDL with FORMS_DDL 14-19

Using FORMS_DDL 14-21

Summary 14-23

Practice Session Overview: Lesson 14 14-25

Practice 14 14-26

Lesson 15: Using Reusable ComponentsIntroduction 15-3

Reusable Components 15-5

Reusable Components List 15-7

The Calendar Class 15-11

Calendar Object Group Content 15-13

Built-in for Manipulating the Calendar 15-15

Summary 15-17

Practice Session Overview: Lesson 15 15-19

Practice 15 15-20

Appendix A: Practice SolutionsPractice 1 Solutions A-2

Practice 2 Solutions A-5

Practice 3 Solutions A-9

Practice 4 Solutions A-12

Practice 5 Solutions A-16

Practice 6 Solutions A-18

Practice 7 Solutions A-21

Practice 8 Solutions A-25

Practice 9 Solutions A-29

Practice 10 Solutions A-34

Practice 11 Solutions A-36

Practice 12 Solutions A-42

Page 10: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................x Oracle Developer: Build Forms II

.....................................................................................................................................................Contents

Practice 13 Solutions A-45

Practice 14 Solutions A-49

Practice 15 Solutions A-55

Appendix B: Table Descriptions and DataSummit Sporting Goods Database Diagram B-2

S_CUSTOMER Description B-3

S_CUSTOMER Data B-4

S_DEPT Description and Data B-8

S_EMP Description B-9

S_EMP Data B-10

S_ITEM Description B-13

S_ITEM Data B-14

S_ORD Description and Data B-16

S_PRODUCT Description B-17

S_PRODUCT Data B-18

S_REGION Description and Data B-22

S_TITLE Description and Data B-23

Oracle8 objects: types, tables B-24

Appendix C: Project Builder AddendumIntroduction C-3

Team Development with Project Builder C-5

Generating and Printing Project Reports C-11

Defining New Module Types C-13

Identifying New Module Types C-15

Describing New Module Types C-17

Actions for New Module Types C-19

An Icon for New Module Types C-21

Modifying Types Using Actions C-23

Customizing Actions by Using Macros C-25

Customizing the Launcher C-29

Inheritance in Project Builder C-31

Actions C-33

Page 11: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II xi

.....................................................................................................................................................Contents

Summary C-35

Appendix D: Introduction to Oracle8 Object FeaturesIntroduction D-3

New Oracle8 Data Types D-5

Object Types D-7

Creating Oracle8 Objects D-11

Object Columns D-13

Object Views D-15

INSTEAD-OF Triggers D-17

Referencing Objects D-19

Displaying Oracle8 Objects in the Object Navigator D-21

Summary D-29

Appendix E: Menu Run-Time ParametersIntroduction E-3

Substitution Parameters E-5

Defining a User-Named Substitution Parameter E-7

Substitution Parameter Built-ins E-9

Validating a Substitution Parameter Value E-11

Summary E-13

Appendix F: Handling Server-Side ErrorsIntroduction F-3

Obtaining the Cause of Declarative-Constraint Violations F-5

Customizing Oracle Server Error Messages F-7

Example Procedure for Handling Oracle Server Errors F-9

Summary F-13

Appendix G: EMP_PKG PackagePackage Specification G-2

Package Body G-4

Appendix H: Working with ActiveX ControlsIntroduction H-3

Page 12: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................xii Oracle Developer: Build Forms II

.....................................................................................................................................................Contents

What Are VBX, OCX, and ActiveX Controls? H-5

Comparison of VBX, OCX, and ActiveX Controls H-7

ActiveX in Form Builder H-9

Implementing an ActiveX Control H-11

Inserting an ActiveX Control in an ActiveX Control Item H-13

Importing ActiveX Control Methods and Events Packages H-15

Setting and Getting ActiveX Control Properties H-17

Invoking ActiveX Control Methods H-21

Responding to ActiveX Control Events H-23

Handling Exceptions H-25

Registering an ActiveX Control H-27

Summary H-29

Appendix I: Using Oracle Server Roles at Run TimeUsing Oracle Server Roles at Run Time I-3

Procedures for Managing Roles I-7

Appendix J: Instructor NoteIntroduction J-2

How the Project Is Organized J-3

Project Setup J-4

Launching the Files J-8

Page 13: Build Forms II Volume 1 Instructor Guide 7196298

.................................

Preface

Page 14: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................xiv Oracle Developer: Build Forms II

.....................................................................................................................................................Preface

Instructor NoteGeneral course information for instructors:

PowerPoint Slides The slide show provides many builds to facilitate your explanation. Of course, you can modify these builds if you prefer, depending upon your familiarity with PowerPoint.

All slides include a small arrow at the bottom of the screen that is displayed on the final build, so that you know when one slide finishes and the next slide begins. On the last slide of a lesson the arrow points to the left instead of the right.

If you modify a build, make sure that this arrow is the last object in the build order.

Demonstrations A set of demonstrations is provided to help you with your explanations. You can launch the demonstration files from Project Builder. For additional information, see Appendix J, “Instructor Note.”

Practice Sessions Students might want to view the form that they are asked to produce in each question. Solution files of all forms are available in the LAB_SOL directory. You can also launch them from Project Builder. See Appendix J “Instructor Note” for additional information.

Page 15: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II xv

.....................................................................................................................................................Profile

Profile

Before You Begin This CourseBefore you begin this course, you should have the following qualifications:

• Thorough knowledge of:

- Creating simple applications with Oracle Developer Form Builder

- Creating SQL query statements

• Working experience of:

- Creating PL/SQL constructs, including conditional statements, procedures, and functions

- Creating PL/SQL stored (server) procedures and functions

• Knowledge of using a graphical user interface (GUI)

PrerequisitesThe following instructor-led training (ILT) course: Oracle Developer: Build Forms I

Suggested Follow-up Courses• Oracle Developer: Build Reports

• Oracle Developer: Deploy Web-Based Applications

• Oracle Designer: Design and Generate Oracle Developer Applications

How This Course Is OrganizedOracle Developer: Build Forms II is an instructor-led course featuring lectures and hands-on exercises. Online demonstrations and written practices reinforce the concepts and skills introduced.

Page 16: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................xvi Oracle Developer: Build Forms II

.....................................................................................................................................................Preface

Related Publications

Oracle Publications

Additional Publications• read.me file

• relnotes.pdf file

Title Part NumberOracle Developer Guidelines for Building Applications, Release 6

A50994-1

Oracle Developer Getting Started, Release 6 A50995-1

Page 17: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................Oracle Developer: Build Forms II xvii

.....................................................................................................................................................Typographic Conventions

Typographic Conventions

Typographic Conventions in TextConvention Element ExampleBold italic Glossary term (if

there is a glossary)The algorithm inserts the new key.

Caps and lowercase Buttons,check boxes, triggers,windows

Click the Executable button.

Select the Can’t Delete Card check box.

Assign a When-Validate-Item trigger . . .

Open the Master Schedule window.

Courier new,case sensitive (default is lowercase)

Code output, directory names, filenames,passwords, pathnames,URLs, user input, usernames

Code output: debug.seti(’I’,300);

Directory: bin (DOS), $FMHOME (UNIX)

Filename: Locate the init.ora file.

Password: Use tiger as your password.

Pathname: Open c:\my_docs\projects

URL: Go to http://www.oracle.com

User input: Enter 300

Username: Log on as scott

Initial cap Graphics labels (unless the term is a proper noun)

Customer address (but Oracle Payables)

Italic Emphasized words and phrases,titles of booksand courses, variables

Do not save changes to the database.

For further information, see Oracle7 Server SQL Language Reference Manual.

Enter [email protected], where user_id is the name of the user.

Quotation marks Interface elements with long names that have only initial caps; lesson and chapter titles in cross-references

Select “Include a reusable module component” and click Finish.

This subject is covered in Unit II, Lesson 3, “Working with Objects.”

Uppercase SQL column names, commands, functions, schemas, table names

Use the SELECT command to view information stored in the LAST_NAME column of the EMP table.

Page 18: Build Forms II Volume 1 Instructor Guide 7196298

.....................................................................................................................................................xviii Oracle Developer: Build Forms II

.....................................................................................................................................................Preface

Typographic Conventions in Code

Typographic Conventions in Navigation PathsThis course uses simplified navigation paths, such as the following example, to direct you through Oracle Applications.

(N) Invoice—>Entry—>Invoice Batches Summary (M) Query—>Find (B) Approve

This simplified path translates to the following:

1 (N) From the Navigator window, select Invoice—>Entry—>Invoice Batches Summary.

2 (M) From the menu bar, select Query—>Find.

3 (B) Click the Approve button.

N = Navigator, M = Menu, B = Button

Arrow Menu paths Select File—>Save.Brackets Key names Press [Enter].

Commas Key sequences Press and release these keys one at a time:[Alt], [F], [D]

Plus signs Key combinations Press and hold these keys simultaneously:[Ctrl]+[Alt]+[Del]

Convention Element ExampleCaps and lowercase Oracle Forms

triggersWhen-Validate-Item

Lowercase Column names, table names

SELECT last_name

FROM s_emp;

Passwords DROP USER scott

IDENTIFIED BY tiger;

PL/SQL objects OG_ACTIVATE_LAYER

(OG_GET_LAYER (’prod_pie_layer’))

Lowercase italic Syntax variables CREATE ROLE role

Uppercase SQL commands and functions

SELECT userid

FROM emp;

Convention Element Example

Page 19: Build Forms II Volume 1 Instructor Guide 7196298

................................

1

Managing Projectswith Project Builder

Page 20: Build Forms II Volume 1 Instructor Guide 7196298

1-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteTopic Timing

Lecture 40 minutes

Practice 25 minutes

Total 65 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:• Define Project Builder terminology• Identify the uses of Project Builder• Recognize the components of the

Project Builder user interface• Create projects and subprojects

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

• Invoke actions associated with entries• Create entries from files and

subdirectories• Establish dependencies among project

entries• Build files and projects• Deliver a project by using the Delivery

Wizard

Page 21: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewOne of the most difficult aspects of application development is managing the files that make up an application. Large applications can consist of hundreds of files and millions of lines of code. In addition, files that are important to the project as a whole but that are not compiled into the application itself, such as design specifications, test scripts, and documentation, must also be tracked and maintained. This lesson explains how to use Oracle Developer Project Builder to help you manage application development.

Additional Project Builder features are covered in Appendix C, “Project Builder Addendum.”

ObjectivesAfter completing this lesson, you should be able to do the following:

• Define Project Builder terminology

• Identify the uses of Project Builder

• Recognize the components of the Project Builder user interface

• Create projects and subprojects

• Invoke actions associated with entries

• Create entries from files and subdirectories

• Establish dependencies among project entries

• Build files and projects

• Deliver a project by using the Delivery Wizard

Instructor NoteIndividual components—Form Builder, Report Builder, and so on—do not have splash screens. You see a splash screen only when you start Project Builder.

Oracle Developer demonstrations include the project file that was used to create them. This file provides an excellent prebuilt demonstration that you can use to show students all the capabilities of Project Builder.

Page 22: Build Forms II Volume 1 Instructor Guide 7196298

1-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Copyright Oracle Corporation, 1999. All rights reserved.

What Is Project Builder?

Page 23: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-5......................................................................................................................................................

......................................................................................................................................................Introducing Project Builder

Introducing Project BuilderFor developers working on large, complex projects, managing the files that make up those projects is always a difficult and time-consuming task. A typical Oracle Developer project might consist of tens or hundreds of files. These files are of various types; for example:

• Forms modules and their corresponding executables

• Reports modules and their corresponding executables

• Graphics modules and their corresponding executables

• PL/SQL libraries

• Icons and bitmaps

• Dynamic-link libraries built from C source files

• Text documents such as test scripts and specifications

• Test data

• SQL scripts

The developer faced with these files must constantly ask questions such as:

• What files make up this project?

• How do files depend on one another?

• Which files have been modified and need to be rebuilt?

• Which files are to be delivered to the deployment environment?

• What type of file is this, and how do I print, edit, or build it?

Many developer hours are wasted trying to resolve such issues of configuration and management. Project Builder brings these tasks under control as an integral part of the Oracle Developer product.

Page 24: Build Forms II Volume 1 Instructor Guide 7196298

1-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteDemonstration: Use the Oracle Developer: Build Forms II project to illustrate the terminology. Show the different nodes, the Build From FMB action for the Form Builder executable type, and also the ORACONNECT macro.

Copyright Oracle Corporation, 1999. All rights reserved.

Project Builder Terminology

Project

Subproject

Project Entry

Registry

Type

Action

Macro

Collection of components

Projects contained within other projects

Representation of project items in theProject Navigator

Storehouse of information

Category of files

Command string

Variable to customize and extend actions

Term Description

Copyright Oracle Corporation, 1999. All rights reserved.

Project Builder Terminology

Projectentries

Subproject Subproject

Projectentries

Projectentries

Type Type

Actions Actions

Macros Macros

Built-inMacros

RegistryGlobal User

Project

Page 25: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-7......................................................................................................................................................

......................................................................................................................................................Project Builder Terminology

Project Builder TerminologyProject Builder is based upon the concepts of projects and subprojects.

Term Description

Project A project is a collection of pointers to the files that compose an application. Files might include form modules, icons, or C source.

Subproject A subproject is a project contained within another project, and it enables a finer level of organizational granularity. You can organize your forms, reports, and displays in their own subdirectories, or even organize your direc-tories by functional groups corresponding to sections of your application.

Project Entry

A project entry is a representation of a file in your application. When you delete a project entry from the Project Navigator, you do not delete the file, only a pointer to the file.

Type A type is a category of file to which a file belongs, such as form, report, or C source. A type determines which actions can be performed against files of that type. Project Builder recognizes file types primarily by default extension; for example, .txt for text files.

Action An action is a command string that applies to types, such as print, edit, or build. Actions can act on individual components or on several components at a time.

Macro A macro is a variable used to customize and extend actions. There are several predefined macros, such as {name} and {path}. For example, Project Builder inserts all the information you have specified for connecting to a database into the ORACONNECT macro, which is included in all commands that require database connection. The informa-tion in the macro is then inserted into the action so you can log on automati-cally.

Registry A registry is a storehouse of information about a project.

Page 26: Build Forms II Volume 1 Instructor Guide 7196298

1-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteInsist on the word deliver. Do not use the word deploy. Project Builder is not yet able to deploy an application to end users. The only thing that Project Builder does is package a set of files.

Copyright Oracle Corporation, 1999. All rights reserved.

Project Builder Benefits

• View all files associated with anapplication in a common navigator

• Automate actions

• Share projects among team members

• Define commonly used connect strings

• Deliver your application to end users

Page 27: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-9......................................................................................................................................................

......................................................................................................................................................Project Builder Benefits

Project Builder BenefitsProject Builder helps ease the burden of managing large, complex applications.

Viewing All Files Associated with an Application in a Common NavigatorYou can associate all of the files in your application simply by adding them to the same project. You can then view a graphical presentation of the project in a familiar “navigation” style.

This method enables you to track a large application as a single entity and to determine the dependencies between modules.

Automating ActionsProject Builder enables you to initiate on files common actions such as Edit, Print, and Build from directly within the Project Navigator. Project Builder ships with default actions that can be modified and customized. Customization of actions is covered in Appendix C, “Project Builder Addendum.”

Sharing Projects Among Team MembersCommon storage areas, called registries, enable developers to share information about projects.

Defining Commonly Used Connect StringsWith Project Builder, you can define all your most-used database connect strings and store their definitions under the Connections node. You can then assign a connection to projects, subprojects, types, or individual project entries by dragging the connection from the Connections node and dropping it on the desired project, subproject, type, or project entry.

Delivering Application to End UsersProject Builder includes a wizard that simplifies packaging your application for end users. You have the option of delivering your entire application, or delivering only those files that have been updated from the previous release.

Page 28: Build Forms II Volume 1 Instructor Guide 7196298

1-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteDemonstration: Use the Oracle Developer: Build Forms II project to show the components. Expand the Summit application subproject node, and change the Project Navigator view. Launch Form Builder from the Launcher.

1 Launcher 3 Pop-up menu

2 Project Navigator 4 Property Palette

Copyright Oracle Corporation, 1999. All rights reserved.

Project Builder User Interface

1

2

3

4

Page 29: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-11......................................................................................................................................................

......................................................................................................................................................Project Builder User Interface

Project Builder User InterfaceProject Builder has four main components: the Project Navigator, the pop-up menus, the Property Palette, and the Launcher toolbar.

The Project NavigatorThe Project Navigator is the main window for managing and organizing the entries in a project. It can be displayed in one or two views.

The Pop-up MenusUse the pop-up menus to launch actions against entries from the Project Navigator.

1 Select the entry.

2 Click the right mouse button.

3 Select one of the available actions shown on the pop-up menu.

Note: You can add the commands you consider most useful to the type-specific pop-up menus available from the Project Navigator.

The Property PaletteProject Builder includes the Property Palette for connections, types, entries, and projects. Using the Property Palette, you can view and modify properties, actions, and macros. You can also add new actions and macros to types, entries, and projects.

The LauncherProject Builder also provides the Launcher, a customizable toolbar to which you can add all the tools, including third-party tools, that you need to edit your project file. Customizing the Launcher is covered in Appendix C, “Project Builder Addendum.”

View Description

Project view The entries in a project are organized by project and subproject, then by type. This is useful to see all of the entries of a particular type, for example, all of the PL/SQL libraries used in a project.

Dependency view The entries in a project are organized by dependencies between files; for example, an object file depends on a source file and a number of header files.

Page 30: Build Forms II Volume 1 Instructor Guide 7196298

1-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Project Builder User Interface

• Filtered views

• Password protection

Page 31: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-13......................................................................................................................................................

......................................................................................................................................................Project Builder User Interface

Project Builder User InterfaceProject Builder user interface enables you to view a subset of the entries, and to limit access to the project.

Filtered ViewsA filter allows you to display only those projects or project items in the Project Navigator that meet certain criteria. When you apply a filter, the objects that do not match the criteria specified in the filter definition are hidden from view.

To create a filter, select Navigator—>Manage Filters from the main menu. Click the Add Filter button. The Add Filter dialog box is displayed. Enter a name for the filter in the Filter name field.

Use the tabs (General, File, Project, Delivery, Connection, and Macros) to specify values for the project or item properties you want the filter to locate. All properties are joined by AND; no provisions are made for OR conditions. As you add criteria, the filter definition is recorded in the Current filter criteria field.

To remove criteria from your filter, select the property and its value in the Current filter criteria field and click Remove.

When you finish creating your filter, click the OK button.

Password ProtectionYou can set passwords for projects to protect them from unauthorized viewing or modification. When a user tries to open a password-protected project, a dialog prompts the user to enter the password. If the user cannot supply the correct password, access to the project is denied.

To set a password for a project file select the node for the project you want to protect. Select FileAdministration—>Set Project Password to display the Set Project Password dialog.

Enter the password in the New password field. The password may be of any length and may contain any characters. The password does not expire. Enter the password again in the Confirm password field to verify the spelling. Click the OK button.

When you or another user attempts to open this project, a dialog prompts you to enter the password.

Page 32: Build Forms II Volume 1 Instructor Guide 7196298

1-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteDemonstration: Create a new project by using the Project Wizard. Name your project Summit Application and add all the files for the Summit application. Explain that a connection is a named set of a username, a password, and a connect string that can be assigned as a group to a project entry or type.

Copyright Oracle Corporation, 1999. All rights reserved.

Creating Projectsand Subprojects

Copyright Oracle Corporation, 1999. All rights reserved.

Specifying User Defaults

Page 33: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-15......................................................................................................................................................

......................................................................................................................................................Creating Projects and Subprojects

Creating Projects and SubprojectsA project is a collection of pointers to the files that make up an application, and the project registry file is the physical file in which this information is stored. Your first job in creating a project is to define the project registry file.

The Project WizardThe Project Wizard provides an easy-to-use interface for creating a project.

To create a project using the Project Wizard, click the Project Wizard icon on the toolbar and:

• Define the project

• Specify user defaults

• Add files to the project

You can also create a new project without the Project Wizard by using the New Project tool available on the toolbar and by setting project properties in the Property Palette.

Defining the ProjectIn the Project Wizard, you can choose to:

• Create a standalone project (the default)

• Create a subproject, a project that is part of a larger project

When defining the project, you must:

• Name your project.

• Select a default directory for the project registry file.

• Name the project registry file.

Specifying User DefaultsNext, you can specify:

• The author of the project

• A default connection to a data source such as an Oracle Server. This connection will apply to all files within your project unless it is overridden.

• Any comments that you want to add

Note: This information is optional but can be used to identify and document your projects in a team development environment.

Page 34: Build Forms II Volume 1 Instructor Guide 7196298

1-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteThe directory structure of a project can have far-reaching consequences. Suppose you include modules in a project that are located in a directory that is not a child of the project directory. Then you create actions that search for and modify project modules. How will you find the “orphan” modules? How will you create alternative actions with hard-coded paths? It is not portable. Perhaps you can search from the root, but this is not efficient.

Recommendations:

• Locate modules in the project directory or in a directory that is a child of the project directory (a good choice when adding subprojects).

• Use only relative paths. In other words, create a project and subprojects that mirror your actual directory structure.

Copyright Oracle Corporation, 1999. All rights reserved.

Adding Project Files

• Add files through the Project Wizard.

• Add files to a project at any later time.

• Specify that implicitcomponents beadded to theprojectautomatically.

Page 35: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-17......................................................................................................................................................

......................................................................................................................................................Adding Project Files

Adding Project Files

Accepting the Project WizardThe last step allows you either to add files to your project from within the Project Wizard (the default) or to create an empty project. When you select Finish, the Project Wizard creates your new project.

The Add Files Dialog BoxIf you choose to add files to your project from within the Project Wizard, you can immediately select files to be included as entries in your project. You can also add other components at any later time.

Note: The dialog box always inserts the full path unless the module you want to add is in the project directory.

In all other instances, the dialog box forces a full path. In that case, you can manually change it to the relative path by:

• Selecting the item (for example, a subproject) in the Project Navigator

• Displaying the Property Palette

• Editing the Filename property

Page 36: Build Forms II Volume 1 Instructor Guide 7196298

1-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteCreate a subproject from a subdirectory. You can use the directory structure where the instructor demo files are stored.

Copyright Oracle Corporation, 1999. All rights reserved.

Creating Subprojectsfrom Subdirectories

Page 37: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-19......................................................................................................................................................

......................................................................................................................................................Subdirectories Added as Subprojects

Subdirectories Added as SubprojectsYou can add an entire subdirectory of files as a subproject by selecting Project—>Add Directory to Project… from the Add Directory to Project dialog box, choose the directory and click OK. You have created a subproject with the same name as the subdirectory, and all of the files in the subproject are registered.

If the selected subdirectory has subdirectories of its own, they are added as subprojects to the newly created subproject, and their files are registered.

Page 38: Build Forms II Volume 1 Instructor Guide 7196298

1-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteDemonstration: Create a connection. Add it to a project and to an entry.

Copyright Oracle Corporation, 1999. All rights reserved.

Creating Connections

Copyright Oracle Corporation, 1999. All rights reserved.

Assigning a Connect String

Page 39: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-21......................................................................................................................................................

......................................................................................................................................................Creating Connections

Creating ConnectionsIn a typical project, the developer has a number of databases to work against. For example, there might be a small “scratch” database where the developer can create any test data he or she needs; a large test database that contains the data for a formal test suite; and perhaps databases running different versions of Oracle to test backward compatibility or new features.

With Project Builder the developer can define and save the connect strings associated with these various databases, and then easily associate those connections with the project files, simply by dragging a connection and dropping it on the entry for the file. When the Form module is next opened from Project Builder, Form Builder automatically connects to the database before opening the form.

Define a Connect String1 Select the Connections node in the Project Navigator and choose New

Connection from the pop-up menu to display the Add Connection dialog box.

2 Type a title in the Title text box. The title provides the label for the connect string in the Project Navigator.

3 Type a username, password, and connect string in the corresponding text boxes.

4 (Optional) Add comments in the Comments text field.

5 Click OK to accept the dialog and add the connection to your list of possible connections.

Assign a Connect String to a Project or a Project Item1 In the Project Navigator, expand the Connections node. Select the

connection you want to associate with the project or project item.

2 Drag and drop the connection on the project or project item.

The new connect string is inserted into the appropriate actions for all items in the project (if you assigned it to a project) or the project item.

Page 40: Build Forms II Volume 1 Instructor Guide 7196298

1-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteDemonstration:

• Open a Form Builder file.

• Edit a SQL file or a text file.

• Show how to create and assign a connect string, because students will have to do it in the practice session.

• Display the Property Palette by selecting Tools––>Property Palette. Mention that it is impossible to describe all the properties, because they differ from type to type. Explain that the properties are classified by family:

- General information

- Connections

- Actions

- Macros

Do not demonstrate the other options. They are covered later in this lesson. Just explain what they mean.

Copyright Oracle Corporation, 1999. All rights reserved.

Working with Project Files

• Open and edit files• Add, modify, or remove files and types• Specify dependencies• Compile the project• Package the project

Page 41: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-23......................................................................................................................................................

......................................................................................................................................................Working with Project Files

Working with Project FilesWhen your project is set up, you can use Project Builder to:

• Open and edit the files

• Specify dependencies

• Build the project

• Package the project for delivery

Editing FilesProject Builder comes with a large number of the most common actions already defined. For example:

• Selecting Open from the pop-up menu for a text file may invoke Notepad.

• Selecting Open from the pop-up menu for a form may invoke Form Builder.

If necessary, you can modify the predefined commands for any type. You can also launch a tool from the Launcher. For more information, see Appendix C, “Project Builder Addendum.”

Adding, Modifying, and Removing File TypesProject Builder comes with a large number of the most common file types already defined. You can define new file types, alter existing file types, or remove file types. For more information, see Appendix C, “Project Builder Addendum.”

Page 42: Build Forms II Volume 1 Instructor Guide 7196298

1-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteTo explain the needs of explicit dependencies, you can use the dependence between two.fmb files. When you make an object a subclass of a form and you change the parent definition. you must build the child.

Copyright Oracle Corporation, 1999. All rights reserved.

Implicit Dependencies

Deduces dependencies from

• Deliverable Type property

• Build From < type> action

ExampleType

Deliverable Type

Build From FMB

FMB-Form Builder document

FMX-Form Builder executable

..\bin\ifcmp60.exe

Copyright Oracle Corporation, 1999. All rights reserved.

Explicit Dependencies

Add explicitdependencies in theNavigator:

• Select the parent,click Add Files.

• Cut the child; pasteit onto the parent.

Select Navigator—>Dependency View.

Page 43: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-25......................................................................................................................................................

......................................................................................................................................................Establishing Dependencies

Establishing DependenciesProject dependencies refer to the order in which project entries depend on each other. For example, a Form Builder executable file (.fmx) depends on a Form Builder module file (.fmb), which may depend on a Form Builder library file (.pll), and so on.

Implicit DependenciesProject Builder automatically deduces many dependencies from the Deliverable Type property and the Build From <type> action of interdependent types.

• The Deliverable Type property specifies whether the type of file delivered to the end user.

• The Build From <type> action specifies the command used to build a file of a given type.

ExampleThe type Form Builder module (.fmb files) has a deliverable type of Form Builder executable (.fmx files). Therefore, Project Builder can deduce that any .fmx files in your project are dependent on the associated .fmb files, and if those .fmb files change, the .fmx files must be rebuilt based on the Build From <type> action defined for the Forms Executable (.fmx) type. If there is no .fmx file already in your project, Project Builder will show it as an item that is implied by the existence of the .fmb.

Explicit DependenciesSometimes you will have dependencies that Project Builder cannot determine automatically. For instance, your form may contain calls to program units in a PL/SQL library. If the interfaces to the program units in the library change, you need to rebuild the Form Builder executable (.fmx).

To allow the developer to include such dependencies in the project definition, dependencies can be added manually. To indicate that an .fmx depends on a PL/SQL library:

1 Select the entry (.fmx file).

2 Select Project––>Add Files to Project.

3 Select the files to be added as a dependency of the selected entry.

Note: To see the dependencies in the project, select Dependency View in the Project Navigator.

Page 44: Build Forms II Volume 1 Instructor Guide 7196298

1-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Callouts

Instructor NoteDemonstration: Show all the options.

If you want to demonstrate the Build Selection option, be sure to select the .fmx entries, and be sure not to select the .fmb entries.

If you want to demonstrate the Build All option, be sure that you illustrate this option on a small project (with few files). Use, for example, the project that you created earlier (Summit Application).

1 Build All

2 Build Selection

3 Build Incremental

Copyright Oracle Corporation, 1999. All rights reserved.

Building ProjectsThree build options:

1

3

2

Page 45: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-27......................................................................................................................................................

......................................................................................................................................................Building Projects

Building ProjectsProject Builder easily enables you to ensure that the “build” is up-to-date. You can update your project and build all dependencies by using one of three build options in the Project Builder Project menu:

Build Option Description

Build Selection Select one or more files in the Project Navigator, and choose Build Selection from the Project menu. Project Builder rebuilds the selected files only.

Build All To build all files in the project, select the project in the Project Navigator and choose Build All. Project Builder builds all files, regardless of whether you have modified them since the previous compilation.

Build Incremental To build modified files only, select Build Incremental from the Project menu, or click the equivalent toolbar button. Project Builder automatically determines which files need to be built, by examining the file time stamps to determine which files have been modified and rebuilding those that are out of date.

Page 46: Build Forms II Volume 1 Instructor Guide 7196298

1-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Delivering the Project

• Set the Deliver File property: Specifiescomponents that are the deliverables

• Specify the Deliver the Selected File(s)action: Defines how to package adeliverable file

• Set the PACKFILE macro: Specifies thename of the .zip or .tar file

Page 47: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-29......................................................................................................................................................

......................................................................................................................................................Delivering Projects

Delivering ProjectsAfter a project is completed, the remaining task is to deliver the executable files, help files, supporting media (such as sounds, images, videos, or icons), and any other files that the end user will need to have installed. Typically, the delivery process involves setting certain delivery properties and invoking the delivery wizard.

The Deliver File PropertyTo simplify this task, Project Builder includes the Deliver File property, which allows you to indicate which entries represent files to be delivered to the end user.

Usually the Deliver File property will be inherited from the type. For some files this may not be appropriate. In this case, you can simply override the setting on individual entries, as with any other property. Alternatively, you might choose to organize all the deliverables into a separate subproject, and then set the Deliver File property on that subproject to Yes, which then all the files in the subproject will then inherit.

The Deliver the Selected Files ActionBefore packaging your files, you must define the Deliver the Selected Files to be the exact command needed to archive the files. Typically, the definition for this action uses the PACKFILE macro.

The PACKFILE MacroBefore packaging your files, you must define the PACKFILE macro to be the name of the .zip or .tar file that is the result of the Deliver action.

Actions and Macros are explained in Appendix C, “Project Builder Addendum.”

Page 48: Build Forms II Volume 1 Instructor Guide 7196298

1-30 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Instructor NoteDemonstration: Deliver a project as an Oracle Installer script.

Copyright Oracle Corporation, 1999. All rights reserved.

Delivering the Project

Page 49: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-31......................................................................................................................................................

......................................................................................................................................................Delivering Projects

Delivering Projects (continued)Once you’ve developed and tested your project (the application that is a collection of forms, reports, graphics, and PLSQL modules), you need a way to package and deploy it on your target environments. The Delivery Wizard can help you accomplish these tasks by providing the means to:

• Copy or FTP your completed project, or product, to a staging area.

• Generate the necessary scripts so your product is installable on Windows 95 and NT through the Oracle Installer.

• Run your customized Deliver action against a project.

To invoke the Delivery Wizard, select Tools—>Delivery Wizard from the main menu.

Delivery Using an Oracle Installer ScriptThe Delivery Wizard can create the files you need to install your application using Oracle Installer.

• Select the project you want to deliver, and whether you want all of the files, or only changed files delivered.

• Select the radio button “Deliver locally and create Oracle Installer scripts.” Enter the destination directory for the scripts.

• Enter the name of the script, a program group name for the script, and a version number. You may choose to have the Oracle Developer runtime environment installed at the same time, if you wish.

• Select the files for delivery. These will be preselect according to each files Delivery property.

• Specify the subdirectories in which you want the files delivered. You may also specify a start menu label for any file.

• Specify andy environmental variables that need to be set.

Delivery Using the Customized Delivery ActionYou may also use the Delivery Wizard to package files in an archive file, such as a .zip file or a .tar file. With this method, you must define the Deliver the Selected Files action and the PACKFILE macro. Actions and Macros are explained in Appendix C, “Project Builder Addendum.”

Page 50: Build Forms II Volume 1 Instructor Guide 7196298

1-32 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

n

Instructor NoteFor additional information about Project Builder, and especially how to use Project Builder in a team environment, see Appendix C, “Project Builder Addendum.”

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Defining Project Builder terminology

• Using the Project Navigator

• Creating connections

• Defining dependencies

• Building and delivering a project

Page 51: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-33......................................................................................................................................................

......................................................................................................................................................Summary

Summary

Project Builder Basics• Define Project Builder terminology

• Identify Project Builder uses

• Describe Project Navigator features

Building a Project• Create projects and subprojects

• Create connections

• Open project files

• Build and deliver projects

Note: For additional information about Project Builder, see Appendix C, “Project Builder Addendum.”

Page 52: Build Forms II Volume 1 Instructor Guide 7196298

1-34 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Practice SolutionsFor practice solutions, see Appendix A, “Practice Solutions.”

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 1 Overview

This practice covers the following topics:

• Creating an initial project

• Creating a connection

• Experimenting with the various ProjectNavigator views

• Creating subprojects and adding filesand subdirectories to them

• Delivering a project

Page 53: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-35......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 1

Practice Session Overview: Lesson 1This practice guides you through creating a project and adding entries.

Practice Contents• Create an initial project

• Create a connection

• Experiment with various Project Navigator views

• Create subprojects and add files and subdirectories to them

• Deliver a project

Page 54: Build Forms II Volume 1 Instructor Guide 7196298

1-36 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Practice 11 Create a connection to the database.

a Create a new connection.

b Name the connection SUMMIT and specify the connect string. Your instructor should provide this information.

2 Create an initial project.

a Create a new project (use the Project Wizard).

b Name the project “Oracle Developer: Build Forms II”. Assign to this project the connection created earlier, and save it as summit.upd in the Lab directory. Do not add files to this project.

a Using the Project Wizard, create a subproject named Summit Application that belongs to Oracle Developer: Build Forms II.

b From the labs directory, add:

- baseball.tif

- calendar.pll

- copy.ico

- customers.fmb

- Form_Builder_II.olb

- pr11_2f.txt

- pr7_3a.sql

c Give a file items a more meaningful title.

3 Create a subproject and add files to it.

4 Explore the Project Navigator.

a Examine the state of the Project Navigator. Note that Project Builder has added executable versions of the Oracle source files that you added to the project.

b Turn off the Show Implicit Items option. Note what happens to the Project Navigator display.

c Experiment with Project Builder’s different views.

5 Deliver the project.

a Invoke the Delivery Wizard and deliver all files.

b Create Oracle Installer scripts on your local file system.

c Include all the deliverable files in the project.

d Accept the default delivery directories.

Page 55: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 1-37......................................................................................................................................................

......................................................................................................................................................Practice 1

e Do not set any environmental variables upon installation.

f Verify the settings, and finish the delivery.

If you have time...

6 Create a subproject from a subdirectory and add files to it.

Using the Project Wizard, create a subproject named Lab_Sol that belongs to Oracle Developer: Build Forms II. Automatically include all files in that subdirectory.

Page 56: Build Forms II Volume 1 Instructor Guide 7196298

1-38 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 1: Managing Projects with Project Builder

Page 57: Build Forms II Volume 1 Instructor Guide 7196298

................................

2

Creating a Menu Module

Page 58: Build Forms II Volume 1 Instructor Guide 7196298

2-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteTopic TimingLecture 50 minutes

Practice 40 minutes

Total 90 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Identify the components of a menu

• Create, save, and attach menu modules

• Set menu properties by using theProperty Palette

• Create menu toolbars

• Create pop-up menus

Page 59: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewBy default, each form module uses the same menu structure, called the Default menu. This lesson teaches you how to customize this menu and how to create your own menu modules. You will also learn how to enhance your application by including menu toolbars and pop-up menus.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Identify the different components of a menu module

• Create, save, and attach menu modules

• Set menu properties by using the Property Palette

• Create menu toolbars

• Create pop-up menus

Page 60: Build Forms II Volume 1 Instructor Guide 7196298

2-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteDemonstration: Run the Orders form (orders.fmb) to explain the components. Open the Default menu (menudef.mmb) to illustrate the hierarchical structure of a menu.

Copyright Oracle Corporation, 1999. All rights reserved.

Components of the MenuModule

Mainmenu

Menu item

Individual menu Menu toolbar

Copyright Oracle Corporation, 1999. All rights reserved.

Hierarchical Structure of a Menu

Menumodule

Individualmenu

Submenu

Menuitems

Menuitem

Menuitem

Individualmenu

Menuitems

Page 61: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-5......................................................................................................................................................

......................................................................................................................................................Components of the Menu Module

Components of the Menu Module

What Is a Menu Module?A menu module is a hierarchically structured object that provides a quick and easy method for operating your Forms application. Like the form module, the menu module is one of the main components of an application.

Each menu module displays as a pull-down menu. A pull-down menu comprises a set of options, displayed horizontally under the application window title. Each option can represent a submenu or an action. Selecting a submenu displays a vertical list. Selecting an action executes the action.

What Is a Menu?A menu is a list of related options. Each option performs a different action. You can create three menu types in Forms:

• Main menu:

- Displays horizontally in the menu bar

- Contains options (menu items) that are typically individual menus

• Individual menu: Displays vertically

• Submenu: Displays vertically and to the right of the menu item that calls it

What Is a Menu Item?A menu item is an option that you can choose from a menu. Each menu item has an associated command that enables the user to perform an action.

What Is a Menu Toolbar?A menu toolbar is a toolbar of iconified buttons that represent individual items from your menu. For a menu module, you can have a vertical and a horizontal menu toolbar.

Page 62: Build Forms II Volume 1 Instructor Guide 7196298

2-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteThe path for menudef.mmb is

ORACLE_HOME/Tools/Devdem60/Demo/Forms.

Open the Default menu (menudef.mmb), and show the menu items in the menu editor.

Copyright Oracle Corporation, 1999. All rights reserved.

Default Menu

Action

SaveClear AllPrintPrint SetupExit

Edit

CutCopyPasteEditDisplay List

Block

PreviousNextClear

Field

PreviousNextClearDuplicate

Record

PreviousNextScroll UpScroll DownInsertRemoveLockDuplicate Clear

Query

EnterExecuteCancelLast CriteriaCount HitsFetch Next Set

Help

HelpKeysListDisplay ErrorDebug

Page 63: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-7......................................................................................................................................................

......................................................................................................................................................The Default Menu

The Default Menu

What Is the Default Menu?The Default menu is not a separate menu module and is built in to every form module. The Default menu includes standard commands for editing, navigating, and database interaction, such as Action—>Save.

When you build a form module, it automatically uses the Default menu. The Default menu is internal to Oracle Forms. You can replace the Default menu with a custom menu. A custom menu is stored in a separate module that has a suffix of .mmb. A custom menu that is exactly the same as the Default menu, menudef.mmb, ships with Oracle Forms.

Examining the Default MenuYou can look at the structure of the Default menu by opening the file called menudef.mmb. This file contains a menu module with an identical structure to that of the Default menu. Once you have opened the menudef.mmb module, you can see its objects in the Object Navigator.

You can see that the menu module consists of a main menu (starting point), menus, and menu items.

Page 64: Build Forms II Volume 1 Instructor Guide 7196298

2-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Technical NoteBy default, the Menu Editor displays a pull-down menu, with the top-level menu displayed horizontally. If you are developing a full-screen menu, you may want to display the top-level menu vertically, so that the display matches the way your menu will appear at run time. To change the orientation, click the Switch Orientation button.

Instructor NoteIn the Menu Editor, the key sequences [Ctrl] + the down arrow and [Ctrl] + the right arrow create, respectively, a menu item below and to the right of an existing object.

Use the Default menu (menudef.mmb) to show the Menu Editor functionalities. Show the steps to move a menu or a menu item. Show the steps to copy a menu to another level. Explain the alert duplicate menu or reuse the original. Demonstrate that if you move a submenu to a parent item with the Command Type property set to PL/SQL or Null, Form Builder displays an alert.

Copyright Oracle Corporation, 1999. All rights reserved.

The Menu EditorDisplaymenu

CreateDown

CreateRight

SwitchOrientation

Menu tab Expandedmenu

Collapsedmenu

Page 65: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-9......................................................................................................................................................

......................................................................................................................................................The Menu Editor

The Menu Editor

What Is the Menu Editor?The Menu Editor is a graphical design facility for laying out, modifying, and viewing menu modules and their objects. Use the Menu Editor to carry out all of your menu design work.

Two Ways to Display the Menu Editor• Double-click the icon to the left of the menu module entry in the Object

Navigator.

• Select Tools—>Menu Editor.

Tools Specific to the Menu Editor ToolbarYou have seen the majority of the tools from the Menu Editor toolbar in the Layout Editor; however, some are specific to the Menu Editor.

Tool Function

Display Menu

Determines the highest level menu that the Menu Editor displays. (Choose from all the menus in your menu module.)

Create Down Creates a new menu item below the currently active one

Create Right Creates a new menu item to the right of the currently active one

Switch Orientation

Allows display of the top-level menu vertically or horizontally

Page 66: Build Forms II Volume 1 Instructor Guide 7196298

2-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteCreate the following menu:

File Edit Query

Save Clear Record Enter

Exit Clear Block Execute

Sort > By Order Id

By Order Date

Copyright Oracle Corporation, 1999. All rights reserved.

Creating a Menu Module

Page 67: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-11......................................................................................................................................................

......................................................................................................................................................Creating a Menu Module

Creating a Menu ModuleThe first step when creating a menu is to define a new menu module by using the Object Navigator. Once the module is created, you need to create menus and menu items in the Menu Editor. When the Menu Editor is displayed, it shows a menu called MAIN_MENU, with one item labeled New Item.

Creating a Main Menu from the Menu EditorTo create menu items for the Main menu, select New Item from the Menu Editor (it is usually selected already).

1 Type a menu label to replace the default label.

2 Click the Create Right icon.

3 Type a new label to replace the default label.

4 Repeat steps 2 and 3 to add more items to the Main menu.

Note: The label is the text that is displayed for the menu item at run time. The label may differ from the name, which you can use programmatically and which must follow PL/SQL naming conventions.

Creating an Individual Menu1 In the Main menu, select the parent item.

2 Click the Create Down icon.

3 Type a new label to replace the default label.

4 Repeat steps 2 and 3 to add more menu items to the current individual menu.

Note: Forms places a shaded rectangle, or handle, to the left of the first menu item. You can use it to move the menu along with all its items.

Creating a Submenu1 Select the parent item on the individual menu.

2 Click the Create Right icon.

3 Replace the default label.

4 Select Menu—>Create Down to add another item to the submenu.

5 Replace the default label.

6 Repeat steps 4 and 5 to add more submenu items.

Page 68: Build Forms II Volume 1 Instructor Guide 7196298

2-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteDo not spend a long time going through all the menu module properties; instead point out that they are here for convenience. Also, context-sensitive help is available.

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Module Properties

Main MenuMenu DirectoryMenu FilenameStartup CodeShare Library with Form

Use SecurityModule Roles

Page 69: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-13......................................................................................................................................................

......................................................................................................................................................Module Properties

Module Properties

Property Description

Main Menu Property that specifies the name of the individual menu in the module that is the main or starting menu at run time

For a pull-down menu, the main menu is automatically set to the name of the first menu that you create. Users cannot navigate above this menu in the menu hierarchy.

Menu Directory Path used by Forms as a pointer to the directory for the run-time .mmx file; only used by menu modules that are saved to the database

Menu Filename Filename used by Forms as a pointer to the run-time .mmx file; only used by menu modules that are saved to the database

Startup Code PL/SQL code executed when a menu module is loaded in memory

Share Library with Form

Property that enables to be loaded in memory a single copy of a PL/SQL library, if this library is used by the form module and the menu module

Use Security Property that when set to Yes enforces security at run time (Set this property to No to test the menu module without having to be a member of any database role.)

Module Roles Property that displays the Menu Module Roles dialog box, where you can list the roles assigned to the menu module (Roles defined must be assigned to individual menu items in the Menu Editor.)

Page 70: Build Forms II Volume 1 Instructor Guide 7196298

2-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteDo not spend a long time going through all the menu properties; instead point out that they are here for convenience.

The Tear-Off property is available for the Motif window manager.

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Properties

Page 71: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-15......................................................................................................................................................

......................................................................................................................................................Menu Properties

Menu Properties

Property Description

Tear-Off Menu Enables the menu to be dragged from the menu bar and repositioned elsewhere on the screen (available only if your window manager supports this feature)

Page 72: Build Forms II Volume 1 Instructor Guide 7196298

2-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Technical NoteRadio menu items must belong to a radio group. All of the radio items for a radio group must be contiguous on the same menu. Radio group names are internal names that are not displayed at run time.

Instructor NoteThe mappings of logical accelerator keys to physical device keys are defined in the run-time resource file. You must edit the resource file in Oracle Terminal to change the key mappings. You can also create additional accelerator keys in Oracle Terminal (ACCELERATOR6, ACCELERATOR7, and so on), which you can then associate with menu items in a menu module.

Demonstration next page: Use the Summit menu (m_summit.mmb) file to show the different menu item types. You can attach it to the ORDERS form and run it to illustrate the menu items at run time. You can also use the Customized menu (menu.mmb) file.

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Item Properties

• Enabled

• Label

• Menu Item Type

• Magic Item

• Menu Item RadioGroup

• Command Type

• Menu Item Code

• Submenu Name

• KeyboardAccelerator

• Icon in Menu

• Icon Filename

Page 73: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-17......................................................................................................................................................

......................................................................................................................................................Menu Item Properties

Menu Item Properties

Properties Specific to Menu Item

Defining Menu Access KeysForms indicates an access key by underlining one special character in the menu item. Users can then issue the menu item command by pressing a key combination such as [Alt] + [character].

Specifying the Underline Character

Menu Item Property FunctionEnabled Specifies whether the menu item is an active and mouse

manipulatable (Inactive menu items are displayed in grey.)Label Specifies the text that appears in the menu itemMenu Item Type Determines how this menu item displays (Choose from

Plain, Check, Radio, Separator, and Magic.)Magic Item Specifies that one of the predefined menu items for custom

menus should be usedMenu Item Radio Group Determines which radio group this menu item belongs toCommand Type Determines the type of command that this menu item calls

(Choose from Null, Menu, PL/SQL, or SQL*Plus.)Menu Item Code Specifies the command that this menu item invokesSubmenu Name Specifies the menu that this menu item invokesKeyboard Accelerator Determines which logical function key is associated with

this menu item (Accelerator keys are named ACCELERATOR1 through ACCELERATOR5.)

Icon in Menu Specifies if an icon is displayed in the menu itemIcon Name Specifies the name of the icon to display

Development Run Timeexecute query execute queryeXecute query eXecute queryExe&cute Query Execute QueryExecute &Query Execute Query

Page 74: Build Forms II Volume 1 Instructor Guide 7196298

2-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Item Types

PlainCheck

Radio

Magic

Separator

Copyright Oracle Corporation, 1999. All rights reserved.

Magic Items

• About

• Undo

• Clear

• Copy

• Cut

• Paste

• Help

• Quit

• Window

Page 75: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-19......................................................................................................................................................

......................................................................................................................................................Menu Item Types

Menu Item TypesYou can customize a menu by using different item types. In addition to plain menu items, Form Builder supports four types of special menu items.

Choosing a Menu Item Type

Magic ItemsSome Magic menu items include default functionality. Because a Magic item provides the standard actions of a graphical user interface (GUI), a copy or paste action is already defined at the menu level. All you need to do is set the item to the Magic type and define the desired action (standard or specific).

Menu Item Type DescriptionPlain Creates a standard text menu item (This is the Default menu item type.)Check Creates a menu item that has two possible states (Check menu item

functionality is defined using PL/SQL.)Radio Creates a set of mutually exclusive buttons, each representing a differ-

ent action (To assign a radio item to a group, enter the name of the group in the Menu Item Radio Group field in the Properties window.)

Separator Creates a separating horizontal line for grouping menu itemsMagic Creates a menu item with predefined functionality

Magic Item Command Type Default Functionality?About Undo

Any except Menu No. You must assign a command to these items to perform the desired function.

ClearCopyPasteCut

Null Yes. These items perform the default operations indicated by their names.

Help Menu No. You must define a submenu to be called by the Magic Help item, and you must assign commands to the items on that submenu.

Quit Null Yes. The Quit command, by default, exits from the form after asking the user to save any changes.

Window Null or Menu Yes. The window item invokes a default submenu that lists all open windows. Users can activate a window by selecting it from the submenu.

Page 76: Build Forms II Volume 1 Instructor Guide 7196298

2-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Item Command Types

Null

Menu

PL/SQL

Plus

Form

Macro

Does not issue a command

Invokes a submenu

Executes a PL/SQL command

Spawns a process to SQL*Plus

Backward compatibility

Backward compatibility

Page 77: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-21......................................................................................................................................................

......................................................................................................................................................Menu Item Command Types

Menu Item Command TypesEvery menu item must have a valid command type. Most menu items execute PL/SQL commands, so their command type is PL/SQL. However, if a menu item is composed of submenus, the command type must be set to Menu. (For example, all items on the Main menu must have the command type set to Menu.) In that case, the Menu Item Code property is replaced by the Submenu Name property.

Choosing a Command Type

Note: The command types of Form and Macro are available for compatibility with SQL*Menu V4.0. and SQL*Menu V.5.0.

Viewing Menu Item CommandsTo view the menu item command associated with a menu item, you must take one of the following actions:

• Double-click the icon to the left of the menu item entry in the Object Navigator

• Use the Menu Item Code or Submenu Name property in the Property Palette

• Right-click on the menu item in the Object Navigator or Menu Editor and select PL/SQL Editor from the pop-up menu

Command Type DescriptionNull Specifies that the menu item does not issue a command (The

NULL command is required for Separator menu items and optional for all other types of items.)

Menu Invokes a submenu (Valid submenu name is the name of the submenu to be invoked.)

PL/SQL (default) Executes a PL/SQL command (Valid menu item code is a PL/SQL block, including calls to built-in and user-named subprograms.)

Plus Specifies that the menu item code spawn a process to SQL*Plus.

Page 78: Build Forms II Volume 1 Instructor Guide 7196298

2-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Technical NoteFor more flexible or complex requirements, use the existing Toolbar canvas in form modules.

Instructor NoteThe Default menu toolbar works very well; however, building your own menu and menu toolbar is not so easy. For example, you have to create separator items for every space that you require to group the items. Also, the menu toolbar icons appear in exactly the same order as the menu options, which might not be what you want.

Demonstration: Use the menu that you created earlier, and set the properties to display the Save option in a menu toolbar. Use the save.ico file.

Copyright Oracle Corporation, 1999. All rights reserved.

Implementing Menu ToolbarsToolbar as part of menu module:

• Contains only buttons corresponding tomenu items

• Is displayed above “normal” toolbars

• Executes the same code as menu items

• Is enabled and disabled, visible andhidden, in synchronization withcorresponding menu item

Page 79: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-23......................................................................................................................................................

......................................................................................................................................................Implementing Menu Toolbars

Implementing Menu Toolbars

What Is a Menu Toolbar?A menu toolbar is a set of iconic buttons that represent individual items from a menu. When you create a custom form menu, you can specify that some of its items appear on a menu toolbar.

You need to provide icons to represent the associated buttons on the menu toolbar. If you use the default form menu, Form Builder attaches a default menu toolbar to your form automatically.

Menu toolbars allow developers to easily provide toolbar shortcuts to menu commands without duplicating code or effort.

Menu Toolbar Orientation You can assign menu items to a horizontal or a vertical menu toolbar. Form Builder locates a horizontal menu toolbar at the very top of a form (just beneath the pull-down form menu.) A vertical menu toolbar appears at the far left of a form (to the left of any existing toolbar canvas).

Creating a Menu ToolbarTo create a menu toolbar, you have to set up the following menu item properties.

Property Description

Visible in Horizontal Menu Toolbar

Specifies that the menu item should appear (represented by an icon) on the horizontal toolbar of a form

Visible in Vertical Menu Toolbar

Specifies that the menu item should appear (represented by an icon) on the vertical toolbar of a form

Icon Filename Specifies the name of the icon resource that you want to represent the iconic button

Page 80: Build Forms II Volume 1 Instructor Guide 7196298

2-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Module StorageMenu module definition:•.mmb• Stored in files or database tables

Menu module executable:

• .mmx

• Stored in files

Menu module text:

• .mmt

• Stored in files

Page 81: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-25......................................................................................................................................................

......................................................................................................................................................Storing the Menu Module

Storing the Menu Module

Saving the Menu Module DefinitionAs with the form module, you can save your menu module definition to either of the following storage formats.

You can save your menu module definition by either of the following actions:

• Clicking the Save icon in the Object Navigator

• Selecting File—>Save

Creating an Executable VersionBefore you can use your customized menu module, you must create an executable version. To do so, select File—>Administration—>Compile File.

The resulting file that you create has the .mmx extension. A menu module executable file containing binary code is not portable between operating systems.

Storage Format DescriptionFile with .mmb extension

Menu module binary file, a binary representation of the menu structure that is portable between operating systems

Database table A table representation of the menu structure that is portable between databases

Page 82: Build Forms II Volume 1 Instructor Guide 7196298

2-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Technical NoteIf you want to use the Default menu without the associated menu toolbar, replace the value DEFAULT&SMARTBAR in the Menu Module property with DEFAULT only.

Copyright Oracle Corporation, 1999. All rights reserved.

Form Module Properties

Menu moduleto use withthis formmodule

Specifythat menumoduleis storedin the file system

Page 83: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-27......................................................................................................................................................

......................................................................................................................................................Attaching the Menu Module

Attaching the Menu ModuleTo use your customized menu module, you must attach it to a form module. When you attach a customized menu module to a form module, you are effectively replacing the Default menu with your own.

Attaching the Menu Module to the Form Module1 Ensure that the menu module has been generated.

2 Select the form module to which you want to attach your menu.

3 Invoke the Property Palette for the form module.

4 Replace the value DEFAULT&SMARTBAR in the Menu Module property with your menu module name.

5 Ensure that the Menu Source property has a value of:

a File, if the menu module is stored in the file system

b Database, if the menu module is stored in the database

6 Generate your form module.

Page 84: Build Forms II Volume 1 Instructor Guide 7196298

2-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteDemonstration: Run the Customers form (customers.fmb) demonstration. Navigate to the Comments item, and click the right mouse button.

Copyright Oracle Corporation, 1999. All rights reserved.

What Is a Pop-up Menu?

Menu that appears on thescreen at the location itwas invoked:

• Enables users toaccess commonly usedfunctions easily

• Is accessed by pressingthe right mouse button(Microsoft Windows andMotif)

Properties...Layout Editor...PL/SQL Editor...

Help

Cut Ctrl+XCopy Ctrl+CPaste Ctrl+V

Copyright Oracle Corporation, 1999. All rights reserved.

Incorporating Pop-up Menus

• Pop-up menus are:– Top-level objects in the object

navigator, such as alerts, blocks, andso on

– Built through the Property Palette orMenu Editor

– Part of a form module as opposed toa separate menu module

– Associated with items and canvasesby using a new pop-up menu property

• Pre-Popup-Menu trigger providesdynamic control

Page 85: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-29......................................................................................................................................................

......................................................................................................................................................Pop-up Menus

Pop-up MenusPop-up menus are context-sensitive menus. You attach pop-up menus to an item or canvas, and display them by right click on that item or canvas. Pop-up menus enable end users to quickly access common functions and commands.

Pop-up menus are top-level objects in the Object Navigator (similar to alerts, blocks, canvases, and so on) and belong to a form module (as opposed to form menus, which belong to a separate menu module).

Items on a pop-up menu should be contextual to the menu’s associated objects. For example, you would not include text-editing items on the pop-up menu for a two-digit numeric item. You might include such items on the pop-up menu for a multiline text item, however.

Incorporating Pop-up Menus1 In the Object Navigator of a form, click the Pop-up Menus node, and

click the Create button on the toolbar.

Form Builder creates a pop-up menu and gives it a default name, such as MENU1.

2 In the Object Navigator or Menu Editor, create a main pop-up menu, submenus (if any), and menu items.

3 Assign commands to the menu items.

4 Attach the menu to items and canvases with a new Pop-up Menu property.

Rules for Incorporating Pop-up Menus• To show pop-up menus for a canvas, the mouse must be on the canvas

only.

• Pop-up menu items can be parents of submenus (if the platform allows it), magic menu items, or separators.

Pre-Popup-Menu TriggerYou can use this trigger to add dynamic control at run time, prior to displaying the menu. For example, you can use the trigger to identify the cursor context and navigate to a different item if necessary.

Instructor NoteBeginning with release 6, pop-up menus support icons, check boxes, and option buttons.

Page 86: Build Forms II Volume 1 Instructor Guide 7196298

2-30 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Menu module components

• The Default menu

• Creating a menu module

• Menu properties

• Menu module storage

• Menu module and form moduleassociation

• Pop-up menu

Page 87: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-31......................................................................................................................................................

......................................................................................................................................................Summary

SummaryIn this lesson, you learned how to add, create, and customize menu modules.

The Menu Module Components• Main menu

• Menu

• Menu item

• Menu toolbar

The Default Menu• Automatically used with every form module

• Can be customized

Creating a Menu Module

Properties •

• Menu module properties

• Menu properties

• Menu item properties

Implementing a Menu Toolbar

Menu Module Storage• Database tables

• .mmb file extension

• .mmx file extension

• .mmt file extension

Menu Module and Form Module AssociationUsing the form module properties of Menu Module and Menu Source

Creating a Pop-up Menu• Incorporate pop-up menus

• Rules to incorporate pop-up menus

• Pre-Popup-Menu trigger

Page 88: Build Forms II Volume 1 Instructor Guide 7196298

2-32 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Instructor NoteThe practice overview in this lesson and the ones that follow are provided only as guides. Outline the practice in the level of detail appropriate for the course participants.

For this lab, use the DO_KEY built-in. At this stage of the course, students do not yet know this built-in. Explain it briefly and tell them that it is covered in detail in Lesson 4.

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 2 Overview

This practice covers the following topics:

• Creating a simple menu module

• Incorporating some of the menu itemsin the menu toolbar

• Compiling and attaching the menu tothe ORDERS form

• Creating a pop-up menu

Page 89: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-33......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 2

Practice Session Overview: Lesson 2This practice guides you through creating a custom menu, and creating a pop-up menu.

Practice Contents• Create a simple menu module

• Incorporate menu items in the menu toolbar

• Compile and attach a menu to a form

• Create a pop-up menu

Page 90: Build Forms II Volume 1 Instructor Guide 7196298

2-34 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

Practice 21 Create a new menu module.

a Using the following screenshot as a guideline, create a new menu module called M_SUMMIT.

• File Menu

Label

Menu Item Type

Command Type

Menu Item Code

Visible in Menu

Visible in Horiz. Menu Toolbar

Icon Filename

Save Plain PL/SQL DO_KEY(’COMMIT_FORM’);

Yes Yes Save

Clear Plain PL/SQL DO_KEY(’CLEAR_FORM’);

Yes Yes Abort

Null1 Separator Null Yes Yes

Exit Plain PL/SQL DO_KEY(’EXIT_FORM’);

Yes Yes Exit

Null2 Separator Null No Yes

Page 91: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 2-35......................................................................................................................................................

......................................................................................................................................................Practice 2

• Edit Menu

• Sort By Menu

• Query Menu

LabelMenu Item Type

Magic Item

Command Type

Visible in Menu

Visible in Horiz. Menu Toolbar

Icon Filename

Cut Magic Cut Null Yes Yes Cut

Copy Magic Copy Null Yes Yes Copy

Paste Magic Paste Null Yes Yes Paste

Null3 Separator Null No Yes

Menu Label

Menu Item Type

Menu Item Radio Group

Command Type Menu Item Code

Order Id Radio Order_By PL/SQL SET_BLOCK_PROPERTY(’ s_ord’, order_by, ’ id’ ) ;

Customer Id Radio Order_By PL/SQL SET_BLOCK_PROPERTY(’ s_ord’, order_by,’ customer_id’ ) ;

Sales Rep Id Radio Order_By PL/SQL SET_BLOCK_PROPERTY(’ s_ord’, order_by,’ sales_rep_id’ ) ;

LabelMenu Item Type

Command Type Menu Item Code

Visible in Horiz. Menu Toolbar

Icon Filename

Enter Query

Plain PL/SQL DO_KEY(’ENTER_QUERY’);

Yes query

eXe-cute Query

Plain PL/SQL DO_KEY(’EXECUTE_QUERY’);

Yes execute

Page 92: Build Forms II Volume 1 Instructor Guide 7196298

2-36 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 2: Creating a Menu Module

b Save as M_SUMMIT and compile the menu module.

c Attach the menu module to the ORDERS form.

d Save and compile the form module.

e Run and test the ORDERS form.

2 Add pop-up menus to the CUSTOMERS form.

a Open the CUSTOMERS form module.

b Copy the EDIT_MENU menu from the M_SUMMIT menu module to the CUSTOMERS form. Attach this pop-up menu to the Comments item.

c Save and compile the form module.

Page 93: Build Forms II Volume 1 Instructor Guide 7196298

................................

3

Managing Menu Modules

Page 94: Build Forms II Volume 1 Instructor Guide 7196298

3-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Instructor NoteTopic TimingLecture 50 minutes

Practice 40 minutes

Total 90 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Control the menu programmatically

• Manage the interaction between themenu and form documents

• Implement application security throughthe menu

Page 95: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewIn this lesson, you will learn how to modify menus dynamically, as well as how to control application security through menu access.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Control the menu programmatically by using menu built-ins

• Customize menu modules by using substitution parameters

• Implement menu security by using both database roles and the appropriate built-ins

Page 96: Build Forms II Volume 1 Instructor Guide 7196298

3-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Instructor NoteThe DO_KEY built-in is explained in the next lesson. Stress that it is very important to use this built-in for generic coding.

Copyright Oracle Corporation, 1999. All rights reserved.

Using PL/SQL in Menu ItemCode

• Similar to PL/SQL code in form triggers

• You can share code between a formmodule and a menu module by usingthe following:

– Libraries

– User-defined triggers

– DO_KEY built-in

Copyright Oracle Corporation, 1999. All rights reserved.

Using PL/SQL in Menu ItemCode

• Menu modules generated independently

• Restrictions:

– Cannot directly reference values ofform objects

– Must use NAME_IN built-in function

– Cannot use direct assignment forform objects

– Must use COPY built-in procedure

Page 97: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-5......................................................................................................................................................

......................................................................................................................................................Using PL/SQL in Menu Item Code

Using PL/SQL in Menu Item Code

Using PL/SQL in Menu Item CommandsPL/SQL menu item commands are structurally similar to form triggers. In addition to standard application functions such as navigation, validation, and database interaction, you can use PL/SQL menu item commands to perform any actions.

Sharing Code Between a Form Module and a Menu ModuleYou can share code between form modules and menu modules in three ways:

• Setting up libraries and attaching them to the modules

• Creating user-defined triggers in the form module and calling them from a standard trigger in a form module, or calling them from a menu item in a menu module (Use EXECUTE_TRIGGER to fire the user-defined trigger.)

• Using the DO_KEY built-in to fire the corresponding trigger or function from a menu item

RestrictionsMenu modules are generated independently of form modules.

In PL/SQL command menu items:

• You cannot directly reference the value of form module objects.

• You must use the NAME_IN built-in function to determine the current value of the object.

• You cannot use direct assignment to set the value of a form module object.

• You must use the COPY built-in procedure.

ExampleIF :s_emp.title = ’MANAGER’ THEN ...-- INCORRECT

IF NAME_IN(’s_emp.title’) = ’MANAGER’ THEN ... -- CORRECT

:s_product.name := ’PUMP’; -- INCORRECT

COPY(’PUMP’, ’s_product.name’); -- CORRECT

Page 98: Build Forms II Volume 1 Instructor Guide 7196298

3-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Instructor NoteDemonstration: Use the Summit menu (m_summit.mmb) file to show examples of these built-ins.

Copyright Oracle Corporation, 1999. All rights reserved.

Built-ins for Setting and GettingMenu Item Properties

• FIND_MENU_ITEM

• GET_MENU_ITEM_PROPERTY

• SET_MENU_ITEM_PROPERTY

• ITEM_ENABLED

• MENU_SHOW_KEYS

Page 99: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-7......................................................................................................................................................

......................................................................................................................................................Useful Built-in Menu Subprograms

Useful Built-in Menu SubprogramsYou can change certain menu characteristics dynamically at run time by using built-in subprograms.

Using some of these subprograms, you can get or change menu item properties. Using others, you can hide, display, or replace the current menu.

Setting and Getting Menu Item Properties

ExampleThis procedure finds the ID of a menu item before setting multiple properties.

DECLARE

mi_id MenuItem;

BEGIN

mi_id := Find_Menu_Item(’Preferences.AutoCommit’);

/* Determine the current checked state of the AutoCommit menu checkbox item and toggle the checked state */

IF Get_Menu_Item_Property(mi_id,CHECKED) = ’TRUE’ THEN

Set_Menu_Item_Property(mi_id,CHECKED,PROPERTY_FALSE);

ELSE

Set_Menu_Item_Property(mi_id,CHECKED,PROPERTY_TRUE);

END IF;

END;

Built-in DescriptionFIND_MENU_ITEM This function gets the ID of a menu item. The receiving

variable must be declared as a menu item type. Use it as soon as you reference the same menu item more than once.

GET_MENU_ITEM_PROPERTY This function returns the current value of the given property for a specified menu item.

SET_MENU_ITEM_PROPERTY This procedure modifies the state of a menu-item-specific characteristic.

ITEM_ENABLED This function returns the Boolean value TRUE when the menu item is enabled and FALSE when the menu item is disabled.

MENU_SHOW_KEYS This procedure displays the Keys screen for the menu module at run time.

Page 100: Build Forms II Volume 1 Instructor Guide 7196298

3-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Technical Note REPLACE_MENU replaces the menu for all windows in the application. If you are using CALL_FORM, REPLACE_MENU replaces the menu for both the calling form and the called form with the specified menu.

Copyright Oracle Corporation, 1999. All rights reserved.

Built-ins for Showing and Hidingthe Current Menu

REPLACE_MENU

Character mode built-ins:

• HIDE_MENU

• SHOW_MENU

• MENU_REDISPLAY

Page 101: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-9......................................................................................................................................................

......................................................................................................................................................Showing and Hiding the Current Menu

Showing and Hiding the Current Menu

ExampleUse a standard procedure to change which root menu in the current menu application appears in the menu bar. A single menu application may have multiple root menus, which an application can set dynamically at run time.

PROCEDURE Change_Root_To(root_menu_name VARCHAR2) IS

BEGIN

Replace_Menu(’MYAPPLSTD’, PULL_DOWN, root_menu_name);

END;

Built-in DescriptionREPLACE_MENU Procedure for replacing the current menu with a specific one,

without making it active (Use this procedure, to modify the display style and security.)

HIDE_MENU Procedure hiding the current menu SHOW_MENU Displays the current menu without activating it MENU_REDISPLAY Redraws the current menu on the screen

Page 102: Build Forms II Volume 1 Instructor Guide 7196298

3-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Copyright Oracle Corporation, 1999. All rights reserved.

Managing Menu Security

• Defining security roles

• Choosing roles for the menu module

• Assigning access to menu items

• Setting the Use Security property

Copyright Oracle Corporation, 1999. All rights reserved.

What Is a Role?

Role

Users

Privileges

Page 103: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-11......................................................................................................................................................

......................................................................................................................................................Managing Menu Security

Managing Menu Security

What Is Menu Security?Using menu security, you can set up access rights on menu items. You can choose between two security policies for the users:

• Grant users access to all menu items in a module

• Grant users access only to specific menu items

When you want to deny a user access to a menu item, you can either hide the item or disable it.

What Is a Role?A role is a group of users sharing the same privileges. With Form Builder, you can manage menu security through Oracle server roles.

When you create a role, you can grant access privileges to each item individually. If access is granted only to some roles, only users belonging to those roles can access those items.

Using this feature, you can deliver the same application for different kinds of users.

Implementing Menu SecurityFirst, define the different types of users who will use the menus, their profiles, and their needs. Then follow the steps below:

1 Define security roles in the database.

2 Choose roles for the module in Form Builder.

3 Assign access to menu items.

4 Set the Use Security property.

Page 104: Build Forms II Volume 1 Instructor Guide 7196298

3-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Technical NoteIf Use Security is modified, you must recompile the menu module.

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Module Roles Window

Select Menu Module Roles:

Copyright Oracle Corporation, 1999. All rights reserved.

Use Security Property

• Set to Yes to enforce security

• Set to No to ignore security: Enables thedeveloper to test the application

Page 105: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-13......................................................................................................................................................

......................................................................................................................................................Defining Security Roles

Defining Security Roles

Defining New RolesMenu security is based on the Oracle server roles. You can create these from the Oracle server, using SQL statements.

The following SQL commands implement roles.

Assigning Roles to the Menu ModuleTo associate a particular role with a menu item, you must define all the roles used in that menu module:

1 In the Object Navigator, select the menu module.

2 In the Properties window, select the Menu Module Roles property.

3 Click More... to open the Menu Module Roles dialog box.

4 Enter the names of the roles that you want to choose for this menu module.

5 Click OK to accept the roles list.

Note: The role must exist in the database.

Setting the Use Security PropertyThe Use Security property determines whether Form Builder should take account of the specified roles at run time.

When Use Security is set to Yes, Forms enforces security.

When Use Security is set to No:

• Forms ignores security.

• Your users can access all menu items.

• You can test your application without being a member of all roles.

Command ActionCREATE ROLE Creates a new roleGRANT Assigns the role to a user (This command allows you

to give a set of privileges to a user at one time.)ALTER USER...DEFAULT ROLE Controls which role is assigned by default to users

when they connect to the database

Page 106: Build Forms II Volume 1 Instructor Guide 7196298

3-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Instructor NoteYou can manipulate roles dynamically at run time by using Form Builder. For example, you can select views from the data dictionary to get information about existing roles. Subprograms belonging to the DBMS_SESSION package enable you to modify the roles that are used by the menu module to enforce security. Tell students that if they want more details about DBMS_SESSION, they can read Appendix I, “Using Oracle Server Roles at Run Time.”

Copyright Oracle Corporation, 1999. All rights reserved.

Menu Item Roles Window

Select Menu Item Roles:

Page 107: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-15......................................................................................................................................................

......................................................................................................................................................Assigning Access to Menu Items

Assigning Access to Menu ItemsAfter defining roles to use for the current menu module, you must specify the role or the roles that will have access to each menu item.

1 Select the desired menu item in the Menu Editor or in the Object Navigator.

2 Select the Item Roles property in the Properties window.

3 Click More... in the Menu Item Roles dialog box, which contains the role names associated with the menu module.

4 Select the role in the list to assign a role to the selected menu item.

5 Set the Display without Privilege property to specify how Forms should display the item if the current user does not have access to the item.

If set to Yes, the item is displayed disabled.If set to No, the item is hidden completely.

Note: Roles assigned to an item are highlighted. All others are displayed as usual. To assign the same roles to many items, select the items first by “Shift-clicking” or “Control-clicking” in the Menu Editor or Object Navigator, then select the roles through the Menu Item Roles property.

For additional information on how to manipulate Oracle server roles at run time, see Appendix I, “Using Oracle Server Roles at Run Time.”

Page 108: Build Forms II Volume 1 Instructor Guide 7196298

3-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• PL/SQL in menu item commands

• Built-ins for use with menus

• Implementing menu security

Page 109: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-17......................................................................................................................................................

......................................................................................................................................................Summary

Summary

PL/SQL in Menu Item Commands• Typical PL/SQL uses

• Restrictions for PL/SQL in menu item commands

Built-ins for Use with Menu Modules• Showing and hiding the current menu:

- HIDE_MENU

- REPLACE_MENU

- SHOW_MENU

- MENU_REDISPLAY

• Getting and setting menu properties:

- FIND_MENU_ITEM

- GET_MENU_ITEM_PROPERTY

- SET_MENU_ITEM_PROPERTY

Page 110: Build Forms II Volume 1 Instructor Guide 7196298

3-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Instructor NoteThe practice overview in this lesson and the ones that follow are provided only as guides. Develop the practice with the level of detail appropriate for the students. This lab uses a lot of PL/SQL code. Because this is not a coding course, we provide the code. Take time to explain this practice so that students understand the code that they will import.

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 3 Overview

This practice covers the following topics:• Enhancing the menu with a check

menu item• Synchronizing the Image Activate menu

item with the Image button• Disabling irrelevant menu items

according to form context

Page 111: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 3-19......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 3

Practice Session Overview: Lesson 3This practice guides you through enhancing custom menus for the ORDERS and EMPLOYEE forms.

Practice Contents• Add a check menu item.

• Enhance the menu so that the Image Activate menu item is synchronized with the Image button. If the image is displayed, a check should appear next to the Image Activate menu item.

• For the EMPLOYEE form, disable the menu items that are not relevant.

Page 112: Build Forms II Volume 1 Instructor Guide 7196298

3-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 3: Managing Menu Modules

Practice 31 Define a check menu item.

a Open the M_SUMMIT menu module and create a new menu item to the right of Query and rename it Image.

b Create a new menu item under Image and name it Image Activate.

c Import the text for the Image Activate menu item by using the pr3_1c.txt file. The menu item name must be IMAGE_ACTIVATE.

d Save and compile the menu module.

e Run and test the ORDERS form.

2 Synchronize the menu module with the form.

a Write startup code for the M_SUMMIT menu module that synchronizes the Image Activate menu item with the Image button. You can import the pr3_2a.txt file.

b Save and compile your module.

3 The menu items Sort By and Image are not relevant to the CUSTOMERS form and therefore should have no effect.

a Attach the menu module to the CUSTOMERS form.

b Modify the startup code of the M_SUMMIT menu module to disable these options when the CUSTOMERS form is opened. You can replace the existing code with the code from the pr3_3b.txt file. You may need to change the code to conform to the exact names you gave to the Main Menu and its menu items.

c Save and compile the module.

d Run the CUSTOMERS form and test your application.Execute a Query and click the Orders button to move to the ORDERS form. Note that the Sort By and Image menu items are disabled when the CUSTOMERS form is current, and that they are enabled when the ORDERS form is current.

Menu Label Menu Item Type Command Type

Image Activate Check PL/SQL

Page 113: Build Forms II Volume 1 Instructor Guide 7196298

................................

4

ProgrammingFunction Keys

Page 114: Build Forms II Volume 1 Instructor Guide 7196298

4-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Instructor NoteTopic TimingLecture 40 minutes

Practice 40 minutes

Total 80 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Define key triggers and their uses

• Program function keys

• Describe the characteristics of keytriggers

• Classify key triggers

• Associate function keys with interfacecontrols

Page 115: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewThe Oracle Developer Form Builder components enable you to redefine the actions of function keys. This lesson shows you how to define key triggers to intercept and supplement the usual behavior of the function keys with which your users navigate the Oracle Developer application.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Define key triggers and their uses

• Program function keys

• Classify key triggers

• Associate function keys with interface controls

Page 116: Build Forms II Volume 1 Instructor Guide 7196298

4-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Copyright Oracle Corporation, 1999. All rights reserved.

Key Triggers

What is a key trigger?

Example:

Using Key-Exit, display an alert and exitthe application if the user answers Yes.

SET_ALERT_PROPERTY(′question_alert′, ALERT_MESSAGE_TEXT,′Do you really want to leave the form? ′);

IF SHOW_ALERT(′question_alert′) = ALERT_BUTTON1 THEN EXIT_FORM; -- default functionality

END IF;

SET_ALERT_PROPERTY(′question_alert′, ALERT_MESSAGE_TEXT,′Do you really want to leave the form? ′);

IF SHOW_ALERT(′question_alert′) = ALERT_BUTTON1 THEN EXIT_FORM; -- default functionality

END IF;

Page 117: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-5......................................................................................................................................................

......................................................................................................................................................Key Triggers

Key TriggersIf you press a function key, Forms usually performs the default function associated with that key. You can modify the standard functionality of a function key by defining a key trigger for that function key.

What Is a Key Trigger?A key trigger, like any other trigger, is a subprogram that is executed when a certain event occurs. In the case of a key trigger, the event is pressing the function key for which the trigger is defined. The trigger is usually named after the event that causes it to fire. When the key trigger is defined for a function key, the usual functionality of the key is replaced by the PL/SQL text of the trigger. In this respect, key triggers resemble “on” triggers.

ExampleThe form level Key-Exit trigger below displays an alert to ask to the end user if he or she wants to leave the form.

SET_ALERT_PROPERTY(’question_alert’, ALERT_MESSAGE_TEXT, ’Do you really want to leave the form?’);

IF SHOW_ALERT(’question_alert’) = ALERT_BUTTON1 THEN

EXIT_FORM; -- default functionality

END IF;

Note: If you also want to execute the default functionality of the function key, you must ensure that the key trigger includes the built-in function associated with the key.

ExampleThe following form-level Key-Menu trigger disables [Block Menu] for a form.

BEGIN

NULL;

END;

Page 118: Build Forms II Volume 1 Instructor Guide 7196298

4-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Instructor NoteDemonstration: Open the LOV Form (Orders2.fmb). Change those properties for the Key-Duprec trigger at the form level. Run the form.

Copyright Oracle Corporation, 1999. All rights reserved.

Key Trigger Propertiesand PL/SQL Editor

Display in “Keyboard Help”“Keyboard Help” Text

Page 119: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-7......................................................................................................................................................

......................................................................................................................................................Defining Key Triggers

Defining Key TriggersYou define key triggers in the same way that you define any other trigger. However, the following two properties on the Properties window for triggers apply to key triggers only.

Property DescriptionDisplay in Keyboard Help Specifies whether a key trigger description is displayed in the

run-time Keys Help windowKeyboard Help Text Specifies the text that is displayed in the run time Keys Help

window if the display in the Keyboard Help property is set to Yes (If you want the default description to be displayed, leave this property blank.)

Page 120: Build Forms II Volume 1 Instructor Guide 7196298

4-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Copyright Oracle Corporation, 1999. All rights reserved.

Characteristics of Key Triggers

• You cannot redefine all function keyswith key triggers.

• Key triggers are defined at all threelevels.

• A key trigger can contain SELECTstatements and all built-ins.

• Key triggers can fire in Enter Querymode.

Copyright Oracle Corporation, 1999. All rights reserved.

Characteristics of Key Triggers

[Accept]

[Clear Form]

[Create Record]

[Delete Record]

Key-Commit

Key-Clrfrm

Key-Crerec

Key-Delrec

COMMIT_FORM

CLEAR_FORM

CREATE_RECORD

DELETE_RECORD

Function Key Built-in Key Trigger

Page 121: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-9......................................................................................................................................................

......................................................................................................................................................Characteristics of Key Triggers

Characteristics of Key Triggers

Rules of Key Triggers• You cannot redefine all function keys with key triggers. Some keys are

handled by the terminal or window interface manager rather than by Forms. Examples of such static function keys are [Clear Item], [Left], [Right], and [Toggle Insert/Replace].

• You can define key triggers at all three levels: form, block, and item.

• You can use SELECT statements, restricted built-in functions, and unrestricted built-ins.

• Key triggers can fire in Enter Query mode.

Note: You cannot use all built-ins in Enter Query mode.

If you do not redefine a function key, a built-in function performs its default functionality when you press the key. Therefore, in most cases, a built-in function and a key trigger are associated with a function key. The following table gives some examples of this association.

Function Keys, Their Associated Built-in Functions, and Key Triggers

Note: This list is incomplete.

Function Key Built-in Function Key Trigger[Accept] COMMIT_FORM Key-Commit[Create Record] CREATE_RECORD Key-Crerec[Delete Record] DELETE_RECORD Key-Delrec[Duplicate Record] DUPLICATE_RECORD Key-Duprec[Enter Query] ENTER_QUERY Key-Entqry[Execute Query] EXECUTE_QUERY Key-Exeqry[List] LIST_VALUES Key-Listval[Next Item] NEXT_ITEM Key-Next-Item[Down] DOWN Key-Down[Next Record] NEXT_RECORD Key-Nxtrec

[Exit] EXIT_FORM Key-Exit

Page 122: Build Forms II Volume 1 Instructor Guide 7196298

4-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Technical NoteThe function keys Fn do not necessarily map to F1, F2, F3, and so on.

Copyright Oracle Corporation, 1999. All rights reserved.

Classification of Key Triggers

• Function key triggers

• Key-Fn triggers and Oracle Terminal

• Key-Others triggers

Page 123: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-11......................................................................................................................................................

......................................................................................................................................................Classification of Key Triggers

Classification of Key TriggersYou can distinguish among different types of key triggers. Learning these classifications will help you understand when to use key triggers.

Types of Key Triggers

Category DescriptionFunction key triggers Key triggers that are associated with existing function keys

(They fire when the associated function key is pressed.)Key-Fn triggers Key triggers that are associated with the logical Runform keys

F0 through F9 (Before you can use these Key triggers, you or the DBA must use Oracle Terminal to map these logical keys to physical keys or key sequences. They fire when the associated physical key or key sequence is pressed.)

Key-Others trigger A key trigger that is associated with all keys that can have key triggers associated with them, but are not currently redefined by a function key trigger at any level

Page 124: Build Forms II Volume 1 Instructor Guide 7196298

4-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Technical NoteSince mouse-event key triggers are not executed when the mouse is used to initiate window interaction, you should not place code that needs to be executed every time the window interaction occurs in a mouse-event key trigger.

Instructor NoteDemonstration for next page pair:

• Use the LOV Form (Orders2.fmb) demonstration to show preventing duplication of the primary key by using the Key-Duprec trigger.

• Use the same demonstration to illustrate a call of a customized list of values (LOV) form instead of the native Forms LOV, using Key-Listval. To do this click the product LOV button. Do not explain in detail the code associated with this button, because the students will write it later in this course.

Copyright Oracle Corporation, 1999. All rights reserved.

Classification of Key Triggers

Mouse-event key triggers:

• Key-Next-Item

• Key-Prev-Item

• Key-Nxtrec

• Key-Prvrec

• Key-Up

• Key-Down

• Key-Scrup

• Key-Scrdown

• Key-Nxtblk

• Key-Prvblk

Page 125: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-13......................................................................................................................................................

......................................................................................................................................................Classification of Key Triggers

What Are Mouse-Event Key Triggers?Mouse-event key triggers are function key triggers whose associated default functionality can also be activated directly with the mouse.

Examples• The Key-Nxtblk trigger is a mouse-event key trigger, because the

NEXT_BLOCK functionality can also be activated using the mouse by clicking in the next block. In this case, a possible Key-Nxtblk trigger will not fire.

• The Key-Exeqry trigger is not a mouse-event key trigger, because the EXECUTE_QUERY functionality cannot be activated by simply clicking the mouse. It can be activated by the mouse only if a trigger is defined that fires as a result of the mouse action.

Page 126: Build Forms II Volume 1 Instructor Guide 7196298

4-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Copyright Oracle Corporation, 1999. All rights reserved.

Using Key Triggers

• Adjust user interface

• Disable a (set of) function keys

• Replace or extend functionality offunction keys

• Add additional function keys

• Be careful with Key-Others

• Do not use for validation

Copyright Oracle Corporation, 1999. All rights reserved.

Specific Key Trigger Uses

• Call an LOV form

• Check for detail records before deletinga master record

• Prevent duplication of the primary key

• Adjust toolbar buttons for Enter Querymode

Page 127: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-15......................................................................................................................................................

......................................................................................................................................................Using Key Triggers

Using Key TriggersYou should use key triggers sparingly. Often you must define many key triggers to trap a certain event completely. Mouse-event key triggers can be circumvented with the mouse. Use key triggers only if you want to adjust the default user interface.

Common Uses• Disable function keys

• Replace or extend the default functionality of function keys

• Add additional keys for custom functions using Key-Fn triggers

• Disable a set of function keys using Key-Others

When Not to Use Key Triggers• To perform validation; use validation triggers instead

• To amend navigation; use navigational triggers instead

• To perform data manipulation; use transactional triggers instead

Specific Key Trigger Uses• Call a list of values (LOV) form instead of the native Forms LOV, using

Key-Listval

• Check if detail records exist before deleting a master record if the master block and detail lock are in separate forms, using Key-Delrec

• Prevent duplication of the primary key when duplicating a record, using Key-Duprec

• Adjust behavior of toolbar buttons when Enter Query mode is entered or left, using Key-Entqry

Technical NoteTo determine if a Key-Others trigger applies to a function key, Forms looks for associated key triggers at all levels. For example, if you define the Key-Others trigger at the block level, it will not fire for function keys for which a key trigger is defined at the form level.

Page 128: Build Forms II Volume 1 Instructor Guide 7196298

4-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Instructor NoteDemonstration: Use the LOV Form + Duplication Primary Key (Orders2.fmb) demonstration, and show the code for the CONTROL.EXIT_BUTTON button. Also show the Key-Exit trigger at form level.

Copyright Oracle Corporation, 1999. All rights reserved.

Association with OtherInterface Controls

Syntax: DO_KEY(built_in_name)

Example: To customize actions when userexits the form with [Exit Form], a button,or a menu item:

1. Key-Exit

-- custom actions when user tries to exitEXIT_FORM;...

-- custom actions when user tries to exitEXIT_FORM;...

Copyright Oracle Corporation, 1999. All rights reserved.

Association with OtherInterface Controls

2. In When-Button-Pressed and Menu item code:

TDO_KEY(‘Key-Exit’) gives run-timeerror

TCorresponding interface controldescriptions

DO_KEY(‘EXIT_FORM’);

Page 129: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-17......................................................................................................................................................

......................................................................................................................................................Association with Other Interface Controls

Association with Other Interface ControlsYou can often activate the same functionality in various ways, such as by pressing a function key, choosing a menu item, clicking a button, or performing direct manipulation with the mouse. In this case, you want to specify the PL/SQL code to be executed only once. You can use the built-in function DO_KEY to accomplish this.

What Is DO_KEY?DO_KEY is a built-in function that executes the key trigger associated with the built-in that is specified as its parameter. If no key trigger is defined, the specified built-in is executed.

SyntaxDO_KEY(built_in_name)

ExampleExit a Form by clicking [Exit Form] or an Exit button, or by choosing a menu item.

1 Define a Key-Exit trigger at form level.

2 Call DO_KEY by using:

a The When-Button-Pressed trigger on the associated Exit button

b The menu-item code for the menu item that exits the form using DO_KEY(’EXIT_FORM’);

Interface Control DescriptionsIf the same functionality is activated by various interface controls, you should also make sure that the controls have the same descriptions.

Interface Control Property for Description Changeable at Run Time?Function key Show keys description NoMenu item Menu-item label YesButton Button label YesMouse event Not applicable Not applicable

Page 130: Build Forms II Volume 1 Instructor Guide 7196298

4-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Display in Keyboard Help and KeyboardHelp Text

• Key-Fn, Key-Others, and mouse-eventkey triggers

• Using key triggers

• Function keys, buttons, menu items,and mouse events

• Example: DO_KEY(‘EXIT_FORM’);

Page 131: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-19......................................................................................................................................................

......................................................................................................................................................Summary

Summary

Understanding Key Triggers• They fire when the associated function key is pressed.

• They are defined like any other trigger.

• Special properties are Display in Keyboard Help and Keyboard Help Text.

Classification of Key Triggers• Function key triggers

• Key-Fn triggers

• Key-Others

• Mouse-event key triggers

Uses of Key Triggers• Disable function keys

• Replace or extend default behavior of function keys

• Add function keys using Key-Fn triggers

• Adjust set of function keys using Key-Others

Association with Other Interface Controls• Function keys, buttons, menu items, mouse events

• Keys description, button label, menu-item label

Page 132: Build Forms II Volume 1 Instructor Guide 7196298

4-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 4 OverviewThis practice covers the following topics:

• Examining the behavior of[Duplicate Record] at run time

• Redefining [Duplicate Record]

– To create a new record beforeduplication

– To clear primary key items afterduplication

• Changing the behavior of function keysaccording to context

Page 133: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-21......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 4

Practice Session Overview: Lesson 4This practice guides you though redefining function keys with key triggers. In the process, you will investigate the behavior of the Key-Others trigger.

Practice Contents• Examine the behavior of [Duplicate Record] at run time.

• Use a key trigger to redefine [Duplicate Record] to create a new record before duplicating. Ensure that the primary key of the new record is empty.

• Disable all function keys on the master block except for [Execute Query], [Up], [Down], and [Enter Query].

• Test the effects of the key triggers on the master block.

• Add a form-level Key-Exit trigger to perform default exit functionality.

• Run the form again to test the effects of this key trigger.

Page 134: Build Forms II Volume 1 Instructor Guide 7196298

4-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Practice 41 Create and modify a key trigger.

a Open the ORDERS form module and replace the M_SUMMIT menu module with the DEFAULT&SMARTBAR menu.

b Run the form and make sure that you understand the default behavior of [Duplicate Record], by invoking it once while the cursor is on a queried record in the S_ORD block and again when the cursor is on a new record.

c Redefine [Duplicate Record] so that a new record is created before the record duplication occurs. Redefine [Duplicate Record] at the form level.

d In the S_ORD block, redefine [Duplicate Record] in such a way that the Id item is emptied after duplication. This code should be executed in addition to and after the form level code.

e In the S_ITEM block, redefine [Duplicate Record] in such a way that the item_id, product_id, description, and price items are emptied after duplication. This code should be executed in addition to and after the form level code.

f Save, generate, and test the ORDERS form.

If you have time...

2 Disable function keys.

a Make sure that only the function keys [Duplicate Record], [Execute Query], [Enter Query], [Create Record], [Clear Block], [Up], and [Down] can be used for the S_ORD master block. All function keys should be available for the S_ITEM detail block.

b Test whether you can exit from the form by selecting the [Exit] key in the master block.

c Add a form-level Key-Exit trigger to perform the exit functionality of the CONTROL.EXIT_BUTTON item.

d Test again whether you can exit from the form by selecting [Exit] in the master block. Explain this behavior.

e Modify the When-Button-Pressed trigger of the CONTROL.EXIT_BUTTON item to activate the same functionality when you select the [Exit] function key. Remove the existing code.

3 Create and modify a key trigger.

a Create an alert called DELETE_ALERT.

Page 135: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 4-23......................................................................................................................................................

......................................................................................................................................................Practice 4

b For the S_ORD and S_ITEM blocks, redefine [Delete Record] so that the alert is displayed when a record is deleted. Modify the message displayed, depending on the block where the cursor is.

c Specify new text to be displayed in the run-time Show Keys help window.

Page 136: Build Forms II Volume 1 Instructor Guide 7196298

4-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 4: Programming Function Keys

Page 137: Build Forms II Volume 1 Instructor Guide 7196298

................................

5

Responding to MouseEvents

Page 138: Build Forms II Volume 1 Instructor Guide 7196298

5-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Instructor NoteTopic TimingLecture 40 minutes

Practice 30 minutes

Total 70 minutes

Instructor NoteDemonstration for the next page pair: Use the Cursor Style (cursor_style.fmb) demonstration to show the mouse cursor style.

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Define mouse events

• Cause a form module to respond tomouse movement

• Cause a form module to respond tomouse button actions

• Drag and drop items

Page 139: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewThe keyboard, menu, and mouse are the operator’s tools for interacting with the Forms application. This lesson demonstrates how to write an application that responds to mouse events.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Define mouse events

• Cause a form module to respond to mouse movement

• Cause a form module to respond to mouse button actions

• Drag and drop items

Page 140: Build Forms II Volume 1 Instructor Guide 7196298

5-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Instructor NoteDo not forget to change the cursor style to DEFAULT in case of a trigger failure.

Copyright Oracle Corporation, 1999. All rights reserved.

Mouse Events

• Point at which processing can beinfluenced

• Identified by:

– Mouse movement

– Mouse button action

Copyright Oracle Corporation, 1999. All rights reserved.

Mouse Cursor Style

To change the cursor style dynamically:

DEFAULT

BUSY

CROSSHAIR

HELP

INSERTION

GUI-specific arrow symbol

GUI-specific busy symbol

GUI-specific crosshair symbol

GUI-specific help symbol

GUI-specific insertion symbol

SET_APPLICATION_PROPERTY(CURSOR_STYLE,

′value′);

Page 141: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-5......................................................................................................................................................

......................................................................................................................................................What Are Mouse Events?

What Are Mouse Events?An event is a point during a Forms process at which you can influence the processing behavior. Every object can have processing events with which you can associate PL/SQL code (triggers).

A mouse event is an event that can be identified by a mouse movement or a mouse button action.

The Seven Mouse EventsThe Forms mouse events can be divided in two groups: mouse movement events and mouse button-initiated events.

The mouse movement events are:

• Entry into an item or canvas

• Exit from an item or canvas

• General movement

The events that correspond to mouse button actions are:

• Click

• Double-click

• Up

• Down

Mouse Cursor StyleForm Builder allows you to change dynamically the cursor style. Use thefollowing built-in to do it:

SET_APPLICATION_PROPERTY( CURSOR_STYLE, ’ value’);

The valid settings for the cursor style property are:

• BUSY

• CROSSHAIR

• DEFAULT

• HELP

• INSERTION

Page 142: Build Forms II Volume 1 Instructor Guide 7196298

5-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Technical NoteUsing the When-Mouse-Enter, When-Mouse-Leave, and When-Mouse-Move triggers can affect the performance of your form, because these triggers have the potential to fire frequently.

Instructor NoteDemonstration: Use the Simple Mouse Events (mouse_event.fmb) demonstration to illustrate a humorous use of the When-Mouse-Enter trigger.

You can also use the Mouse Events (mouse.fmb) demonstration to illustrate all the mouse triggers and system variables.

Copyright Oracle Corporation, 1999. All rights reserved.

Mouse Movement Triggers

When-Mouse-Enter

When-Mouse-Leave

When-Mouse-Move

Page 143: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-7......................................................................................................................................................

......................................................................................................................................................Responding to Mouse Movement

Responding to Mouse MovementYou can initiate an action whenever mouse movement occurs, by defining the mouse movement triggers.

The Three Mouse Movement Triggers

Uses of the Mouse Movement Triggers• Use When-Mouse-Move in conjunction with the

SYSTEM.MOUSE_X_POS and SYSTEM.MOUSE_Y_POS system variables to return the exact position of the mouse within an item.

• Use When-Mouse-Leave to update an item value without causing the cursor to navigate out of the current item.

Trigger UseWhen-Mouse-Enter Fires when the user moves the mouse into an

item or canvas-viewWhen-Mouse-Leave Fires when the user moves the mouse out of

an item or canvas-view

When-Mouse-Move Fires when the user moves the mouse within an item or canvas-view

Page 144: Build Forms II Volume 1 Instructor Guide 7196298

5-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Technical NoteThe SYSTEM.MOUSE_FORM system variable is NULL if the platform is not a GUI platform.

Instructor NoteDemonstration: Use the Mouse Events (mouse.fmb) demonstration to illustrate all the mouse triggers and system variables.

Demonstration for the next page pair: Use the Mouse Events (mouse.fmb) demonstration to illustrate all the mouse triggers and system variables.

1 MOUSE_FORM 5 MOUSE_RECORD_OFFSET

2 MOUSE_CANVAS 6 MOUSE_X_POS

3 MOUSE_ITEM 7 MOUSE_Y_POS

4 MOUSE_RECORD

Copyright Oracle Corporation, 1999. All rights reserved.

Navigation in a Block

1

2

3

4

6

7

5

Page 145: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-9......................................................................................................................................................

......................................................................................................................................................Responding to Mouse Movement

The Mouse Position System VariablesUse the following system variables to determine when the mouse has moved, where it has moved from, and where it has moved to.

Variable UseSYSTEM.MOUSE_FORM Identifies the form module that the mouse is

currently inSYSTEM.MOUSE_CANVAS Identifies the canvas that the mouse is currently

on

SYSTEM.MOUSE_ITEM Identifies the item that the mouse is currently inSYSTEM.MOUSE_RECORD Identifies the record number that the mouse is

currently inSYSTEM.MOUSE_RECORD_OFFSET Identifies the number of the record that the mouse

is currently in, relative to the first visible record; uses a 1-based index

SYSTEM.MOUSE_X_POS Identifies the x coordinate of the mouse’s current position (If the mouse is positioned on a canvas, the x coordinate is measured relative to the top left corner of the canvas. If the mouse is in an item, the x coordinate is measured relative to the top left corner of the item.)

SYSTEM.MOUSE_Y_POS Identifies the y coordinate of the mouse’s current position (If the mouse is positioned on a canvas, the y coordinate is measured relative to the top left corner of the canvas. If the mouse is in an item, the y coordinate is measured relative to the top left corner of the item.)

Page 146: Build Forms II Volume 1 Instructor Guide 7196298

5-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Technical NoteClick and double-click work only if the mouse stays on the item (or canvas) throughout the down-up action.

Copyright Oracle Corporation, 1999. All rights reserved.

Mouse Button Action Triggers

click

click

When-Mouse-Down

When-Mouse-Up

When-Mouse-Click

When-Mouse-Doubleclickclick

Copyright Oracle Corporation, 1999. All rights reserved.

Mouse Event Trigger Sequence

1.

2.

3.

4.

5.

6.

When-Mouse-Down

When-Mouse-Up

When-Mouse-Click

When-Mouse-Down

When-Mouse-Up

When-Mouse-Doubleclick

Page 147: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-11......................................................................................................................................................

......................................................................................................................................................Responding to Mouse Button Actions

Responding to Mouse Button ActionsYou can initiate an action whenever a mouse button action occurs by defining the mouse button action triggers.

The Mouse Button Action Triggers

Firing Sequence for Mouse Button Action TriggersWhen you double-click an item or canvas, you are potentially causing the following triggers to fire in the order in which they are listed. Similarly, when you click an item or canvas, the triggers that precede the When-Mouse-Click trigger will fire.

• When-Mouse-Down

• When-Mouse-Up

• When-Mouse-Click

• When-Mouse-Down

• When-Mouse-Up

• When-Mouse-Doubleclick

Trigger UseWhen-Mouse-Down Initiates an action when the user presses the

mouse button down while the mouse is point-ing to an item or a canvas

When-Mouse-Up Initiates an action when the user presses and releases the mouse button while the mouse is pointing to an item or a canvas

When-Mouse-Click Initiates an action when the user clicks on an item or canvas

When-Mouse-Doubleclick Initiates an action when the user double-clicks an item or canvas

Page 148: Build Forms II Volume 1 Instructor Guide 7196298

5-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Instructor NoteThere are now more useful system variable names for the mouse button state. SYSTEM.MOUSE_BUTTON_MODIFIERS should be used in place of SYSTEM.MOUSE_BUTTON_SHIFT_STATE.

The values returned by SYSTEM.MOUSE_BUTTON_MODIFIERS are invariant across all platforms and languages.

• SYSTEM.MOUSE_BUTTON_SHIFT_STATE returns the string, but in the language of the operating system.

• SYSTEM.MOUSE_BUTTON_MODIFIERS always returns the same string, regardless of OS language.

Demonstration: Use the Mouse Events (mouse.fmb) demonstration to illustrate all the mouse triggers and system variables.

Demonstration for the next page pair: Use the Drag and Drop (dragdrop.fmb) demonstration to show an example of drag and drop use. Click an employee number, and drag this employee to a department.

Copyright Oracle Corporation, 1999. All rights reserved.

Mouse Button ActionSystem Variables

SYSTEM.MOUSE_BUTTON_PRESSED

SYSTEM.MOUSE_BUTTON_MODIFIERS

AltCtrl

Page 149: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-13......................................................................................................................................................

......................................................................................................................................................Responding to Mouse Button Actions

The Mouse Button System VariablesUse the following system variables to determine which of the mouse buttons was pressed and which special key, if any, was used.

If the operator holds down the [Ctrl] and [Shift] keys while pressing the mouse button, SYSTEM.MOUSE_BUTTON_MODIFIERS contains the value Shift+Control+.

Variable UseSYSTEM.MOUSE_BUTTON_PRESSED Identifies which mouse button was pressed

(values of 1-5, where 1 is the left mouse button)

SYSTEM.MOUSE_BUTTON_MODIFIERS Identifies which special key was pressed to modify the usual mouse button action (possible values are Shift+, Caps Lock+, Control+, Alt+, Command+, Super+, and Hyper+)

Page 150: Build Forms II Volume 1 Instructor Guide 7196298

5-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Instructor NoteA library named drag.pll is shipped with the product. Use the following steps as a demonstration:

1 Create a new form module and a new text item manually.

2 Attach the PL/SQL library drag.pll to your form.

3 For this item, create a When-Mouse-Down trigger, a When-Mouse-Move trigger, and a When-Mouse-Up trigger.

In the When-Mouse-Down trigger, include the following statement:

MOUSE.CLICK;

You can also include code here to change the cursor to indicate that a drag operation is occurring.

In the When-Mouse-Move trigger, include the following statement:IF :SYSTEM.MOUSE_BUTTON_PRESSED =’1’ THEN

MOUSE.MOVE;

END IF;

In the When-Mouse-Up trigger, add your application-specific code, which should check where the object has been dropped, and take appropriate action.

Copyright Oracle Corporation, 1999. All rights reserved.

Drag and Drop

Items in original positions

Item-A highlighted

Items repositioned

Page 151: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-15......................................................................................................................................................

......................................................................................................................................................Responding to Mouse Button Actions

What Is Drag and Drop?The drag and drop functionality is the ability for users to move items around the canvas and arrange them in the order they want.

Implementing Drag and Drop FunctionalityYou can use the mouse button action triggers (When-Mouse-Down and When-Mouse-Up) and the mouse position system variables to implement drag and drop functionality in your form module.

You need to consider the following when implementing drag and drop:

• Changing the appearance of the item you want to drag and drop: Use the SET_ITEM_PROPERTY built-in and a visual attribute.

• Changing the appearance of the cursor during the drag and drop process: Use SET_APPLICATION_PROPERTY(cursor_style, ‘value’).

• Holding the name of the item being dragged and dropped.: Use a global variable to store the initial value of SYSTEM.MOUSE_ITEM.

• Setting the new position, according to the mouse position: Use SET_ITEM_PROPERTY(:global.variablename, position, :SYSTEM.MOUSE_X_POS, :SYSTEM.MOUSE_Y_POS).

• Repositioning other items that may be affected

Page 152: Build Forms II Volume 1 Instructor Guide 7196298

5-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Mouse events

• Responding to mouse movement

– Mouse position system variables

– Mouse movement triggers

• Responding to mouse button actions

– Mouse button system variables

– Mouse button triggers

Page 153: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-17......................................................................................................................................................

......................................................................................................................................................Summary

SummaryIn this lesson, you saw how to write an application that responds to mouse events.

Mouse Events • Entry to a canvas or an item

• Exit from a canvas or an item

• Move the cursor

• Click

• Double-click

• Up

• Down

• Responding to mouse movement

• Mouse position system variables

Mouse Movement Triggers• When-Mouse-Enter

• When-Mouse-Leave

• When-Mouse-Move

Responding to Mouse Button Actions• Mouse button system variables

• Mouse button triggers

- When-Mouse-Click

- When-Mouse-Doubleclick

- When-Mouse-Up

- When-Mouse-Down

Page 154: Build Forms II Volume 1 Instructor Guide 7196298

5-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 5 Overview

This practice covers the following topics:

• Invoke an editor when the operatordouble-clicks an item

• Define mouse-event trigger to displaythe Help canvas

Page 155: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 5-19......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 5

Practice Session Overview: Lesson 5This practice guides you through using mouse-event triggers and mouse system variables.

Practice Contents• Define a mouse-event trigger to invoke an editor on the

S_CUSTOMER.COMMENTS item.

• Modify the control.help button to a display item.

• Assign a value of “?” to the CONTROL.SHOW_HELP_BUTTON display item when the user enters the form.

• Display the CV_HELP canvas when the mouse enters the CONTROL.SHOW_HELP_BUTTON display item.

Page 156: Build Forms II Volume 1 Instructor Guide 7196298

5-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 5: Responding to Mouse Events

Practice 5In this practice, you provide additional functionality in your forms by defining mouse-event triggers.

1 In the CUSTOMERS form, define a mouse-event trigger on S_CUSTOMER.COMMENTS that invokes the item’s editor when the user double-clicks the item.

2 In the ORDERS form convert the CONTROL.SHOW_HELP_BUTTON button into a display item capable of displaying a single large character. Change the item type property and choose a font that allows large character sizes (such as Times New Roman). Set the font size to 24. Set Bevel to none. Adjust the item size so that one character is visible inside it. Since only the first character of the item name is visible in the Layout Editor, this item appears as S. The item’s background color should match the toolbar, and its text color should be green.

3 In the ORDERS form, define a When-Mouse-Enter trigger at form level that assigns a value of? to the display item CONTROL.SHOW_HELP_BUTTON. This should occur only when the mouse is in the CV_ORDER canvas.

4 Create a When-Mouse-Enter trigger on CONTROL.SHOW_HELP_BUTTON that uses the SHOW_VIEW built-in to display the CV_HELP. Remove the When-Button-Pressed trigger.

5 Create a When-Mouse-Leave trigger on CONTROL.SHOW_HELP_BUTTON that hides the CV_HELP. Use the HIDE_VIEW built-in to achieve this. Delete the CONTROL.HIDE_HELP_BUTTON button.

6 Save, compile, and run the ORDERS form to test. The stacked canvas, CV_HELP is displayed only if the current item is not obscured. Ensure, at least, that the first entered item in the form is CV_HELP will not obscure.

If you have time...

7 Modify the When-Mouse-Enter and When-Mouse-Leave triggers to display the Cv_Help canvas, even if the current item is obscured. You can replace the existing code with the code from the pr5_7_1.txt and pr5_7_2.txt files.

Page 157: Build Forms II Volume 1 Instructor Guide 7196298

................................

6

Controlling Windowsand Canvases

Programmatically

Page 158: Build Forms II Volume 1 Instructor Guide 7196298

6-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Instructor NoteTopic TimingLecture 40 minutes

Practice 45 minutes

Total 85 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

ObjectivesAfter completing this lesson, you shouldbe able to do the following:

• Display a form document in multiplewindows

• Write code to interact with windows

• Manipulate windows programmatically

• Manipulate canvas-viewsprogrammatically

• Use large data blocks

Page 159: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewYou should already be familiar with setting window and canvas properties at design time. This lesson covers the triggers and built-ins that you can use to manage the properties and behavior of windows and canvases at run-time.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Display a form module in multiple windows

• Write code to interact with windows

• Manipulate windows programmatically

• Manipulate canvas-views programmatically

• Use large data blocks

Page 160: Build Forms II Volume 1 Instructor Guide 7196298

6-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Copyright Oracle Corporation, 1999. All rights reserved.

Using Window-InteractionTriggers

System variable:SYSTEM.EVENT_WINDOW

When-Window-Activated

When-Window-Deactivated

When-Window-Closed

When-Window-Resized

Enforces navigation

Deactivates a window

Closes a window

Maintains visualstandards

Trigger Use

Page 161: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-5......................................................................................................................................................

......................................................................................................................................................Using Window-Interaction Triggers

Using Window-Interaction TriggersYou can use four window-interaction triggers to provide extra functionality whenever a user interacts with a window. These triggers should be defined at the form level.

The common uses for those triggers are the following:

Keeping Track of the Triggered WindowThe SYSTEM.EVENT_WINDOW system variable contains the name of the last window for which a window-interaction trigger fired. You can use this system variable to perform different actions for different windows in your window-interaction triggers.

Note: Help with triggers is available by pressing [Ctrl] + [H] and selecting PL/SQL Reference - Triggers.

Trigger CharacteristicWhen-Window-Activated Fires when a window is made the active window (Note

that window activation can occur independently of navi-gation.)

When-Window-Deactivated Fires when a user deactivates a window by setting the input focus to another window

When-Window-Closed Fires when a user closes a window by using a window-manager-specific Close command

When-Window-Resized Fires when a window is resized, either by the user or through a trigger (It also fires at form startup, but not when a window is made into an icon.)

Trigger UseWhen-Window-Activated Captures initial settings of window properties; enforces

navigation to a particular item whenever the window is activated

When-Window-Deactivated Deactivates a windowWhen-Window-Closed Closes a window programmaticallyWhen-Window-Resized Maintains visual standards; captures window properties

Page 162: Build Forms II Volume 1 Instructor Guide 7196298

6-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Technical NoteIn Microsoft Windows, you can reference the multiple-document interface (MDI) application window with the FORMS_MDI_WINDOW constant. FORMS_MDI_WINDOW is used with certain built-in functions and procedures that relate to windows.

Copyright Oracle Corporation, 1999. All rights reserved.

Built-ins for ManipulatingWindows

• FIND_WINDOW

• GET_WINDOW_PROPERTY

• HIDE_WINDOW

• MOVE_WINDOW

• RESIZE_WINDOW

• SET_WINDOW_PROPERTY

• SHOW_WINDOW

Page 163: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-7......................................................................................................................................................

......................................................................................................................................................Built-ins for Manipulating Windows

Built-ins for Manipulating Windows

Built-in Description

FIND_WINDOW Returns the internal window ID (of data type WINDOW) of a window with the given name

GET_WINDOW_PROPERTY Returns the current value of the specified window property for the given window

HIDE_WINDOW Hides the window

MOVE_WINDOW Moves the window to the location specified by the given coordinates

RESIZE_WINDOW Changes the window to the specified width and height

SET_WINDOW_PROPERTY Sets the specified window property for the given window to a specified value

SHOW_WINDOW Makes the window visible at the current or specified display position

Page 164: Build Forms II Volume 1 Instructor Guide 7196298

6-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Technical NoteREPLACE_CONTENT_VIEW does not hide the stacked canvas already displayed in the window, whereas SHOW_VIEW and SET_VIEW_PROPERTY (with the Visible property) display the given canvas in front of any stacked canvas.

Instructor NotePoint out that the GET_ built-ins are the most important ones when writing generic code.

Demonstration for the next pages: Use the Tab Pages (tab_page.fmb) demonstration to show those system variables. Click a tab page and press [F1]; a message is displayed.

Use the same demonstration to show how to enforce navigation when a user selects a tab page.

Use the same demonstration to illustrate the TOPMOST_TAB_PAGE argument. Click the TopMost Tab Page button.

Copyright Oracle Corporation, 1999. All rights reserved.

Built-ins for ManipulatingCanvases

• FIND_CANVAS• FIND_VIEW• GET_CANVAS_PROPERTY• GET_VIEW_PROPERTY• HIDE_VIEW• REPLACE_CONTENT_VIEW• SCROLL_VIEW• SET_CANVAS_PROPERTY• SET_VIEW_PROPERTY• SHOW_VIEW

Page 165: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-9......................................................................................................................................................

......................................................................................................................................................Built-ins for Manipulating Canvases

Built-ins for Manipulating Canvases

Built-in DescriptionFIND_CANVAS Returns the internal canvas ID (of data type CAN-

VAS) of a canvas with the given nameFIND_VIEW Returns the internal view ID (of data type

VIEWPORT) of a canvas with the given nameGET_CANVAS_PROPERTY Returns the current value of the specified canvas prop-

erty for the given canvasGET_VIEW_PROPERTY Returns the current value of the specified view prop-

erty for the canvasHIDE_VIEW Hides the canvasREPLACE_CONTENT_VIEW Replaces the content canvas currently displayed in the

window with the specified content canvasSCROLL_VIEW Moves the view of a given canvas to a different posi-

tion on its canvas (does not move the window to a different position on the screen)

SET_CANVAS_PROPERTY Sets the specified canvas property for the given canvas to a specified value

SET_VIEW_PROPERTY Sets the specified view property for the given canvas to a specified value

SHOW_VIEW Makes the given canvas visible at the current display position

Page 166: Build Forms II Volume 1 Instructor Guide 7196298

6-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Instructor NoteThe trigger does not fire if the end user presses [Next Item] + [Tab] to navigate from one field to another in the same block but on different tab pages.

Copyright Oracle Corporation, 1999. All rights reserved.

Working with Tab-StyleCanvases

The When-Tab-Page-Changed trigger fireswhen a user:

• Clicks a tab

• Uses the Next Tab Page or Previous TabPage function keys

Page 1 Page 3Page 2 click

Previous Tab Page

NextTab Page

Copyright Oracle Corporation, 1999. All rights reserved.

Working with Tab-StyleCanvases

Tab canvases system variables:

• :SYSTEM.TAB_NEW_PAGE

• :SYSTEM.TAB_PREVIOUS_PAGE

Page 167: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-11......................................................................................................................................................

......................................................................................................................................................Working with Tab-Style Canvases

Working with Tab-Style Canvases

When-Tab-Page-Changed TriggerThis form-level trigger fires when there is explicit item or mouse navigation from one tab page to another in a tab canvas. In other words, when the user clicks a tab or presses [Ctrl]+[PgUp] or [Ctrl]+[PgDown].

This trigger is very often used to perform actions when any tab page is changed during item or mouse navigation; for example, to enable or disable items or to set default or related item values.

Be aware that this trigger does not fire when the tab page is changed programmatically and does not fire with implicit navigation.

Tab Canvases System VariablesWithin the When-Tab-Page-Changed trigger, you can reference system variables to determine where you are coming from and going to.

• :SYSTEM.TAB_NEW_PAGE returns the name of the tab page that you are going to.

• :SYSTEM.TAB_PREVIOUS_PAGE returns the name of the tab page that you are coming from.

These system variables return only the page name, not the canvas name, so you must name all tab pages uniquely across the form if you need to be able to identify them programmatically.

Technical NoteWhen you are changing to another tab page, the cursor does not automatically move to a different item. To move the cursor you must include a GO_ITEM statement in the When-Tab-Page-Changed trigger. This is intended functionality to allow users to view other tab pages without navigating the cursor and therefore causing item navigation and validation (as previously mentioned).

Page 168: Build Forms II Volume 1 Instructor Guide 7196298

6-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Instructor NoteTOPMOST_TAB_PAGE returns only the tab page name, and not the canvas name. To set a property, you must concatenate the canvas name with the page name.

Copyright Oracle Corporation, 1999. All rights reserved.

Working with Tab-StyleCanvases

• GET_TAB_PAGE_PROPERTY: Returnsthe tab page label or the tab pagecanvas

• SET_TAB_PAGE_PROPERTY: Enableschanging of the tab page label

• FIND_TAB_PAGE: Returns the tab pageID

Copyright Oracle Corporation, 1999. All rights reserved.

Other Arguments for CanvasBuilt-ins

• GET_CANVAS_PROPERTY: Identify thetopmost tab page

• SET_CANVAS_PROPERTY: Bring apage to the top programmatically

Page 169: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-13......................................................................................................................................................

......................................................................................................................................................Working with Tab-Style Canvases

Built-ins for Manipulating Tab-Style Canvases

Note: The tab page is named using the syntax “CanvasName.PageName.”

ExampleDECLARE

tp_id Tab_Page;

BEGIN

tp_id := Find_Tab_Page(’Canvas2.TabPage1’);

IF Get_Tab_Page_Property(tp_id, enabled) =’FALSE’ THEN

Set_Tab_Page_Property(tp_id, enabled,property_true);

END IF;

END;

Other Arguments for Canvas Built-insIf you want to make a tab page the top-most on its underlying tab canvas, you can use the built-in procedure SET_CANVAS_PROPERTY and set the canvas property TOPMOST_TAB_PAGE. You can also get the top-most tab page by using the built-in function GET_CANVAS_PROPERTY.

GET_CANVAS_PROPERTY(’canvas_name’, TOPMOST_TAB_PAGE)

SET_CANVAS_PROPERTY(’canvas_name’, TOPMOST_TAB_PAGE, page_name)

In the preceding syntax example, page_name is either a constant, in single quotes, or a variable.

Built-in DescriptionFIND_TAB_PAGE Searches the list of tab pages in a given tab canvas and

returns a tab page ID when it finds a valid tab page with the given name (You must define a variable of type TAB_PAGE to accept the return value.)

SET_TAB_PAGE_PROPERTY Sets the tab page properties (ENABLED, LABEL, VISIBLE, VISUAL_ATTRIBUTE) of the specified tab canvas page

GET_TAB_PAGE_PROPERTY Returns property values (CANVAS_NAME, ENABLED, LABEL, VISIBLE, VISUAL_ATTRIBUTE) for a specified tab page

Page 170: Build Forms II Volume 1 Instructor Guide 7196298

6-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Copyright Oracle Corporation, 1999. All rights reserved.

Block 3

Windows and Blocks

Block 1

Block 2

Cursorlocation

Nonactivewindow

Active window

Window 1

Window 2

Page 171: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-15......................................................................................................................................................

......................................................................................................................................................Windows and Blocks

Windows and BlocksForm Builder processes many events based on blocks (and items), which can be completely independent of windows (and canvases). Keep in mind the following characteristics of windows and blocks.

Connection Between Windows and Blocks• A window can contain multiple canvases, and multiple items can be

located on a canvas.

• A block can contain multiple items, and an item is located on one and only one canvas (except for null canvas items).

• A window can contain multiple blocks, and a block can be located on several windows.

Note: In general, put blocks in separate windows. If blocks are closely related (through a foreign-key relationship), put them in the same window.

Window Activation and Block NavigationYou can use the When-Window-Activated trigger to activate another window automatically (see the Closing Windows example later in this lesson).

Transaction ManagementDuring commit processing, Forms processes all base table blocks insequential order. Therefore, transaction management is block-based rather than window-based. However, the user expects to interact with a form in a window-based way.

Page 172: Build Forms II Volume 1 Instructor Guide 7196298

6-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Technical NoteYou can also maximize the MDI window application with the WINDOW_STATE command line parameter:

ifrun60.exe module=customer.fmx userid=my_name/my_password@my_database window_state=maximize

Instructor NoteDemonstration: Use the Window Coding (window.fmb) demonstration to show the two examples described above. Show the When-New-Form-Instance trigger, which includes the code for maximizing the MDI application window.

Show the GET_CURSOR_WINDOW program unit.

Copyright Oracle Corporation, 1999. All rights reserved.

Manipulating Window PropertiesProgrammatically

Maximizing MDI application window

Locating the Cursor window

SET_WINDOW_PROPERTY (forms_mdi_window,

window_state, maximize);

GET_VIEW_PROPERTY (GET_ITEM_PROPERTY (NAME_IN

(′system.cursor_item′), item_canvas),

window_name);

GET_VIEW_PROPERTY (GET_ITEM_PROPERTY (NAME_IN

(′system.cursor_item′), item_canvas),

window_name);

Page 173: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-17......................................................................................................................................................

......................................................................................................................................................Manipulating Window Properties Programmatically

Manipulating Window Properties ProgrammaticallyYou can use the window-interaction triggers and the built-ins for windows to manipulate your windows (and the MDI application window on Microsoft Windows) at run time.

Manipulating the MDI Application Window at Form StartupThe When-New-Form-Instance trigger below implements the following functionality:

• Maximizing the MDI application window

• Setting the window title of the MDI application window

The When-New-Form-Instance Trigger at Form LevelBEGIN

SET_WINDOW_PROPERTY(forms_mdi_window, window_state, maximize);SET_WINDOW_PROPERTY(forms_mdi_window, title, ’Summit Sporting

Goods.’);END;

Locating the Cursor WindowThe cursor may be located in a nonactive window. In this case, you can use the following GET_CURSOR_WINDOW function to find this window.

FUNCTION get_cursor_windowRETURN VARCHAR2ISBEGIN

RETURN (GET_VIEW_PROPERTY(GET_ITEM_PROPERTY( NAME_IN(’system.cursor_item’),item_canvas), window_name));END;

Page 174: Build Forms II Volume 1 Instructor Guide 7196298

6-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Instructor NoteDemonstration: Use the Window Coding (window.fmb) demonstration to show cascaded windows with context. Show the Key-Help trigger, which includes the code for cascading windows with context.

Copyright Oracle Corporation, 1999. All rights reserved.

Cascaded Windowswith Context

Page 175: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-19......................................................................................................................................................

......................................................................................................................................................Showing Multiple Windows

Showing Multiple WindowsWhen using several windows, you should consider how to position them with respect to each other and how to indicate the context in which a certain window is displayed.

The following examples show a form based on departments and employees. The department block and employee block are located in separate windows.

Relative Window PositioningThe When-New-Form-Instance trigger at form level:

DECLAREv_first_window_x NUMBER;v_first_window_y NUMBER;

BEGINDEFAULT_VALUE(’0’, ’global.first_window_x’);DEFAULT_VALUE(’0’, ’global.first_window_y’);v_first_window_x := :global.first_window_x;v_first_window_y := :global.first_window_y;SET_WINDOW_PROPERTY(’window1’, position, v_first_window_x,

v_first_window_y);SET_WINDOW_PROPERTY(’window2’, position, v_first_window_x + 3,

v_first_window_y + 1);SHOW_WINDOW(’window1’);

END;

Display Context in Window TitleThe When-New-Block-Instance trigger on EMP block:

BEGINSET_WINDOW_PROPERTY(’window2’,title,’Employees of Department’

||NVL(TO_CHAR(:dept.id), ’??’));END;

Page 176: Build Forms II Volume 1 Instructor Guide 7196298

6-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Instructor NoteDemonstration: Use the Window Coding (window.fmb) demonstration to show a form using the Close option from the Microsoft Windows System menu.

Copyright Oracle Corporation, 1999. All rights reserved.

Window with Close Optionon System Menu Box

Page 177: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-21......................................................................................................................................................

......................................................................................................................................................Closing Windows

Closing WindowsUse the Close Menu item on the system-menu box to provide the user with a means for closing windows. Because there is no default behavior in Forms when a user chooses the Close Menu item, you must define aWhen-Window-Closed trigger.

The following examples show a form based on departments and employees. The department block and employee block are located in separate windows. The When-Window-Closed and When-Window-Activated triggers implement the following functionality:

• Exiting from the form or hiding the window that is closed by the user (Forms automatically activates another window.)

• Navigating to the newly activated window

Note: The function GET_CURSOR_WINDOW, discussed in an earlier example, is used here.

The When-Window-Closed Trigger at Form LevelBEGIN

IF :SYSTEM.EVENT_WINDOW = ’WINDOW1’ THENDO_KEY(’exit_form’);

ELSIF :SYSTEM.EVENT_WINDOW = ’WINDOW2’ THENHIDE_WINDOW(’window2’);

END IF;END;

The When-Window-Activated Trigger at Form LevelBEGIN

IF :SYSTEM.EVENT_WINDOW = get_cursor_window THENRETURN;

ELSIF :SYSTEM.EVENT_WINDOW = ’WINDOW1’ THENGO_BLOCK(’s_dept’);

ELSIF :SYSTEM.EVENT_WINDOW = ’WINDOW2’ THENGO_BLOCK(’s_emp’);

END IF;END;

Page 178: Build Forms II Volume 1 Instructor Guide 7196298

6-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Instructor NoteDemonstration: Use the large block (Tab_Page.fmb) demonstration to illustrate the example above. The larg_emp.sql file drops and creates the S_LARGE_EMP table.

Copyright Oracle Corporation, 1999. All rights reserved.

Blocks with Many Items

Copyright Oracle Corporation, 1999. All rights reserved.

Blocks with Many Items

Page 179: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-23......................................................................................................................................................

......................................................................................................................................................Blocks with Many Items

Blocks with Many ItemsOne way to deal with blocks with many items is to use one window with one content canvas and one tabbed canvas with several pages in the following manner:

1 Divide the items into logical groups and name each group.

2 Place the main group on the content canvas.

3 Create a tabbed canvas on the content canvas.

4 Place each of the other groups on a separate pages of a tabbed canvas.

This technique works equally well for single record and multirecord blocks.

Page 180: Build Forms II Volume 1 Instructor Guide 7196298

6-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Window-interaction triggers

• SYSTEM.EVENT_WINDOW

• Built-ins for manipulating windows

• Built-ins for manipulating canvases

• Built-ins for manipulating tab canvases

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Windows and blocks

– Multiple blocks correspond tomultiple windows.

– Window activation does not inducenavigation.

– Transaction management is block-oriented.

Page 181: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-25......................................................................................................................................................

......................................................................................................................................................Summary

Summary

Window-Interaction Triggers• When-Window-Activated

• When-Window-Deactivated

• When-Window-Closed

• When-Window-Resized

Use the SYSTEM.EVENT_WINDOW system variable to keep track of the triggered window.

Built-ins for Manipulating Windows• FIND_WINDOW

• GET_WINDOW_PROPERTY

• SET_WINDOW_PROPERTY

• HIDE_WINDOW

• SHOW_WINDOW

• MOVE_WINDOW

• RESIZE_WINDOW

Built-ins for Manipulating Canvases• FIND_CANVAS, FIND_VIEW

• GET_CANVAS_PROPERTY

• GET_VIEW_PROPERTY

• SET_CANVAS_PROPERTY

• SET_VIEW_PROPERTY

• HIDE_VIEW

• SHOW_VIEW

• REPLACE_CONTENT_VIEW

• SCROLL_VIEW

Windows and Blocks• Windows may contain multiple blocks and blocks may be located on

several windows.

• Forms will not automatically navigate to an item located in an activated window.

• Transaction management is block-oriented rather than window-oriented.

Page 182: Build Forms II Volume 1 Instructor Guide 7196298

6-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 6 Overview

This practice covers the following topics:

• Building a multiple-window form

– Using window interaction triggers

– Using window and canvas-viewbuilt-ins

• Controlling window size by usingwindow built-ins

• Enhancing the tab canvas functionality

Page 183: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 6-27......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 6

Practice Session Overview: Lesson 6This practice guides you through managing multiple windows and canvases programmatically.

Practice Contents• Build a multiple-window form and use the appropriate window

interaction triggers and built-ins to implement the behavior specified.

• Make sure that a user cannot make any window larger than it was at the startup of the form.

If you have time...

• Display a hint or description for the current tab page.

• Change the label on the Comment tab page when it is the topmost page.

Page 184: Build Forms II Volume 1 Instructor Guide 7196298

6-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 6: Controlling Windows and Canvases Programmatically

Practice 61 Manipulate a multiple-window form.

a Open the ORDERS form module.

b Make sure that when a user closes the orders window by way of the system-menu box, the form is exited. Also make sure that when a user closes the inventory window by way of the system-menu box, the cursor navigates to the orders window. If cursor navigation succeeds, the inventory window should closed. Create a When-Window-Closed trigger. You can import the pr6_1b.txt file.

c Save, compile, and test the form.

d Make sure that a user cannot make any window larger than it was at the startup of the form. You should save the size of the windows at the startup of the form, and create a procedure called CHECK_WINDOW_SIZE that resets the size of the current window if the new width and height are larger than the initial one. Create a When-New-Form-Instance trigger. You can replace the existing code with the code from the pr6_1d1.txt file. Next, create the procedure CHECK_WINDOW_SIZE. You can import the code from the pr6_1d2.txt file. Create a When-Window-Resized trigger that calls the procedure.

2 Manipulate the MDI application window.

a Open the CUSTOMERS form module.

b At the startup of the form, maximize the MDI application window, and display an appropriate title. You can import the pr6_2b.txt file.

If you have time...

3 Open the EMPLOYEES form, and use the CONTROL.HELP_TAB text item to display a hint or description for the current tab page.

a Create a When-Tab-Page-Changed trigger to populate this item with an appropriate message for each page. You can import the pr6_3a.txt file.

b Test and verify your module.

c Modify the When-Tab-Page-Changed trigger to change the label on the Comment tab page. When Comment is the topmost page, change its label to Employee XX, where XX is the employee’s ID number (emp.id). When any other tab page is topmost, change the label back to Comment. You can import the pr6_3c.txt file.

Page 185: Build Forms II Volume 1 Instructor Guide 7196298

................................

7

Defining Data Sources

Page 186: Build Forms II Volume 1 Instructor Guide 7196298

7-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteTopic TimingLecture 50 minutes

Practice 50 minutes

Total 100 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:• Describe the various data source types• Base a data block on a FROM clause

query• Describe the advantages of using a

FROM clause query

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

• Base a data block on a stored procedure• Return a REF cursor from a stored

procedure• Return a table of records from a stored

procedure• Select the appropriate data source for a

data block

Page 187: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewThis lesson introduces you to the different data source types that can be used for data blocks. This lesson also provides you with some guidelines for choosing the best data source for the job.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Describe the various data source types

• Base a data block on a FROM clause query

• Discuss the advantages of using a FROM clause query

• Base a data block on a stored procedure that returns a REF cursor

• Select the appropriate data source for a data block

Page 188: Build Forms II Volume 1 Instructor Guide 7196298

7-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Copyright Oracle Corporation, 1999. All rights reserved.

Data Source Types

Query

Company Name:

Company Code:

Balance:

DML

TableTable

Transactionaltrigger

Transactionaltrigger

FROM clause query

Storedprocedure

Storedprocedure

Page 189: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-5......................................................................................................................................................

......................................................................................................................................................Data Source Types

Data Source TypesIn the previous course, Oracle Developer: Build Forms I, you learned that a data block had a base table that served as the data source for both queries and DML operations. A base table is not the only source for a data block, however, and you can specify the data source for the query separately from DML.

Data Sources for Query OperationsFor query operations, you can base your blocks on:

• Database tables or views

• Stored procedures

• Transactional triggers

• The FROM clause query (subquery)

You can also change the base table of a block dynamically at run time.

Data Sources for DML OperationsFor DML operations, you can base your blocks on:

• Database tables or views

• Stored procedures

• Transactional triggers

A data block based on a stored procedure can return data from a REF cursor or a PL/SQL table of records. If your data block has database-intensive multiple validation lookup or derived fields, this method of partitioning application logic onto the server can improve application performance.

Page 190: Build Forms II Volume 1 Instructor Guide 7196298

7-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteDemonstration: Run the from_clause.sql and from_clause3.sql scripts to illustrate a FROM clause query.

Copyright Oracle Corporation, 1999. All rights reserved.

Basing a Data Blockon a FROM Clause Query

SELECT...

FROM...

WHERE...

(SELECT...

FROM...

WHERE...)

Copyright Oracle Corporation, 1999. All rights reserved.

Why Use a FROM ClauseQuery?

Perform joins, lookups, and calculationson the server (thus avoiding multiplenetwork trips) without having to define aview every time

• Improves developer productivity

• Reduces the burden on the DBA

• Improves performance

Page 191: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-7......................................................................................................................................................

......................................................................................................................................................Basing a Data Block on a FROM Clause Query

Basing a Data Block on a FROM Clause QueryYou can use a FROM clause as the data source for a data block. A FROM clause is a feature of the Oracle 7.3 Server that enables you to nest a SELECT statement in the FROM clause of a SELECT statement.

A FROM clause is a valid query block data source, but it is not a valid DML block data source. The value returned from a FROM clause is a subset of records from the original query.

ExampleSELECT deptno, sal_total

FROM

( SELECT deptno, SUM(sal) sal_total

FROM emp

HAVING SUM(sal) > 5000

GROUP BY deptno

)

ORDER BY deptno ;

Why Use a FROM Clause Query?FROM clauses are used to perform:

• Joins

• Lookups

• Calculations

This is done without having to create a view on the server. FROM clauses can also be used to prototype views and to increase performance.

Using a FROM clause as a block data source is similar to using a view based on an updatable join as a block data source. However, a FROM clause provides you with more control, because the presence of a DBA is not required to define the view.

Note: The FROM clause produces results that are identical to an updatable join-view from the client side, but for which there is no defined view on the server.

Page 192: Build Forms II Volume 1 Instructor Guide 7196298

7-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Copyright Oracle Corporation, 1999. All rights reserved.

Basing a Data Blockon a Stored Procedurefor Query Operations

Return data by way of:• REF cursor• A Table of records

ProcedureEmpno Ename Job Hiredate

1234 Jones Clerk 01-Jan-95

1235 Smith Clerk 01-Jan-95

1236 Adams Clerk 01-Jan-95

1237 Clark Clerk 01-Jan-95

Company Name:

Company Code:

Balance:

Querying Data block

Copyright Oracle Corporation, 1999. All rights reserved.

Basing a Data Blockon a Stored Procedure

for DML Operations

Return data by way of a table of records

ProcedureEmpno Ename Job Hiredate

1234 Jones Clerk 01-Jan-95

1235 Smith Clerk 01-Jan-95

1236 Adams Clerk 01-Jan-95

1237 Clark Clerk 01-Jan-95

Company Name:

Company Code:

Balance:

UpdatingData block

Page 193: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-9......................................................................................................................................................

......................................................................................................................................................Basing a Data Block on a Stored Procedure

Basing a Data Block on a Stored ProcedureYou can base a data block on a stored procedure. A stored procedure returns a data block by using either a REF cursor or a table of records.

What Is a REF Cursor?A REF cursor defines a SELECT statement that is the source of the records. You can use this cursor to perform array fetches of SELECT statements opened by a server-side procedure.

A REF cursor is a pointer to a server-side cursor variable. It is analogous to a pointer in C in that it is an address to a location in memory. The stored procedure returns a reference to a cursor that is open and populated by a SELECT statement to be used as a block data source.

A stored procedure that uses a REF cursor can be used only as a query block data source; it cannot be used as a DML block data source. Using a REF cursor is ideal for queries that depend only on variations in SQL SELECT statements and not PL/SQL.

What Is a Table of Records?A table of records is a PL/SQL V2.3 variable that is essentially an array of rows.

You can think of a table of records as an image of a table in memory. The server-side procedure constructs this array, usually based on parameters passed to it, and passes back the resulting “set” of records to a data block. Forms treats the resulting table of records exactly as if it were fetching a series of rows from a table.

Unlike a view or a REF cursor, you are not limited to what you can express as a SQL SELECT statement. Anything you can code in PL/SQL is possible; for example, a tree-walk that includes a join.

Using a table of records is extremely efficient in terms of the savings on network traffic, because it takes a single round trip (from client to server) to execute the stored procedure and a single round trip to return the records.

Page 194: Build Forms II Volume 1 Instructor Guide 7196298

7-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteDemonstration: Edit the RefCurSpec.sql and RefCurBody.sql scripts to show the code of a stored procedure using a REF cursor.

Copyright Oracle Corporation, 1999. All rights reserved.

Example of Query Usinga REF Cursor Procedure

Define a package specification with:

• The objects returned by the REF cursor

• The REF cursor

• The query procedure: Data returnedthrough the first argument that is an INOUT argument

Define a package body: Write the code forthe query procedure

Page 195: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-11......................................................................................................................................................

......................................................................................................................................................Example of a Query Using a REF Cursor Procedure

Example of a Query Using a REF Cursor ProcedureThis is an example of a stored procedure that returns a REF cursor as a block data source. A package is used to group the related data types and procedures logically.

-- Define Package Specification

PACKAGE emp_pkg IS

-- Defines the objects returned by the REF Cursor

TYPE emprec IS RECORD ( empno emp.empno%TYPE,

ename emp.ename%TYPE );

-- Defines the Ref Cursor

TYPE empcur IS REF CURSOR RETURN emprec;

-- Defines the procedure used for querying records

PROCEDURE empquery_refcur ( block_data IN OUT empcur,

p_deptno IN NUMBER);

END;

-- Defines Package Body

PACKAGE BODY emp_pkg IS

PROCEDURE empquery_refcur ( block_data IN OUT empcur,

p_deptno IN NUMBER)

IS

BEGIN

OPEN block_data FOR

SELECT empno, ename

FROM emp

WHERE deptno = NVL( p_deptno, deptno )

ORDER BY empno;

END;

END;

Page 196: Build Forms II Volume 1 Instructor Guide 7196298

7-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteDemonstration: Edit the TorQuerySpec.sql and TorQueryBody.sql scripts to show the code of a stored procedure using a table of records.

Copyright Oracle Corporation, 1999. All rights reserved.

Example of Query Usinga Table of Records Procedure

Define a package specification with:• The structure of each row of the table• The table of records• The procedure used for querying

records: Data returned through the firstargument; that is, an IN OUT argument

Define a package body: Write the code forthe query procedure

Page 197: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-13......................................................................................................................................................

......................................................................................................................................................Example of Query Using a Table of Records Procedure

Example of Query Using a Table of Records ProcedureThis is an example of a stored procedure that returns a table of records as a block data source. A package is used to group the logically related data types and procedures.

-- Define Package Specification

PACKAGE emp_pkg IS

-- Defines each row of the table

TYPE emprec IS RECORD ( empno emp.empno%TYPE,

ename emp.ename%TYPE );

-- Defines the Table of records

TYPE emptab IS TABLE OF emprec INDEX BY BINARY_INTEGER;

-- Defines the procedure used for querying records

PROCEDURE empquery_tab ( block_data IN OUT emptab,

p_deptno IN NUMBER );

END;

-- Defines Package Body

PACKAGE BODY emp_pkg IS

PROCEDURE empquery_tab ( block_data IN OUT emptab,

p_deptno IN NUMBER )

IS

i NUMBER;

CURSOR empsel IS

SELECT empno, ename

FROM emp

WHERE deptno = NVL( p_deptno, deptno );

BEGIN

OPEN empsel;

i := 1;

LOOP

FETCH empsel INTO block_data(i).empno,

block_data(i).ename;

EXIT WHEN empsel%NOTFOUND;

i := i + 1;

END LOOP;

END;

END;

Page 198: Build Forms II Volume 1 Instructor Guide 7196298

7-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Note See Appendix F, “Handling Server-Side Errors, for code details.

Instructor NoteDemonstration: Edit the TorDMLSpec.sql and TorDMLBody.sql scripts to show the code of a stored procedure using a table of records.

Copyright Oracle Corporation, 1999. All rights reserved.

Example of DML Usinga Table of Records Procedure

Define a package specification with:• The structure of each row of the table• The table of records• A procedure to insert rows• A procedure to update rows• A procedure to delete rows• A procedure to lock rows

Define a package body: Write the code foreach DML procedure

Page 199: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-15......................................................................................................................................................

......................................................................................................................................................Example of DML Using a Stored Procedure

Example of DML Using a Stored ProcedureThis is an example of a stored procedure that inserts rows using a table of records as a block data source. A package is used to group the logically related data types and procedures. You should define procedures that update, delete, and lock rows also.

-- Define Package Specification

PACKAGE emp_pkg IS

-- Defines each row of the table

TYPE emprec IS RECORD ( empno emp.empno%TYPE,

ename emp.ename%TYPE,

mgr emp.mgr%TYPE,

deptno emp.deptno%TYPE );

-- Defines the Table of records

TYPE emptab IS TABLE OF emprec INDEX BY BINARY_INTEGER;

-- Defines the procedure used for inserting records

PROCEDURE empinsert ( block_data IN emptab );

END;

-- Defines Package Body

PACKAGE BODY emp_pkg IS

PROCEDURE empinsert ( block_data IN emptab )

IS

i NUMBER;

cnt NUMBER;

BEGIN

cnt := block_data.count;

FOR i IN 1..cnt LOOP

INSERT INTO emp (empno, ename, mgr, deptno)

VALUES (block_data(i).empno, block_data(i).ename,

block_data(i).mgr, block_data(i).deptno);

END LOOP;

END;

END;

Page 200: Build Forms II Volume 1 Instructor Guide 7196298

7-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Copyright Oracle Corporation, 1999. All rights reserved.

Returning a REF Cursor

Query

Fetched rows

REF cursor

REF cursor

Procedure

SQLSELECT

21

3

4

Copyright Oracle Corporation, 1999. All rights reserved.

Returning a Table of Records

Query

Table of records

Cursor

Cursor

Procedure

AnyPL/SQL

code

21

3

4

Page 201: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-17......................................................................................................................................................

......................................................................................................................................................Deciding Whether to Use a REF Cursor or a Table of Records

Deciding Whether to Use a REF Cursor or a Tableof RecordsWhen deciding whether to use a REF cursor or a table of records, take into account the following considerations.

Queries or DML on a TableExecuting queries or DML on a table takes one round trip per array size of rows returned.

Queries with Stored Procedure Returning a REF CursorExecuting queries using a stored procedure that returns a REF cursor takes one round trip to execute the stored procedure(1, 2), plus one round trip (3, 4) per array size of rows returned.

Queries or DML with Stored Procedure Using PL/SQL Tables of RecordsExecuting queries or DML with stored procedures using PL/SQL tables of records takes one round trip to execute the stored procedure (1,2) plus one round trip (3,4) for all the rows.

Performance Implications of REF Cursors or Table of RecordsIf you are dealing with a large number of rows, the disadvantage of PL/SQL tables of records is that all the rows must be processed at once. For querying, this means you might retrieve rows that the user does not need and never displays.

• REF cursor: The number of records fetched depends on the Array Fetch property value.

• Table of records: All records are fetched.

If you want to view all records, a table of records is more efficient. However, if the table of records returns 10,000 records and you look only at 3, it is not an efficient option. For querying and DML, you use an unnecessary amount of memory because all the rows must be in memory at the same time.

Page 202: Build Forms II Volume 1 Instructor Guide 7196298

7-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteDemonstration: If they do not already exist, create and populate the EMP and DEPT tables using the UTLSample.sql file. Run the TorDMLSpec.sql and TorDMLBody.sql scripts.

Create a new form module. Base the block on a stored procedure.

The query procedure is emp_pkg.empquery.

The insert procedure is emp_pkg.empinsert.

The update procedure is emp_pkg.empupdate.

The delete procedure is emp_pkg.empdelete.

The lock procedure is emp_pkg.emplock.

Copyright Oracle Corporation, 1999. All rights reserved.

Data Block Wizard

Use the Data Block Wizard to specify thefollowing:

• Data source type

• Query procedure

• Insert procedure

• Update procedure

• Delete procedure

• Lock procedure

Page 203: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-19......................................................................................................................................................

......................................................................................................................................................Data Block Wizard

Data Block WizardThe Data Block Wizard simplifies and automates the process of creating blocks. You saw how to use it in the previous course, Oracle Developer: Build Forms I.

Use the Data Block Wizard even if you want to create a data block based on stored procedure. You just have to specify the following:

Property Description

Data source type Specifies if the data block is based on a table or a stored procedure

Query procedure Name of the procedure used to query rows

Insert procedure Name of the procedure used to insert rows

Update procedure Name of the procedure used to update rows

Delete procedure Name of the procedure used to delete rows

Lock procedure Name of the procedure used to lock rows

Page 204: Build Forms II Volume 1 Instructor Guide 7196298

7-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteDemonstration: Use the form created previously to illustrate these properties.

Copyright Oracle Corporation, 1999. All rights reserved.

Data Block Propertiesfor Queries

Copyright Oracle Corporation, 1999. All rights reserved.

Data Block Properties for DML

Page 205: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-21......................................................................................................................................................

......................................................................................................................................................Data Block Properties

Data Block Properties

Data Block Properties for Queries

Data Block Properties for DML

Property Description

Query Data Source Type Specifies the query data source type for the data block

Query Data Source Name Used only used if the query data source type is Table, Subquery, or Procedure

Query Data Source Columns Specifies the names and data types of the columns associated with the query data source (Used only if the query data source type is Table, Subquery, or Procedure.)

Query Data Source Arguments Specifies the names, data types, and values of the argu-ments that are to be passed to the procedure for query-ing data (Used only if the query data source type is Procedure.)

Property Description

DML Data Target Type Specifies the DML data source type for the data block

DML Data Target Name Specifies the name of the DML data source for the data block (Used only if the DML data target type is Table.)

(Insert, Update, Delete, Lock) Procedure Name

Specifies the name of the procedure to be used (Used only if the DML data target type is Procedure.)

(Insert, Update, Delete, Lock) Procedure Result Set Columns

Specifies the names and data types of the result set columns associated with the procedure (Used only if the DML data target type is Procedure.)

(Insert, Update, Delete, Lock) Procedure Arguments

Specifies the names, data types, and values of the arguments that are to be passed to the procedure (Used only if DML data target type is Procedure.)

Page 206: Build Forms II Volume 1 Instructor Guide 7196298

7-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Instructor NoteDemonstration: Use the Stored Procedures demonstration to illustrate how to use the same block to display data from different tables. Before the demonstration, run the OrderSpecs.sql and OrderBody.sql scripts.

Copyright Oracle Corporation, 1999. All rights reserved.

Data Source Guidelines

Base a data block on a FROM clausequery to:

• Create a “dynamic” view

• Perform validation and DML on theserver side

Copyright Oracle Corporation, 1999. All rights reserved.

Data Source Guidelines

Base a data block on a storedprocedure to:

• Increase control and security

• Specify a SELECT statement at run time

• Query or update multiple tables

• Perform complex computations

• Perform validation and DML on theserver side

Page 207: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-23......................................................................................................................................................

......................................................................................................................................................Data Source Guidelines

Data Source Guidelines

Using a FROM Clause QueryYou base a data block on a FROM clause query to:

• Create a dynamic view

• Perform validation and DML on the server side

Using Stored ProceduresYou base a data block on a stored procedure when you want to:

• Increase control and security

Using a stored procedure, you do not have to grant select access on the table to the users, just EXECUTE privileges on the procedure.

• Specify a SELECT statement at run time

Using a REF cursor, if the logged-on user is a manager, open the cursor as SELECT lastname, salary FROM s_emp; otherwise open the cursor as SELECT lastname, null FROM s_emp.

• Base a block on multiple tables

Using a REF cursor and depending on some parameter to the procedure, you could open the cursor either as SELECT * FROM open_orders (current data) or as SELECT * FROM closed_orders (old data).

• Perform complex computations and decisions

Using a table of records, return the salary of all employees that you manage, but NULL for the salary of other employees.

• Perform validation and DML on the server side

If your data block has multiple validation lookup or derived fields that are database-intensive, this method of partitioning the application logic onto the server can vastly improve the performance of applications.

• Encapsulate logic within a subprogram

• Reduce traffic through array processing, using a REF cursor

Page 208: Build Forms II Volume 1 Instructor Guide 7196298

7-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Copyright Oracle Corporation, 1999. All rights reserved.

Data Source Guidelines

YES

YES

YES

YES

YES

YES

Table

View

FROM Clause

Proc-Ref Cur

Proc-Table Rec

Transac. Trigger

YES

YES

NO

NO

YES

YES

Data Source Query DML

Page 209: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-25......................................................................................................................................................

......................................................................................................................................................Data Source Guidelines

Data Source Type RestrictionsWhen deciding on a data block source, consider your requirements:

• Will the block be used only to query records?

• Will the block be used to perform inserts, updates, and deletes?

• Will the block be used to perform both query and DML?

To decide, you should also consider the functional restrictions for each data source type:

Data Source Allows Query Allows DML

Table Yes Yes

View Yes Yes

FROM Clause Yes No

Procedure Using a REF Cursor Yes No

Procedure Using a Table of Records Yes Yes

Transactional Trigger Yes Yes

Page 210: Build Forms II Volume 1 Instructor Guide 7196298

7-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

New data sources:

• Stored procedure (query and DML)

• FROM clause query (query only)

Stored procedures return:

• REF cursors—limited to a singleSELECT statement

• Table of records—can be a complexprocedure

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

Use the Data Block Wizard to specify:

• Data source type

• Procedures for queries, updates,deletes, and locking

• Master-detail relationships

Page 211: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-27......................................................................................................................................................

......................................................................................................................................................Summary

Summary

New Data Sources• Stored procedure (query and DML)

• FROM clause query (query only)

Stored Procedures Return• REF cursors—limited to a single SELECT statement

• Table of records—can be a complex procedure

Using the Data Block Wizard• Specify data source type

• Specify procedures for queries, updates, deletes, and locking

• Specify master-detail relationships

Page 212: Build Forms II Volume 1 Instructor Guide 7196298

7-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 7 Overview

This practice covers the following topics:

• Modifying the EMP block to base it on anested SELECT statement

• Enabling DML on the EMP block

• Creating a package containing a storedprocedure to return a Ref cursor

• Basing a block on the previous storedprocedure

Page 213: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-29......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 7

Practice Session Overview: Lesson 7This practice guides through using other data sources.

Practice Contents• Base a block on a nested SELECT statement

• Enable DML on a block based on a nested SELECT statement

• Create a package containing a stored procedure to return a REF Cursor

• Base a block on a stored procedure

Page 214: Build Forms II Volume 1 Instructor Guide 7196298

7-30 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

Practice 71 Base the EMP block on a subquery.

a Open the EMPLOYEES form module.

b Set the Query Data Source Type EMP block property to From Clause Query.

c In the Query Data Source Name property enter the SELECT statement. Your query should return all the columns from the S_EMP table joined with the columns from the S_DEPT table. Remember to enclose your select SELECT statement in parentheses. You can copy and paste the content of the pr7_1c.txt file.

The SELECT statement is:(SELECT e.ID,

USERID,

LAST_NAME,

FIRST_NAME,

START_DATE,

TITLE,

MANAGER_ID,

DEPT_ID,

SALARY,

COMMISSION_PCT,

COMMENTS,

d.ID NUM,

REGION_ID,

NAME

FROM s_emp e, s_dept d

WHERE e.dept_id = d.id)

d When a block’s Query Data Source Type is Table, the ROWID of each row is implicitly queried when the row is retrieved from the database. This ROWID value is used in the WHERE clause of any subsequent UPDATE, DELETE, or SELECT FOR UPDATE statements issued by Oracle Forms.When a block’s Query Data Source Type is From Clause Query, the ROWID value is not implicitly retrieved. Therefore, the ROWID value cannot be used in subsequent statements. Instead, Oracle Forms constructs the WHERE clause using the primary key values of each row.

Page 215: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 7-31......................................................................................................................................................

......................................................................................................................................................Practice 7

Configure the EMP block so that Oracle Forms will use the primary key values when constructing the WHERE clause. Set the KeyMode property for the EMP block to Updatable. Set the Enforce Primary Key property for the EMP block to Yes. Set the Primary Key property for the Id item to Yes.

e Save, run, and test your module.

2 Enable DML on the EMP block without using transactional triggers.

a Set the block DML Target Name.

b Prevent Oracle Forms from attempting to update the columns from the S_DEPT table. On the Property Palette for the item, set the Query Only property to Yes, and the Update Allowed and Insert Allowed properties to No for the S_DEPT items (NUM, NAME, REGION_ID).

c Remove the appropriate transactional triggers.

d Save, run, and test your module.

If you have time...

3 Create a server-side package containing a procedure to return a REF cursor.

Using the code in the pr7_3a.sql file in your labs directory, create the Orders package body and package specification.

4 Modify the Ord_Sum block in the ord_sum.fmb module to base it on the stored procedure.

a Open the ord_sum.fmb module. Change the Query Data Source Type of the Ord_Sum block to Procedure. Change the DML Data Target Type to None (this block does not allow any inserts, updates, or deletes).

b Set the Query Data Source Name to the name of the stored procedure in the package.

c Specify the Query Data Source Columns to match the items in the Ord_Sum block.

The column names and types are:

ID, NumberNAME, Varchar2(255)TOTAL, Number

d Specify the procedure arguments. The first argument is the REF cursor that will be used by Forms to populate the block. The second argument is used to pass the value of the list box

Page 216: Build Forms II Volume 1 Instructor Guide 7196298

7-32 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 7: Defining Data Sources

(:Choose.View_Type) to the procedure to determine which SELECT statement is used. These arguments should match the arguments to the package procedure.

e Add a trigger on the View_Type item so that the data in the Ord_Sum block is updated when the list box value changes.

Hint: You need to execute a query in the Ord_Sum block.

5 Save and run your form. Observe the behavior of the record count in the console and the scroll bar as you scroll through the records. What do you deduce from this behavior?

Page 217: Build Forms II Volume 1 Instructor Guide 7196298

................................

8

Working with Oracle8Objects in Form Builder

Page 218: Build Forms II Volume 1 Instructor Guide 7196298

8-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Instructor NoteTopic TimingLecture 30 minutes

Practice 25 minutes

Total 55 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

ObjectivesAfter completing this lesson, you shouldbe able to:

• Recognize which object types aresupported

• Describe how object types arerepresented within Oracle Developer

• Create a block based on an object table

• Create a block based on a relation tablewith an object or a REF column

• Populate a REF column with an LOV

Page 219: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewThis lesson reviews certain object features of Oracle8 and explains how these objects are displayed in the Object Navigator.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Recognize which Oracle8 object types are supported

• Describe how Oracle8 objects are represented within Oracle Developer

• Create a block based on an object table

• Create a block based on a relational table with an object column or REF column

• Populate a REF column with an LOV

Page 220: Build Forms II Volume 1 Instructor Guide 7196298

8-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Instructor NoteThese pages review object type fundamentals. Additional object type information can be found in Appendix D, “Introduction to Oracle8 Object Features.”

Copyright Oracle Corporation, 1999. All rights reserved.

Object Types

Ship

Cancel

Hold

Checkstatus

Attributes

Methods

ORDERpo_nocustinfoline_itemsamount

Page 221: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-5......................................................................................................................................................

......................................................................................................................................................What Are Object Types?

What Are Object Types?An object type is a user-defined composite data type. It is in some ways similar to a record type, and in some ways similar to a package.

An object type is similar to a record type in that it is composed of one or more subparts that are of predefined data types. Record types call these subparts “fields,” but object types call these subparts “attributes.” And just as the fields of a record type can be of other record types, the attributes of an object type can be of other object types. Such an object type is called “nested.”

Object types are like record types in another sense: Both of them must be declared as types before the actual object or record can be declared.

An object type is also similar to a package. After an object is declared, its attributes are similar to package variables. And like packages, object types can contain procedures and functions. In object types, these subprograms are known as “methods.”

Like packages, object types can be declared in two parts: a specification and a body. Like package variables, attributes declared in the object type specification are public and those declared in the body are private. And as with package subprograms, all methods are defined in the package body, but only those whose specification appears in the object type specification are public methods.

Page 222: Build Forms II Volume 1 Instructor Guide 7196298

8-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Instructor NoteThese pages review object type fundamentals. Additional object type information can be found in Appendix D, “Introduction to Oracle8 Object Features.”

Copyright Oracle Corporation, 1999. All rights reserved.

Review of Objects

• Object tables

• Object columns

• Object views

• INSTEAD-OF triggers

DECLARE

BEGIN

EXCEPTION

END;

Page 223: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-7......................................................................................................................................................

......................................................................................................................................................Review of Objects

Review of ObjectsWith an object type, you can create object tables, object columns, object views, and INSTEAD-OF triggers.

Object TablesAfter you have declared an object type, you can create objects based on the type. One way to do this is to create a table whose rows are objects of that object type. Rows in an object table are assigned object IDs (OIDs) and can be referenced using a REF type.

Object ColumnAnother construct that can be based on an object type is an object column in a relational table. In the object table, the rows of a table are objects. In a relational table with an object column, the column is an object. The table usually has standard columns, as well as one or more object columns. Object columns are not assigned OIDs, and thus cannot be referenced using object REF values.

Object ViewAn object view transforms the way a table appears to a user, without changing the actual structure of the table. Object views make relational tables look like object tables. Objects accessed through object views are assigned OIDs, and can be referenced using object REFs.

INSTEAD OF Triggers INSTEAD OF triggers provide a transparent way of modifying views that cannot be modified directly through SQL DML statements (INSERT, UPDATE, and DELETE). These triggers are called INSTEAD-OF triggers because, unlike with other types of triggers, the Oracle server fires the trigger instead of executing the triggering statement. The trigger performs update, insert, or delete operations directly on the underlying tables.

Technical NoteThe Database Trigger editor has been enhanced to include the INSTEAD OF triggering event.

Page 224: Build Forms II Volume 1 Instructor Guide 7196298

8-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Instructor NoteThese pages review object type fundamentals. Additional object type information can be found in Appendix D, “Introduction to Oracle8 Object Features.”

Copyright Oracle Corporation, 1999. All rights reserved.

References to Objects

Page 225: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-9......................................................................................................................................................

......................................................................................................................................................Object REFs

Object REFsWhen a row in an object table or object view is created, it is assigned automatically a unique identifier called an object Id (OID). This OID value can be stored in attributes of other objects, or columns of other tables. The stored copy of the OID then becomes a pointer, or REF, to the original object. (Object columns are not assigned OIDs and cannot be pointed to by a REF.)

In relational databases, primary key values are used to identify records uniquely. In object-relational databases, OIDs provide an alternate method.

With relational tables, you can associate two records by storing the primary key of one record in one of the columns (the foreign key column) of another. In a similar way, you can associate two objects by storing the OID of one object in an attribute of another. Or you can associate a row in a relational table to an object by storing the OID of an object in a column of a relational table. The attribute or column that holds the OID is of data type REF.

Remember, the object itself is not stored in the table, only the OID value for the object.

Page 226: Build Forms II Volume 1 Instructor Guide 7196298

8-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Oracle8 in DeveloperSupported Oracle8 features• Large objects: BLOB, CLOB, NCLOB,

BFILE• User-defined objects

– Object table– Column object– REF column

Unsupported Oracle8 features• Collection types• Stored procedures that return object values

Page 227: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-11......................................................................................................................................................

......................................................................................................................................................Supported Oracle8 Features

Supported Oracle8 FeaturesA number of new features provided in the Oracle8 Server are available in Oracle Developer. This allows greater scalability and performance in your application.

Oracle Developer adds support for the following Oracle8 data types:

• Large objects (LOBs): BLOB, CLOB, NCLOB, BFILE

• User-defined Oracle8 objects

• An object table, where the entire table is based on a single object type (Oracle Developer treats each column in an object table as an individual data item.)

• A column object in an object or relational table, where the column is based on an object type definition

• A REF column in an object or a relational table, where that column’s values are pointers to rows in a separate object table

Unsupported Oracle8 FeaturesNot all Oracle8 features are currently supported by Oracle Developer. The major unsupported features are:

• Collection types, including nested tables and varying arrays

• Stored procedures that return object values

Page 228: Build Forms II Volume 1 Instructor Guide 7196298

8-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

How Developer Treats Objects

Attr_A1

Attr_A2

Object_A

Object_B

Attr_B1

Attr_B2

Attr_A3

Nested Objects

Attr_A1

Object_A

Attr_A3

Attr_A2_B1

Attr_A2_B2

Items in a Form

Page 229: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-13......................................................................................................................................................

......................................................................................................................................................How Oracle Developer Treats Objects

How Oracle Developer Treats ObjectsAs you have learned, Oracle8 tables can contain objects. In its support for the Oracle8 Server, Oracle Developer allows you to access these objects in an application.

A table itself can be based on an object (a table object), one or more of the table columns can be based on an object (a column object), or one or more of the tables’ columns can contain a reference to an object stored in another table (REF column). Each of these objects can itself contain objects.

In these cases, the columns and attributes form a hierarchy among the Oracle8 data types. However, Oracle Developer has no hierarchy of items. Each item lies directly below the block. Therefore, Oracle Developer must collapse the hierarchy before the columns and attributes are mapped to items within a block. Both the hierarchy of the columns and attributes and the “flattened” nature of the resulting items are represented in Oracle Developer’s displays and dialog boxes.

Page 230: Build Forms II Volume 1 Instructor Guide 7196298

8-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Object Display

Object Type

Object Table

Object Column

Object REF

Page 231: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-15......................................................................................................................................................

......................................................................................................................................................Object Type Displays

Object Type DisplaysThe Object Navigator lists declared types in the “Database Objects” section, along with tables, views, and other Oracle objects. The objects in the screenshot are based on the following syntax: -- type declaration

CREATE TYPE dept_type AS OBJECT(id NUMBER,

name VARCHAR2(25),

region_id NUMBER(7) )

/

-- object table

CREATE TABLE oo_dept_table OF dept_type;

-- object column

CREATE TABLE rel_emp_table_ObjCol (id NUMBER(7),

last_name VARCHAR2(25),

first_name VARCHAR2(25),

userid VARCHAR2(8),

start_date DATE, manager_id NUMBER(7),

title VARCHAR2(25),

dept_id dept_type,

salary NUMBER(11,2),

commission_pct NUMBER(4,2) );

-- ref column

CREATE TABLE rel_emp_table_RefCol (id NUMBER(7), last_name VARCHAR2(25),

first_name VARCHAR2(25), userid VARCHAR2(8),

start_date DATE, manager_id NUMBER(7), title VARCHAR2(25), dept_id REF dept_type,

salary NUMBER(11,2),

commission_pct NUMBER(4,2) );

Page 232: Build Forms II Volume 1 Instructor Guide 7196298

8-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Creating Data Blocks Basedon Oracle8 Objects

• Blocks based on object tables

• Blocks based on object columns

• Blocks with REF lookups

Page 233: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-17......................................................................................................................................................

......................................................................................................................................................Creating Data Blocks Based on Oracle8 Objects

Creating Data Blocks Based on Oracle8 ObjectsOracle Developer Release 6 enables you to create data blocks based on Oracle8 objects in a Form Builder application. The Data Block Wizard has been enhanced to support object tables. The fields of an object are displayed in a hierarchy underneath the object column in the wizard’s Table page. Like objects in the Object Navigator, object columns can be expanded or collapsed in the display.

A data block can be based on:

• An object table

• A column object

• A REF column

Page 234: Build Forms II Volume 1 Instructor Guide 7196298

8-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Blocks Based on Object Tables

Page 235: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-19......................................................................................................................................................

......................................................................................................................................................Selecting Object Table Columns

Selecting Object Table ColumnsYou can create a data block based on a user-defined object table. In the Data Block Wizard, you select object tables the same way you select relational tables. In the wizard’s Table page, when you select an object table as the data source, it is expanded and each of its components is displayed in the Available Columns window. An outline format with indenting is used to show each component of the object.

You select the type attributes the same way you select relational table columns. Oracle Developer treats each component in an object table as a separate column, and allows you to select these columns individually.

The syntax below creates an object table based on an object type:CREATE TYPE dept_type AS OBJECT

(id NUMBER,

name VARCHAR2(25),

region_id NUMBER(7) )

/

CREATE TABLE oo_dept_table OF dept_type

/

In the diagram, the wizard shows all the columns of the object table OO_DEPT_TABLE (ID, NAME, REGION_ID). Select any or all as data block items.

Page 236: Build Forms II Volume 1 Instructor Guide 7196298

8-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Blocks Based on ObjectColumns

Page 237: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-21......................................................................................................................................................

......................................................................................................................................................Selecting Object Column Attributes

Selecting Object Column AttributesIf you base a block on an object or relational table with an object column, the attributes of the object column appear indented beneath the name of the object column in the Data Block Wizard. Oracle Developer treats each attribute as a separate column. You can select any combination of columns or object column attributes. Once selected, they all “collapse” to the same level as an item within the new block.

Data items selected from an object are given the default name ColumnObjectName_ItemName. Selecting the object column name itself has the effect of selecting all of the attributes of the object column.

The syntax below creates a table with an object column:CREATE TYPE dept_type AS OBJECT

(id NUMBER,

name VARCHAR2(25),

region_id NUMBER(7) )

/

CREATE TABLE rel_emp_table_ObjCol (

id NUMBER(7),

last_name VARCHAR2(25),

first_name VARCHAR2(25),

userid VARCHAR2(8),

start_date DATE,

manager_id NUMBER(7),

title VARCHAR2(25),

dept_id dept_type,

salary NUMBER(11,2),

commission_pct NUMBER(4,2) );

In the diagram, the wizard displays ID, NAME, and REGION_ID as columns you can select as data block items.

Page 238: Build Forms II Volume 1 Instructor Guide 7196298

8-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Blocks with REF Lookups

Page 239: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-23......................................................................................................................................................

......................................................................................................................................................Blocks with REF Lookups

Blocks with REF LookupsIf you base a block on an object or relational table with a REF column, the attributes of the object being referenced appear below the REF column in the Available Columns window.

Once selected, the attributes of the REF column are made into items, just like standard columns. However, the items based on REF column attributes are created with a QUERY ONLY property value of “YES,” and INSERT ALLOWED and UPDATE ALLOWED properties of “NO.”

The syntax below creates a table with a REF data type:CREATE TYPE dept_type AS OBJECT

(id NUMBER,

name VARCHAR2(25),

region_id NUMBER(7) )

/

CREATE TABLE rel_emp_table_RefCol (

id NUMBER(7),

last_name VARCHAR2(25),

first_name VARCHAR2(25),

userid VARCHAR2(8),

start_date DATE,

manager_id NUMBER(7),

title VARCHAR2(25),

dept_id REF dept_type,

salary NUMBER(11,2),

commission_pct NUMBER(4,2) );

As seen in the diagram, the REF column name (DEPT_ID) appears twice in the column selection list. It appears once as a heading for the referenced object’s attributes and then again as a pointer. The column is selectable.

Page 240: Build Forms II Volume 1 Instructor Guide 7196298

8-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Using the REF Lookup Value

Select REF attribute columns: Thiscauses the columns to appear as dataitems at runtime.

Select the REF item itself:

• This causes the item to be placed on aNull canvas.

• The item does not appear at run time.

• The item is available for codingpurposes.

Page 241: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-25......................................................................................................................................................

......................................................................................................................................................The REF Column Value

The REF Column ValueThe double listing of the REF column name affords you different choices. As with a regular column object, you can select any or all of a REF’s attribute columns. Selecting the first instance of the REF name in the diagram on the previous page selects all its parts.

When you select one or more of the REF’s attribute columns, they appear as normal data items in the data block at run time.

You can also select the REF itself, which is the second entry in the diagram on the previous page. If the REF column itself is included in the block, it is created as a nondisplay item and placed by default on the Null canvas. Although the REF item does not appear on the canvas at run time, it is still available for coding purposes.

Page 242: Build Forms II Volume 1 Instructor Guide 7196298

8-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

LOVs for REFs

Page 243: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-27......................................................................................................................................................

......................................................................................................................................................LOVs for REFs

LOVs for REFsUsers need to have available an LOV from which they can choose the appropriate new value. The Data Block Wizard presents this window, which gives you an easy way to create an LOV.

How to Create the LOV1 Select the REF desired.

2 For the REF selected, the wizard lists all the associated tables. Select the table of your choice.

The wizard builds the LOV from the values in this table.

Note: The same LOV gets attached to all the lookup items associated with a particular REF.

REFs are defined on object types, not on specific tables. Therefore, a REF can point to multiple tables.

Page 244: Build Forms II Volume 1 Instructor Guide 7196298

8-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Most Oracle8 object types aresupported.

• Indentations represent nested objects.

• Blocks can be based on object tables.

• Blocks can be based on tables withobject columns or REF columns.

• REF columns can be populated with anLOV.

Page 245: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-29......................................................................................................................................................

......................................................................................................................................................Summary

Summary• Oracle Developer supports most, but not all, of the Oracle8 object types.

• In Oracle Developer, object types are displayed like columns, where indentation shows the nesting of objects.

• Blocks can be based on object tables.

• Blocks based on object or relational tables can include object columns or REF columns.

• REF columns can be populated with an LOV.

Page 246: Build Forms II Volume 1 Instructor Guide 7196298

8-30 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 8 Overview

This practice covers the following topics:

• Creating a block based on an objecttable

• Creating a block based on a relationaltable with an object column

• Creating a block based on a relationaltable with a REF column

• Populating a REF column with an LOV

Page 247: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-31......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 8

Practice Session Overview: Lesson 8This practice provides experience with blocks based on tables with Oracle8 object features.

Practice Contents• Create a block based on an object table

• Create a block based on a relational table with an object column

• Create a block based on a relational table with a REF column

• Populate a REF column with an LOV

Page 248: Build Forms II Volume 1 Instructor Guide 7196298

8-32 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Practice 81 Create a block based on a relational table.

a Create a new form called OO_DEPT.

b Create a block by using the Data Block Wizard. Base the block on the object table OO_DEPT_TABLE, and include all the columns. Do not enforce data integrity.

c Finish following the Data Block Wizard and invoke the Layout Wizard. Select all available items for display, and use a tabular layout with three displayed records and a scroll bar. Do not enter a frame title.

d Test and save the form.

2 Create a block based on a relational table with an object column.

a Create a form called OBJ_COL.

b Create a block by using the Data Block Wizard. Base the block on the relational table REL_EMP_TABLE_OBJCOL. Select the columns ID, FIRST_NAME, and LAST_NAME. Expand the object column DEPT_ID and select the attributes ID and NAME. Note the name that is given to the new item. Do not enforce data integrity.

c Finish following the Data Block Wizard and invoke the Layout Wizard. Select all available items for display. Change the prompt for item DEPT_ID to Department ID and DEPT_ID_NAME to Department Name. Use a form layout. Do not enter a frame title. Finish following the wizard.

d Examine the properties for the item dept_id_name. Pay particular attention to the database properties. Later, you will compare and contrast these properties with the properties set for a REF column.

e Test and save the form.

3 Create a block based on a relational table with an REF column and an LOV to populate the REF column.

a Create a form called REF_COL.

b Create a block by using the Data Block Wizard. Base the block on the relational table REL_EMP_TABLE_REFCOL. Select the columns ID, FIRST_NAME and LAST_NAME. Do not enforce data integrity.

c Note that there are two items called DEPT_ID. The first is expandable and has the term “LOOKUP” in parenthesis after the name. The second represents the REF column value itself. Expand

Page 249: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 8-33......................................................................................................................................................

......................................................................................................................................................Practice 8

the first DEPT_ID item and select the attributes ID and NAME. (Do not select the second DEPT_ID item. The REF item is included automatically when the LOV is created.)

d The Data Block Wizard offers to create an LOV for the REF item dept_id. Select the check box, and select OO_DEPT_TABLE as the source for the LOV.

e Finish following the Data Block Wizard and invoke the Layout Wizard. Select all available items for display. Do not enter a frame title. (Note that the REF item DEPT_ID is included in the list of items in the Object Navigator but is not included in the list of available items in the Layout Wizard. REF item values are normally not displayed, so by default the REF item is assigned to the Null canvas.)

f Examine the database properties for the item DEPT_ID_NAME. Pay particular attention to the database properties. Notice that the Query Only property is set to Yes.

g Select the item DEPT_ID from the Object Navigator, and examine the Canvas property. Also, notice that an LOV and associated record group now exist.

h Test and save the form, including the LOV.

Page 250: Build Forms II Volume 1 Instructor Guide 7196298

8-34 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 8: Working with Oracle8 Objects in Form Builder

Page 251: Build Forms II Volume 1 Instructor Guide 7196298

................................

9

Controlling Data BlockRelationships

Page 252: Build Forms II Volume 1 Instructor Guide 7196298

9-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Instructor NoteTopic TimingLecture 30 minutes

Practice 30 minutes

Total 60 minutes

Demonstration for the next page pair: Use the Coordination-Type Toggle (Orders3.fmb) demonstration to create explicitly a relation between the S_ITEM and S_INVENTORY blocks.

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Define block coordination

• Coordinate data blocks by using REFrelations

• Describe the characteristics andprinciples of relation-handling code

• Implement a coordination-type toggle

• Force one commit per master record

Page 253: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewYou have seen how form modules consist of data blocks based on related tables. This lesson shows how you can modify the relationship between two data blocks to affect the way in which deletes are handled and to what extent the data blocks are coordinated at query time. Also, it explains how to create relationships based on object REFs.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Define block coordination

• Coordinate data blocks by using REF relations

• Describe the characteristics and principles of relation-handling code

• Implement a coordination-type toggle

• Force one commit per master record

Page 254: Build Forms II Volume 1 Instructor Guide 7196298

9-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Copyright Oracle Corporation, 1999. All rights reserved.

Relations

• Logical objects that handle therelationship between two blocks

• Created implicitly with a master-detailform module

• Created explicitly with the New Relationdialog box

Page 255: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-5......................................................................................................................................................

......................................................................................................................................................Creating a Relation

Creating a Relation

What Is a Relation?A relation is a Form Builder object that handles the relationship between two associated blocks.

You can create a relation either:

• Implicitly with a master-detail form module

• Explicitly in the Object Navigator

Implicit RelationsWhen you create a master-detail form module, a relation is automatically created. This relation is named in the format masterblock_detailblock, for example, S_ORD_S_ITEM.

Explicit RelationsIf a relation is not established when default blocks are created, you can create your own by setting the properties in the New Relation dialog box. Like implicitly created relations, PL/SQL program units and triggers are created automatically when you explicitly create a relation.

Instructor NoteThe creation of explicit relations was covered in the Oracle Developer: Build Forms I course. Use these pages to review the fact that relations can be created implicitly or explicitly.

Page 256: Build Forms II Volume 1 Instructor Guide 7196298

9-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Instructor NoteExplain to students the importance of the Copy Value from Item property for implementing block coordination.

Demonstration: Use the Coordination-Type Toggle (Orders3.fmb) demonstration to show the objects used to implement a block coordination.

Copyright Oracle Corporation, 1999. All rights reserved.

Block Coordination• Coordination-causing event• Block-coordination phases:

– Clear phase executed before changeof master record

– Populate phase executed afterchange of master record

• Implementation of block coordination:– The Copy Value from Item property– Relation-handling triggers– Relation-handling procedures

Page 257: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-7......................................................................................................................................................

......................................................................................................................................................Block Coordination

Block CoordinationTo maintain a master-detail relationship, Forms coordinates the master and detail blocks to ensure that only the detail records that belong to the current master record are displayed.

Coordination-Causing EventsAny event that changes the master record is called a coordination-causing event or a coordination operation. Forms automatically coordinates the master and detail blocks again when you move to another master record.

Block Coordination Phases

Implementation of Block CoordinationForms implements block coordination through the following elements:

• The Copy Value from Item property on the foreign-key item in the detail block, which specifies the corresponding primary-key item in the master block

• Relation-handling triggers, which fire during the Clear and Populate phases of block coordination

• Relation-handling procedures, which are called from relation-handling triggers

Note: The elements above are controlled through the relation object.

Phase DescriptionClear Forms clears all detail blocks before it navigates to the new master record.

Possible changes in detail blocks are deleted. If the Clear phase fails, Forms stops coordination processing and does not navigate to the new master record.

Populate Forms queries all detail blocks after it has navigated to the new master record, unless the coordination type is Deferred.

Page 258: Build Forms II Volume 1 Instructor Guide 7196298

9-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Copyright Oracle Corporation, 1999. All rights reserved.

Blocks with REF Relations

Page 259: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-9......................................................................................................................................................

......................................................................................................................................................Coordinate Blocks Using REFs

Coordinate Blocks Using REFsMany object-oriented languages implement master-detail relations by storing in the detail data an internal identifier to the master data. This internal identifier is known as a reference (REF). To support object-oriented programming, the Data Block Wizard enables you to choose to base the relation on a REF rather than on a foreign key.

To create a master-detail relation based on a REF, the detail block must contain the REF column. Create a master-detail form using REFs by doing the following in the Data Block Wizard:

1 Create the master block and choose the columns you wish to include as items in the block. Complete the Layout Wizard steps to finish creating and laying out the master block.

2 Create the detail block. When you choose columns, you must choose the REF column, because this value will be used to establish the relationship. You should not choose the lookup columns, because doing so causes the detail block to duplicate items that are already displayed in the master block.

3 On the Master-Detail page of the wizard, click the Create Relationship button. A dialog box appears listing all possible master blocks for the relationship. Select the appropriate master block and click OK and then Finish.

4 Complete the Layout Wizard steps to finish creating and laying out the detail block.

Page 260: Build Forms II Volume 1 Instructor Guide 7196298

9-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Technical NoteRelation-handling triggers fire only if you have defined a corresponding relation.

Copyright Oracle Corporation, 1999. All rights reserved.

Characteristics of Relation-Handling Triggers

• On-Clear-Details: Implements the Clearphase

• On-Populate-Details: Implements thePopulate phase

• On-Check-Delete-Master: Implementsthe restricted-delete rule

• Effect of trigger failure

Page 261: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-11......................................................................................................................................................

......................................................................................................................................................Characteristics of Relation-Handling Triggers

Characteristics of Relation-Handling TriggersForms automatically creates and maintains relation-handling triggers to implement block coordination and restricted-delete foreign-key rules.

Note: If you specify a cascade-delete foreign-key rule for a relation, Form Builder uses a Pre-Delete trigger to implement this rule. However, this is a commit trigger, not a relation-handling trigger, and can also be used outside the context of relations.

Trigger DescriptionOn-Clear-Details Fires when a coordination-causing event occurs in a

master block, before Forms navigates to the new master record. This trigger implements the Clear phase and is defined at the form level. If it fails, the coordination-causing event is aborted.

On-Populate-Details Fires when a coordination-causing event occurs in a master block, after Forms has navigated to the new master record. However, this trigger fires only if an On-Clear-Details trigger is also defined. This trigger implements the Populate phase and is defined for each master block. If it fails, it can cause the wrong detail records to be displayed for the current master record.

On-Check-Delete-Master Fires when you attempt to delete the current master record, before Forms deletes the record. If it fails, the record deletion is aborted.

Page 262: Build Forms II Volume 1 Instructor Guide 7196298

9-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Copyright Oracle Corporation, 1999. All rights reserved.

Principles of Relation-HandlingCode

Three relation-handling procedures:• CLEAR_ALL_MASTER_DETAILS• QUERY_MASTER_DETAILS• CHECK_PACKAGE_FAILURE

Adding your own code to relation-handling triggers:• Forms adds comments around code.• You add your own code before or after

these comments.

Page 263: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-13......................................................................................................................................................

......................................................................................................................................................Principles of Relation-Handling Code

Principles of Relation-Handling CodeForms automatically creates and maintains the PL/SQL code that is executed in the relation-handling triggers. You can add your own code to these triggers.

Three Relation-Handling Procedures

Note: The CLEAR_ALL_MASTER_DETAILS procedure gives you an example of how to recursively walk through a hierarchical tree of blocks.

Adding Your Own Code to Relation-Handling TriggersForms adds comments around the PL/SQL code that it generates for relation handling, for example:

---- Begin default relation program section--BEGIN

CLEAR_ALL_MASTER_DETAILS;END;---- End default relation program section--

You can add PL/SQL code to relation-handling triggers before the “Begin default relation program section” comment or after the “End default relation program section” comment.

Note: Forms will not delete a relation-handling trigger to which you have properly added PL/SQL code.

Procedure Called FromCLEAR_ALL_MASTER_DETAILS On-Clear-Details trigger defined on the form

levelQUERY_MASTER_DETAILS On-Populate-Details trigger defined for each

master blockCHECK_PACKAGE_FAILURE On-Populate-Details trigger and the previous

procedures

Page 264: Build Forms II Volume 1 Instructor Guide 7196298

9-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Technical NoteYou can use these system variables in the On-Clear-Details trigger only. Assign their values to global variables to broaden the scope.

Copyright Oracle Corporation, 1999. All rights reserved.

Obtaining Relation-HandlingInformation

System variables for relation handling:

• SYSTEM.MASTER_BLOCK

• SYSTEM.COORDINATION_OPERATION

Built-ins for relation handling:

• GET_FORM_PROPERTY

• GET/SET_BLOCK_PROPERTY

• GET/SET _RELATION_PROPERTY

Page 265: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-15......................................................................................................................................................

......................................................................................................................................................Obtaining Relation-Handling Information

Obtaining Relation-Handling InformationYou can use system variables and built-ins to obtain more information about block coordination and relation properties. This is useful if you want to modify the default relation-handling triggers.

System Variables for Relation Handling

Built-ins for Relation Handling

(*): You can also set those properties using the Set-Relation-Property built-in.

Name DescriptionSYSTEM.MASTER_BLOCK Contains the name of the master block that

drives the current block coordinationSYSTEM.COORDINATION_OPERATION Contains the name of a block

coordination-causing event that occurred on the driving master block (Value examples of this system variable include NEXT_RECORD, SCROLL_DOWN, MOUSE, DELETE_RECORD, and EXECUTE_QUERY.)

Name Properties Concerning RelationsGET_FORM_PROPERTY FIRST_BLOCK,

LAST_BLOCK GET_BLOCK_PROPERTY COORDINATION_STATUS(*),

NEXTBLOCK, PREVIOUSBLOCK, FIRST_DETAIL_RELATION, FIRST_MASTER_RELATION

GET_RELATION_PROPERTY AUTOQUERY(*), DEFERRED_COORDINATION(*), MASTER_DELETES(*), PREVENT_MASTERLESS_OPERATION(*), DETAIL_NAME, MASTER_NAME, NEXT_DETAIL_RELATION, NEXT_MASTER_RELATION

Page 266: Build Forms II Volume 1 Instructor Guide 7196298

9-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Instructor NoteDemonstration: Use the Coordination-Type Toggle (Orders3.fmb) demonstration to show the example described above. Select Query––>Deferred.

Copyright Oracle Corporation, 1999. All rights reserved.

Implementinga Coordination-Type Toggle

Define a procedure that toggles betweenimmediate and deferred coordination

• Use GET_BLOCK_PROPERTY to obtainrelation name.

• Use GET_RELATION_PROPERTY toobtain current coordination type.

• Use SET_RELATION_PROPERTY toswitch to other coordination type.

Copyright Oracle Corporation, 1999. All rights reserved.

Implementinga Coordination-Type Toggle

Call this procedure from:

• When-Checkbox-Changed trigger

• Menu item of type Check

Page 267: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-17......................................................................................................................................................

......................................................................................................................................................Implementing a Coordination-Type Toggle

Implementing a Coordination-Type ToggleYou can use relation-handling built-ins to offer users the choice betweenimmediate and deferred coordination.

This example procedure can be used in a simple master-detail form and can serve as a starting point for more complex situations; for example, you can call this procedure from a When-Checkbox-Changed trigger on a check box that represents the coordination type, or from a menu item of type Check

PROCEDURE toggle_query_sync(p_master_block in VARCHAR2)IS

v_rel_name VARCHAR2(30);v_rel_id RELATION;

BEGINv_rel_name := GET_BLOCK_PROPERTY(p_master_block,

first_master_relation);IF v_rel_name IS NOT NULL THEN

v_rel_id := FIND_RELATION(v_rel_name);IF GET_RELATION_PROPERTY(v_rel_id, deferred_coordination) =

’FALSE’ THENSET_RELATION_PROPERTY(v_rel_id,deferred_coordination,

property_true);SET_RELATION_PROPERTY(v_rel_id,autoquery,property_true);MESSAGE(’Query-synchronization mode: deferred.’);

ELSESET_RELATION_PROPERTY(v_rel_id,deferred_coordination,

property_false);MESSAGE(’Query-synchronization mode: immediate.’);

END IF;END IF;

END toggle_query_sync;

.

Page 268: Build Forms II Volume 1 Instructor Guide 7196298

9-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Instructor NoteDemonstration: Use the Commit Per Master (Mascmt.fmb) demonstration to illustrate the example described above.

Copyright Oracle Corporation, 1999. All rights reserved.

Forcing a Commit Per Master

Define a procedure that:

• Updates the commit status byperforming validation

• Checks the commit status of the masterrecord

• Raises FORM_TRIGGER_FAILURE incase of changes

Copyright Oracle Corporation, 1999. All rights reserved.

Forcing a Commit Per Master

Call the procedure:

• In the On-Clear-Details trigger

• Before the “Begin default relationprogram section” comment

Page 269: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-19......................................................................................................................................................

......................................................................................................................................................Forcing a Commit Per Master

Forcing a Commit Per MasterIn some cases, you must commit changes in master-detail forms before a change of master record takes place (for example, when checking database-level constraints, such as a mandatory relationship).

You must call the procedure below from the On-Clear-Details trigger before the “Begin default relation program section” comment. Note that if the On-Clear-Details trigger fails, the change of master record is aborted.

PROCEDURE check_master_changeIS

v_master_record NUMBER;BEGIN

-- Force update of record status. VALIDATE(record_scope);IF FORM_SUCCESS THEN

-- Check if master record has been modified. v_master_record :=

GET_BLOCK_PROPERTY(NAME_IN(’system.master_block’), current_record);

IF GET_RECORD_PROPERTY(v_master_record, NAME_IN(’system.master_block’),status) IN (’INSERT’, ’CHANGED’) THEN

MESSAGE(’You must commit first before you go to another master record.’);

RAISE form_trigger_failure;END IF;

ELSE-- Validation error.

RAISE form_trigger_failure;END IF;

END check_master_change;

Page 270: Build Forms II Volume 1 Instructor Guide 7196298

9-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Copyright Oracle Corporation, 1999. All rights reserved.

SummaryCreating relations:• Implicitly• Explicitly

Relation properties:• For deletion• For coordination

Block coordination:• Coordination-causing events change

the master record• Clear and populate

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

Coordinating blocks with REFs

Elements involved in block coordination:

• Copy Value from Item property

• Relation-handling triggers andprocedures

Characteristics of relation-handlingtriggers

Obtaining relation-handling information

Page 271: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-21......................................................................................................................................................

......................................................................................................................................................Summary

Summary

Creating Relations• Implicitly, when a block is created through the New Block facility

• Explicitly, by creating the relation separately from the related blocks

Relation PropertiesFor controlling behavior on deletion of master records and coordination of data between blocks

Block Coordination• Coordination-causing events cause a change of the master record.

• The two block-coordination phases are the Clear and Populate phases.

• Base coordination of blocks on REF values.

Elements Involved in the Implementation of Block Coordination• The Copy Value from Item property

• Relation-handling triggers and procedures

Characteristics of Relation-Handling Triggers• On-Clear-Details implements the Clear phase.

• On-Populate-Details implements the Populate phase.

• On-Check-Delete-Master implements restricted-delete rules.

Principles of Relation-Handling Code• The three relation-handling procedures are

CLEAR_ALL_MASTER_DETAILS, QUERY_MASTER_DETAILS, and CHECK_PACKAGE_FAILURE.

• Add your own code to relation-handling triggers before or after comments generated by Forms.

Obtaining Relation-Handling Information• There are two system variables for relation handling.

• Built-ins for relation handling can be used to get relation names and to get or set relation properties.

Page 272: Build Forms II Volume 1 Instructor Guide 7196298

9-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 9 Overview

This practice covers the following topics:

• Examining and changing relationproperties

• Implementing a coordination-typetoggle for a master-detail form

• Implementing foreign-key delete rulesfor a master-detail form

• Creating a relation based on REF values

Page 273: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-23......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 9

Practice Session Overview: Lesson 9This practice guides you through choosing the appropriate user-initiated and forms event triggers to implement the desired form functionality.

Practice Contents• Examining and changing relation properties

• Using check boxes to implement a coordination-type toggle for a master-detail form.

- The first check box should enable a user to toggle between immediate coordination and deferred coordination.

- The second check box should enable a user to toggle between auto query and no auto query in the detail block.

• Implementing foreign-key delete rules for a master-detail form.

• Creating a relation based on REF values.

Page 274: Build Forms II Volume 1 Instructor Guide 7196298

9-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Practice 91 Open the ORDERS form and examine the properties of the relation

called S_ORD_S_ITEM.

a Note the deletion and coordination property values.

b Run the ORDERS form and test the way deletes are handled.

2 Implement a query coordination-type toggle.

a Add two check boxes to the control block with the following properties:

b Use the Layout Editor to position the checkboxes appropriately in the Toolbar canvas.

c Make sure that the first check box enables a user to toggle between immediate coordination and deferred coordination. You can import the pr9_2c.txt file.

d Make sure that the second check box enables a user to toggle between automatic query and no automatic query for the detail block. This check box should be disabled if the other check box

Property Check Box 1 Check Box 2

Name IMMEDIATE AUTO_QUERY

Enabled Yes No

Label Immediate Auto Query

Value When Checked Y Y

Value When Unchecked N N

Check Box Mapping of Other Value

CHECKED UNCHECKED

Keyboard Navigable No No

Mouse Navigate No No

Data Type CHAR CHAR

Initial Value Y Y

DataBase Item No No

Canvas TOOLBAR TOOLBAR

Page 275: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 9-25......................................................................................................................................................

......................................................................................................................................................Practice 9

indicates immediate coordination. You can import the pr9_2d.txt file.

e Test and save the form.

If you have time...

3 Add a detail block based on a REF relation to the OO_DEPT table.

a Open the OO_DEPT form in the Object Navigator.

b Create a new block by using the Data Block Wizard. Base the block on the table REL_EMP_TABLE_REFCOL, and include the id, first_name, last_name, and dept_id REF columns. Do not enforce data integrity, and do not create an LOV.

c Create a relationship between the two blocks using the REF value.

d Finish following the Data Block Wizard and invoke the Layout Wizard. Select all available items for display, and use a tabular layout with three displayed records and a scroll bar. Do not specify a frame title.

e Test and save the form.

4 Synchronize the check boxes at form startup.

a Open the ORDERS form module.

b Create a procedure called INIT_RELATION_CHECK_BOXES. This procedure synchronizes the IMMEDIATE and AUTO_QUERY check boxes with the current default value. You can import the pr9_4b.txt file.

c Call this procedure from the When-New-Form-Instance trigger.

5 Implement foreign-key delete rules.

a Open the CUSTOMERS form module. Change the Menu Module property to DEFAULT&SMARTBAR.

b Create a procedure called CHECK_DEL_CUS. This procedure displays an error message as soon as a user tries to delete a customer for which matching orders exist. You can import the pr9_5b.txt file.

c Call the procedure when a user selects the delete function key.

d Save, compile, and run the module.

Page 276: Build Forms II Volume 1 Instructor Guide 7196298

9-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 9: Controlling Data Block Relationships

Page 277: Build Forms II Volume 1 Instructor Guide 7196298

................................

10

Building Multiple FormApplications

Page 278: Build Forms II Volume 1 Instructor Guide 7196298

10-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteTopic TimingLecture 50 minutesPractice 50 minutes Total 100 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Describe the different ways of invokingadditional forms

• Open, call, and close forms

• Navigate between forms

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

• Control opened forms and called forms

• Manage transaction processing foropened forms and called forms

• Choose the most appropriate methodfor invoking forms

• Pass form parameters

Page 279: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewYou have already seen that Oracle Developer applications frequently consist of more than one form. This lesson revisits the topic of multiple form applications and takes a deeper look into the ways in which one form module can invoke another and the effects this has on transaction processing.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Describe the various ways of invoking additional form modules

• Open, call, and close form modules

• Navigate between form modules

• Control open form modules and called form modules

• Manage transaction processing for open and called form modules.

• Choose the most appropriate method for invoking form modules

• Pass form parameters

Page 280: Build Forms II Volume 1 Instructor Guide 7196298

10-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteExplain that “different transaction scopes” refers to the SESSION/NO_SESSION parameter of the OPEN_FORM built-in.

Copyright Oracle Corporation, 1999. All rights reserved.

OPEN_FORM to InvokeAdditional Forms

A B

• Modeless

• Different transactionscopes

OPEN_FORM(′form_name′, activate_mode,

session_mode, data_mode, paramlist);

OPEN_FORM(′form_name′, activate_mode,

session_mode, data_mode, paramlist);

Copyright Oracle Corporation, 1999. All rights reserved.

Characteristics of OPEN_FORM

• Restricted

• Not valid in Enter Query mode

• No savepoint issued

• Modeless with respect to other openedforms

• Session run time option:FORMS50_SESSION

Page 281: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-5......................................................................................................................................................

......................................................................................................................................................OPEN_FORM to Invoke Additional Forms

OPEN_FORM to Invoke Additional FormsThis built-in procedure opens another form in a modeless fashion; that is, a user can freely switch between open forms. You can open a form within the same transaction scope or within a new transaction scope.

SyntaxOPEN_FORM(’form_name’, activate_mode, session_mode, data_mode, paramlist);

Characteristics of OPEN_FORM• Is a restricted procedure

• Causes opened form to be modeless

• Can start a new database session

Using Data Mode to Share PL/SQL Variable DataThe data mode parameter can be used to share PL/SQL variable data between forms. Create a package that contains the PL/SQL variables to be shared, and place the package in a library. Attach the library to all the forms that are to share the data. In the OPEN_FORM command, set the data_mode to SHARE_LIBRARY_CODE. Any changes made by one form are visible to the other forms. This method of sharing data between forms is preferable to global variables because the PL/SQL variables benefit from PL/SQL’s strong typing and because PL/SQL variables are stored and accessed more efficiently than global variables.

Parameter Description

form_name The file holding the executable module

activate_mode Either ACTIVATE (the default) or NO_ACTIVATE

session_mode Either NO_SESSION (the default) or SESSION

data_mode Either NO_SHARE_LIBRARY_DATA (the default) or SHARE_LIBRARY_DATA

paramlist Either the name (in quotes) or internal ID of a parameter list(This argument is optional.)

Page 282: Build Forms II Volume 1 Instructor Guide 7196298

10-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteExplanation for next page pair: Explain that NEXT_FORM stops the execution of subsequent statements in the trigger or program unit.

Stress that the When-New-Form-Instance trigger does not fire on navigation into a form unless the form is being started. Point out that the When-Window-Activated trigger should be used for synchronizing forms in a multiple-form application.

Demonstration for next page pair: Use the Multiple Form (Customer - Form 1) (Mf_cus.fmb), Multiple Form (Order - Form 2) (Mf_ord.fmb), and Multiple Form (Item - Form 3) (Mf_itm.fmb) files to demonstrate the navigational and validation aspects of multiple-form applications.

You can also use the Open/Call_Form (DEPT form) (dept.fmb) and Open/Call_Form (EMP form) (emp.fmb) to illustrate when the triggers fired.

Copyright Oracle Corporation, 1999. All rights reserved.

Closing Forms

• CLOSE_FORM:– form_name

– form_id

• Characteristics of CLOSE_FORM:– Restricted– Not valid in Enter-Query mode– CLOSE_FORM or EXIT_FORM– Cannot close a form that called

another form

Page 283: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-7......................................................................................................................................................

......................................................................................................................................................Closing Forms

Closing Forms

SyntaxCLOSE_FORM(form_name);CLOSE_FORM(form_id);

Characteristics of the CLOSE_FORM Procedure• CLOSE_FORM is a restricted procedure that is not valid in Enter Query

mode.

• When the specified form is the current form, CLOSE_FORM is equivalent to EXIT_FORM.

• You cannot close a form that has called another form with CALL_FORM.

Parameter Description

form_name The module name of the form (not the .fmx filename)

form_id The internal form module ID of the form (of type Form Module)

Page 284: Build Forms II Volume 1 Instructor Guide 7196298

10-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

Navigating Between Forms

Built-ins for navigation between forms:

• NEXT_FORM

• PREVIOUS_FORM

• GO_FORM

Copyright Oracle Corporation, 1999. All rights reserved.

Navigating Between Forms

Navigation and validation aspects:

• Each open form has a current item.

• There is no validation when navigatingbetween forms.

• No triggers fire when navigatingbetween forms, except the When-Window-Activated/Deactivated andWhen-Form-Navigate triggers.

• Click the noncurrent item in the otherform.

Page 285: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-9......................................................................................................................................................

......................................................................................................................................................Navigating Between Forms

Navigating Between FormsYou can programmatically navigate between multiple forms that have been opened with the OPEN_FORM built-in, just as you can navigate between blocks within one form.

Built-ins for Navigation Between Forms

Navigation and Validation Aspects of Inter-form Navigation• In a multiple-form application, each open form has one item that is the

current item for that form.

• When you are navigating between open forms, no validation occurs in the starting form. When you return to the starting form and attempt to navigate within that form, normal validation is enforced.

• When you are navigating between (current items of) open forms, no triggers fire. The only exceptions are the When-Window-Activated, When-Window-Deactivated, and When-Form-Navigate triggers. Even the navigational triggers do not fire when you are navigating between open forms.

• If you click a noncurrent item of an open form, triggers that would usually fire, when you are navigating from the current item to the target item, fire. In this case, navigational triggers also fire and validation occurs as required.

Built-in DescriptionNEXT_FORM Navigates to the open form with the next highest sequence number

(Forms are placed in sequence in the order that they were invoked at run time.) If there is no form with a higher sequence number, the built-in navigates to the form with the lowest sequence num-ber.

PREVIOUS_FORM Navigates to the open form with the next lowest sequence number (If there is no form with a lower sequence number, this built-in navigates to the form with the highest sequence number.)

GO_FORM Navigates to the specified form (You can use the form-module name or the form-module ID as the form specification.)

Page 286: Build Forms II Volume 1 Instructor Guide 7196298

10-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

Opening Forms Within the SameSession

• Commit processing in all forms withinthe same session, in a certain order

• If error occurs, then focus set toinitiating form

• Messages per open form within thesame session

• CLEAR_FORM usually causes aROLLBACK statement

Copyright Oracle Corporation, 1999. All rights reserved.

Opening Forms in DifferentSessions

Runform Server

A

Connection

B

Session

C

Page 287: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-11......................................................................................................................................................

......................................................................................................................................................Transaction Processing for Opened Forms

Transaction Processing for Opened Forms

Opening Forms Within the Same SessionAt run time, Form Builder automatically establishes a single connection to the Oracle server. By default, one database session is created for this connection. When you open forms within the same session, consider these issues:

• If you issue a commit, all forms will be processed in the order in which they were opened, starting with the current form.

• If an error occurs during commit processing, Form Builder sets the input focus to the form that initiated the commit.

• Commit processing usually causes messages to occur for every open form within the same session. Because Form Builder maintains a message line per open form, a user may have to acknowledge messages from noncurrent open forms. This could be confusing.

• If you issue a CLEAR_FORM command, Form Builder will usually issue a ROLLBACK statement, which rolls back all the changes in the database and releases all locks. However, noncurrent open forms are not cleared.

Opening Forms in Different SessionsThe multiple-session feature of the Oracle server enables a single client to establish multiple database sessions within a single connection. All Oracle server transaction management and read-consistency features are implemented at the session level. Therefore, commit processing, record locking, and read-consistency behavior for two forms in different sessions is the same as it would be for two independent forms with separate connections.

• You can turn the Session option on for all Runform invocations by setting the FORMS50_SESSION environment variable to True.

• Forms Runform must be running with the Session option turned on when you execute OPEN_FORM with the SESSION_MODE parameter set to SESSION.

Page 288: Build Forms II Volume 1 Instructor Guide 7196298

10-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteDemonstration: Use the Open/Call_Form (DEPT form) (dept.fmb) and Open/Call_Form (EMP form) (emp.fmb) to illustrate the CALL_FORM built-in.

Copyright Oracle Corporation, 1999. All rights reserved.

CALL_FORM to InvokeAdditional Forms

A B

• Modal

• Returns to callingform

CALL_FORM(′form_name′, display,

switch_menu, query_mode,

data_mode, paramlist);

CALL_FORM(′form_name′, display,

switch_menu, query_mode,

data_mode, paramlist);

Copyright Oracle Corporation, 1999. All rights reserved.

Characteristics of CALL_FORM

• Unrestricted• Valid in Enter Query mode• Savepoint issued• Modal with respect to calling form• Does not cause navigation and

validation• Forms called from query-only form are

always query-only• Exiting a called form

Page 289: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-13......................................................................................................................................................

......................................................................................................................................................CALL_FORM to Invoke Additional Forms

CALL_FORM to Invoke Additional FormsThis built-in procedure calls another form in a modal fashion with respect to the calling form; that is, you cannot work in the calling form. When the called form is exited, Form Builder returns to the calling form.

SyntaxCALL_FORM(’form_name’, display, switch_menu, query_mode, data_mode, paramlist);

Characteristics of CALL_FORM• Is valid in Enter Query mode

• Causes Forms to issue a savepoint

• Causes called form to be modal

• Does not cause navigation or validation in the initial form

• Can call a form in Query Only mode

• Propagates query-only parameter through all subsequent called forms

• Returns control to the calling form and resumes processing of the PL/SQL code at the statement immediately following the calling statement (This occurs when Forms exits the called form.)

Parameter Description

form_name The file holding the executable form module

display Either HIDE (the default) or NO_HIDE (This defines whether the call-ing form should be hidden from view while the called form is running.)

switch_menu Either NO_REPLACE (the default) or DO_REPLACE (This defines whether the current menu module should be replaced by the default menu of the called form.)

query_mode Either NO_QUERY_ONLY (the default) or QUERY_ONLY (This defines whether the called form should run in Query Only mode.)

data_mode Either NO_SHARE_LIBRARY_DATA (the default) or SHARE_LIBRARY_DATA

paramlist Either the name (in quotes) or internal ID of a parameter list(This argument is optional.)

Page 290: Build Forms II Volume 1 Instructor Guide 7196298

10-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteDemonstration: Use the Open/Call_Form (DEPT form) (dept.fmb) and Open/Call_Form (EMP form) (emp.fmb) to illustrate the Post-Only mode.

Copyright Oracle Corporation, 1999. All rights reserved.

Save Not Allowedin Post-Only Mode Form

A calling form has unapplied changes. Save not allowed.

Copyright Oracle Corporation, 1999. All rights reserved.

Transaction Processingfor Called Forms

• Characteristics of Post-Only mode:

– Commit not allowed, only a post

– Full rollback not allowed, only arollback to savepoint

• Rollback behavior of called forms

• Call savepoints and post savepoints

Page 291: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-15......................................................................................................................................................

......................................................................................................................................................Transaction Processing for Called Forms

Transaction Processing for Called FormsIf you call forms, you need to understand the commit and rollback processing between the forms.

What Is Post-Only Mode?When a calling form has pending updates or deletes that have not been explicitly posted or committed, Form Builder runs the called form in Post-Only mode. Additionally, any form called from a form running in Post-Only mode is also in Post-Only mode. In Post-Only mode, you can submit DML statements to the database, but you can not commit the changes. You can only commit the changes after you exit the form that is running in Post-Only mode.

Characteristics of Post-Only ModeIf a form runs in Post-Only mode, Forms does not allow certain commit processing operations to prevent losing locks in the calling form.

• A commit is not allowed, only a post. In other words, the changes are written to the database, but a commit statement is not issued. An error message appears on the status line: “A calling form has unapplied changes. Save not allowed.” If a user makes changes in the called form and then exits from the form, Forms usually asks if the user wants to apply (post), rather than Save (commit), the changes that were made.

• A full rollback is not allowed, only a rollback to savepoint.

Rollback Behavior of Called FormsIf a user exits from a called form, Form Builder issues a rollback to the call savepoint that was set when the form was called. This means that all changes posted in the called form are rolled back upon exit from the called form. This is because of the EXIT_FORM built-in default arguments:

EXIT_FORM(ask_commit, to_savepoint);

Do not confuse call savepoints, which are set when a form is called or started, with post savepoints, which are set at the start of a post.

Page 292: Build Forms II Volume 1 Instructor Guide 7196298

10-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteDemonstration: Open the Open/Call_Form (DEPT form) (dept.fmb) and Open/Call_Form (EMP form)(emp.fmb) demonstrations. Remove the comments in the Key-Exit and Key-Commit triggers.

Copyright Oracle Corporation, 1999. All rights reserved.

Transaction Processingfor Called Forms

IF <form called> THEN

POST;

ELSE

COMMIT_FORM;

END IF;

IF <form called> THEN

POST;

ELSE

COMMIT_FORM;

END IF;

Examples of adjusting default transactionprocessing:

Key-Commit on form

Copyright Oracle Corporation, 1999. All rights reserved.

Transaction Processingfor Called Forms

Key-Exit on form

Adjust labels of corresponding buttonsand menu items

IF <form called> THEN

EXIT_FORM(ASK_COMMIT, NO_ROLLBACK);

ELSE

EXIT_FORM;

END IF;

Page 293: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-17......................................................................................................................................................

......................................................................................................................................................Transaction Processing for Called Forms

Adjusting Default Transaction Processing for Called FormsThe characteristics of Post-Only mode and the rollback behavior of called forms require that you adjust default transaction processing as follows:

• Redefine [Commit] so that processing performs a post when the form is called.

• Redefine [Exit] so that processing does not perform a rollback when the form is called.

• You may want to adjust the labels of possible buttons and menu items that correspond to [Commit] and [Exit].

ExamplesKey-Commit trigger at form level:

BEGINIF GET_APPLICATION_PROPERTY(calling_form) is not null THEN

POST;ELSE

COMMIT_FORM;END IF;

END;

Key-Exit trigger at form level:BEGIN

IF GET_APPLICATION_PROPERTY(calling_form) is not null THENEXIT_FORM(ask_commit, no_rollback);

ELSEEXIT_FORM;

END IF;END;

Page 294: Build Forms II Volume 1 Instructor Guide 7196298

10-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

NEW_FORM to InvokeAdditional Forms

A B

Replaces calling form

NEW_FORM(′form_name′, rollback_mode,

query_mode, data_mode,

paramlist);

NEW_FORM(′form_name′, rollback_mode,

query_mode, data_mode,

paramlist);

Page 295: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-19......................................................................................................................................................

......................................................................................................................................................NEW_FORM to Invoke Additional Forms

NEW_FORM to Invoke Additional FormsThis built-in procedure exits from the current form and executes the specified new form. The new form completely replaces the current form.

SyntaxNEW_FORM(’form_name’, rollback_mode, query_mode, data_mode, paramlist);

Parameter Description

form_name The file holding the executable form module

rollback_mode Either TO_SAVEPOINT (the default), NO_ROLLBACK, or FULL_ROLLBACK

query_mode Either NO_QUERY_ONLY (the default) or QUERY_ONLY (This defines whether the called form should run in Query Only mode.)

data_mode Either NO_SHARE_LIBRARY_DATA (the default) or SHARE_LIBRARY_DATA

paramlist Either the name (in quotes) or internal ID of a parameter list(This argument is optional.)

Page 296: Build Forms II Volume 1 Instructor Guide 7196298

10-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Technical NoteYou can obtain information about the call form stack by using the GET_APPLICATION_PROPERTY built-in with the CALLING_FORM parameter.

Instructor NoteThe slide illustrates the restrictions on using OPEN_FORM and CALL_FORM.In this scenario, Form A calls Form B, Form B then opens Form C, Form C then opens Form D; and Form B then calls Form E.

• The call is not allowed to navigate to Forms A and B.

• The current call form stack consists of Forms A, B, and E.

• A form cannot be called from Form C and D.

• Changes in any form are rolled back to the savepoint (S.P.) that was set when Form E was called.

Copyright Oracle Corporation, 1999. All rights reserved.

Controlling Openedand Called Forms

Form A

Form B

S.P. CALL_FORM

Form C

OPEN_FORM

Form DOPEN_FORM

Form E

S.P. CALL_FORM

Form F

CALL_FORM

Form A+B+E = Call form stack

Page 297: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-21......................................................................................................................................................

......................................................................................................................................................Controlling Open Forms and Called Forms Together

Controlling Open Forms and Called Forms TogetherWhen you invoke multiple forms with OPEN_FORM and CALL_FORM in the same application, you should be aware of certain restrictions.

Call Form StackWhen you call a form with CALL_FORM, the calling form is disabled until the operator exits from the called form. However, a called form can in turn call other forms. When successive forms are loaded by way of CALL_FORM in this way, the resulting form hierarchy is known as the call form stack.

Restrictions on Using OPEN_FORM with CALL_FORM• Navigation: Any attempt to navigate programmatically to a disabled

form in a call form stack is disallowed.

• Calling forms: An open form cannot execute the CALL_FORM built-in if a call form stack has been initiated by another open form. In other words, you can have only one call form stack per Runform session.

• Rollback: Forms issues a savepoint when calling a form with CALL_FORM. Any subsequent rollback, in any form, rolls back only the changes that were made since this savepoint.

Page 298: Build Forms II Volume 1 Instructor Guide 7196298

10-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

Different Ways of InvokingForms

• When to use OPEN_FORM

• When to open a form in a new session

• When to use CALL_FORM

• When to use NEW_FORM

Page 299: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-23......................................................................................................................................................

......................................................................................................................................................Different Ways of Invoking Forms

Different Ways of Invoking Forms

When to Use OPEN_FORMOPEN_FORM is the preferred method of invoking another form. Because open forms are modeless, a user can freely switch between them. OPEN_FORM is most appropriate for invoking forms from the application-system menu. A drawback of OPEN_FORM is that it may be difficult to keep multiple open forms synchronized. For example, you may want the current order in an ORDERS form always to belong to the current customer in a CUSTOMERS form.

When to Open a Form in a New SessionCreating new sessions is usually appropriate for forms that manage transactions that are logically independent. If the open forms act on tables that are closely related, data manipulation of all those forms could be considered part of one transaction. Therefore, the forms should be opened in the same session.

Note: You can also consider using CALL_FORM in this situation.

When to Use CALL_FORMUse CALL_FORM if you want the invoked form to be modal. This is appropriate if the invoked form is used to set data in the invoking form; for example, in the case of an LOV form. Another reason may be that you want to make it easier to keep the invoking and invoked forms synchronized.

When to Use NEW_FORMThe main advantage of this built-in is that it conserves memory because the invoked form replaces the invoking form. It is particularly useful in Web-based applications.

Page 300: Build Forms II Volume 1 Instructor Guide 7196298

10-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

Using Form Parameters• What is a form parameter?• How to create a form parameter

Copyright Oracle Corporation, 1999. All rights reserved.

Passing Values to a Form

Form B

Design-timeparameters

P1

P2

P3

Runform

command line

Form A

Run time

Parameterlist

OPEN_FORMCALL_FORMNEW_FORM

Page 301: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-25......................................................................................................................................................

......................................................................................................................................................Using Form Parameters

Using Form Parameters

What Is a Form Parameter?Form parameters provide a mechanism for supplying values that a form requires at startup. These parameters are form variables that you define at design time in the Parameter Properties window.

Creating a Form Parameter1 In the Object Navigator, create a parameter.

2 In the Property Palette window for the parameter, set the desired values for Name, Subclass Information, Parameter Data Type, Maximum Length, Parameter Initial Value, and Comments.

Passing Parameter Values to a FormYou can start a form from the command line or invoke it from another form. In both cases, you can specify values for form parameters.

• Specify the parameters on the Runform command line.

• Programmatically assign the parameters to a parameter list and specify the parameter list in the call to OPEN_FORM, CALL_FORM, or NEW_FORM.

Page 302: Build Forms II Volume 1 Instructor Guide 7196298

10-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Instructor NoteDemonstration: Use the Multiple Form (Order - Form 2)(Mf_ord.fmb) demonstration to show the properties of the CUS_ID form parameter.

Copyright Oracle Corporation, 1999. All rights reserved.

Using Form Parameters

• Passing a form parameter at run time:

• Referencing form parameters fromwithin a module:

– :PARAMETER.parameter_name

– ‘PARAMETER. parameter_name’

ifrun60 module=orditem userid=scott/tiger cus_id=202

Page 303: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-27......................................................................................................................................................

......................................................................................................................................................Using Form Parameters

ExamplePass a value for the CUS_ID form parameter to the ORDITEM form by way of the Runform command line. Note that MODULE and USERID are predefined command line parameters.

ifrun60.exe module=orditem userid=scott/tiger cus_id=202

Referencing Form ParametersYou can reference form parameters in a way similar to how you would access Forms variables.

• To reference the parameter contents, use bind-variable syntax: :PARAMETER.parameter_name, where the reserved word PARAMETER is the fixed part.

• To reference the parameter name, put the fully qualified name between single quotation marks: ‘PARAMETER.parameter_name’

ExampleAssign the value of the CUS_ID form parameter to the CUSTOMER_ID item in the ORDER block.

:order.customer_id := :PARAMETER.cus_id;

Page 304: Build Forms II Volume 1 Instructor Guide 7196298

10-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Technical NoteYou must define the parameters whose values are being passed to a form in that form at design time.

Copyright Oracle Corporation, 1999. All rights reserved.

Parameter Lists

OPEN_FORM( …, )

CALL_FORM( …, )

NEW_FORM( …, )

The default parameter list is DEFAULT.

CUS_ID

ORDERS

TEXT_PARAMETER

DATA_PARAMETER

‘204’

‘RG_ORD’

Parameterlist

Page 305: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-29......................................................................................................................................................

......................................................................................................................................................Parameter Lists

Parameter ListsOne way to supply form parameter values is to specify a parameter list in the call to the built-in that invokes the form.

What Is a Parameter List?A parameter list is a named programmatic construct that lists parameter names (called keys), their types, and their values. You can specify parameter lists in the calls to the following built-ins:

• CALL_FORM

• OPEN_FORM

• NEW_FORM

• RUN_PRODUCT

Two Parameter Types

Default Parameter List Each form includes a built-in parameter list named DEFAULT. The DEFAULT parameter list contains all of the form parameters that were defined in the form at design time. Like any other parameter list, the DEFAULT parameter list can be specified in the call to the built-ins that can invoke a form.

Type DescriptionText Parameter A simple parameter with a scalar, noncomposite CHAR value.

You must use this type of parameter, unless you want to pass a record group to another Oracle product.

Data Parameter A parameter whose value must always be the name of a record group defined in the current form. Data parameters are used to pass data to products invoked with the RUN_PRODUCT built-in. You cannot pass data parameters to forms.

Page 306: Build Forms II Volume 1 Instructor Guide 7196298

10-30 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Technical NoteYou cannot create a parameter list named DEFAULT or one that already exists. Use GET_PARAMETER_LIST and ID_NULL to check whether a parameter list already exists.

Instructor NoteUse the Multiple Form (Customer - Form 1) (Mf_cus.fmb) demonstration to show the PASS_CUS procedure, which creates a parameter list and adds the CUS_ID parameter.

Demonstration for the next page pair: Use the Multiple Form (Customer - Form 1) (Mf_cus.fmb) file to show the methods of passing data between forms in a multiple-form application. Show the When-Button-Pressed trigger on the CTL.OPEN_FORM button and explain that the final argument to the OPEN_FORM built-in is the parameter list name.

Point out the use of a global variable in the first line of the code.

Copyright Oracle Corporation, 1999. All rights reserved.

Creating and ManipulatingParameter Lists

ADD_PARAMETER

GET_PARAMETER_ATTR

SET_PARAMETER_ATTR

DELETE_PARAMETER

CUS_ID

ORDERS

TEXT_PARAMETER

DATA_PARAMETER

‘204’

‘RG_ORD’

DESTROY_PARAMETER_LIST

Key Type ValueCREATE_PARAMETER_LIST

Name

Parameter

list ID

Page 307: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-31......................................................................................................................................................

......................................................................................................................................................Creating and Manipulating Parameter Lists

Creating and Manipulating Parameter ListsYou can programmatically create and manipulate parameter lists only by using the following built-ins:

Built-in DescriptionCREATE_PARAMETER_LIST Creates a parameter list with the given name and

returns the ID of this parameter listDESTROY_PARAMETER_LIST Deletes the given, programmatically created

parameter list (and all its parameters)GET_PARAMETER_LIST Returns the internal parameter list ID (of type

PARAMLIST) of a parameter list with the given name (This built-in is similar to the FIND_object built-ins.)

ADD_PARAMETER Adds a parameter with a specified name (also called key), type (TEXT_PARAMETER or DATA_PARAMETER), and value (in CHAR for-mat) to the given parameter list

DELETE_PARAMETER Deletes the parameter with the specified name from the given parameter list

GET_PARAMETER_ATTR Gets the type and value of the parameter with the specified name in the given parameter list

SET_PARAMETER_ATTR Sets the type and value of the parameter with the specified name in the given parameter list

Page 308: Build Forms II Volume 1 Instructor Guide 7196298

10-32 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Technical NoteGlobal variables are used more often than parameters for passing data between forms.

Copyright Oracle Corporation, 1999. All rights reserved.

Passing Data Between Forms Form A

Run timeParameter list

P1

P2P3

Form B

Design-timeparameters

P1

P2P3

OPEN_FORM(*)

1. If a parameter list exists, destroy it.2. Create a parameter list.3. Add a text parameter to a list with the value of an item.4. Open a form with this parameter list.

Copyright Oracle Corporation, 1999. All rights reserved.

Passing Data Between Forms• Characteristics of form parameters:

– Can be used only as input parameters– Have data type CHAR, NUMBER, or

DATE– CHAR parameter can be up to 64 K long– Can be design-time objects

• Characteristics of global variables:– Are programmatic constructs– Have type CHAR(255)– Are visible to all forms in the current

Runform session

Page 309: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-33......................................................................................................................................................

......................................................................................................................................................Passing Data Between Forms

Passing Data Between FormsYou can pass data to other forms by using form parameters, as shown in the following example. The next section compares this approach with the global variable approach.

ExampleThe When-Button-Pressed trigger on the CTL.OPEN_ORDITEM item:

DECLAREv_pl_id PARAMLIST;

BEGINIF not ID_NULL(GET_PARAMETER_LIST(’cus’)) THEN

DESTROY_PARAMETER_LIST(’cus’);END IF;v_pl_id := CREATE_PARAMETER_LIST(’cus’);ADD_PARAMETER(v_pl_id,’cus_id’,text_parameter,

TO_CHAR(:cus.id));OPEN_FORM(’orditem’, activate, no_session,

no_share_library_data, ’cus’);END;

Note: You must define the CUS_ID parameter in the ORDITEM form at design time, because each run-time parameter must have a corresponding design-time parameter in the target form.

Form Parameters and Global Variables• Form parameters can be used only as input parameters; the invoked form

cannot return modified form-parameter values to the invoking form. Therefore, global variables are the preferred method for communicating between forms.

• Advantages of form parameters include:

- They have a data type of CHAR, NUMBER, or DATE.

- The length of a CHAR parameter can be up to 64 K.

- They can be design-time objects.

- Global variables are always programmatic constructs of type CHAR(255). They are visible to all the forms in the current Runform session.

Page 310: Build Forms II Volume 1 Instructor Guide 7196298

10-34 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Opening, calling, and closing forms:

– OPEN_FORM, CALL_FORM, andCLOSE_FORM

– Multiple database sessions perconnect possible

• Navigation: NEXT_FORM,PREVIOUS_FORM, and GO_FORM

• Restrictions on the call form stack

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Transaction processing– Opened forms: Within same or

different sessions– Called forms: Post-Only mode; a

rollback to savepoint• Using form parameters and parameter

lists– Methods for parameter passing– Referencing form parameters– Text parameters and data parameters– Built-ins for parameter lists

Page 311: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-35......................................................................................................................................................

......................................................................................................................................................Summary

Summary

The Three Built-ins for Invoking Forms• OPEN_FORM

• CALL_FORM

• NEW_FORM

Opening, Calling, and Closing Forms• OPEN_FORM

• CALL_FORM

• CLOSE_FORM

Built-ins for Navigation Between Forms• NEXT_FORM

• PREVIOUS_FORM

• GO_FORM

Controlling Open Forms and Called Forms Together Restrictions on the call form stack

Transaction Processing for Open FormsWithin the same session or different sessions

Transaction Processing for Called Forms• Characteristics of Post-Only mode

• Rollback behavior of called forms: default rollback to savepoint

Using Form Parameters• Passing parameter values to a form by way of Runform command line or

parameter list

• Referencing form parameters using PARAMETER.parameter_name

Using Parameter Lists• The two parameter types: text parameters and data parameters

• The default parameter list named DEFAULT

• Built-ins for creating and manipulating parameter lists

Page 312: Build Forms II Volume 1 Instructor Guide 7196298

10-36 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 10 OverviewThis practice covers implementing abutton on CUSTOMER to callEMPLOYEE:

• Performing an automatic query on theEMPLOYEE form based on the currentSales Rep ID in the CUSTOMER form

• Ensuring that posted changes inEMPLOYEE are not rolled back

• Ensuring that [Commit] performs a postwhen EMPLOYEE is called from anotherform

Page 313: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 10-37......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 10

Practice Session Overview: Lesson 10This practice guides through managing several interacting forms within one application.

Practice ContentsImplement a button on the CUSTOMER form to call the EMPLOYEE form.

• Perform an automatic query on the EMPLOYEE form based on the current sales rep ID in the CUSTOMER form.

• Ensure that posted changes in the EMPLOYEE form are not rolled back on exit.

• Ensure that when the EMPLOYEE form is called by another form, [Commit] performs a post.

Page 314: Build Forms II Volume 1 Instructor Guide 7196298

10-38 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 10: Building Multiple Form Applications

Practice 101 Produce a multiple form application by linking the CUSTOMERS and

the EMPLOYEES forms.

a In the control block of the CUSTOMERS form, create a button called EMPLOYEE_BUTTON. Place it on the CV_CUST canvas, below the Orders button.

b Define a trigger for CONTROL.EMPLOYEE_BUTTON that calls the EMPLOYEES form with the current sales representative ID.

- Change the Mouse Navigate property of CONTROL.EMPLOYEE_BUTTON to No.

- Create a parameter list called SALES.

- Add the SALES_ID parameter to the parameter list. The type of this parameter is TEXT_PARAMETER, and it is initialized with the value of the SALES_REP_ID item.

- Invoke the EMPLOYEES form by using the CALL_FORM built-in.

You can import the pr10_1b.txt file.

c Open the EMPLOYEES form module.

d In the Object Navigator, create a parameter called SALES_ID.

e Add a trigger to ensure that queries on the employee block are restricted by the value of the SALES_ID parameter. Replace the existing code with the code in the pr10_1e.txt file.

f Save and compile each form, then run the CUSTOMERS form module. Test the application by exiting the EMPLOYEE form using the menu or the toolbar.

If you have time...2 Transaction processing for called forms:

a Make sure that any changes in the EMPLOYEES form that are posted by a user are not rolled back by Forms upon exit.

b Make sure that when the CUSTOMERS form calls the EMPLOYEES form, [Commit] performs a post. You can import the pr10_2b.txt file.

c Save and compile each form, then run the CUSTOMERS form module and test your application.

Page 315: Build Forms II Volume 1 Instructor Guide 7196298

................................

11

Working with RecordGroups

Page 316: Build Forms II Volume 1 Instructor Guide 7196298

11-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteTopic TimingLecture 50 minutes

Practice 40 minutes

Total 90 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:• Describe the record group object• Use record groups• Define record groups at design time• Control record groups by using built-in

functions• Define query record groups

programmatically• Define nonquery record groups

programmatically

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

• Manipulate record group rows• Define lists of values (LOVs)

programmatically• Manipulate list items programmatically• Implement dynamic list items• Add values to combo boxes

Page 317: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewRecord groups are useful constructs for storing structured data, and they can be manipulated at run time. This lesson covers how to create, modify, and delete record groups at design time and programmatically at run time. It also covers how you apply record groups in useful ways, such as for dynamic list items.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Describe the record group object

• Use record groups

• Define record groups at design time

• Control record groups by using built-in functions

• Define query record groups programmatically

• Define nonquery record groups programmatically

• Manipulate record group rows

• Define lists of values (LOVs) programmatically

• Manipulate list items programmatically

• Implement dynamic list items

• Add values to condo boxes

Page 318: Build Forms II Volume 1 Instructor Guide 7196298

11-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Copyright Oracle Corporation, 1999. All rights reserved.

Record Groups

Three record group types:

Design Time

Run Time

SOURCE

TIME

Based on aSELECT

Statement

Not Basedon a SELECT

Statement

QUERY

QUERY

STATIC

NON QUERY

Copyright Oracle Corporation, 1999. All rights reserved.

Record Groups

Record groups and LOVs

• Forms implicitly creates query recordgroups.

• Use SET_LOV_PROPERTY to replacedefault record group.

...

IF Get_LOV_Property(lov_id,GROUP_NAME) = ’GROUP1’

THEN

Set_LOV_Property(lov_id,GROUP_NAME,’GROUP2’);

END IF;

...

...

IF Get_LOV_Property(lov_id,GROUP_NAME) = ’GROUP1’

THEN

Set_LOV_Property(lov_id,GROUP_NAME,’GROUP2’);

END IF;

...

Page 319: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-5......................................................................................................................................................

......................................................................................................................................................Record Groups

Record Groups

What Is a Record Group?A record group is an internal Forms data structure that is similar to a database table. It can have columns of type CHAR, NUMBER, or DATE, and its data is stored in rows. Record groups exist in local Forms memory, rather than in the database.

Three Record Group Types

Note: When you create a record group, you cannot specify its type explicitly. The type is implied by when and how you create the record group.

Record Groups and LOVsWhen you create a list of values (LOV) based on a query, Form Builder implicitly creates a query record group. In this case, the columns and rows of the record group are determined by the LOV-SELECT statement. At run time, you can call the SET_LOV_PROPERTY built-in function to replace the default record group of an LOV with another one. Use the GROUP_NAME property.

Type DescriptionQuery Record Group A record group with an associated SELECT statement. The

columns in the record group derive their properties from the columns in this SELECT statement. The rows in the record group are the rows retrieved by this SELECT statement. This type of record group can be created at design time and at run time.

Nonquery Record Group A record group without an associated query. The columns and rows of the record group are defined programmatically at run time and can also be modified at run time.

Static Record Group A record group without an associated query. The columns and rows of the record group are defined at design time and cannot be modified programmatically at run-time.

Page 320: Build Forms II Volume 1 Instructor Guide 7196298

11-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Copyright Oracle Corporation, 1999. All rights reserved.

Uses for Record Groups

• Constructing dynamic SELECTstatements

• Storing form-configuration information

• Communicating within a form

• Passing data to other forms

• Passing data to other Oracle products

• Populating or storing list items

Page 321: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-7......................................................................................................................................................

......................................................................................................................................................Using Record Groups

Using Record GroupsRecord groups are very powerful constructs offered by Forms. Some useful record group applications are listed below.

Constructing Dynamic SELECT StatementsThe SELECT statement on which a query record group is based can be constructed programmatically at run time. As a consequence, you can write very generic program units; for example, accepting a table name as parameter.

Storing Form-Configuration InformationBecause a record group is a structured data type, you can use it as a convenient means for storing information about the current form. Such information may describe the way in which the form is set up or configured, and is usually retrieved at form startup.

Communicating Within a FormBecause a record group is a structured data type, you can use it to exchange related data within a form. For example, different program units or different invocations of the same program unit might access the record group data. This offers you an alternative to a set of scalar variables, such as help items or global variables.

Passing Data to Other FormsYou can create a global record group at run time that is visible to all forms in an application.

Passing Data to Other Oracle ProductsYou can use the RUN_PRODUCT built-in to pass data by way of a record group to another Oracle product, specifically Report Builder and Graphics Builder. This eliminates the need to perform a query again in the other Oracle product if it has already been executed by Forms.

Populating or Storing List ItemsYou can transfer the values of a record group to a list item. Because the record group may be based on a dynamically constructed SELECT statement, this ability gives you the opportunity to create dynamic list items. The data transfer is bidirectional; you can also transfer the values of a list item to a record group. (This can be considered “storing” the list item.)

Page 322: Build Forms II Volume 1 Instructor Guide 7196298

11-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show how you create query record groups (CUSTOMER_ID) and static record groups (STATIC_GROUP).

Copyright Oracle Corporation, 1999. All rights reserved.

Defining Record Groupsat Design Time

Copyright Oracle Corporation, 1999. All rights reserved.

Column Specification andRecord Group Property Sheet

Page 323: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-9......................................................................................................................................................

......................................................................................................................................................Defining Record Groups at Design Time

Defining Record Groups at Design Time

Creating a Query Record Group1 In the Object Navigator, create a record group.

Forms displays the New Record Group dialog box.

2 Click the Based on the Query Below... radio button and then enter a SELECT statement in the Query Text field.

3 Click OK. Forms validates the SELECT statement and closes the dialog box.

Note: Use column aliases for expressions in the SELECT clause. Otherwise, Forms generates an unreadable name for the corresponding column of the record group.

Creating a Static Record Group1 In the Object Navigator, create a record group.

Forms displays the New Record Group dialog box.

2 Click the Static Values radio button and then click OK.Forms displays the Column Specification dialog box.

3 Enter the names of the columns in the Column Name list.

4 Specify the Data Type, Length, and Column Values properties for each column.Note that these properties apply to the column currently selected in the Column Name list.

5 Click OK to accept the record group definition.

Modifying the SELECT Statement of a Query Record Group1 In the Object Navigator, select the desired record group.

2 In the Properties window, call the Editor from the Record Group Query property.

3 Modify the SELECT statement as desired and then click OK.

Modifying the Column Definitions of a Record Group1 In the Object Navigator, select the desired record group.

2 In the Properties window, double-click the Column Specifications property. Forms displays the Column Specification dialog box.

3 Select a column and modify its Data Type, Length, and Column Values properties as desired and then click OK.

Page 324: Build Forms II Volume 1 Instructor Guide 7196298

11-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NotePoint out that CREATE_GROUP_FROM_QUERY does not populate the record group. ADD_GROUP_ROW adds an empty row. Row No is an internal number.

Copyright Oracle Corporation, 1999. All rights reserved.

Creating and Deleting RecordGroups

CREATE_GROUP CREATE_GROUP_FROM_QUERY

Recordgroup ID

Recordgroup ID

ID Name

DELETE_GROUP

Name, QueryName

Copyright Oracle Corporation, 1999. All rights reserved.

Modifying the Structure

Row No ID Name Address1 201 Unisports23 203 Delhi Sports4 204 Womansport

ADD_GROUP_ROW

DELETE_GROUP_ROW

ADD_GROUP_COLUMN

Page 325: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-11......................................................................................................................................................

......................................................................................................................................................Built-in Functions for Controlling Record Groups

Built-in Functions for Controlling Record GroupsYou can create and modify query and nonquery record groups programmatically at run time by using the following built-in functions.

Creating and Deleting Record Groups

Modifying the Structure of Record Groups

Built-in Function DescriptionCREATE_GROUP Creates a nonquery record group with the given

name and returns the ID of this record groupCREATE_GROUP_FROM_QUERY Creates a query record group with the given

name based on the given SELECT statement and returns the ID of this record group (Note that this built-in function does not populate the record group.)

DELETE_GROUP Deletes the given, programmatically created record group

Built-in Function DescriptionADD_GROUP_COLUMN Adds a column of the specified data type (and

column width for CHAR columns) to the given record group and returns the ID of this group column

ADD_GROUP_ROW Adds a row with the specified row number to the given record group

DELETE_GROUP_ROW Deletes the specified row or all rows of the given record group

Page 326: Build Forms II Volume 1 Instructor Guide 7196298

11-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Technical NotePOPULATE_GROUP built-in function returns 0 when population succeeds and 1 if population does not succeed.

Copyright Oracle Corporation, 1999. All rights reserved.

Populating Query RecordGroups

ID Name201 Unisports202 SImms Athletics203 Delhi Sports204 Womansport

POPULATE_GROUP

(_WITH_QUERY)

SELECT ID, name

FROM s_customer

Copyright Oracle Corporation, 1999. All rights reserved.

Getting and Setting RecordGroup Cell Values

ID NameSET_GROUP_CHAR_CELL

GET_GROUP_NUMBER_CELL

Page 327: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-13......................................................................................................................................................

......................................................................................................................................................Built-in Functions for Controlling Record Groups

Populating Record Groups

Note: You can convert a nonquery record group into a query record group by using the POPULATE_GROUP_WITH_QUERY built-in function to populate the nonquery record group.

Getting Record Group Cell Values

Built-in Function DescriptionPOPULATE_GROUP Executes the query associated with the given

query record group and returns a number indicating success or failure (The retrieved rows replace any existing rows in the record group.)

POPULATE_GROUP_WITH_QUERY Executes the specified SELECT statement for the given record group and returns a number indicating success or failure (The retrieved rows replace any existing rows in the record group.)

SET_GROUP_CHAR_CELL, SET_GROUP_DATE_CELL,SET_GROUP_NUMBER_CELL

Sets the value for the record group cell identified by the given record group column and row number (The record group column must be of data type VARCHAR2 or LONG, DATE, or NUMBER, respectively.)

Built-in Function DescriptionGET_GROUP_CHAR_CELL, GET_GROUP_DATE_CELL, GET_GROUP_NUMBER_CELL

Returns the value for the record group cell identified by the given record group column and row number (The record group column must be of data type VARCHAR2 or LONG, DATE, or NUMBER, respectively.)

Page 328: Build Forms II Volume 1 Instructor Guide 7196298

11-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteExplain the built-ins and describe how with SET_GROUP_SELECTION, if you select rows 2 and 4, the associated selection numbers are 1 and 2. Explain that the record group type (query, nonquery, static) and time of creation (design time or run time) determine which built-in functions are valid for a particular record group.

Copyright Oracle Corporation, 1999. All rights reserved.

Selection No Row No1

1 23

2 4

Processing Record Group Rows

ID Name201 Unisports202 Simms Athletics203 Delhi Sports204 Womansport

GET_GROUP_SELECTION_COUNT

SET_GROUP_SELECTIONGET_GROUP_SELECTION

GET_GROUP_ROW_COUNT

Page 329: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-15......................................................................................................................................................

......................................................................................................................................................Built-in Functions for Controlling Record Groups

Processing Record Group Rows

Finding Record Group Objects

Built-in Function DescriptionGET_GROUP_ROW_COUNT Returns the number of rows in the given

record groupSET_GROUP_SELECTION Marks the specified row in the given record

group by associating a selection number with the row

UNSET_GROUP_SELECTION Deselects the row with the specified row number in the given record group

RESET_GROUP_SELECTION Deselects all selected rows in the given record group

GET_GROUP_SELECTION_COUNT Returns the number of selected rows in the given record group

GET_GROUP_SELECTION Returns the row number of the row with the specified selection number of the given record group

Built-in Function DescriptionFIND_GROUP Returns the internal record group ID (of type RECORDGROUP)

of a record group with the given name (This function can also be used for record groups created at design time.)

FIND_COLUMN Returns the internal group column ID (of type GROUPCOLUMN) of a record group column with the given name (Note that this name must include the record group name as a prefix. This function can also be used for group columns created at design time.)

Page 330: Build Forms II Volume 1 Instructor Guide 7196298

11-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show the code for creating a query record group. Use the DEFINE_QUERY_RECORD_GROUP procedure.

Copyright Oracle Corporation, 1999. All rights reserved.

Defining Query Record GroupsProgrammatically

Find record group

Yes ID NULL? No

Create group from query

Populate group

Page 331: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-17......................................................................................................................................................

......................................................................................................................................................Defining Query Record Groups Programmatically

Defining Query Record Groups ProgrammaticallyThe PL/SQL code below illustrates how you can create and populate a query record group.

Note: The query record groups can also be defined at design time.DECLAREv_rg_id RECORDGROUP;v_errcode NUMBER;

BEGIN--Make sure that record group doesn’t already exist.v_rg_id := FIND_GROUP(’customers’);IF ID_NULL(v_rg_id) THEN

--Create query record group.v_rg_id := CREATE_GROUP_FROM_QUERY(’customers’,

’SELECT id, name FROM s_customer ORDER BY id’);END IF;--Populate query record group with associated query.v_errcode := POPULATE_GROUP(v_rg_id);

END;

You can replace the associated query of a query record group by calling the POPULATE_GROUP_WITH_QUERY built-in function.

v_errcode := POPULATE_GROUP_WITH_QUERY(v_rg_id,’SELECT id, name FROM s_customerwhere region_id = 1 ORDER BY id’);

Page 332: Build Forms II Volume 1 Instructor Guide 7196298

11-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show the code for creating a nonquery record group. Use the DEFINE_NON_QUERY_RECORD_GROUP procedure.

Copyright Oracle Corporation, 1999. All rights reserved.

Defining Nonquery RecordGroups Programmatically

Find record group

Yes ID NULL? No

Create group Delete group rows

Add group columns Find group columns

Add group row

Set group cell values

Page 333: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-19......................................................................................................................................................

......................................................................................................................................................Defining Nonquery Record Groups Programmatically

Defining Nonquery Record Groups ProgrammaticallyThe PL/SQL code below illustrates how you can create and populate a nonquery record group. Note that you cannot define nonquery record groups at design time.

DECLAREv_rg_id RECORDGROUP;v_gc1_id GROUPCOLUMN;v_gc2_id GROUPCOLUMN;

BEGIN--Make sure that record group doesn’t already exist.v_rg_id := FIND_GROUP(’customers’);IF ID_NULL(v_rg_id) THEN

--Create non-query record group.v_rg_id := CREATE_GROUP(’customers’);--Add NUMBER and CHAR group column to record group.v_gc1_id := ADD_GROUP_COLUMN(v_rg_id,’id’,number_column);

v_gc2_id := ADD_GROUP_COLUMN(v_rg_id,’name’,char_column,50);ELSE

--Delete all existing group rows.DELETE_GROUP_ROW(v_rg_id,all_rows);--Find ids of group columns for later use.v_gc1_id := FIND_COLUMN(’customers.id’);v_gc2_id := FIND_COLUMN(’customers.name’);

END IF;--Add one group row to record group.ADD_GROUP_ROW(v_rg_id,1);--Fill r g cells of group row 1 with item values.SET_GROUP_NUMBER_CELL(v_gc1_id,1,:cus.id);SET_GROUP_CHAR_CELL(v_gc2_id,1,:cus.name);

END;

You can convert the nonquery record group into a query record group by calling the POPULATE_GROUP_WITH_QUERY built-in function.

Page 334: Build Forms II Volume 1 Instructor Guide 7196298

11-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show the code for manipulating record group rows. Use the GET_VALUE_GRPROW function to show the code that you use to search for a specific value in a record group.

Explain that this technique can be used with a combo box to determine whether or not the value already exists in the record group.

Copyright Oracle Corporation, 1999. All rights reserved.

Manipulating Record GroupRows

Get number of group rows

For allgrouprows

Cell value=given value

Yes No

Return rownumber

Return NULL

Page 335: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-21......................................................................................................................................................

......................................................................................................................................................Manipulating Record Group Rows

Manipulating Record Group RowsThe function below illustrates how you can loop through all rows of a record group.

FUNCTION get_value_grprow/* Returns row number of group row that contains the

specified value in the given group column.

Returns NULL if the value is not found. */( p_rg_id in RECORDGROUP,p_gc_id in GROUPCOLUMN,

p_value in VARCHAR2)RETURN number IS

v_grprow_count NUMBER;BEGIN

v_grprow_count := GET_GROUP_ROW_COUNT(p_rg_id);FOR v_grprow_no IN 1 .. v_grprow_count LOOP

IF GET_GROUP_CHAR_CELL(p_gc_id,v_grprow_no) = p_value THENRETURN(v_grprow_no);

END IF;END LOOP;RETURN(null);

END;

Page 336: Build Forms II Volume 1 Instructor Guide 7196298

11-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show the code for manipulating selected record group rows.

Use the SELECT_EVEN_ROWS procedure to show the code for searching for a specific row in a record group.

Use the GET_VALUE_GRPSEL function to show the code for looping through the row in a record group.

Explain that the even number can be identified by using the MOD function.

Copyright Oracle Corporation, 1999. All rights reserved.

Manipulating Selected RecordGroup Rows

Get number of group rows

For allgrouprows

Row numbereven?

Yes No

Mark rowas selected

Page 337: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-23......................................................................................................................................................

......................................................................................................................................................Manipulating Selected Record Group Rows

Manipulating Selected Record Group RowsThe following procedure illustrates how you can select the rows of a record group.

PROCEDURE select_even_rows--Marks all group rows with even row numbers as selected. (p_rg_id in RECORDGROUP)

ISv_grprow_count NUMBER;

BEGINv_grprow_count := GET_GROUP_ROW_COUNT(p_rg_id);FOR v_grprow_no IN 1 .. v_grprow_count LOOPIF MOD(v_grprow_no,2) = 0 THENSET_GROUP_SELECTION(p_rg_id,v_grprow_no);

END IF;END LOOP;

END;

The function below illustrates how you can loop through all selected rows of a record group.

FUNCTION get_value_grpsel/* Returns selection number of selected group row that contains the specified value in the given group column. Returns NULL if the value is not found. */(p_rg_id in RECORDGROUP,p_gc_id in GROUPCOLUMN,p_value in VARCHAR2)RETURN NUMBER ISv_grpsel_count NUMBER;v_grprow_no NUMBER;

BEGIN--Only loop through the selected group rows.v_grpsel_count := GET_GROUP_SELECTION_COUNT(p_rg_id);FOR v_grpsel_no IN 1 .. v_grpsel_count LOOP--Get row number of selected row.v_grprow_no := GET_GROUP_SELECTION(p_rg_id,v_grpsel_no);IF GET_GROUP_CHAR_CELL(p_gc_id,v_grprow_no) = p_value THENRETURN(v_grpsel_no);

END IF;END LOOP;RETURN(null);

END;

Page 338: Build Forms II Volume 1 Instructor Guide 7196298

11-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Technical NoteIf a global record group is created from (or populated with) a query while executing a Form A, and the query string contains bind variable references that are local to A (:block.item or :PARAMETER.param), then when Form A terminates execution, the global query record group is converted to a global nonquery record group. The record group retains its data, but a subsequent POPULATE_GROUP is considered an error.

Instructor NoteDemonstration: Use the Global Record Groups (Orders2.fmb) demonstration to illustrate the use of a global record group. Click the product_lov button to display a list of values form. Press [Ctrl] and click the products that you want. Then click the OK button. The products selected are returned by way of a global record group to the ORDERS form. You can show the When-Mouse-Click trigger of the lov_product form.

Copyright Oracle Corporation, 1999. All rights reserved.

Defining Global Record Groups

• Record group visible to all forms in anapplication

• “Scope” parameter

– FORM_SCOPE (default)

– GLOBAL_SCOPE

...CREATE_GROUP(group_name, scope);

...CREATE_GROUP_FROM_QUERY(group_name,

query, scope);

...CREATE_GROUP(group_name, scope);

...CREATE_GROUP_FROM_QUERY(group_name,

query, scope);

Page 339: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-25......................................................................................................................................................

......................................................................................................................................................Defining Global Record Groups

Defining Global Record GroupsA global record group allows creation at run time of record groups that are visible to all forms in an application.

Scope ParameterA “scope” parameter can be added to the CREATE_GROUP and CREATE_GROUP_FROM_QUERY built-ins. The value for this scope can be either:

• FORM_SCOPE

• GLOBAL_SCOPE

If you omit this parameter, the default is FORM_SCOPE.

Once created, a global record group persists for the remainder of the application.

Page 340: Build Forms II Volume 1 Instructor Guide 7196298

11-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Copyright Oracle Corporation, 1999. All rights reserved.

Manipulating List ItemsProgrammatically

• ADD_LIST_ELEMENT

• DELETE_LIST_ELEMENT

• CLEAR_LIST

• GET_LIST_ELEMENT_LABEL

• GET_LIST_ELEMENT_VALUE

• GET_LIST_ELEMENT_COUNT

• POPULATE_LIST

• RETRIEVE_LIST

Copyright Oracle Corporation, 1999. All rights reserved.

CHAR Column 1

Using a Record Groupwith a List Item

Labels Values

CHAR Column 2

POPULATE_LIST RETRIEVE_LIST

Page 341: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-27......................................................................................................................................................

......................................................................................................................................................Manipulating List Items Programmatically

Manipulating List Items ProgrammaticallyWhen you define a list item at design time, you specify the possible labels and values on the Properties window. However, you can also manipulate list items programmatically at run time by using built-in functions. Some of these functions require the use of record groups.

Using a Record Group with a List ItemYou can transfer information between a list item and a record group by using the POPULATE_LIST and RETRIEVE_LIST built-in functions. The record group that is used as the second parameter for these functions must satisfy these requirements:

• The record group must contain exactly two group columns of type CHAR.

• The first group column must store the list element label.

• The second group column must store the list element value.

Built-in Function DescriptionADD_LIST_ELEMENT Adds a list element (label and value) at the speci-

fied position (index) to the given list itemCLEAR_LIST Clears all list elements from the given list item

(After clearing, the list item contains only the null element.)

DELETE_LIST_ELEMENT Deletes the list element at the specified position (index) from the given list item

GET_LIST_ELEMENT_COUNT Returns the number (in CHAR format) of list ele-ments in the given list item, including list elements with NULL values

GET_LIST_ELEMENT_LABEL Returns the label of the list element at the specified position (index) in the given list item

GET_LIST_ELEMENT_VALUE Returns the value of the list element at the speci-fied position (index) in the given list item

POPULATE_LIST Clears the given list item and populates the list item with the values from the specified record group

RETRIEVE_LIST Retrieves the list elements (labels and values) from the given list item and stores them in the specified record group

Page 342: Build Forms II Volume 1 Instructor Guide 7196298

11-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show the code of the POPULATE_LIST_WITH_QUERY procedure.

Explain that the When-Create-Record trigger is used because it is too late for the When-List-Changed trigger to here.

Another option is to use the When-Mouse-Down trigger.

Copyright Oracle Corporation, 1999. All rights reserved.

Implementing Dynamic ListItems

Find record group

Yes ID NULL? No

Create group rrom query

Populate group

Yes Success? No

Populate list

Display first list label

Page 343: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-29......................................................................................................................................................

......................................................................................................................................................Implementing Dynamic List Items

Implementing Dynamic List ItemsThe procedure and trigger below illustrate how you can populate a list itemprogrammatically at run-time using a given SELECT statement.

Note: The retrieved rows are transferred to the list item by way of a record group.

PROCEDURE populate_list_with_query--Populates the given list item with the specified query.(p_list_item in VARCHAR2,p_query in VARCHAR2)IS/* Name the record group after the list item (no

block prefix). */cst_rg_name constant VARCHAR2(30) :=

GET_ITEM_PROPERTY(p_list_item,item_name);v_rg_id RECORDGROUP;

BEGINv_rg_id := FIND_GROUP(cst_rg_name);IF ID_NULL(v_rg_id) THENv_rg_id := CREATE_GROUP_FROM_QUERY(cst_rg_name,p_query);

END IF;IF POPULATE_GROUP(v_rg_id) = 0 THEN

POPULATE_LIST(p_list_item,v_rg_id);/* Force display of first list element label

in the list item. */COPY(GET_LIST_ELEMENT_VALUE(p_list_item,1),p_list_item);

END IF;END populate_list_with_query;

When-Create-Record on the ORD BlockBEGIN

POPULATE_LIST_WITH_QUERY(’ord.customer_id’,’SELECT name, to_char(id) FROM s_customer ORDER BY name’);

END;

Note: In this example, the customer name is the (visible) list label and the customer ID is the (actual) list value.

Page 344: Build Forms II Volume 1 Instructor Guide 7196298

11-30 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Instructor NoteDemonstration: Use the Record Groups (Code Examples) (rec_grp.fmb) demonstration to show the code of the ADD_COMBO_BOX_ELEMENT procedure.

Copyright Oracle Corporation, 1999. All rights reserved.

Adding Values to Combo Boxes

Get number of list elements

For alllistelements

Element value=Item value?

Yes No

Return

Add list element with item value

Page 345: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-31......................................................................................................................................................

......................................................................................................................................................Adding Values to Combo Boxes

Adding Values to Combo BoxesFor a combo box, you can choose an existing value from the list, but also type in a new value. The procedure and trigger below show how a new value can be automatically added to the list of existing values of a combo box.

Note: The added list elements are lost when you exit from the form.PROCEDURE add_combo_box_element/* Adds a new list element at the end of the given combo-box list

if it is not already present in the combo-box list. */(p_list_item in VARCHAR2)IS

v_listel_count NUMBER;BEGIN

/* First check if current list-item value is already present in list. */

v_listel_count := GET_LIST_ELEMENT_COUNT(p_list_item);FOR v_listel_idx IN 1 .. v_listel_count LOOP

IF GET_LIST_ELEMENT_VALUE(p_list_item, v_listel_idx)= UPPER(NAME_IN(p_list_item)) THENRETURN;

END IF;END LOOP;/* Current list-item value not found in list;

add new list element at end of list. */ADD_LIST_ELEMENT(p_list_item, v_listel_count + 1,

INITCAP(NAME_IN(p_list_item)),UPPER(NAME_IN(p_list_item)));END;

When-Validate-Item on the ORD.PAYMENT_TYPE Item (combo box)BEGIN

ADD_COMBO_BOX_ELEMENT(:SYSTEM.TRIGGER_ITEM);END;

Page 346: Build Forms II Volume 1 Instructor Guide 7196298

11-32 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

A record group is a data structure similarto a database table.

• Query, nonquery, and static records

• Record groups defined at design time

• Built-in functions for record groups

• Global record groups

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Uses for record groups:– Constructing dynamic SELECT

statements– Storing or passing data– Populating or storing list items

• Manipulating list itemsprogrammatically: Built-in functions forlist items

Page 347: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-33......................................................................................................................................................

......................................................................................................................................................Summary

SummaryA record group is an internal Forms data structure that is similar to a database table.

Three Record Group Types• Query record group

• Non query record group

• Static record group

Defining Record Groups at Design Time• Creating query and static record groups

• Modifying SELECT statements and column definitions of record groups

Built-ins for Controlling Record Groups• Creating and deleting record groups

• Modifying the structure of record groups

• Populating record groups

• Getting record group cell values

• Processing record group rows

• Finding record group objects

Defining a Global Record Group• Created at runtime only

• Visible to all forms in an application

• Scope parameter

Uses for Record Groups• Constructing dynamic SELECT statements

• Storing form configuration information

• Communicating within a form

• Passing data to other Oracle products

• Populating or storing list items

Manipulating List Items Programmatically Built-in for list items

Page 348: Build Forms II Volume 1 Instructor Guide 7196298

11-34 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 11 Overview

This practice covers the following topics:

• Converting a text item into adynamically populated list item

• Creating a list of values form fromwhich you can select multiple valuessimultaneously

Page 349: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-35......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 11

Practice Session Overview: Lesson 11This practice guides you through some useful record group applications.

Practice Contents• Convert a text item into a list item that is populated dynamically at run

time.

• Create a list of values form that allows multiple values to be selected simultaneously and returned to the calling form by way of a global record group.

Page 350: Build Forms II Volume 1 Instructor Guide 7196298

11-36 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Practice 111 Create a dynamic list item. This functionality avoids having to create a

new item to display the department name.

a Open the EMPLOYEES form module.

b Create a design time query record group that contains IDs and names of departments. Name your record group DEPT_ID.

In the Object Navigator, create a record group named DEPT_ID based on the query below:SELECT name || ’ in region ’ || TO_CHAR(region_id) Name, TO_CHAR(id) Id

FROM s_dept

ORDER BY 1

c Convert the text item DEPT_ID into a list item, Combo Box Style. Resize it in the Layout Editor.

d Create an element in the list. Label: Dummy and Value: 0

e Create a procedure called LIST_FROM_DESIGNTIME_GROUP. This procedure accepts the list item name as an argument and populates the list item dynamically at runtime, using the design-time query record group. You can import the pr11_1e.txt file.

f Call the procedure each time a new record is created. You can import the pr11_1f.txt file.

g Save, compile, and test the module.

If you have time...

2 Create a multirecord select list form. This practice shows how to create a list of values where the user can select multiple values. This lab uses a global record group.

a Exit Form Builder.

b Run Form Builder and create a new form based on a template named lov_prod_template.fmb.

c Examine this new module and save it as lov_product.fmb.Create a When-Mouse-Click trigger at the PROD_LOV_BLK block level that selects or clears a record when a user presses Control-clicks for a product.

d Write the code to create a record group if it does not already exist and add columns to the group for each item in the PROD_LOV_BLK block. If the record group exists write the code to

Page 351: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 11-37......................................................................................................................................................

......................................................................................................................................................Practice 11

retrieve the internal ID for each column in the record group.Write the code to check whether the record selected is already in the record group. If so, loop through each item in the record to keep the visual attribute from being highlighted, and then remove the record from the record group.If the user selects a record that was not already in the group, write the code to add the record to the record group and loop through each item in the block to keep the color highlighted.Use the SELECTED and DESELECTED visual attributes in your code to change the color of a selected or cleared record.You can import the pr11_2d.txt file.

e Create the code for the OK button. This button enables the user to exit the form.

f Create the code for the Cancel button in the PROD_LOV_BLK block. Create a When-Button-Pressed trigger that deletes the record group before returning to the ITEM block. You can import the pr11_2f.txt file.

g In the ORDERS form, modify the When-Button-Pressed trigger for the CONTROL.PRODUCT_LOV_BUTTON. The new code should check the existing products in the S_ITEM block, so that products already ordered do not show up in the list. The trigger then calls the PROD_LOV_BLK form, passing the list of existing products using a GLOBAL variable. You can import the pr11_2g.txt file.

h In the LOV_PRODUCT form, create a When-New-Form-Instance trigger to retrieve the list of products excluding the products that exist in the S_ITEM block. You should use the global variable created earlier. You can import the pr11_2h.txt file.

i In the ORDERS form, modify the When-Button-Pressed trigger for the CONTROL.PRODUCT_LOV_BUTTON. After you call the form, the code creates records in the S_ITEM block for each row selected in the record group. The code then deletes the record group.You can import the pr11_2i.txt file. Place the new code after the existing code.

j Save, run, and test your forms. To select multiple items, select the first item, hold the Control key down, and then select other items.

Page 352: Build Forms II Volume 1 Instructor Guide 7196298

11-38 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 11: Working with Record Groups

Page 353: Build Forms II Volume 1 Instructor Guide 7196298

................................

12

Including Chartsand Reports

Page 354: Build Forms II Volume 1 Instructor Guide 7196298

12-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteTopic TimingLecture 40 minutes

Practice 40 minutes

Total 80 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:• Include charts in an application• Integrate other graphics displays in an

application• Include reports in an application

Page 355: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewIn this lesson, you will learn how to include other module types in your application, such as charts built using Graphics Builder and reports built using Report Builder.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Include charts in an application

• Integrate other graphics displays in an application

• Include reports in an application

Page 356: Build Forms II Volume 1 Instructor Guide 7196298

12-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteDemonstration:

Step 1: Open the Employee Form (Emp.fmb)demonstration. Display the CANVAS4 canvas. From the Layout Editor toolbar, change the Block pop-up list from EMP to CONTROL. Using the Chart tool, drag a chart area onto the canvas. (The Employee form is based on the EMP table. If it does not already exist, it can be created by running the utlsample.sql file.

(Instructions for this demonstration continue in the next instructor note.)

Copyright Oracle Corporation, 1999. All rights reserved.

Including Charts by Usingthe Chart Wizard

To invoke the Chart Wizard:

• Use theChart toolto drag achart areaontothe canvas.

• Select Tools—>Chart Wizard.

Page 357: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-5......................................................................................................................................................

......................................................................................................................................................Including Charts by Using the Chart Wizard

Including Charts by Using the Chart WizardYou are able to create charts and reports within the Form Builder without launching separate chart or reports engines.

The Chart Wizard leads you step-by-step through the process of creating a chart from within a form or a report.

Once the chart is created, you can modify or enhance the chart by using Graphics Builder.

Invoking the Chart WizardTo invoke the Chart Wizard:

• From the Layout Editor, use the Chart tool to drag a chart area onto the canvas.

• The New Chart Wizard dialog box appears. Click on the OK button to accept the default option, “Use the Chart Wizard.”

Incorporating a ChartThe steps to create a chart are:

1 Specify a chart type and subtype.

2 Specify the data block that contains the data you want to assign to chart columns.

3 Specify the data to appear on the Category (X) axis of the chart.

4 Specify the data to appear on the Value (Y) axis of the chart.

Follow the prompts on each page of the wizard to specify the settings for the chart you want to create.

Re-Entering the Chart WizardA powerful quality of the Chart Wizard is its ability to operate in reentrant mode. This means you can use the Chart Wizard to modify an existing chart created with the wizard.

To invoke the Chart Wizard in reentrant mode, select the chart object in the Object Navigator, and then select Tools—>Chart Wizard from the menu.

Page 358: Build Forms II Volume 1 Instructor Guide 7196298

12-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteStep 2: Select Column for the chart type.

Step 3: Select the EMP block. (continued)

Copyright Oracle Corporation, 1999. All rights reserved.

Including Charts by Usingthe Chart Wizard

Chart type

Copyright Oracle Corporation, 1999. All rights reserved.

Including Charts by Usingthe Chart Wizard

Arrow indicates that data from the block is represented in the chart.

Page 359: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-7......................................................................................................................................................

......................................................................................................................................................Including Charts by Using the Chart Wizard

Chart TypeSelect the style of chart that you require. The picture on the left of the wizard displays the relevant chart style.

The chart subtype options are context-sensitive; the number and style of options change depending on the chart type that you choose. Choose the chart subtype that you require, and then click Next to continue to the next wizard page.

Data SourceThe next step in the Chart Wizard is to select the block that contains the data you want to represent in the chart. The data block you select determines the data that is available for assignment to the Category and Value axes of your chart.

Chart Type Description

Column Data is plotted as columns.

Bar Data is plotted as horizontal bars.

Pie Data is plotted as individual “slices” showing the relationship of parts to the whole.

Line Data is plotted as points along a line.

Mixed Data is charted using multiple chart types, such as bar and line.

Page 360: Build Forms II Volume 1 Instructor Guide 7196298

12-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteStep 4: Select ENAME for the Category axis.

Step 5: Select SAL for the Value axis. Save into Disp1.ogd. Run your form.

Copyright Oracle Corporation, 1999. All rights reserved.

Including Charts by Usingthe Chart Wizard

Arrow pointsto the Categoryaxis.

Copyright Oracle Corporation, 1999. All rights reserved.

Including Charts by Usingthe Chart Wizard

Arrow points to the Value axis.

Page 361: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-9......................................................................................................................................................

......................................................................................................................................................Including Charts by Using the Chart Wizard

Category AxisTo use the Chart Wizard to map data to your chart’s Category (X) axis:

1 In the Available Fields list, select the field that you want to map to the Category (X) axis of the chart.

2 Transfer the selected field from the Available Fields list to the Category Axis list.

Note

Value AxisTo use the Chart Wizard to map data to your chart’s Value (Y) axis:

1 In the Available Fields list, select the field that you want to map to the Value (Y) axis of the chart.

2 Transfer the selected field from the Available Fields list to the Value Axis list.

Note

Note: You must transfer at least one field from the Available Fields list to the Category Value list before navigating to the next page.

Chart Type Description

Column, Line, Mixed chart Categories appear along the x-axis.

Bar chart Categories appear down the y-axis.

Pie chart Each category represents one segment of the pie.

Chart Type Description

Column, Line, Mixed chart Values are represented by the height of the column against the y-axis.

Bar chart Values are represented by the length of the column against the x-axis.

Pie chart Values are represented by the size of each segment.

Page 362: Build Forms II Volume 1 Instructor Guide 7196298

12-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteThe default name of the Query Name property is Genie_Query. The query is created automatically with the structure of the Data Source Data Block.

Copyright Oracle Corporation, 1999. All rights reserved.

Chart Item Properties

Filename

Execution Mode

Communication Mode

Data Source Data Block

Query Name

Data Source X Axis

Data Source Y Axis

Update on Query

Update on Commit

Page 363: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-11......................................................................................................................................................

......................................................................................................................................................Chart Item Properties

Chart Item PropertiesThe chart item properties are the following:

Property Description

Filename Specifies the name of the file where the chart is stored

Execution Mode Specifies the execution version of Graphics Builder to use: BATCH or RUNTIME

Communication Mode Specifies the communication mode to be used when calling Graphics Builder: SYNCHRONOUS or ASYNCHRONOUS

Data Source Data Block Specifies the block that contains the data to represent in the chart

Query Name Specifies the name of the query used to display the chart

Data Source X Axis Specifies the item name used to map data to the chart Category (X) axis

Data Source Y Axis Specifies the item name used to map data to the chart Value (Y) axis

Update on Query Specifies that the chart is refreshed each time you perform a query

Update on Commit Specifies that the chart is refreshed each time you perform a commit

Page 364: Build Forms II Volume 1 Instructor Guide 7196298

12-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Technical NotePassing data is applicable only if running against a local server.

Instructor NoteYou cannot run a report based on a block that contains a long column.

Demonstration: Open the Customer Form (customers.fmb) demonstration and create a new report object.

Copyright Oracle Corporation, 1999. All rights reserved.

Reporting Within Form Builder

• Create report objects in ObjectNavigator

• Run a report against a local or remoteserver

• Base a report ona data block

Page 365: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-13......................................................................................................................................................

......................................................................................................................................................Reporting Within Form Builder

Reporting Within Form BuilderOracle Developer Form Builder provides the ability to run a report against a local or a remote server with considerable ease. A report object is available that allows you to specify all the commands necessary for running a report.

Using the Report WizardUsing the Report Wizard within Form Builder, you can:

• Create a new report module based on one data block in your form

• Create a new report module

• Use an existing report module

Note: You can modify or enhance the report module by using Report Builder.

Creating a Report Object Based on a Data BlockThe ability to base a report on a data block represents an efficient way of passing data from a form module to a report. Select the Report node in the Object Navigator.

1 Create a new report object by clicking the Create icon.

Form Builder displays the New Report dialog box.

2 Specify a filename and a block name.

3 Click OK.

Form Builder runs Report Builder and displays the Report Wizard.

4 Choose the report style that most closely resembles the report you want to create.

5 Select the fields you would like to display in your report.

6 Select the fields you would like to total by choosing from a list of possible calculations. (This step is optional.)

7 Enter labels and widths for your fields and totals. (This step is optional.)

8 Select a template for your report and then click the Finish button.

The Live Previewer is displayed.

Page 366: Build Forms II Volume 1 Instructor Guide 7196298

12-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteDemonstration: Set the Execution Mode property to RUNTIME, the Communication Mode to SYNCHRONOUS, and the Report Destination Type to PREVIEW.

Copyright Oracle Corporation, 1999. All rights reserved.

Report Object Properties

Filename

Execution Mode

Communication Mode

Data Source Data Block

Query Name

Filename

Execution Mode

Communication Mode

Data Source Data Block

Query Name

Oracle Developer

integration properties

Copyright Oracle Corporation, 1999. All rights reserved.

Report Object Properties

Report Destination Type

Report Destination Name

Report Destination Format

Report Server

Other Report Parameters

Reports properties

Page 367: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-15......................................................................................................................................................

......................................................................................................................................................Report Object Properties

Report Object Properties

Oracle Developer Integration Properties

Reports Properties

Property Name Description

Filename Specifies the name of the report module to be executed by Report Builder

Execution Mode Specifies the execution mode to be used when running Report Builder (Valid numeric constants for this property are BATCH and RUNTIME.)

Communication Mode Specifies the communication mode to be used when running Report Builder. Valid numeric constants for this parameter:

SYNCHRONOUS specifies that control returns to Form Builder only after Report Builder has been exited. The end user cannot work in the form while Report Builder is running.

ASYNCHRONOUS specifies that control returns to the calling application immediately, even if Report Builder has not completed its display.

Data Source Data Block Block name used by Report Builder as data source

Query Name Query name used by Report Builder to retrieve the data (When the report is based on data from a Form Builder block, the query name property value is the block name.)

Property Name Description

Report Destination Type Specifies the type of device that will receive the report output

Report Destination Name Specifies the name of the file, printer, or Oracle Office username (or distribution list) to which the report output will be sent

Report Destination Format Specifies the format of your report (Possible values are PDF, HTML, HTMLCSS, or the printer driver to be used when DESTYPE is File.)

Report Server Name of the remote server on which the report is run

Other Report Parameters Declares additional parameters

Page 368: Build Forms II Volume 1 Instructor Guide 7196298

12-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteExamples of the syntax for RUN_REPORT_OBJECT, FIND_REPORT_OBJECT, REPORT_OBJECT_STATUS, and COPY_REPORT_OUTPUT built-ins are available on the next page.

CANCEL_REPORT_OBJECT is not explained, but you can show the syntax by expanding the Built-in Packages node in the Object Navigator, and then STANDARD Extensions node.

GET_REPORT_OBJECT_PROPERTY and SET_REPORT_OBJECT_PROPERTY are not explained in detail, because these built-ins are similar to the Get and Set built-ins.

Instructor NoteDemonstration: Create a button in the Control block. Write a When-Button-Pressed trigger with the following code:

DECLARE

v_rep VARCHAR2(100);

BEGIN

v_rep := RUN_REPORT_OBJECT(’<your_report_object_name>’);

END;

Copyright Oracle Corporation, 1999. All rights reserved.

Working with Reports

Built-ins for interacting with reports:• RUN_REPORT_OBJECT• FIND_REPORT_OBJECT• CANCEL_REPORT_OBJECT• REPORT_OBJECT_STATUS• COPY_REPORT_OUTPUT• GET_REPORT_OBJECT_PROPERTY• SET_REPORT_OBJECT_PROPERTY• RUN_PRODUCT

Page 369: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-17......................................................................................................................................................

......................................................................................................................................................Working with Reports

Working with ReportsYou can control reports in the Report Server dynamically when running a form by including the following new built-ins in your trigger code:

Built-in Description

RUN_REPORT_OBJECT Runs a specified report on a specified server

FIND_REPORT_OBJECT Returns the internal ID of a report object

CANCEL_REPORT_OBJECT Cancels a report in the server queue

REPORT_OBJECT_STATUS Returns the current status of a report (The status codes can be FINISHED, RUNNING, CANCELED, OPENING_REPORT, ENQUEUED, INVALID_JOB, TERMINATED_WITH_ERROR, or CRASHED.)

COPY_REPORT_OUTPUT Copies the report output back to the client

GET_REPORT_OBJECT_PROPERTY Dynamically gets report object properties at run time

SET_REPORT_OBJECT_PROPERTY Dynamically sets report object properties at run time

RUN_PRODUCT Invokes one of the supported Oracle tools products and specifies the name of the module or modules to be run

Page 370: Build Forms II Volume 1 Instructor Guide 7196298

12-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Instructor NoteIf you want to test the report status when you run a report against a remote server, the Communication Mode report object property must be synchronous.

Copyright Oracle Corporation, 1999. All rights reserved.

Running a Report Againsta Local Server

DECLARE

v_rep VARCHAR2(100);

repid REPORT_OBJECT;

BEGIN

repid := FIND_REPORT_OBJECT(’deptrpt’);

v_rep := RUN_REPORT_OBJECT(repid);

end;

Copyright Oracle Corporation, 1999. All rights reserved.

Running a Report Againsta Remote Server

. . .

repid := FIND_REPORT_OBJECT(’barcode’);

v_rep := RUN_REPORT_OBJECT(repid);

rep_status := REPORT_OBJECT_STATUS(v_rep);

IF rep_status = ’FINISHED’ THEN

COPY_REPORT_OBJECT_OUTPUT(v_rep,’c:\local.pdf’);

HOST(’netscape c:\local.pdf’);

END IF;

. . .

Page 371: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-19......................................................................................................................................................

......................................................................................................................................................Working with Reports

Running a Report Against a Local ServerThis example allows the user to run a report against a local server.

DECLARE

v_rep VARCHAR2(100);

repid REPORT_OBJECT;

BEGIN

repid := FIND_REPORT_OBJECT(’deptrpt’);

v_rep := RUN_REPORT_OBJECT(repid);

end;

Running a Report Against a Remote ServerThis example allows the user to run a report against a remote server. RUN_REPORT_OBJECT returns a string that uniquely identifies the report on the server. This string could be used to get the report status or copy the output across or terminate the report in case the report is being run asynchronously.

DECLARE

v_rep VARCHAR2(100);

repid REPORT_OBJECT;

rep_status VARCHAR2(20);

BEGIN

repid := FIND_REPORT_OBJECT(’barcode’);

v_rep := RUN_REPORT_OBJECT(repid);

rep_status := REPORT_OBJECT_STATUS(v_rep);

IF rep_status = ’FINISHED’ THEN

MESSAGE(’Report Completed’);

COPY_REPORT_OBJECT_OUTPUT(v_rep,’c:\local.pdf’);

/* Once the report output is copied across successfully

depending on the type of the output the file could

be displayed using a Web Browser or an OCX control */

HOST(’netscape c:\local.pdf’);

ELSE

MESSAGE(’Error when running report.’);

END IF;

END;

Page 372: Build Forms II Volume 1 Instructor Guide 7196298

12-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Invoking the Chart Wizard• Reporting features in Form Builder:

– Create report objects– Run against local or remote server– Base reports on data blocks

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Interacting with reports:

– RUN_REPORT_OBJECT

– FIND_REPORT_OBJECT

– CANCEL_REPORT_OBJECT

– REPORT_OBJECT _STATUS

– COPY_REPORT_OUTPUT

– GET_REPORT_OBJECT_PROPERTY

– SET_REPORT_OBJECT_PROPERTY

Page 373: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-21......................................................................................................................................................

......................................................................................................................................................Summary

SummaryIn this lesson, you should have learned how to include charts and reports in your application. You should have learned how to invoke the Chart Wizard.

Reporting Features in Form Builder• Create report objects

• Run against local or remote server

• Base reports on data blocks

Interacting with Reports• RUN_REPORT_OBJECT

• FIND_REPORT_OBJECT

• CANCEL_REPORT_OBJECT

• REPORT_OBJECT_STATUS

• COPY_REPORT_OUTPUT

• GET_REPORT_OBJECT_PROPERTY

• SET_REPORT_OBJECT_PROPERTY

Page 374: Build Forms II Volume 1 Instructor Guide 7196298

12-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 12 Overview

This practice covers the following topics:

• Creating a chart to display the totalorders for each customer

• Creating a report based on theS_CUSTOMER block

• Displaying different report styles

Page 375: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-23......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 12

Practice Session Overview: Lesson 12This practice guides you in incorporating charts into your application, and creating reports by using the Form Builder report object.

Practice Contents• Create a chart to display the total orders for each customer.

• Create a report based on the S_CUSTOMER block.

• Display different report styles.

Page 376: Build Forms II Volume 1 Instructor Guide 7196298

12-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Practice 121 Create a chart object by using the Chart Wizard. This chart should

display the total orders for each customer.

a Open the CUSTOMERS form module.

b Create a new tab page on the TAB_CUSTOMER canvas. Name this page CHART and change the label name.

Open the FormBuilder_II.olb object library. Copy the OBJ_CHART object group into the CUSTOMERS form. This object group contains a block named S_ORD. Only one item from this block is visible: TITLE. This item displays a title for the chart.

c From the Layout Editor, use the Chart tool to drag a chart area onto the chart tab page. Select Use the Chart Wizard from the New Chart Object dialog box. Do not specify a title for the chart.

d Select Column as chart type, Plain as chart subtype.

e Specify the S_ORD block as the data block that contains the data you want to assign to chart columns.

f Select CUSTOMER_NAME to appear on the Category (X) axis, and TOTAL to appear on the Value (Y) axis of the chart.

g Click the Finish button. Save, run, and test your form. To display the chart, click in the Title item on the Chart tab.

2 Create a report object based on the S_CUSTOMER block. This report displays a customer list using a tabular layout. Display only the ID, NAME, COUNTRY, and REGION_ID fields.

a Open the CUSTOMERS form.

b Create a new report object.

This will invoke the Report Builder. Within the Report Wizard:

- Choose the report style Tabular.

- Select the ID, NAME, COUNTRY, and CREDIT_RATING fields.

- Do not select fields to total.

- Change labels and widths for your fields.

- Select a template for your report.

c Save your report and exit Report Builder.

d Set the Execution Mode report object property to runtime and the Report Destination Type report object property to screen.

Page 377: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 12-25......................................................................................................................................................

......................................................................................................................................................Practice 12

e Create a button named CUST_REP_BUTTON into the control block. Display this button on the CV_CUSTOMER canvas.

f Create a When-Button-Pressed trigger on the CUST_REP_BUTTON button to run the report.

g Change the Query All Record property value to Yes for the S_CUSTOMER block.

h Save, run, and test your form. Query a customer record before calling the report.

If you have time...

3 Create a new tab page from which the user can run different report layouts.

a Open the Form_Builder_II.olb object library.

b From the Report tab page, select all the report objects and copy them to the CUSTOMERS form.

c Change the filename property to each report so that the path is correct for your environment.

d From the Report tab page, select the REPORT block and copy it to the CUSTOMERS form. Organize this block so it is the last block in sequence.

e From the Report tab page, select the REPORT tab page object and copy it to the CUSTOMERS form. Organize this tab page so it is the last tab page in sequence.

f Save, run, and test your form.

Page 378: Build Forms II Volume 1 Instructor Guide 7196298

12-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 12: Including Charts and Reports

Page 379: Build Forms II Volume 1 Instructor Guide 7196298

................................

13

Applying Timers

Page 380: Build Forms II Volume 1 Instructor Guide 7196298

13-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Instructor NoteTopic TimingLecture 25 minutes

Practice 30 minutes

Total 55 minutes

Explanation for the next page: Point out that using GET_APPLICATION_PROPERTY(timer_name) returns NULL if called from any trigger other than When-Timer-Expired.

Demonstration for the next page pair: Use the “About...” Information at Startup (Customers.fmb) demonstration to illustrate one use of timers.

Use the Auto Commit/Rollback After Period of Time to illustrate automatically asking for COMMIT after a period of time.

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• Describe timers

• Create a timer

• Modify a timer

• Delete a timer

• Handle timer expiration

Page 381: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewThis lesson covers time-initiated processing; that is, processing that occurs after a certain amount of time has elapsed. The mechanism you use to do this is called a timer and it is created, modified, and deleted at run time.

ObjectivesAfter completing this lesson, you should be able to do the following:

• Describe timers

• Create a timer

• Modify a timer

• Delete a timer

• Handle timer expiration

Page 382: Build Forms II Volume 1 Instructor Guide 7196298

13-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Technical NoteTimers are not suitable means of shutting down an application. It is the job of the operating system to recognize idle processes and shut them down.

Copyright Oracle Corporation, 1999. All rights reserved.

Timers

• What is a timer?

• Built-ins for timers:

– FIND_TIMER

– CREATE_TIMER

– SET_TIMER

– DELETE_TIMER

– GET_APPLICATION_PROPERTY(TIMER_NAME)

Copyright Oracle Corporation, 1999. All rights reserved.

Timers

• When-Timer-Expired trigger

• Using timers:

– Poll database

– Periodically query, commit, orrollback

– Show “About…” information atstartup

Page 383: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-5......................................................................................................................................................

......................................................................................................................................................Timers

TimersTypically, Forms processes events that are (originally) initiated by the user. You can use timers when you want Forms to perform a set of actions after a period of time has elapsed.

What Is a Timer?A timer is a programmatic construct similar to an “internal alarm clock.” You can create, modify, or delete timers by means of built-ins. When you create or modify a timer, you can specify the period of time that elapses before the timer “expires.” Using a trigger, you can specify what actions must be performed at that time.

Built-in Functions for Timers

When-Timer-Expired TriggerThis trigger fires when a timer expires; that is, when the specified time interval of the timer has elapsed.

Uses of Timers• Polling the database to check if a certain event has occurred

• Performing an automatic query at regular intervals

• Showing “About this...” information at form startup

• Performing an automatic commit or rollback after a specific amount of idle time

Built-in DescriptionFIND_TIMER Returns the internal timer ID (of data type

TIMER) of a timer with the given nameCREATE_TIMER Creates a timer with the given name (You can

specify the time interval and whether the timer should repeat on expiration.)

SET_TIMER Changes the settings for the given timer (You can modify the time interval and the repeat behavior.)

DELETE_TIMER Deletes the given timerGET_APPLICATION_PROPERTY The TIMER_NAME property returns the name of

the most recently expired timer.

Page 384: Build Forms II Volume 1 Instructor Guide 7196298

13-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Instructor NoteExplain that:

1 Timer A is created, and when it expires, it is placed in the timer queue.

2 If no other processing is taking place, then the When-Timer-Expired trigger fires for Timer A.

3 After Timer A has been serviced from the queue, it can begin its next iteration.

4 Timer B (a nonrepeating timer) is created in the meantime.

5 When Timer B expires, it cannot be immediately serviced by the When-Timer-Expired trigger, because a query is taking place.

6 After the query is complete, the When-Timer-Expired trigger can fire for Timer B.

Copyright Oracle Corporation, 1999. All rights reserved.

Handling Timer ExpirationTimer Acreated

Timer Bcreated

Start

Timer Aexpired

Repeat

A

When-Timer-Expired (A)Query issued

Timer Bexpired B

Timer Aexpired

Repeat

B,A

Querycomplete

When-Timer-Expired (B)

When-Timer-Expired (A)

Page 385: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-7......................................................................................................................................................

......................................................................................................................................................Handling Timer Expiration

Handling Timer ExpirationWhen a timer expires, the When-Timer-Expired trigger fires and executes the desired actions. If you define more than one timer, you need to know which timer expired and how expired timers are handled.

Timer QueueWhen a timer expires, it is put in a queue of expired timers. Forms services this timer queue on a first-in-first-out basis, but only while it is waiting for user actions. After an expired timer is handled, it is removed from the queue.

Note: A repeating timer will not begin the next iteration while it is still in the timer queue.

When-Timer-Expired TriggerWhen using the When-Timer-Expired trigger remember that it:

• Fires once for each timer that expires, but only after Form Builder has completed any current processing of triggers and built-in functions

• Fires after the specified time interval, rather than exactly on the moment of expiration

• Must be defined at the form level

• Should include the GET_APPLICATION_PROPERTY built-in function for you to find out which timer has expired

ExampleHandle the expiration of two timers named HOUR_ALARM and ABOUT_STARTUP.

DECLARE v_timer_name VARCHAR2(30);BEGINv_timer_name := GET_APPLICATION_PROPERTY(timer_name);IF v_timer_name = ’HOUR_ALARM’ THEN

MESSAGE(’One hour has passed again.’);ELSIF v_timer_name = ’ABOUT_STARTUP’ THEN

DELETE_TIMER(’ABOUT_STARTUP’);END IF;

END;

Page 386: Build Forms II Volume 1 Instructor Guide 7196298

13-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Copyright Oracle Corporation, 1999. All rights reserved.

Creating a Timer

Syntax:

Example:

CREATE_TIMER (timer_name, milliseconds, iterate)CREATE_TIMER (timer_name, milliseconds, iterate)

v_timer_id := CREATE_TIMER (′hour_alarm’, cst_hour);v_timer_id := CREATE_TIMER ( ′hour_alarm’, cst_hour);

Page 387: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-9......................................................................................................................................................

......................................................................................................................................................Creating a Timer

Creating a TimerYou can create a timer by using the CREATE_TIMER built-in function, which returns type TIMER.

Syntax

ExampleAt form startup, create a timer named HOUR_ALARM that expires every hour.

DECLARE cst_hour constant NUMBER(7) := 3600000; --3600000 is one hour in milliseconds v_timer_id TIMER;BEGIN v_timer_id := CREATE_TIMER(’hour_alarm’, cst_hour);END;

CREATE_TIMER(timer_name, milliseconds, iterate)

Parameter Descriptiontimer_name The timer namemilliseconds The duration of the timer in milliseconds (Value must be

between 1 and 2147483648, approximately 25 days.)iterate Specifies whether the timer should repeat upon expiration

(Valid values are REPEAT—the default—and NO_REPEAT.)

Page 388: Build Forms II Volume 1 Instructor Guide 7196298

13-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Copyright Oracle Corporation, 1999. All rights reserved.

Modifying a Timer

Syntax:

Example:

SET_TIMER (timer_name, milliseconds, iterate)

SET_TIMER (timer_id, milliseconds, iterate)

SET_TIMER (timer_name, milliseconds, iterate)

SET_TIMER (timer_id, milliseconds, iterate)

SET_TIMER (′hour_alarm’, no_change, no_repeat );SET_TIMER (′hour_alarm’, no_change, no_repeat );

Page 389: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-11......................................................................................................................................................

......................................................................................................................................................Modifying a Timer

Modifying a TimerYou can modify a timer by using the SET_TIMER built-in procedure.

Syntax

ExampleSet the repeat behavior of a timer named HOUR_ALARM without changing the time interval. The trigger name depends on the situation.

BEGIN SET_TIMER(’hour_alarm’, no_change, no_repeat);END;

SET_TIMER(timer_name, milliseconds, iterate)SET_TIMER(timer_id, milliseconds, iterate)

Parameter Description

timer_name The timer name

timer_id The internal timer ID

milliseconds The duration of the timer in milliseconds (Value must be between 1 and 2147483648—approximately 25 days—or must be NO_CHANGE.)

iterate Specifies whether the timer should repeat upon expiration (Valid values are REPEAT (default), NO_REPEAT, and NO_CHANGE.)

Page 390: Build Forms II Volume 1 Instructor Guide 7196298

13-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Copyright Oracle Corporation, 1999. All rights reserved.

Deleting a Timer

Syntax:

Example:

DELETE_TIMER (timer_name)

DELETE_TIMER (timer_id)

DELETE_TIMER (timer_name)

DELETE_TIMER (timer_id)

...

IF NOT ID_NULL (FIND_TIMER (′hour_alarm′)) THENDELETE_TIMER (‘hour_alarm’);

END IF;

...

...

IF NOT ID_NULL (FIND_TIMER ( ′hour_alarm ′)) THEN

DELETE_TIMER (‘hour_alarm’);

END IF;

...

Page 391: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-13......................................................................................................................................................

......................................................................................................................................................Deleting a Timer

Deleting a TimerYou can delete a timer by using the DELETE_TIMER built-in procedure.

Syntax

Note: Forms generates an error if you attempt to delete a nonexistent timer.

ExampleDelete a timer named HOUR_ALARM after first checking that it exists. The trigger name depends on the situation.

BEGINIF NOT ID_NULL(FIND_TIMER(’hour_alarm’)) THEN

DELETE_TIMER(’hour_alarm’);END IF;

END;

DELETE_TIMER(timer_name)DELETE_TIMER(timer_id)

Parameter Description

timer_name The timer name

timer_id The internal timer ID

Page 392: Build Forms II Volume 1 Instructor Guide 7196298

13-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• A timer is a programmatic construct

• Built-in functions for timers:

– FIND_TIMER

– CREATE_TIMER

– SET_TIMER

– DELETE_TIMER

– GET_APPLICATION_PROPERTY(TIMER_NAME)

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Using timers

• Handling timer expiration:

– Timer queue

– When-Timer-Expired trigger

Page 393: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-15......................................................................................................................................................

......................................................................................................................................................Summary

SummaryA timer is a programmatic construct much like an “internal alarm clock.”

Built-ins for Timers• FIND_TIMER

• CREATE_TIMER

• SET_TIMER

• DELETE_TIMER

• GET_APPLICATION_PROPERTY(TIMER_NAME)

Uses of Timers• Polling the database to check if a certain event has occurred

• Performing an automatic query at regular intervals

• Showing “About this...” information at form startup

• Performing an automatic commit or rollback after a specific amount of idle time

Handling Timer Expiration• When a timer expires, it is put in a first-in-first-out timer queue.

• The When-Timer-Expired trigger fires once for each timer that expires, but only after Forms has completed any current processing.

Page 394: Build Forms II Volume 1 Instructor Guide 7196298

13-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 13 Overview

This practice covers the topics:

• Showing “About...” information at formstartup

• Periodically checking to see if there arelocked records and asking the user tocommit or roll back

Page 395: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 13-17......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 13

Practice Session Overview: Lesson 13This practice guides you through the implementation of time-initiated processing. You will use the appropriate timer built-ins and triggers to create timers and handle timer expiration.

Practice Contents• Show “About...” information at form startup.

• If table rows are locked, display an alert that asks the user to commit or roll back changes after a set period of time.

Page 396: Build Forms II Volume 1 Instructor Guide 7196298

13-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 13: Applying Timers

Practice 131 Show”About...” information at the startup of the form.

a Open the CUSTOMERS form module.

b Add a window and a canvas to the form that are used to display the two control items. This window could be considered an ”About...” window and should be a modal dialog window. Set the Hide on Exit property to Yes for this window.

c Create manually a new control block, called ABOUT. Create two items in the ABOUT block that are used to display the user name and the current date and time.

d Show the ”About...” window for a short period of time at the startup of the form. You can import the pr13_1d1.txt file for the When-New-Form-Instance trigger. Add the new code after the existing code. You can import the pr13_1d2.txt file for the When-Timer-Expired trigger. Append the new code to the end of the existing code.

If you have time...

2 Automatically ask the users if they want to commit after a set period of time.

a Open the CUSTOMERS form module.

b At the startup of the form, create a global variable called GLOBAL.LOCKS_PENDING, which indicates at all times whether rows of the S_CUSTOMER table are locked. Append the new code to the end of the existing code.

c Create the On-Lock trigger to implement the default lock processing, update the global variable, and create the timer. You can import the pr13_2c.txt file.

d Write a When-Timer-Expired trigger to display an alert if locks are still pending after a certain period of time elapses. This alert should ask the user to commit or roll back the changes. You can replace the existing code with the code from the pr13_2d.txt file.

Note: You need to create an alert called ASK_SAVE.

Define an alert (called ASK_SAVE) of style Caution with a Yes and a No button. Define an appropriate message.

e Create the Post-Database-Commit trigger to give the NULL value to the global variable.You can import the pr13_2e.txt file.

f Create the On-Rollback trigger to implement the default rollback processing and give the NULL value to the global variable. You can import the pr13_2f.txt file.

Page 397: Build Forms II Volume 1 Instructor Guide 7196298

................................

14

Using Server Featuresin Form Builder

Page 398: Build Forms II Volume 1 Instructor Guide 7196298

14-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Instructor NoteTopic TimingLecture 25 minutes

Practice 30 minutes

Total 55 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

ObjectivesAfter completing this lesson, you shouldbe able to do the following:• Use Oracle server functionalities in

forms• Deal with server-side PL/SQL• Recognize which PL/SQL8 features are

supported in forms, and which are not• Handle Oracle server errors• Perform DDL commands by using the

FORMS_DDL built-in subprograms

Page 399: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewThis lesson covers the use of Oracle server features in Form Builder applications. You will learn about storing and calling PL/SQL code, handling Oracle server errors, and issuing DDL commands from within forms.

ObjectivesAt the end of this lesson, you should be able to:

• Use Oracle server functionalities in forms

• Deal with server-side PL/SQL

• Recognize which PL/SQL8 features are supported in forms

• Handle Oracle server errors

• Perform DDL commands by using the FORMS _DDL built-in subprograms

Page 400: Build Forms II Volume 1 Instructor Guide 7196298

14-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Using Oracle ServerFunctionality in Forms

Useful Oracle server features:

• Declarative constraints

• Stored program units

• Database triggers

• DDL

Page 401: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-5......................................................................................................................................................

......................................................................................................................................................Using Oracle Server Functionality in Forms

Using Oracle Server Functionality in FormsThe Oracle database offers several powerful features to implement functionality in the Oracle server. You can call that functionality in your forms to handle possible errors.

Oracle Server Features Useful for FormsThe following useful features are available to application developers:

• Declarative integrity constraints

• Stored program units: procedures, functions, and packages

• Built-in database packages

• Database triggers

• Database roles

• DDL

• SQL Optimizer; shared SQL

• Locking

• Sequences

Some of these features are discussed in more depth later in this lesson.

Page 402: Build Forms II Volume 1 Instructor Guide 7196298

14-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Dealing with PL/SQL Code

• Where to store PL/SQL code:

– On the Oracle server

– In the attached PL/SQL libraries

– In the form itself

• Where to call PL/SQL code:

– From database triggers

– From forms triggers

• Application partitioning

Page 403: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-7......................................................................................................................................................

......................................................................................................................................................Dealing with PL/SQL Code

Dealing with PL/SQL CodeYou can store and call your code in two places: the Oracle server and the application.

Where to Store PL/SQL CodeTo maintain your code, you should not store the code in more locations than necessary. The places to store PL/SQL code, in order of preference, are as follows:

1 The Oracle server

2 Attached PL/SQL libraries

3 The form itself

Note: PL/SQL code cannot be stored in the Oracle server if it contains bind variables or calls to Forms built-ins.

Where to Call PL/SQL CodePL/SQL code is eventually called from triggers. Also, for easier maintenance, the places to call PL/SQL code, in order of preference, are as follows:

1 Database triggers

2 Forms triggers

Note: Database triggers fire only at commit time. If you want to give immediate feedback to the user, you must use forms triggers.

Application PartitioningFor enhanced performance, you may want to call or store PL/SQL code on the client side. In Forms, you can drag and drop PL/SQL program units between the Oracle server and the application. In this way, you can optimally divide applications over the available resources. This is called application partitioning.

Page 404: Build Forms II Volume 1 Instructor Guide 7196298

14-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

PL/SQL8 Support in Developer

• Client-side program units cannotsupport Oracle8 object-relatedfunctionality.

• Stored program units can use the newPL/SQL8 features.

Page 405: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-9......................................................................................................................................................

......................................................................................................................................................PL/SQL8 Support

PL/SQL8 SupportOracle Developer Release 6 uses PL/SQL8 in the client and in the server. However, client-side program units currently cannot support Oracle8 object-related functionality.

The Stored Program Unit editor has been extended in Oracle Developer Release 6 to allow editing of the type body (methods) and type specification (attributes) of Oracle8 user-defined data types.

Object Iron PackagesThe Object Iron is a set of database packages that helps you to access tables containing instances of Oracle8 object types. The packages generate a table-specific package, which you use to access data from the specified table. After generation, the table-specific package appears under the Stored Program Units node. It contains code that allows you to select, insert, update, delete, and lock records in the specified table.

Instructor Note Oracle Developer is backward-compatible with client-side program units built using PL/SQL Version 2. Client-side program units created with previous releases will run against the PL/SQL8 engine with no modification. Although stored program units created with previous releases will run against PL/SQL8, because of syntax incompatibility between PL/SQL8 and PL/SQL Version 2, these stored program units may compile with errors.

Page 406: Build Forms II Volume 1 Instructor Guide 7196298

14-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

New PL/SQL8 Scalar Types

• NCHAR and NVARCHAR2

• SIGNTYPE

• FLOAT

• NATURALN

• POSITIVEN

• PLS_INTEGER

Page 407: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-11......................................................................................................................................................

......................................................................................................................................................New PL/SQL8 Scalar Data Types

New PL/SQL8 Scalar Data Types• NCHAR stores fixed-length (blank-padded if necessary) NLS character

data. How the data is represented internally depends on the national character set, which might use a fixed-width encoding such as US7ASCII or a variable-width encoding such as JA16SJIS.

• NVARCHAR2 stores variable-length NLS character data. How the data is represented internally depends on the national character set, which might use a fixed-width encoding such as WE8EBCDIC37C or a variable-width encoding such as JA16DBCS.

• SIGNTYPE lets you restrict an integer variable to the values -1, 0, and 1, which is useful in programming tri-state logic.

• FLOAT is a subtype of NUMBER. However, you cannot specify a scale for FLOAT variables. You can specify only a binary precision.

• NATURALN is like subtype NATURAL but prevents the assignment of NULL.

• POSITIVEN is like subtype POSITIVE but prevents the assignment of NULL.

• PLS_INTEGER stores signed integers. Its magnitude range is -2147483647 ... 2147483647. PLS_INTEGER values require less storage than NUMBER values. Also, PLS_INTEGER operations use machine arithmetic, so they are faster than NUMBER and BINARY_INTEGER operations, which use library arithmetic.

Besides the database character set, which is used for identifiers and source code, PL/SQL8 now supports a second character set called the national character set, which is used for NLS data. The PL/SQL data types NCHAR and NVARCHAR2 allow you to store character strings formed from the national character set.

Page 408: Build Forms II Volume 1 Instructor Guide 7196298

14-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Unsupported Client-SidePL/SQL8 Features

• Untrusted external procedures

• Object types

• Collection types

• LOB types

• Methods

• Objects as stored procedure parameters

Page 409: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-13......................................................................................................................................................

......................................................................................................................................................Unsupported Client-Side PL/SQL8 Features

Unsupported Client-Side PL/SQL8 FeaturesThe following features are supported in server-side PL/SQL8 but are not currently supported in client-side PL/SQL8:

• Object types

• Collection types

• LOB types

• Methods

• Objects as stored procedure parameters

Because these features are supported in server-side PL/SQL8, you can use them by writing stored (server-side) subprograms, and calling the subprograms from Oracle Developer. However, the last restriction requires that you decompose any object data types before returning them to the client side.

Page 410: Build Forms II Volume 1 Instructor Guide 7196298

14-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Instructor NoteDemonstration: Use the Handling of Server Errors (errh.fmb) file to demonstrate causes of Oracle server errors. Show the code in the DEMO_RAISE_ERROR procedure and then drag it to the Oracle server. Create a Before-Insert database trigger on the S_ORD table. Run the form and show an implicit update causing an error by attempting to change the primary key value. Attempt an insert and commit. Use [Display Error] to display the database trigger error. Add comments to the first line of the Key-Help trigger and remove the comments from the second line. Run the form and press [Help] to show that the explicit insert, followed by commit, also results in the database triggers firing.

Copyright Oracle Corporation, 1999. All rights reserved.

Causes of Oracle Server Errors

Base table block

Implicit DML

Trigger/PU

Explicit DML

Stored PU call

Declarativeconstraint

Databasetrigger

Storedprogram unit

Form Oracle Server

Page 411: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-15......................................................................................................................................................

......................................................................................................................................................Handling Errors Raised by the Oracle Server

Handling Errors Raised by the Oracle ServerOracle server errors can have different causes: for example, a declarative constraint or a stored program unit. You should know how to handle errors that may occur in different situations.

Causes of Oracle Server Errors

Types of DML StatementsDeclarative-constraint violations and firing of database triggers are in turn caused by DML statements. For error-handling purposes, you must distinguish between the following two types of DML statements:

Cause Error MessageDeclarative constraint Causes predefined error messageDatabase trigger Error message specified in RAISE_APPLICATION_ERROR

Stored program unit Error message specified in RAISE_APPLICATION_ERROR

Type DescriptionImplicit DML DML statements that are associated with base table blocks.

Implicit DML is also called base table DML. By default, Forms constructs and issues these DML statements.

Explicit DML DML statements that a developer explicitly codes in triggers or program units.

Page 412: Build Forms II Volume 1 Instructor Guide 7196298

14-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Instructor NoteStress that the On-Error trigger and the DBMS_ERROR_CODE and DBMS_ERROR_TEXT functions are specifically for handling errors in implicit DML. (Implicit DML consists of the INSERT, UPDATE, and DELETE statements implicitly created when changes to a form are saved.) The PL/SQL functions SQLCODE and SQLERRM are for use with explicit DML. (Explicit DML consists of the INSERT, UPDATE, and DELETE statements explicitly written into PL/SQL blocks in the form.)

Copyright Oracle Corporation, 1999. All rights reserved.

Trapping Server Errors

Base table block

On-Error:DBMS_ERROR_CODEDBMS_ERROR_TEXT

Explicit DML/PU call

When Others:SQLCODESQLERRM

Constraint

DB trigger

Stored PU

Predefinedmessage

RAISE_APPLICATION_

ERROR

RAISE_APPLICATION_

ERROR

Form Oracle Server

Page 413: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-17......................................................................................................................................................

......................................................................................................................................................Handling Errors Raised by the Oracle Server

How to Trap Different Types of Oracle Server Errors

Note: Declarative-constraint violations and database triggers may be caused by both implicit DML and explicit DML. Stored program units are always called explicitly from a trigger or program unit.

Technical NoteThe values of DBMS_ERROR_CODE and DBMS_ERROR_TEXT are not automatically reset following successful execution.

FRM-Error Messages Caused by Implicit DML Errors If an implicit DML statement causes an Oracle server error, Forms displays one of these FRM-error messages:

• FRM-40508: ORACLE error: unable to INSERT record.

• FRM-40509: ORACLE error: unable to UPDATE record.

• FRM-40510: ORACLE error: unable to DELETE record.

You can use ERROR_CODE to trap these errors in an On-Error trigger and then use DBMS_ERROR_CODE and DBMS_ERROR_TEXT to determine the ORA-error code and message.

Note: The errors reported by the DBMS_ERROR_CODE and DBMS_ERROR_TEXT built-ins are the same as what a user would see after selecting [Display Error].

Appendix F, “Handling Server-Side Errors” covers server-side error handling in more detail.

Type Error HandlingImplicit DML Use the Forms built-ins DBMS_ERROR_CODE and

DBMS_ERROR_TEXT in an On-Error trigger.Explicit DML Use the PL/SQL functions SQLCODE and SQLERRM in a

WHEN OTHERS exception handler of the trigger or program unit that issued the DML statements.

Stored program unit Use the PL/SQL functions SQLCODE and SQLERRM in a WHEN OTHERS exception handler of the trigger or program unit that called the stored program unit.

Page 414: Build Forms II Volume 1 Instructor Guide 7196298

14-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Performing DDLwith FORMS_DDL

• Syntax: FORMS_DDL (statement);

• Parameter (<=32 K):PL/SQL block, DMLor DDL statement

• Characteristics:

– Unrestricted; valid in Enter Querymode

– Statement must not contain bind-variable references

Copyright Oracle Corporation, 1999. All rights reserved.

Performing DDLwith FORMS_DDL

• Characteristics:– Statement cannot return results

directly– Use FORM_SUCCESS to check

success of statement• Hints:

– Query record group insteadFORMS_DDL with SELECT

– Call stored program unit instead ofFORMS_DDL

Page 415: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-19......................................................................................................................................................

......................................................................................................................................................Performing DDL with FORMS_DDL

Performing DDL with FORMS_DDLForms is intended primarily to perform DML operations. However, in some cases you may find it useful to issue DDL statements from a form. You can do this using the FORMS_DDL built-in function.

SyntaxFORMS_DDL(statement);

DescriptionFORMS_DDL issues dynamic SQL statements at run time, including server-side PL/SQL and DDL.

ParameterThe specified statement can be any string expression up to 32K representing a:

• PL/SQL block

• DML statement

• DDL statement

Do not end the PL/SQL block with a slash or the DML or DDL statement with a semicolon.

CharacteristicsFORMS_DDL is an unrestricted procedure that is also valid in Enter Query mode.

• The specified statement must not contain bind-variable references. However, you can concatenate the values of bind variables into the specified string.

• The statement executed using FORMS_DDL cannot return results to Forms directly.

• Use the FORM_SUCCESS built-in to check whether the statement issued using FORMS_DDL executed correctly.

Note: Consider using a query record group with a SELECT statement or calling a stored program unit, instead of executing FORMS_DDL.

Page 416: Build Forms II Volume 1 Instructor Guide 7196298

14-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Instructor NoteDemonstration: Use the Handling of Server Errors (errh.fmb) demonstration file to show the code for the CREATE_TEMP_TABLE procedure. This procedure is called from the Pre-Commit trigger. Show the code for the EXEC_PROC procedure.

Explain that the Post-Database-Commit trigger does not fire when changes are issued through the FORMS_DDL built-in, because Form Builder is not aware of such changes.

Copyright Oracle Corporation, 1999. All rights reserved.

• Example: Create temporary table

• Example: Execute procedure with givennameFORMS_DDL (‘BEGIN ‘ || p_proc_name ||‘; END; ‘);IF not FORM_SUCCESS THEN

handle_server_error(DBMS_ERROR_CODE, DBMS_ERROR_TEXT);

END IF;

FORMS_DDL (‘BEGIN ‘ || p_proc_name ||‘; END; ‘);IF not FORM_SUCCESS THEN

handle_server_error(DBMS_ERROR_CODE, DBMS_ERROR_TEXT);

END IF;

Performing DDLwith FORMS_DDL

FORMS_DDL (‘CREATE table temp (n_col number)‘);IF not FORM_SUCCESS THEN

MESSAGE (‘Table creation failed.‘);RAISE form_trigger_failure;

END IF;

Page 417: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-21......................................................................................................................................................

......................................................................................................................................................Using FORMS_DDL

Using FORMS_DDLThe following examples show how you can use the FORMS_DDL built-in function.

ExampleCreate a temporary table at the start of a post.

Pre-commit trigger at form level:BEGIN

FORMS_DDL(’CREATE table temp(n_col number)’);IF not FORM_SUCCESS THEN

MESSAGE (’Table creation failed.’);RAISE form_trigger_failure;

END IF;END;

ExampleExecute a procedure with a given name. This is useful if you want to determine dynamically which procedure should be executed in a certain situation.

PROCEDURE exec_proc (p_proc_name IN VARCHAR2)ISBEGIN

FORMS_DDL(’BEGIN ’|| p_proc_name ||’; END;’); IF not FORMS_SUCCESS THEN

handle_server_error(DBMS_ERROR_CODE,DBMS_ERROR_TEXT);END IF;

END;

Note: If the FORMS_DDL built-in fails, Forms sets the DBMS_ERROR_CODE and DBMS_ERROR_TEXT built-ins. Therefore, you can handle Oracle server errors using the HANDLE_SERVER_ERROR procedure discussed earlier.

Always test the SYSTEM.FORM_STATUS before calling the FORMS_DDL built-in.

Page 418: Build Forms II Volume 1 Instructor Guide 7196298

14-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Summary• Oracle server features useful for Form

Builder

• Dealing with PL/SQL code

• PL/SQL8 supported and unsupportedfeatures

• Trap errors raised by the Oracle server

– Implicit DML

– Explicit DML or stored program units

• Performing DDL with FORMS_DDL

Page 419: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-23......................................................................................................................................................

......................................................................................................................................................Summary

Summary

Oracle Server Features Useful for Form Builder• Declarative integrity constraints

• Stored program units

• Database triggers

• DDL

Dealing with PL/SQL Code• Store PL/SQL code in

- Oracle server

- Library

- Form

• Call PL/SQL code from

- Database trigger

- Form trigger

• Application partitioning

Handling Errors Raised by the Oracle Server• Causes: declarative constraints, database triggers, stored program units

• Trap implicit-DML errors by using DBMS_ERROR_CODE and DBMS_ERROR_TEXT in an On-Error trigger

• Trap explicit DML errors and stored program unit errors by using SQLCODE and SQLERRM in a WHEN OTHERS exception handler

Performing DDL with FORMS_DDL Parameter is a string (less than or equal to 32 K) representing a PL/SQL block or DML or DDL statement.

Page 420: Build Forms II Volume 1 Instructor Guide 7196298

14-24 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 14 Overview

This practice covers the following topics:

• Handling errors caused by declarative-constraint violation

• Handling errors caused by storedprogram units

Page 421: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-25......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 14

Practice Session Overview: Lesson 14This practice guides you through handling Oracle server errors.

Practice Contents• Handle errors caused by declarative-constraint violations.

• Handle errors caused by stored program units.

Page 422: Build Forms II Volume 1 Instructor Guide 7196298

14-26 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Practice 141 Handle errors caused by declarative constraints violations.

a Open the CUSTOMERS form module. This form is based on the S_CUSTOMER table. A primary key constraint is declared on the column Id.

b Run the CUSTOMERS form and try to add a new customer with an existing customer number. Assign the new record an Id of 201 and a name of Dummy. What FRM-error message do you get? What Oracle server error message do you get? (Select [Display Error] to see the message.)

c Which trigger must you use to trap error messages caused by violation of this constraint?

d Which built-in functions must you use to get error messages caused by violations of this constraint?

e Trap and replace the default constraint-violation message with your own message. Use the function STRIP_CONSTRAINT_NAME to detect which constraint was violated. You can import the pr14_1e1.txt file to create the function and the pr14_1e2.txt file to replace the existing code in the trigger.

Note: The function STRIP_CONSTRAINT_NAME accepts a complete server error message, strips away the error number and prefix, and returns a more readable error message. The details of this function are covered in Appendix F, “Handling Server Side Errors.”

f Save and compile the form. Try to insert a duplicate Id value, and note the displayed message.

If you have time...

2 Handle errors caused by stored program units.

a Open the CUSTOMERS form module.

b Implement immediate primary-key checking in the CUSTOMERS form by creating a procedure called CHECK_PK_CUST. Call this procedure from an appropriate trigger. You can import the pr14_2b1.txt file to create the procedure and the pr14_2b2.txt file to replace the existing code in the trigger.

c Run the form and try to add a new customer with an existing customer number. Enter an Id value of 201 and press [Next Item] to fire the When-Validate-Item trigger. What error do you get?

Page 423: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 14-27......................................................................................................................................................

......................................................................................................................................................Practice 14

d Drag the CHECK_PK_CUST procedure to the database under your user account. Delete the local CHECK_PK_CUST procedure in your form.

e Examine the stored procedure CHECK_PK_CUST in the Stored Program Unit editor. Explain the errors that are shown. Correct the errors by using RAISE_APPLICATION_ERROR.

f Run the form and try to add a new customer with an existing customer number. What FRM-error messages do you get? What Oracle server error message do you get? (Select [Display Error] to see the message.)

g Which trigger must you use to trap error messages caused by stored procedures?

h Which built-in functions must you use to get error messages caused by stored procedures?

i Trap and replace the default error message with your own message. Use the function STRIP_APPLICATION_ERROR to get the application-error text. You can import the pr14_2i1.txt file to create the function and the pr14_2i2.txt file to replace the existing code in the trigger.

j Save, compile and test the form.

Page 424: Build Forms II Volume 1 Instructor Guide 7196298

14-28 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 14: Using Server Features in Form Builder

Page 425: Build Forms II Volume 1 Instructor Guide 7196298

................................

15

Using ReusableComponents

Page 426: Build Forms II Volume 1 Instructor Guide 7196298

15-2 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Instructor NoteTopic TimingLecture 25 minutes

Practice 45 minutes

Total 70 minutes

Copyright Oracle Corporation, 1999. All rights reserved.

Objectives

After completing this lesson, you shouldbe able to do the following:

• List the reusable components

• Include the calendar object in anapplication

Page 427: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-3......................................................................................................................................................

......................................................................................................................................................Introduction

Introduction

OverviewIn this lesson, you will learn about the reusable components that are available with Oracle Developer. You will learn how these components can fit into any application.

ObjectivesAfter completing this lesson, you should be able to do the following:

• List the reusable components

• Include the calendar object in an application

Page 428: Build Forms II Volume 1 Instructor Guide 7196298

15-4 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Instructor NoteMany of the demonstrations contain objects and techniques that the students may want to copy. They may reuse the icons, images, ActiveX controls, menus, and all other files provided in the demonstrations in their own applications. They may also include the components within a product of their own, including a commercial product that they sell to third parties. There is no license or fee required for any such reuse.

These components are provided as is. Oracle Corporation makes no warranty as to their correctness or their fitness for any particular purpose. If they reuse any of these components in their own applications, whether modified or unmodified, they do so entirely at their own risk. Oracle Corporation does not provide any support for these components.

ActiveX (OCX) controls are provided solely for demonstration purposes. Oracle does not support these controls and makes no guarantee as to their reliability. For their own applications, Oracle strongly recommends that they purchase supported, commercial controls such as those supplied by our Open Tools Initiative partners.

Oracle Corporation retains all copyrights on these demonstrations, components, icons, ActiveX controls, and images.

Copyright Oracle Corporation, 1999. All rights reserved.

Reusable Components

I’m the calendar

I’m the navigator

Page 429: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-5......................................................................................................................................................

......................................................................................................................................................Reusable Components

Reusable ComponentsOracle Developer contains a complete set of demonstrations that illustrate the power and productivity of the product. These demonstrations contain many tips and techniques that you can copy and use in your own applications.

Reusable Component DefinitionA reusable component is a generic object (object group, block, PL/SQL library, and so on), that you can reuse in all your applications. You can create your own reusable components (code and object) by using the generic programming characteristics.

This release also includes a number of reusable components that enable you to easily and rapidly build applications that provide power and performance while conforming to GUI standards. These components are customizable.

Technical NoteSome of the demonstrations and reusable components require PL/SQL features that are supported only in Oracle7 release 7.3 or later. If your database does not support these features, certain packages will be created but marked as Invalid. If you try to run a demonstration that requires these objects, you will see a warning that the packages are invalid.

Page 430: Build Forms II Volume 1 Instructor Guide 7196298

15-6 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Instructor NoteDemonstration: Use the Orders (Orders.fmb) to demonstrate the implementation of the calendar class and the picklist class.

Navigate to the DATE_ORDERED item and press [F9] to display the calendar.

Click the PRODUCT_LOV button to display the picklist form.

Copyright Oracle Corporation, 1999. All rights reserved.

Reusable Components List

• ActiveX controls

• Calendar class

• Navigator class

• Online Help class

• Picklist class

• Wizard class

• Drag & Drop PL/SQL Library

• Form Builder Utilities PL/SQL Library

Page 431: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-7......................................................................................................................................................

......................................................................................................................................................Reusable Components List

Reusable Components ListThe reusable components include:

Reusable Component Description

ActiveX controls An ActiveX control is a stand-alone software component that you can include in your Form Builder application. Five ActiveX controls are shipped with Oracle Developer: Image, Sound, Spread Table, Tabsheet, and a Video object.

Calendar class This component enables you to add a calendar or date list of values to your application.

Navigator class This component enables you to add an Explorer-style interface to your application. This component is very similar to Object Navigator.

Online help class This component enables you to easily add a Help system to an application, and to provide functionality that mimics the Windows Help system. It allows you to provide context- sen-sitive help to end users. The help text is stored in the data-base so that it can be easily shared among all users, making updates and changes immediately available to everybody.

Picklist class This component enables you to easily add a picklist or chooser-style interface to an application, and to provide functionality that mimics the picklists of wizards and other dialogs.

Wizard class This component enables you to easily add a wizard-style interface to an application, and to provide functionality that mimics the wizards of the Oracle Developer builders and other Windows products.

Drag and drop PL/SQL library

This PL/SQL library provides simple procedures to help implement drag and drop or direct manipulation interfaces.

Form Builder utilities PL/SQL library

This PL/SQL library contains a procedure to write out the contents of a block.

Page 432: Build Forms II Volume 1 Instructor Guide 7196298

15-8 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Copyright Oracle Corporation, 1999. All rights reserved.

Reusable Components List

• Conversion PL/SQL Library

• Window System Interface PL/SQLLibrary

• Standard Object Library

• Oracle Applications Object Library

• Standard Menus

• Sample Icons

Page 433: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-9......................................................................................................................................................

......................................................................................................................................................Reusable Components List

Reusable Component Description

Conversion PL/SQL library This PL/SQL library contains procedures to perform complex conversions.

Window system interface PL/SQL library

This PL/SQL library contains many commonly used routines specific to the Windows environment. The utility consists of a PL/SQL library and a Windows dynamic-link library (DLL) and can be used from any of the Oracle Developer builders.

The PL/SQL library uses the ORA_FFI package and can be used as a model for creating your own DLL calls. The utility FFI_GEN is also available to help you generate a PL/SQL interface to DLLs.

Standard object library The standard object library, stndrd20.olb, contains stan-dard classes and visual attribute groups to help you build applications that conform to a standard look and feel. The standards can be used as provided, or you may choose to extend or modify them for your own requirements. These standards are designed to provide a Windows look and feel. Where appropriate, the objects in the library are set as Smart-Classes so that they can be readily applied to the objects that you create in your forms.

Oracle applications object library

This object library, appsstds.olb, contains property classes and visual attribute groups that enable you to build modules that have the same look and feel as OracleApplications. These standards have a Windows look and feel, but they have also been designed for maximum portabil-ity.

Standard menus These demonstrations include a number of standard menus that you may want to reuse and customize.

Sample icons Sample icons can be found in ORACLE_HOME\TOOLS\DEVDEM60\DEMO\BIN\ICON. This directory includes all of the icons used in the demon-strations and sample menus.

Page 434: Build Forms II Volume 1 Instructor Guide 7196298

15-10 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Copyright Oracle Corporation, 1999. All rights reserved.

The Calendar Class

Copyright Oracle Corporation, 1999. All rights reserved.

Creating a Calendar

To create a calendar:

1. Copy or make the Calendar Object Group a subclass.

2. Attach the PL/SQL library CALENDAR.PLL.

3. Create a Key-Listval trigger.

4. Call Date_LOV.Get_Date.

Page 435: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-11......................................................................................................................................................

......................................................................................................................................................The Calendar Class

The Calendar ClassThis component enables you to easily add a calendar or date list of values to an application. The Calendar window automatically displays the calendar according to the NLS settings that are currently in effect, adjusting the start of the week (for example, Sunday in the United States, Monday in Western Europe) and the month and day names accordingly.

Creating a CalendarTo create a calendar, follow the steps below:

1 Open the stndrd20.olb object library. From the Components page, copy or subclass the Calendar object group.

2 Attach the PL/SQL library calendar.pll, which contains the Date_LOV package, to your module.

3 Create a Key-Listval trigger on the date item for which you would like to use the Date List of Values window. Add code to display the calendar using the Date_LOV package.

4 If you want the end user to be able to close the Date List of Values window by clicking the WindowClose button in the title bar, create a form-level When-Window-Closed trigger.

The calendar appears whenever the end user invokes a list of values for the date item. A single calendar can be reused on many different date items. Simply create a Key-Listval trigger for each item.

Page 436: Build Forms II Volume 1 Instructor Guide 7196298

15-12 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Copyright Oracle Corporation, 1999. All rights reserved.

Calendar Object Group Content

Page 437: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-13......................................................................................................................................................

......................................................................................................................................................Calendar Object Group Content

Calendar Object Group ContentThe component contains many different Form Builder objects. You can customize those objects for your specific application.

The BlocksThe calendar object contains two blocks:

• Date_Control_Block: This block contains the buttons that control which month and year is displayed.

• Date_Button_Block: This block contains the buttons that represent each day of the month.

The CanvasThe calendar class contains a content canvas named Date_Lov_Canvas. This canvas contains all the items from both blocks.

The WindowThe calendar class contains a window named Date_Lov_Window. This window is used to display the Date_Lov_Canvas.

The Visual AttributesThe calendar class contains three visual attributes:

• Date_Normal_VA: This visual attribute contains the attributes for a date button that is displayed normally.

• Date_Selected_VA: This visual attribute contains the attributes for a date button that is displayed as selected.

• Date_Weekend_VA: This visual attribute contains the attributes for a date button that is displayed as a weekend day.

Page 438: Build Forms II Volume 1 Instructor Guide 7196298

15-14 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Copyright Oracle Corporation, 1999. All rights reserved.

Built-in for Manipulatingthe Calendar

Use Date_LOV.Get_Date to display thecalendar

• Syntax

• Exampledate_lov.get_date(sysdate,’s_ord.date_ordered’,240,

60,’Order Date’,’OK’,’Cancel’,TRUE,FALSE,FALSE);

date_lov.get_date(sysdate,’s_ord.date_ordered’,240,

60,’Order Date’,’OK’,’Cancel’,TRUE,FALSE,FALSE);

date_lov.get_date( display_date,return_item,

v_x_pos,v_y_pos,v_title,v_ok,

v_cancel,v_highlight,v_autoconfirm,v_autoskip );

Page 439: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-15......................................................................................................................................................

......................................................................................................................................................Built-in for Manipulating the Calendar

Built-in for Manipulating the CalendarTo use the calendar class, you have to attach a PL/SQL library called calendar.pll. This library contains a package called DATE_LOV. This package contains routines that the developer uses to interact with the component.

Date_LOV.Get_Date ProcedureThis procedure displays the calendar with the month and year specified in the Display_Date argument. The day of the month is displayed with bold numbers. The date chosen by the end user is returned to the item specified by the Return_Item argument.

. . .PROCEDURE Date_LOV.Get_Date(display_date DATE, return_item VARCHAR2, v_x_pos NUMBER := 0, v_y_pos NUMBER := 0, v_title VARCHAR2 := ’Date List of Values’, v_ok VARCHAR2 := ’OK’, v_cancel VARCHAR2 := ’Cancel’, v_highlight BOOLEAN := TRUE, v_autoconfirm BOOLEAN := TRUE, v_autoskip BOOLEAN := FALSE );. . .

Argument Description

display_date The date to display when the Date List of Values window first appears

return_item The name of the block and item to which to return the chosen date

v_x_pos Specifies the X coordinate of the Date List of Values window

v_y_pos Specifies the Y coordinate of the Date List of Values window

v_title Title to display in the Date List of Values window

v_ok Label for the OK button

v_cancel Label for the Cancel button

v_highlight Specifies that weekend days appear in a different color

v_autoconfirm Specifies that the date immediately be returned when the end user clicks a day

v_autoskip Specifies that the input focus moves to the next item in sequence

Page 440: Build Forms II Volume 1 Instructor Guide 7196298

15-16 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Copyright Oracle Corporation, 1999. All rights reserved.

Summary

• Reusable components• Calendar class:

– Create a calendar class– Built-in to manipulate the calendar

class

Page 441: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-17......................................................................................................................................................

......................................................................................................................................................Summary

Summary

Reusable Components• The purpose of a reusable component

• Reusable components list

The Calendar Class• Create a calendar

• Calendar Object Group content

• Built-in for manipulating the calendar

Page 442: Build Forms II Volume 1 Instructor Guide 7196298

15-18 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Copyright Oracle Corporation, 1999. All rights reserved.

Practice 15 Overview

• Creating a picklist to display and selectthe products available

• Adding a calendar on items:

– s_ord.date_ordered

– s_ord.date_shipped

Page 443: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-19......................................................................................................................................................

......................................................................................................................................................Practice Session Overview: Lesson 15

Practice Session Overview: Lesson 15This practice guides you through some useful reusable components.

Practice Contents• Create a picklist to display and select the products available.

• Add a calendar on the S_ORD.DATE_ORDERED and S_ORD.DATE_SHIPPED items.

Page 444: Build Forms II Volume 1 Instructor Guide 7196298

15-20 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components

Practice 151 Create a picklist by using the picklist class. This picklist enables the end

user to make selections from two lists, one showing the products available and the other showing the objects selected.

Note: To reuse the code you wrote in practice 10 question 2, we have provided most of the code by way of an object library.

a Create a new form module.

b Open the Form_Builder_II.olb object library.

c From the Picklist Basic tab page, drag and copy the PICKLIST_BASIC object group to the Object Groups node in your module and release it. Copy the object group, do not subclass the object group. This object group contains a canvas, a window, and a block. The block contains two buttons, with the code to return the products selected in the picklist to the orders form.

d From the Picklist Class tab page, copy the PICKLIST object group into your new form module. This object group contains all the objects to implement the picklist. Organize the CONTROL block so it is the last block in sequence.

e Attach the picklist.pll library to your form.

f Create a When-New-Form-Instance trigger to populate the List_In. Create an instance of the picklist with the CREATE_PICKLIST procedure. Populate the List_in, using the POPULATE_PICKLIST_WITH_QUERY function, with the results of a query that returns the IDs, names, and suggested prices from the S_PRODUCT table. (Retrieve the list of products excluding the products that exists in the S_ITEM block. You should use the global variable from practice 11.) Select the first element in the list by using the SET_PICLIST_SELECTION procedure, and display both lists by using the DISPLAY_PICKLIST procedure. You can import the pr15_1f.txt file.

g Save your form using the filename PickList.fmb. Compile your form.

h Open the ORDERS form module.

i Modify the When-Button-Pressed trigger for the CONTROL.PRODUCT_LOV_BUTTON so that it calls your new form module. Comment out the old CALL_FORM line, it called an LOV from an earlier lab.

Page 445: Build Forms II Volume 1 Instructor Guide 7196298

Oracle Developer: Build Forms II 15-21......................................................................................................................................................

......................................................................................................................................................Practice 15

j Save, run, and test your form.

If you have time ...

2 In the ORDERS form, add a calendar on the S_ORD.DATE_ORDERED item and S_ORD.DATE_SHIPPED item.

a From the calendar page of the Form_Builder_II.olb object library, copy the calendar object group.

b Attach the PL/SQL library calendar.pll, which contains the Date_LOV package, to your module.

c Create a Key-Listval trigger on the date ordered item. Add code to display the calendar using the Date_LOV package. You can import the pr15_2c.txt file.

d Create a Key-Listval trigger on the date shipped item. Add code to display the calendar using the Date_LOV package.You can import the pr15_2d.txt file.

e Save, run, and test your form.

Page 446: Build Forms II Volume 1 Instructor Guide 7196298

15-22 Oracle Developer: Build Forms II......................................................................................................................................................

......................................................................................................................................................Lesson 15: Using Reusable Components