2015年3月19日 星期四

[Oracle]Oracle Form 觸發器執行順序

以下來源網址:http://blog.csdn.net/papaya14/article/details/7638428
-----------(以下僅簡體轉正體,未更動內容一絲分毫)

Form的Trigger的優先順序是從item,到block,到form級別,如果另外設置Execution Hierarch屬性(override,before,after),則按照設置後的循序執行。如果是override的話,則執行完這個級別的觸發器,就不往上執行了,before就是執行完這個級別的觸發器後,如果上一個級別也有這個觸發器的話,繼續去執行,after就是先去執行上一個級別的觸發器,然後再回來執行。感覺觸發器比較難理解的還是每一種觸發器觸發的時間,和在開發中怎麼使用。目前瞭解的就是pre-…,when-new-…-instance,when-…-validate,post-query和幾個on-…觸發器

觸發器執行順序:

1.當打開FORM時:
(1)PRE-FORM
(2)PRE-BLOCK(BLOCK級)
(3)WHEN-NEW-FORM-INSTANCE
(4)WHEN-NEW-BLOCK-INSTANCE
(5)WHEN-NEW-RECORD-INSTANCE
(6)WHEN-NEW-ITEM-INSTANCE
2.當填寫一行記錄完成後,游標移動到下一條記錄的時候:
(1)WHEN-VALIDATE-RECORD
(只將填寫的記錄與資料庫中已存在的記錄作唯一性的驗證,如果只是頁面上的資料重複而資料庫中沒有與其重複的值則不會報錯.)
(2)WHEN-NEW-RECORD-INSTANCE
(3)WHEN-NEW-ITEM-INSTANCE
3.當點擊“保存”時
(1)WHEN-VALIDATE-RECORD
(將頁面上的所有資料提交到資料庫,若頁面上有重複的資料,則提交第一次時成功但只是將資料先寫到資料庫中一類似臨時表的地方,在提交第二條重複記錄的時候報錯,執行交易復原,原來執行成功的指令也將被撤銷)
(2)PRE-INSERT
(3)ON-INSERT
(4)POST-INSERT
(5)POST-FORMS-COMMIT
(6)PRE-BLOCK(BLOCK級)
(7)KEY-COMMIT
(8)WHEN-NEW-ITEM-INSTANCE
4.當游標移動到當前資料塊中已經顯示的行上時:
(1)WHEN-REMOVE-RECORD
(2)WHEN-NEW-RECORD-INSTANCE
(3)WHEN-NEW-ITEM-INSTANCE
當在該行上的不同ITEM移動時:
(4)WHEN-NEW-ITEM-INSTANCE
5.當要進行修改時(在記錄中的某個項上進行了修改時):
(1)ON-LOCK
6.在修改完成後進行保存時:
(1)WHEN-VALIDATE-RECORD
(2)PRE-UPDATE
(3)ON-UPDATE
(4)POST-FORMS-COMMIT
(5)PRE-BLOCK(BLOCK級)
(6)KEY-COMMIT
(7)WHEN-NEW-ITEM-INSTANCE
7.刪除一條記錄時:
(1)ON-LOCK
(2)WHEN-REMOVE-RECORD
(3)KEY-DELREC
(4)WHEN-NEW-RECORD-INSTANCE
(5)WHEN-NEW-ITEM-INSTANCE
8.F11查詢過程:
(1)WHEN-CLEAR-BLOCK
(2)WHEN-NEW-RECORD-INSTANCE
(3)WHEN-NEW-ITEM-INSTANCE
在輸入查詢準則後點CTRL+F11:
(4)PRE-QUERY
(5)WHEN-CLEAR-BLOCK
(6)POST-QUERY
(7)WHEN-NEW-RECORD-INSTANCE
(8)WHEN-NEW-ITEM-INSTANCE
9.CRRL+F11:
(1)WHEN-CLEAR-BLOCK
(2)PRE-QUERY
(3)WHEN-CLEAR-BLOCK
(4)POST-QUERY(每查一條記錄,觸發一次)
(5)WHEN-NEW-RECORD-INSTANCE
(6)WHEN-NEW-ITEM-INSTANCE
10.從查詢狀態(F11)轉為輸入狀態(F4)時:
(1)WHEN-CLEAR-BLOCK
(2)KEY-EXIT
(3)WHEN-NEW-RECORD-INSTANCE
(4)WHEN-NEW-ITEM-INSTANCE
11.手電筒查詢過程:
(1)QUERY_FIND(BLOCK級)
輸入查詢準則後,點擊“查詢”按鈕:
(2)WHEN-CLEAR-BLOCK
(3)PRE-QUERY
(4)WHEN-CLEAR-BLOCK
(5)POST-QUERY
(6)WHEN-NEW-RECORD-INSTANCE
(7)WHEN-NEW-ITEM-INSTANCE
12.點擊“New”時:
(1)WHEN-NEW-RECORD-INSTANCE
(2)WHEN-NEW-ITEM-INSTANCE
13.點擊“EditField”時:
(1)KEY-EDIT
14.點擊“WindowHelp”時:
(1)KEY-HELP
15.點擊“ClearRecord”時:
(1)WHEN-REMOVE-RECORD
(2)POST-QUERY
(3)WHEN-NEW-RECORD-INSTANCE
(4)WHEN-NEW-ITEM-INSTANCE
16.點擊F4關閉時:
(1)KEY-EXIT
(2)POST-FORM
17.點擊“CloseForm”按鈕關閉時:
(1)KEY-EXIT
(2)POST-FORM
18.點擊“Translations”按鈕時:
(1)TRANSLATIONS
19.點擊小叉號關閉時:
(1)WHEN-WINDOW-CLOSED
(2)CLOSE-WINDOW
(3)KEY-EXIT
(4)POST-FORM
20.選中LOV列表:
(1)KEY-LISTVAL
(2)WHEN-NEW-ITEM-INSTANCE
21.選中記錄前面的小條時:
(1)WHEN-NEW-RECORD-INSTANCE
(2)WHEN-NEW-ITEM-INSTANCE(資料項目級)
(3)WHEN-NEW-ITEM-INSTANCE
22.游標上下移動時:
(1)WHEN-NEW-RECORD-INSTANCE
(2)WHEN-NEW-ITEM-INSTANCE
Tag標籤: Oracle Form Builder觸發器執行順序



