Previous | Table of Contents | Next

Page 388

block, executing a query, or displaying a message. Appendix A, "Built-In Subprograms," contains the names and descriptions of the subprograms available for use by the developer. Some of the subprograms can be considered a complete PL/SQL statement. Execute_query is an example of a subprogram that can be used as a complete statement. Other subprograms must be followed by an expression that supplies a value to the subprogram. The go_block subprogram is an example of this type. It must have the name of a block following the function name in order to know where to move the input focus. The subprogram name or subprogram name and expression must end with a semi-colon.

FIG. 15.6
The PL/SQL editor
displaying the block
one items.


In every master-detail form I create, I use two triggers that contain the go_block subprogram. These triggers are the Key-entqry and a When-button-pressed trigger. These triggers redefine the enter-query function key as well as the Query button. The triggers are defined so that the input focus moves to block one before placing the form into the query mode. Entering a query while the input focus is in a detail block causes the query to be performed in the detail block. I do not allow users to query detail blocks. If they did, they would simply get a subset of the block's records. I believe that when a user clicks the query button on a master-detail form they intend to query the master record the majority of the time. Placing the go_block subprogram in the triggers saves the form users from having to manually move the cursor to block one. Figure 15.7 displays the modified When-Button-Pressed trigger used for the Query button. Designer created the button's trigger and PL/SQL code at the time the button palette was created.

NOTE
You should modify the When-button-pressed trigger for the Query button and add a Key-entqry trigger to the empch15.fmb form. This will allow you to see the effect of the triggers. Be sure to perform queries before making the changes.n

Figure 15.8 shows the PL/SQL code for the form level Key-entqry trigger that also needs to be created. This trigger fires whenever the F7 function key is clicked . Because it is a form-level trigger, the location of the cursor does not determine whether it will be fired.

These examples were used to illustrate how the behavior of a form can be modified by the use of triggers that use subprograms. Be sure to look at Appendix A to see the various subprograms and restrictions on their usage.

Page 389


Fig. 15.7
The When-Button-
Pressed trigger for the
Query button after a
go_block subprogram
was added.




Fig. 15.8
The form-level trigger
Key-entqry used to
always place block one
in the query mode
when the F7 function
key is clicked.



Using System and Global Variables

At times, it is important to control or monitor system parameters. This can be done by using system variables. In Figure 15.7, the if condition uses a system variable called mode to determine the current mode of the form. The trigger places the form in the query mode if the form is currently in the input or update mode. It executes the query if it is in the query mode. If the trigger had performed the enter_query subprogram when the form was in the query mode, an error would have occurred. In Figure 15.7, the system variable is used to prevent the error from occurring.

Another very useful system variable is message_level. All Oracle errors have a numeric severity rating. The lowest rating is 0 and the highest level is 25. The messages on the lower end of the scale are generally informational in nature. They do not usually affect the data or cause problems. It is convenient to occasionally shut these messages off so the user does not see them. Raising the value of the system's message level causes Forms Runtime to stop displaying certain error messages. Oracle does not display messages that have a rating lower than the value of the system message level.

TIP
I have several applications that use PL/SQL fired from a trigger to create records. After the records are inserted into the database, I issue a commit to save the records permanently. A message appears

Page 390

continued

stating No changes were pending on the form. This message tells the user the form did not contain modifications and the commit did not affect form records. This is true, but it is useless information. I do not like users to see this message, so I change the message level to 20 before the commit command and return it to 0 immediately after the command.

The available system variables and their descriptions are contained in Appendix A, "Built-in Subprograms." Figure 15.9 contains several examples of system variables. The syntax requires the variable to be proceeded by the keyword system. A colon precedes the expression because it is a nondatabase field.



FIG. 15.9
Examples of system
variable expressions.


The local variables and items created for a form are only available as long as the form is active. As soon as the form is closed, the area of memory where the values are stored is purged. It is a very common need to keep values available after the application is closed. For instance, when you call another application, you may want to carry the primary key to the new application so the application will know what records to retrieve.

Values can be placed in memory for the life of the session through the use of global variables. Global variable expressions consist of the variable name preceded by the keyword global. The variable does not have to be assigned a character type. It will assume the character type of the value it is assigned. Later in this chapter, you'll see a security scheme that contains global variables. They are used to carry security values to the applications in a system.

tip
When you use global variables in a system that calls a number of forms, it is good practice to initialize all global variables in the start-up application. This initialization can consist of assigning a null value to the variable. If you reference the global variable in a trigger and it has never been referenced, Forms Runtime will issue an error message. This procedure will eliminate the possibility of the error.

Previous | Table of Contents | Next