A user-named subprogram is a named PL/SQL function or procedure that you write in a form, menu, or library module. Although triggers are the primary way to add programmatic control to an Oracle Forms application, user-named subprograms supplement triggers by allowing you to reuse code without having to enter it in multiple triggers.
Unlike triggers, which execute in response to application events, a user-named subprogram must be called explicitly within your application. A user-named subprogram that you define in a form module can be called from any trigger in that module.
Just as Built-in subprograms save you the trouble of writing code for common functions like navigation and database interaction, user-named subprograms provide a way to reuse application-specific code that you write yourself.
If you find yourself writing the same lines of code in more than one trigger or menu item command, you should consider writing a user-named subprogram instead.
In most applications, operators can perform the same operation in more than one way, and from more than one window or menu. For example, an order-entry application might allow an operator to calculate an order total by pressing a key, clicking a button, or selecting a menu item from a menu. Without a user-named subprogram, you would need to write the same calculation formula in a Key trigger, a When-Button-Pressed trigger, and a menu-item command.
A better way is to write the calculation formula once in a user-named subprogram. You can give the subprogram a meaningful name, say, calculate_totals, and then call it by name from any trigger or menu item in which the formula is required.
Like Built-in subprograms, user-named subprograms can take parameters. When you declare the parameters for a subprogram, you specify their data type, mode, and default value, if any. By using parameters to pass actual values, you can create more generic subprograms that use values that are supplied programmatically at runtime.