Triggers in Oracle Forms
Triggers are blocks of PL/SQL code that are written to perform tasks when a specific event occurs within an application. In effect, an Oracle Forms trigger is an event-handler written in PL/SQL to augment (or occasionally replace) the default processing behavior. Every trigger has a name, and contains one or more PL/SQL statements. A trigger encapsulates PL/SQL code so that it can be associated with an event and executed and maintained as a distinct object.
Block Processing Triggers:
Block processing triggers fire in response to events related to record management in a block.
When-Create-Record Perform an action whenever Oracle Forms attempts to create a new record in a block.
When-Clear-Block Perform an action whenever Oracle Forms flushes the current block; that is, removes all records from the block.
When-Database-Record Perform an action whenever Oracle Forms changes a record’s status to Insert or Update, thus indicating that the record should be processed by the next COMMIT_FORM operation.
Interface Event Triggers:
Interface event triggers fire in response to events that occur in the form interface. Some of these triggers, such as When-Button-Pressed, fire only in response to operator input or manipulation. Others, like When-Window-Activated, can fire in response to both operator input and programmatic control.
When-Button-Pressed Initiate an action when an operator selects a button, either with the mouse or through keyboard selection.
When-Checkbox-Changed Initiate an action when the operator toggles the state of a check box, either with the mouse or through keyboard selection.
When-Image-Activated Initiate an action whenever the operator double-clicks an image item.
When-Image-Pressed Initiate an action whenever an operator clicks on an image item.
When-Radio-Changed Initiate an action when an operator changes the current radio button selected in a radio group item.
When-Window-Activated Initiate an action whenever an operator or the application activates a window.
When-Window-Closed Initiate an action whenever an operator closes a window with the window manager’s Close command.
When-Window-Deactivated Initiate an action whenever a window is deactivated as a result of another window becoming the active window.
Master/Detail Triggers:
Oracle Forms generates master/detail triggers automatically when a master/detail relation is defined between blocks. The default master/detail triggers enforce coordination between records in a detail block and the master record in a master block. Unless developing custom block-coordination schemes, you do not need to define these triggers.
On-Check-Delete-Master Fires when Oracle Forms attempts to delete a record in a block that is a master block in a master/detail relation.
On-Clear-Details Fires when Oracle Forms needs to clear records in a block that is a detail block in a master/detail relation because those records no longer correspond to the current record in the master block.
On-Populate-Details Fires when Oracle Forms needs to fetch records into a block that is the detail block in a master/detail relation so that detail records are synchronized with the current record in the master block.
Message-Handling Triggers:
Oracle Forms automatically issues appropriate error and informational messages in response to runtime events. Message handling triggers fire in response to these default messaging events.
On-Error Replace a default error message with a custom error message, or to trap and recover from an error.
On-Message To trap and respond to a message; for example, to replace a default message issued by Oracle Forms with a custom message.
Validation Triggers:
Validation triggers fire when Oracle Forms validates data in an item or record. Oracle Forms performs validation checks during navigation that occurs in response to operator input, programmatic control, or default processing, such as a Commit operation.
When-Validate-Item
When-Validate-Record
Navigational Triggers:
Navigational triggers fire in response to navigational events. Navigational triggers can be further sub-divided into two categories: Pre- and Post- triggers, and When-New-Instance triggers. Pre- and Post- Triggers fire as Oracle Forms navigates internally through different levels of the object hierarchy. When-New-Instance-Triggers fire at the end of a navigational sequence that places the input focus on a different item.
Pre-Form Perform an action just before Oracle Forms navigates to the form from “outside” the form, such as at form startup.
Pre-Block Perform an action before Oracle Forms navigates to the block level from the form level.
Pre-Record Perform an action before Oracle Forms navigates to the record level from the block level.
Pre-Text-Item Perform an action before Oracle Forms navigates to a text item from the record level.
Post-Text-Item Manipulate an item when Oracle Forms leaves a text item and navigates to the record level.
Post-Record Manipulate a record when Oracle Forms leaves a record and navigates to the block level.
Post-Block Manipulate the current record when Oracle Forms leaves a block and navigates to the form level.
Post-Form Perform an action before Oracle Forms navigates to “outside” the form, such as when exiting the form.
When-New-Form-Instance Perform an action at form start-up. (Occurs after the Pre-Form trigger fires).
When-New-Block-Instance Perform an action immediately after the input focus moves to an item in a block other than the block that previously had input focus.
When-New-Record-Instance Perform an action immediately after the input focus moves to an item in a different record.
When-New-Item-Instance Perform an action immediately after the input focus moves to a different item.
Transactional Triggers:
Transactional triggers fire in response to a wide variety of events that occur as a form interacts with the data source.
On-Delete
On-Insert
On-Update
On-Logon
On-Logout
Post-Database-Commit
Post-Delete
Post-Insert
Post-Update
Pre-Commit
Pre-Delete
Pre-Insert
Pre-Update
Query-Time Triggers:
Query-time triggers fire just before and just after the operator or the application executes a query in a block.
Pre-Query Validate the current query criteria or provide additional query criteria programmatically, just before sending the SELECT statement to the database.
Post-Query Perform an action after fetching a record, such as looking up values in other tables based on a value in the current record. Fires once for each record fetched into the block.

打開,關閉,創建,更新記錄的trigger次序
PRE-……
在進入一個form,或是導航到一個新的block時觸發,PRE-……系列的觸發器一般是在WHEN-NEW-……-INSTANCE系列之前,它們如果失敗了的話,就不能成功導航到下一個物件了,只能留在當前的位置。在這些觸發器裡可以設置一些判斷條件來限制是否可以導航到新的位置。
WHEN-NEW-……-INSTANCE
這一類的trigger都是當滑鼠游標每次落到一個新的block,record,item上時觸發的,而且就算失敗了,也不會發生什麼錯誤。但是when-new-form-instance,只有當form啟動時,游標導航到第一個導航塊的第一個導航item時觸發,如果一個應用有多個form,當游標在各個form之間轉換時,並不會觸發它。

POST-TEXT-ITEM和WHEN-VALIDATE-ITEM
Post-text-item的觸發點:當輸入的游標從一個Text-Item 轉到其它item,可以用它來改變item的值,而when-Validate-item雖然也是在離開前觸發,但是作用不同,Post-Text-Item本身是沒有驗證的,when-Validate-item可以用來補充一些驗證(除了form本身的驗證),但是當form驗證成功以後,會把item標誌為‘valid’,而不會再去驗證了,如果這時我們再去修改它的值,那麼就有可能會把無效的值導入到資料庫。在創建和更新一條記錄時,先觸發when-Validate-item,再觸發Post-Text-Item,然後是when-Validate-record。
POST-……系列的都是離開當前的block,record,item時觸發的
WHEN-WINDOW-ACTIVATED
做原材料屬性修改平臺時,第一次使用這個觸發器,用來從另一個window返回時,刷新當前window,代碼寫在了這個觸發器裡。使用之前用fnd_message.debug試驗了一下,打開視窗後不停的彈出message。只要這個視窗在活動期間就會不停的執行這個觸發起裡面的代碼,所以執行的代碼應該用if條件限制一下。
Form的Trigger的優先順序是從item,到block,到form級別,如果另外設置Execution Hierarch屬性(override,before,after),則按照設置後的循序執行。如果是override的話,則執行完這個級別的觸發器,就不往上執行了,before就是執行完這個級別的觸發器後,如果上一個級別也有這個觸發器的話,繼續去執行,after就是先去執行上一個級別的觸發器,然後再回來執行。感覺觸發器比較難理解的還是每一種觸發器觸發的時間,和在開發中怎麼使用。目前瞭解的就是pre-…,when-new-…-instance,when-…-validate,post-query和幾個on-…觸發器

