Working with EXIT_FORM, CLOSE_FORM, and NEW_FORM in Oracle Forms

Oracle Forms applications often consist of multiple forms that interact with each other. Users may need to exit a form, close it without committing changes, or navigate to another form. For these purposes, Oracle provides built-in procedures such as EXIT_FORM, CLOSE_FORM, and NEW_FORM. Each of these procedures serves a unique role in form navigation and transaction handling. Knowing when and how to use them is crucial for building stable and user-friendly Oracle Forms applications.

In this tutorial, we will explore these three built-ins in detail, understand their differences, and see practical examples of how to use them effectively.


EXIT_FORM in Oracle Forms

The EXIT_FORM built-in is used when you want to terminate the current form session and optionally commit or rollback any pending changes. This is the most common way of exiting a form.

Key Points

  • Exits the current form and returns to the calling form or menu.
  • Can commit changes if specified.
  • Can rollback changes if the user chooses not to save.

Syntax

EXIT_FORM([options]);

Options Available

  • NO_VALIDATE โ€“ Exits immediately without validation.
  • ASK_COMMIT โ€“ Prompts the user to save changes if there are uncommitted transactions.
  • DO_COMMIT โ€“ Commits the changes automatically before exiting.

Example

BEGIN
   EXIT_FORM(ASK_COMMIT);
END;

In this case, the user will be prompted whether they want to commit changes before leaving the form.


CLOSE_FORM in Oracle Forms

The CLOSE_FORM built-in is used when you want to close a form that was opened using the OPEN_FORM procedure. Unlike EXIT_FORM, this built-in does not necessarily terminate the Oracle Forms session; it simply closes the specified form.

Key Points

  • Only works on forms opened with OPEN_FORM.
  • Does not exit the entire application; control returns to the calling form.
  • You can close a specific form by passing its name.

Syntax

CLOSE_FORM(form_name);

Example

BEGIN
   CLOSE_FORM('EMPLOYEE_FORM');
END;

This will close the EMPLOYEE_FORM if it was opened previously with OPEN_FORM.

Difference from EXIT_FORM

  • EXIT_FORM exits the current form completely (with commit/rollback options).
  • CLOSE_FORM closes a child form and returns to the parent form without affecting transactions of the parent form.

NEW_FORM in Oracle Forms

The NEW_FORM built-in is used when you want to navigate from one form to another, replacing the current form with a new one. Unlike OPEN_FORM, this does not keep the first form open in memoryโ€”it discards it.

Key Points

  • Loads a new form and discards the current one from memory.
  • Does not return to the calling form.
  • Useful when you want to switch forms in a sequence.

Syntax

NEW_FORM(form_name);

Example

BEGIN
   NEW_FORM('DEPARTMENT_FORM');
END;

This will close the current form and directly open the DEPARTMENT_FORM.

Important Notes

  • Any unsaved changes in the current form may be lost unless committed beforehand.
  • Control never returns to the original form once the new form is loaded.

Comparing EXIT_FORM, CLOSE_FORM, and NEW_FORM

To better understand when to use each built-in, let us compare them side by side:

Built-inPurposeBehaviorUse Case
EXIT_FORMExit from current form with commit/rollback optionsReturns to the menu or calling formWhen you want to leave the form session
CLOSE_FORMClose a form opened with OPEN_FORMReturns to parent formWhen you want to close a secondary or child form
NEW_FORMLoad a new form and discard the current oneDoes not return to old formWhen you want to replace the current form with another

Practical Scenarios

Scenario 1: Exiting with Confirmation

If you want to ensure the user does not lose data, use:

EXIT_FORM(ASK_COMMIT);

This will prompt them to save before exiting.

Scenario 2: Closing a Child Form

Suppose a user opened the EMPLOYEE_FORM from the MAIN_MENU using OPEN_FORM. To close it and return to MAIN_MENU:

CLOSE_FORM('EMPLOYEE_FORM');

Scenario 3: Navigating to a New Form

If the user is in the LOGIN_FORM and you want to switch to the DASHBOARD_FORM after authentication:

NEW_FORM('DASHBOARD_FORM');

Best Practices

  1. Use EXIT_FORM with ASK_COMMIT โ€“ This prevents accidental loss of data.
  2. Use CLOSE_FORM only for child forms โ€“ Avoid using it for main forms.
  3. Use NEW_FORM for sequential workflows โ€“ Best for scenarios like login to main dashboard navigation.
  4. Validate before navigating โ€“ Ensure data integrity by validating inputs before committing or closing.
  5. Always handle exceptions โ€“ Wrap these built-ins in exception blocks to avoid abrupt termination.

Conclusion

Working with EXIT_FORM, CLOSE_FORM, and NEW_FORM in Oracle Forms is essential for controlling user navigation and data management. Each built-in serves a different purposeโ€”EXIT_FORM is for leaving a form with commit/rollback control, CLOSE_FORM is for closing child forms opened via OPEN_FORM, and NEW_FORM is for replacing the current form with a new one. By using them correctly, you can ensure smooth transitions between forms, protect user data, and build more user-friendly Oracle Forms applications.

Get more Vinish.dev tutorials on Google

See my articles more often when you search Google.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted