There are two Built-in subprograms that can be used to display an LOV:
The LIST_VALUES procedure displays an LOV if the following runtime conditions exist:
The LIST_VALUES procedure is often called from a When-New-Item-Instance trigger to display an LOV when the end user or the application navigates to a text item that has an attached LOV.
The LIST_VALUES procedure can also be called from a Key-LISTVAL trigger. This trigger fires when an end user presses [List of Values]. By calling LIST_VALUES from a Key-LISTVAL trigger, you can augment default form processing for the [List of Values] key.
Recall that Oracle Forms displays an LOV by default when the end user presses [List of Values] in a text item to which there is an LOV attached. You can duplicate this default functionality by writing a Key-LISTVAL trigger that calls the LIST_VALUES procedure:
Key-LISTVAL Trigger:
List_Values;
This trigger, as written, is of little value since it merely duplicates default Oracle Forms functionality. However, using a Key-LISTVAL trigger allows you to add subsequent PL/SQL statements that execute after the LOV is displayed, but before Oracle Forms returns to the normal event sequence.
In the following example, an IF statement is added to the previous trigger:
Key-LISTVAL Trigger:
List_Values;
IF :customer.id IS NULL THEN
Go_Item ('customer.id');
END IF;
In this example, when an end user enters the text item and presses [List of Values], Oracle Forms displays the attached LOV, in this case, a List of customer names. After the end user selects a customer from the List, the trigger navigates to another item if the value of one of the return items (customer.id) is NULL.
Remember that end users can dismiss an LOV without making a selection; any PL/SQL statements that execute after the LIST_VALUES procedure should be written accordingly.
The SHOW_LOV function displays an indicated LOV at the specified display coordinates. Unlike LIST_VALUES, SHOW_LOV does not require that the LOV be attached to a text item. For example, you can use SHOW_LOV to allow end users to invoke an LOV by clicking a button or selecting a menu item.
The SHOW_LOV function is a BOOLEAN function that returns TRUE if the end user makes a selection from the LOV and FALSE if the end user cancels the LOV without making a selection.
The simplest way to call the SHOW_LOV function is to assign the return value of SHOW_LOV to a dummy variable, as shown in the following When-Button-Pressed trigger.
When-Button-Pressed Trigger:
DECLARE
dummy BOOLEAN;
BEGIN
dummy := Show_LOV('my_lov',15,10);
END;
The display coordinates specified in the SHOW_LOV argument List (15 and 10) override the LOV's default coordinates.
If you want to take some action based on whether the end user made a selection or canceled the LOV, you could structure your trigger as follows:
When-Button-Pressed Trigger:
IF Show_LOV('my_lov',15,10) THEN
/* the end user made a selection and Oracle Forms returned
** the selected column values to the corresponding
** return items so do something here
*/
Message('Good Choice!');
ELSE
/* The end user canceled the LOV without making a selection
** so do something else instead
*/
Message('Please enter a value.');
END IF;
In this example, the SHOW_LOV function is used as the test condition for an IF-THEN-ELSE construct. If the end user selects a choice from the List, the condition is TRUE and Oracle Forms executes the first set of conditional statements.
If the end user cancels the LOV without making a selection, the condition is FALSE and Oracle Forms executes the second set of conditional statements.