驗證代碼寫在WHEN-VALIDATE-RECORD和PRE-INSERT的不同
驗證代碼寫在WHEN-VALIDATE-RECORD和PRE-INSERT的不同
1、寫在WHEN-VALIDATE-RECORD,可以及時地提示錯誤資訊,如果驗證時要和後臺資料庫關聯的話,那麼要寫在PRE-INSERT,因為PRE-INSERT,ON-INSERT都是一條一條記錄執行的,這樣批量錄入時,每一條記錄的驗證都可以取到最新的資料庫記錄。
2、批量錄入時,有一條的PRE-INSERT不成功,則所有記錄都不能保存成功

Post-Query和When-New-Record-Instance關係
Post-Query和When-New-Record-Instance
假定資料庫中有100條記錄,塊設置顯示行數為10,那麼當游標在顯示出來的記錄間移動時,只觸發When-New-Record-Instance,不觸發Post-Query。當游標移到第十一條記錄時,觸發Post-Query


不可見item的when-validate-item使用
問題:如果一個item是不可見的,那麼改變它的值,還會觸發when-validate-item嗎?
結果:會觸發,但不是在改變它的值後觸發,而是在游標移到另一個block時。關閉窗口時也觸發了。
測試:設block1的item1為不可見,在item2的when-validate-item給tem1賦值,運行時,改變item2的值後,在block1的各item間移動游標都沒有觸發item1的when-validate-item,直到游標離開這個block,或關閉視窗時才觸發。

