FND_REQUEST.SUBMIT_REQUEST的用法說明(提交Request)

FND_REQUEST.SUBMIT_REQUEST函數是用來送出一個Request,傳回一個NUMBER的值。
如果成功,會傳回Request ID的值,失敗則傳回0。

此函數一共有105個參數,前五個參數是定義fnd_request.submit_request自己,
後面的參數則是定義要傳給Concurrent Request的值。而第五個參數要特別注意,
false表示立刻提交,不要被參數名稱給誤導。
如下圖,第六個參數開始設定的值,會依序把值傳給Concurrent Program Parameters

注意:
1、Package使用只需要傳遞需要的參數個數,它會自帶結束的預設值。
2、form則要寫滿105個參數,而且參數結束之後要用一個chr(0)來表示結束。
3、在Toad、PL/SQL Developer、SQL puls等工具內使用,必須初始化global variables。
   也就是利用fnd_global.apps_initialize函數來初始化
4、如果提交Request時,一直傳回0,則檢查是否有初始化環境
5、傳給Concurrent Request的參數個數與定義,可以查詢Request的定義,如下圖:

語法:
Request_id := fnd_request.submit_request(
                  application CHAR, --模組
                  program CHAR,      --應用程式
                  description CHAR,   --說明(可省略)
                  start_time CHAR,    --RUN 時間(可省略)
                  sub_request BOOLEAN, --是否立刻送出Request
                  argument1 CHAR,   --傳給Request的參數1
                  argument2 CHAR,   --傳給Request的參數1
                  argument3 CHAR,   --傳給Request的參數1
                  ....(略)
                  argument100 CHAR);
       
Parameters are as follows:

application - Short name of the application associated with the concurrent
request to be submitted.

program - Short name of the concurrent program (not the executable)
for which the request should be submitted.

description - Description of the request that is displayed in the Concurrent
Requests form. (Optional.)

start_time - Time at which the request should start running, formatted as
HH24:MI or HH24:MI:SS (Optional.)

sub_request - Set to TRUE if the request is submitted from another request
and  should be treated as a sub-request.

argument1...100 - Arguments for the concurrent request; up to 100
arguments are permitted. If submitted from Oracle Forms,
you must specify all 100 arguments.


一、查application(模組)與program(應用程式)名稱的方法
       
方法一:由ERP介面查詢(查Import Items)

由下圖可以得知Short Name就是我們要的Program
位置:「Application Developer」->「Concurrent」->「Program」

依上圖的Application可以找到Short Name,就是我們要的application
位置:「Application Developer」->「Application」->「Register」
   
方法二:執行下列SQL查詢(查Import Item)
SELECT DISTINCT
       fa.APPLICATION_SHORT_NAME, --application(模組)
       fat.APPLICATION_NAME,
       fcp.CONCURRENT_PROGRAM_NAME, --program(應用程式)
       fcpt.USER_CONCURRENT_PROGRAM_NAME,
       fcpT.DESCRIPTION,
       fcpt.LANGUAGE
  FROM fnd_application_tl fat,
       fnd_application fa,
       fnd_concurrent_programs_tl fcpt,
       fnd_concurrent_programs fcp,
       fnd_executables fe
WHERE fat.APPLICATION_ID = fa.APPLICATION_ID
       AND fat.LANGUAGE = fcpt.LANGUAGE
       AND fa.APPLICATION_ID = fcp.APPLICATION_ID
       AND fcpt.CONCURRENT_PROGRAM_ID = fcp.CONCURRENT_PROGRAM_ID
       AND fcp.executable_id = fe.executable_id
       AND fcpt.USER_CONCURRENT_PROGRAM_NAME='Import Items'; --報表名稱
   
   
二、範例,Import Item(mtl_system_items_interface)

1、在Forms內使用

//在Forms中,初始化可以用GLOBAL變數代入
APPS.FND_GLOBAL.apps_initialize(
    user_id =>APPS.FND_GLOBAL.user_id,
    resp_id =>APPS.FND_GLOBAL.resp_id,
    resp_appl_id =>APPS.FND_GLOBAL.resp_appl_id) ;
   
//定義完變數後必須以CHR(0)來表示參數已結束,但是仍然要填滿105個  
v_request_id := fnd_request.submit_request(
    'INV',
     'INCOIN',
     '',
     '',
     FALSE,
    84 ,'1','1','1','1',set_process_id,'2',CHR(0),
     '','','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','',
    '','','','','','','','','','');

2、在Package中使用

//初始化參數只能由SQL中查詢
SELECT user_id
  INTO l_num_user_id
  FROM applsys.fnd_user
  WHERE user_name ='AA123'; --帳號
       
SELECT responsibility_id
   INTO l_num_resp_id
   FROM apps.fnd_responsibility_vl
   WHERE responsibility_name ='Inventory'; --Responsibility Name
       
SELECT application_id
   INTO l_num_resp_appl_id
   FROM applsys.fnd_application
   WHERE application_short_name = 'INV'; --application name

fnd_global.apps_initialize (user_id => l_num_user_id,
                            resp_id => l_num_resp_id,
                            resp_appl_id => l_num_resp_appl_id
                            );

//只需填入需要個數的參數,會自動帶入結束符號。                                
v_request_id:=Fnd_Request.submit_request (
    application   => 'INV',
    Program       => 'INCOIN',
    description   => '',
    start_time    => '',
    sub_request   => FALSE,
    argument1     => 84,
    argument2     => 1,          
    argument3     => 1,
    argument4     => 1,
    argument5     => 1,  -- Delete processed Record
    argument6     => 5000,  -- Set Process id                  
    argument7     => 2   -- Create/Update item
     );
   

三、查詢Request執行狀態的函數

主要是用Fnd_concurrent.wait_for_ruqest函數來得知目前Request執行的狀態。

Fnd_concurrent.wait_for_request會傳回Boolean值,主要參數如下:
function FND_CONCURRENT.WAIT_FOR_REQUEST
    (request_id IN number default NULL, --Request ID
     interval IN number default 60, --檢查的時間間隔
     max_wait IN number default 0, --最大等待時間
     phase OUT varchar2,
     status OUT varchar2,
     dev_phase OUT varchar2,
     dev_status OUT varchar2,
     message OUT varchar2 ) ;
return boolean;


例如:
l_request_status := Fnd_Concurrent.Wait_For_Request(
    l_request_id,
    5,
    0,
    l_phase,
    l_status,
    l_dev_phase,
    l_dev_status,
    l_message);

IF l_request_status THEN
    IF l_dev_status = 'NORMAL' THEN
        NULL;
    ELSE
        Fnd_Message.Debug('Request執行失敗:'||l_dev_status);
        RETURN;
    END IF;
  ELSE
    Fnd_Message.Debug('Request執行失敗');
    RETURN;
END IF;

Windows 11安裝時跳過網路連線