ACCEPT Trigger 講解
ACCEPT  APP_STANDARD.EVENT(‘ACCEPT’); 這個觸發器處理功能表或工具條上調用Save and Proceed (保存並繼續)動作。它執行保存,並移動到指定當作第一個導航塊的塊上。       替換這個觸發器中的代碼,或創建塊級觸發器並把執行類型指定為‘Override’

FOLDER_RETURN_ACTION
FOLDER_RETURN_ACTION
     這個觸發器允許指定客戶華的資料夾事件
     用需要的處理資料夾動作的代碼替換

KEY_DUPREC
APP_STANDARD.EVENT(‘KEY-DUPREC’);
    這個觸發器禁用了Oracle 表單預設的重複記錄的功能

KEY-CLRFRM
KEY-CLRFRM
   APP_STANDARD.EVENT(‘KEY-CLRFRM’);
   這個觸發器在試圖清空form前驗證記錄
   在原來的代碼後添加附加的代碼,通常你你應添加GO_BLOCK如果form中存在多個的區域,使用GO_BLOCK在調用清空from操作後重新填充控制功能表

KEY_MENU
KEY_MENU
  APP_STANDARD.EVENT(‘KEY-MENU’);
   這個觸發器禁用了Oracle froms的Block Menu 命令
   為了啟用從特定的塊對替代的塊通過鍵盤操作,那麼編寫塊級KEY_MENU並且設定執行類型為’Override ’這個觸發器會打開一個與彈出式功能表相同的LOV

KEY_LISTVAL
KEY_LISTVAL
  APP_STANDARD.EVENT(‘KEY-LISTVAL’);
  這個觸發器執行彈性域操作或引用LOV
  創建塊或項級觸發器並設置執行類型為‘Override’,可以使用日曆或動態執行彈性域

ON-ERROR
ON-ERROR
  APP_STANDARD.EVENT(‘ON-ERROR’);
這個觸發器處理伺服器或用戶端的所有的錯誤,使用消息字典調用。
為了捕獲處理指定的錯誤,在調用APP_STANDARD前檢查指定的錯誤declare
original_mess varchar2(80);
begin
IF MESSAGE_CODE = <your message number> THEN
original_mess := MESSAGE_TYPE||’–’||
to_char(MESSAGE_CODE)||’: ’||MESSAGE_TEXT;
––– your code handling the error goes here
message(original_mess);
ELSE
APP_STANDARD.EVENT(’ON_ERROR’);
END IF
end;

POST-FORM
POST-FORM.
  APP_STANDARD.EVENT(‘POST-FORM’);
這個觸發器是預留為以後使用
添加附加的代碼在原有代碼之後。

PRE-FORM
PRE-FORM
FND_STANDARD.FORM_INFO(’$Revision: <Number>$’,
’<Form. Name>’,
’<Application Shortname>’,
’$Date: <YY/MM/DD HH24:MI:SS> $’,
’$Author: <developer name> $’);
APP_STANDARD.EVENT(’PRE–FORM’);
APP_WINDOW.SET_WINDOW_POSITION(’BLOCKNAME’,
’FIRST_WINDOW’);
這個觸發器初始化Oracle 應用的內部值和功能表。在這裡輸入的值將在Oracle應用程式功能表‘Help About Oracle Applications’中看到。
你必須編輯應用程式的簡稱,應用的簡稱控制當使用者選擇‘help’按鈕後哪個應用的線上說明文檔將被調用。如果你將應用的簡稱設置為FND,你的用戶將會看不到任何説明因為Oracle應用程式將不能建立可用的説明目標。
Form的名稱是用戶form名稱(form標題)。
Oracle公司使用源控制系統,它可以自動更新以“$”開頭的值,如果你不使用這個源控制系統你可以按你的開發資訊編輯這些值。
你必須編輯APP_WINDOW中的BLOCKNAME為你自己的block.不要編輯FIRST_WINDOW

QUERY_FIND
QUERY_FIND
APP_STANDARD.EVENT(‘QUERY_FIND’);
這個觸發器將設置顯示字串’Query Find is not available ’
在這個觸發器中替代代碼,當你創建視窗或Row_LOV在你的form中時創建塊級觸發器並設置執行類型為‘Override’

WHEN-NEW-FORM-INSTANCE
WHEN-NEW-FORM-INSTANCE
FDRCSID(’$Header: ... $’);
APP_STANDARD.EVENT(’WHEN–NEW–FORM–INSTANCE’);
–– app_folder.define_folder_block(’template test’,
’folder_block’, ’prompt_block’, ’stacked_canvas’,
’window’, ’disabled functions’);
--app_folder.event(’VERIFY’);
調用 APP_STANDARD.EVENT 是為了在query-only模式下調用FND_FUNCTION.EXECUTE,調用FNDRCSID是為了Oracle 應用程式的源控制系統(source control system).APP_FOLDER 只為了Oracle應用程式內部調用。客戶化form不需要FDRCSID或APP_FOLDER調用,但是如果將它們留在觸發器中也沒有影響。
在現有的代碼前添加附加代碼。

WHEN-NEW-RECORD-INSTANCE
WHEN-NEW-RECORD-INSTANCE
APP_STANDARD.EVENT(‘WHEN-NEW-RECORD-INSTANCE’);
這個觸發器管理Oracle應用程式功能表和工具列
創建塊級觸發器並設置執行類型為‘Before’

WHEN-NEW-ITEM-INSTANCE
WHEN-NEW-ITEM-INSTANCE
APP_STANDARD.EVENT(‘WHEN-NEW-ITEM-INSTANCE’);
這個觸發器管理Oracle應用程式的功能表和工具列
如果你添加彈性域方法調用,你應該添加它在APP_STANDARD.EVENT 調用前調用,通常,你不應該添加任何代碼在這個觸發器中,這樣的代碼將會影響你表單的速度並且影響每一個項

Oracle EBS Form. 中,不能修改的Trigger
Oracle應用程式不支援修改form級的觸發器
CLOSE_THIS_WINDOW
從菜單Action->Close 調用觸發器APP_CUSTOM.CLOSE_WINDOW 。
CLOSE_WINDOW
APP_CUSTOM.CLOSE_WINDOW(:SYSTEM.EVENT_WINDOW);
這個出發其處理所有關閉視窗的事件。編寫處理關閉視窗的事件必須寫在APP_CUSTOM.CLOSE_WINDOW包中
EXPORT
App_standard.event(‘EXPORT’);
這個觸發器是“Action,Export”功能表中的選擇。
FOLDER_ACTION
App_folder.event(:global.folder_action);
KEY-COMMIT
App_standard.event(‘KEY-COMMIT’);
這個觸發器處理正常的提交或form調用
KEY-EDIT
App_standard.event(‘KEY-EDIT’);
這個觸發器處理彈性域或日曆,編輯器操作。
KEY-EXIT
App_standard.event(‘KEY-EXIT’);
這個觸發器處理關閉事件和退出enter-query狀態
KEY-HELP
App_standard.event(‘KEY-HELP’);
這個觸發器調用視窗的説明系統。
LASTRECORD
APP_STANDARD.EVENT(‘LASTRECORD’);
這個觸發器處理功能表(Go ->LAST RECORD)事件
MENU_TO_APPCORE
App_standard.event(:global.menu_to_appcore);
這個觸發器支援Special功能表
STANDARD_ATTACHMENTS
Atchmt_api.invoke;
這個觸發器處理附件功能表或工具按鈕的調用
WHEN-WINDOW-CLOSE
Execute_trigger(‘CLOSE_WINDOW’);
這個觸發器集中了form的關閉事件
WHEN-FORM-NAVIGATE
你不能修改這個觸發器,它包含了標準的行為,當最小化的表單被導航到的時候正常化這個表單。
ZOOM
Appcore_custom.event(‘ZOOM’);
這個觸發器處理功能表或工具條按鈕’Action,Zoom ’事件。

沒有留言:

張貼留言