PL/SQL Script To Submit A Concurrent Request From Backend: by - June 26, 2013 - 18,893 Views - Category: Tags
PL/SQL Script To Submit A Concurrent Request From Backend: by - June 26, 2013 - 18,893 Views - Category: Tags
By Shailender Thallam | June 26, 2013 | 18,893 views | Category: AOL and SYSADMIN AOL SQL
Scripts Tags: fnd_request.submit_request
2 Comments
We can submit a concurrent request from backend using fnd_request.submit_request API. Before submitting
the API we need to set the environment context using fnd_global.apps_initialize
1 /*********************************************************
2
*PURPOSE: To Submit a Concurrent Request from backend *
3
*AUTHOR: Shailender Thallam *
4
5 **********************************************************/
6
--
7
DECLARE
8
9 l_responsibility_id NUMBER;
10 l_application_id NUMBER;
11
l_user_id NUMBER;
12
13 l_request_id NUMBER;
14 BEGIN
15 --
16
SELECT DISTINCT fr.responsibility_id,
17
frx.application_id
18
19 INTO l_responsibility_id,
20 l_application_id
21
FROM apps.fnd_responsibility frx,
22
apps.fnd_responsibility_tl fr
23
29 --
30
--To set environment context.
31
--
32
33 apps.fnd_global.apps_initialize (l_user_id,l_responsibility_id,l_application_id);
34
--
35
36 --Submitting Concurrent Request
37
--
38
l_request_id := fnd_request.submit_request (
39
48 );
49 --
50
COMMIT;
51
--
52
IF l_request_id = 0
THEN
END IF;
--
EXCEPTION
END;
BEGIN
/*First we need to initialize the apps, this will automatically done when we submit the
program from application directly*/
BEGIN
SELECT user_id
INTO v_user_id
FROM fnd_user
WHERE user_name = 'USER NAME';
EXCEPTION
WHEN OTHERS
THEN
v_user_id := NULL;
END;
BEGIN
SELECT fa.application_id, fr.responsibility_id,
fr.responsibility_name, fa.application_short_name
INTO v_app_id, v_resp_id,
v_resp_name, v_app_name
FROM fnd_responsibility_vl fr, fnd_application fa
WHERE responsibility_name LIKE 'Order Management Super User'
AND fr.application_id = fa.application_id;
EXCEPTION
WHEN OTHERS
THEN
v_app_id:=null;
v_resp_id:=null;
v_resp_name:=null;
v_app_name:=null;
END;
-- Initializing apps
fnd_global.apps_initialize (user_id => v_user_id,
resp_id => v_resp_id,
resp_appl_id => v_app_id
);
use_reservation_time_fence : = 'Y';
resertvaton_run_types : = 'RESERVE';
booked : = 'Y';
reservation_mode : = 'PARTIAL';
order_by : = 'ORDERED_DATE';
item : = Inventory_item_id;
warehouse : = Organization_id;
/*These are the parameters of the reserve orders program which will passed as
arguments through fnd_request.submit_request function*/
v_request_id :=
fnd_request.submit_request (v_app_name, /* Short name of the
application under which the program is registered in this it will be ONT since the
Reserve Order program is registered under order management*/
'OMRSVORD', -- Short name of the concurrent program needs
to submitted
NULL, -- concurrent program description OPTIONAL
parameter
SYSDATE, /* Start time parameter which can be used to
mention the actual start of the concurrent program which once again OPTIONAL*/
FALSE, /* Sub request parameters if this program is
need to be submitted from another running request then TRUE needs to passed, but
default is FALSE and an OPTIONAL parameter*/
argument1 => use_reservation_time_fence,
argument2 => '',
argument3 => '',
argument4 => '',
argument5 => '',
argument6 => '',
argument7 => warehouse,
argument8 => item,
argument9 => '',
argument10 => '',
argument11 => '',
argument12 => '',
argument13 => '',
argument14 => '',
argument15 => '',
argument16 => '',
argument17 => '',
argument18 => '',
argument19 => booked,
argument20 => reservation_mode,
argument21 => '',
argument22 => '',
argument23 => '',
argument24 => '',
argument25 => resertvaton_run_types,
argument26 => '',
argument27 => '',
argument28 => order_by,
argument29 => '',
argument30 => '',
argument31 => ''
);
Passing unequal number (or) unmatched additional parameters will complete the
concurrent program with ERROR Status.
COMMIT;
Only after the explicit commit the submitted requested will be available in the
fnd_concurrent_request table and in the Oracle apps.
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'Main Exception'
|| SQLERRM
|| DBMS_UTILITY.format_error_backtrace
);
End;
DECLARE
l_user_id fnd_user.user_id%TYPE;
l_resp_id fnd_responsibility.responsibility_id%TYPE;
l_resp_appl_id fnd_application.application_id%TYPE;
l_set_layout boolean;
l_request_id NUMBER;
l_phase VARCHAR2 (100);
l_status VARCHAR2 (100);
l_dev_phase VARCHAR2 (100);
l_dev_status VARCHAR2 (100);
l_wait_for_request boolean := FALSE;
l_get_request_status boolean := FALSE;
Output_layout_failed EXCEPTION;
request_submission_failed EXCEPTION;
request_completion_abnormal EXCEPTION;
BEGIN
l_request_id := NULL;
COMMIT;
l_set_layout :=
fnd_request.add_layout (template_appl_name => XXERP,
template_code => XXORACLEERPAPPSGUIDE,
Data Template Code
template_language => en,
template_territory => US,
output_format => PDF);
IF l_set_layout
THEN
Submit the Request
l_request_id :=
fnd_request.submit_request (application => XXERP,
program => XXOEAG_PG,
description => ,
start_time => SYSDATE,
sub_request => FALSE,
argument1 => l_person_id);
COMMIT;
IF l_request_id > 0
THEN
l_wait_for_request :=
fnd_concurrent.wait_for_request (request_id => l_request_id,
interval => 60,
max_wait => 0,
phase => l_phase,
status => l_status,
dev_phase => l_dev_phase,
dev_status => l_dev_status,
MESSAGE => l_messase);
COMMIT;
Get the Request Completion Status.
l_get_request_status :=
fnd_concurrent.get_request_status (
request_id => l_request_id,
appl_shortname => NULL,
program => NULL,
phase => l_phase,
status => l_status,
dev_phase => l_dev_phase,
dev_status => l_dev_status,
MESSAGE => l_messase
);
p_request_id := l_request_id;
EXCEPTION
WHEN Output_layout_failed
THEN
DBMS_OUTPUT.put_line (Out put Layout failed);
WHEN request_submission_failed
THEN
DBMS_OUTPUT.put_line (Concurrent request submission failed);
WHEN request_completion_abnormal
THEN
DBMS_OUTPUT.put_line (
Submitted request completed with error || l_request_id
);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (ERROR: || SUBSTR (SQLERRM, 0, 240));
END;
You can Create this as PL/SQL Procedure and register into Concurrent Program also.
fnd_global.apps_initialize(user_id,responsibility_id,application_responsibility_id)
If you are directly running from the database using the TOAD, SQL NAVIGATOR or SQL*PLUS etc. Then you need to initialize the
Apps. In this case use the above API to Initialize the APPS.
DECLARE
l_request_id NUMBER(30);
BEGIN
FND_GLOBAL.APPS_INITIALIZE (user_id => 1318, resp_id => 59966, resp_appl_id => 20064);
l_request_id:= FND_REQUEST.SUBMIT_REQUEST
DBMS_OUTPUT.PUT_LINE(l_request_id);
commit;
END;
**************************************************************
If you are using same code in some procedure and running directly from application then you don't need to initialize. Then you
can comment the fnd_global.apps_initialize API.
DECLARE
l_success NUMBER;
BEGIN
BEGIN
fnd_global.apps_initialize( user_id => 2572694, resp_id => 50407, resp_appl_id => 20003);
l_success :=
fnd_request.submit_request
);
COMMIT;
-- Note:- In the above request Run, I have created the Report, which has one parameter.
IF l_success = 0
THEN
ELSE
END IF;
END;
Note: If you are running directly from database, use DBMS API to display. If you are running directly from application, then Use
the fnd_file API to write the message in the log file.
Exp:
PROCEDURE URSTING_PRG (
errbuf OUT VARCHAR2,
retcode OUT NUMBER,
v_req_id OUT NUMBER,
v_dev_status OUT VARCHAR2,
v_dev_phase OUT VARCHAR2,
v_request_status OUT BOOLEAN,
p_request_id number
) IS
v_layout BOOLEAN;
--v_request_status BOOLEAN;
v_phase VARCHAR2 (2000);
v_wait_status VARCHAR2 (2000);
--v_dev_phase VARCHAR2 (2000);
--v_dev_status VARCHAR2 (2000);
v_message VARCHAR2 (2000);
BEGIN
FND_FILE.PUT_LINE(FND_FILE.LOG,' Starting of Bursting Procedure BURSTING_PRG');
v_req_id :=NULL;
FND_FILE.PUT_LINE(FND_FILE.LOG,' Initializing Apps');
FND_GLOBAL.Apps_Initialize(FND_GLOBAL.USER_ID, FND_GLOBAL.RESP_ID, FND_GLOBAL.RESP_APPL_ID);
v_layout := FND_REQUEST.ADD_LAYOUT('XDO'
,'BURST_STATUS_REPORT'
,'en'
,'US'
,'PDF');
v_req_id:= FND_REQUEST.SUBMIT_REQUEST(
'XDO',
'XDOBURSTREP',
'',
'',
FALSE,
p_request_id,'N',
chr(0),'','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','',
'','','','','','','','','','');
commit;
FND_FILE.PUT_LINE(FND_FILE.LOG,' Submitted the Bursting Program' || '-'|| v_req_id);
FND_FILE.PUT_LINE(FND_FILE.LOG,' Waiting for the Bursting Program');
v_request_status:=
fnd_concurrent.wait_for_request
(request_id => v_req_id,
INTERVAL => 5,
max_wait => 600,
phase => v_phase,
status => v_wait_status,
dev_phase => v_dev_phase,
dev_status => v_dev_status,
MESSAGE => v_message);
commit;
FND_FILE.PUT_LINE(FND_FILE.LOG,' Bursting Program Request Phase' || '-'|| v_dev_phase);
FND_FILE.PUT_LINE(FND_FILE.LOG,' Bursting Program Request Dev status' || '-'|| v_dev_status);
EXCEPTION
WHEN OTHERS THEN
v_req_id := null;
FND_FILE.PUT_LINE(FND_FILE.LOG,' Ending of Bursting Procedure GEPS_BURSTING_PRG');
END BURSTING_PRG;
The following is the Sample Code to Submit the Concurrent Program from the backend.
Note:- This is the Concurrent Program, not the Request Set. To Submit the Request Set from the backend, We have
different API.
I have already document, for submitting the request set from the backend in the Following URL.
http://alloracletech.blogspot.com/2008/07/registering-from-backend.html
DECLARE
l_success NUMBER;
BEGIN
BEGIN
fnd_global.apps_initialize( user_id => 2572694, resp_id => 50407, resp_appl_id => 20003);
-- If you are directly running from the database using the TOAD, SQL-NAVIGATOR or --SQL*PLUS etc. Then you
need to Initialize the Apps. In this case use the above API to --Initialize the APPS. If you are using same code in
some procedure and running directly
--from application then you don't need to initalize.
--Then you can comment the above API.
l_success :=
fnd_request.submit_request
('XXAPP', -- Application Short name of the Concurrent Program.
'XXPRO_RPT', -- Program Short Name.
'Program For testing the backend Report', -- Description of the Program.
SYSDATE, -- Submitted date. Always give the SYSDATE.
FALSE, -- Always give the FLASE.
'1234' -- Passing the Value to the First Parameter of the report.
);
COMMIT;
-- Note:- In the above request Run, I have created the Report, which has one parameter.
IF l_success = 0
THEN
-- fnd_file.put_line (fnd_file.LOG, 'Request submission For this store FAILED' );
DBMS_OUTPUT.PUT_LINE( 'Request submission For this store FAILED' );
ELSE
-- fnd_file.put_line (fnd_file.LOG, 'Request submission for this store SUCCESSFUL');
DBMS_OUTPUT.PUT_LINE( 'Request submission For this store SUCCESSFUL' );
END IF;
--Note:- If you are running directly from database, use DBMS API to display. If you are
-- Running directly from Application, then Use the fnd_file API to write the message
-- in the log file.
END;
I hope the above information is helping you. For any Suggestion or issues with the above, please leave your
comments. I will try to reply back as soon as possible.
-- FND_GLOBAL.APPS_INITIALIZE (ln_user_id,ln_responsibility_id,ln_application_id);
FND_GLOBAL.APPS_INITIALIZE (1312,20434,101);
COMMIT; -- It is Mandatory
IF ln_request_id = 0
THEN
DBMS_OUTPUT.PUT_LINE ('Concurrent Request Failed to Submit.');
ELSE
DBMS_OUTPUT.PUT_LINE('Successfully Submitted the Concurrent Request. Request Id: '||ln_request_id);
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error While Submitting Concurrent Request '||TO_CHAR(SQLCODE)||'-'||SQLERRM);
END;
/
How to submit a concurrent program from pl sql
Using FND_REQUEST.SUBMIT_REQUEST function & by passing the required parameters to it we can
submit a concurrent program from backend.
But before doing so, we have to set the environment of the user submitting the request.
Syntax ............
FND_GLOBAL.APPS_INITIALIZE:
procedure APPS_INITIALIZE(user_id in number,
resp_id in number,
resp_appl_id in number);
FND_REQUEST.SUBMIT_REQUEST:
REQ_ID := FND_REQUEST.SUBMIT_REQUEST ( application => 'Application Name', program =>
'Program Name', description => NULL, start_time => NULL, sub_request => FALSE, argument1 => 1
argument2 => ....argument n );
Example:
First get the USER_ID and RESPONSIBILITY_ID by which we have to submit the program:
SELECT USER_ID,
RESPONSIBILITY_ID,
RESPONSIBILITY_APPLICATION_ID,
SECURITY_GROUP_ID
FROM FND_USER_RESP_GROUPS
WHERE USER_ID = (SELECT USER_ID
FROM FND_USER
WHERE USER_NAME = '&user_name')
AND RESPONSIBILITY_ID = (SELECT RESPONSIBILITY_ID
FROM FND_RESPONSIBILITY_VL
WHERE RESPONSIBILITY_NAME = '&resp_name');
-- First set the environment of the user submitting the request by submitting
-- Fnd_global.apps_initialize().
-- The procedure requires three parameters
-- Fnd_Global.apps_initialize(userId, responsibilityId, applicationId)
-- Replace the following code with correct value as get from sql above
v_request_id := APPS.FND_REQUEST.SUBMIT_REQUEST('AR','RACUST','',
'',FALSE,p_create_reciprocal_flag,p_org_id,
chr(0) -- End of parameters);
EXCEPTION
Output:
DECLARE
V_RETURN_CODE NUMBER;
V_RETURN_MSG VARCHAR2(200);
V_ORG_ID NUMBER := 204;
BEGIN
CALL_RACUST(
P_RETURN_CODE => V_RETURN_CODE,
P_ORG_Id => V_ORG_ID,
P_RETURN_MSG => V_RETURN_MSG
);
DBMS_OUTPUT.PUT_LINE('V_RETURN_CODE = ' || V_RETURN_CODE);
DBMS_OUTPUT.PUT_LINE('V_RETURN_MSG = ' || V_RETURN_MSG);
END;
If Return Code is 0(zero) then it has submitted the Customer Interface program successfully and the
request id will appear in Return Message as :
V_RETURN_CODE = 0
V_RETURN_MSG = Request submitted. ID = 455949
Submit Concurrent Program from back-end
posted Sep 27, 2010, 9:48 PM by Manvesh Vemula [ updated Oct 14, 2010, 2:36 AM ]
We all know that to submit a concurrent program, we login into the oracle applications,
navigate to respective responsibility and finally submit the concurrent program for its
execution.
But how to submit a concurrent program from an integrated development environment like
Toad, SQL Developer, SQL*Plus, etc.? Here is the method.
To submit a concurrent program from back-end, first we need to initialize the apps
environment. In other words, we should set the user, responsibility to which the concurrent
program belongs to or assigned to. For that we use the built-in APPS_INITIALIZE and the syntax
for it is
FND_GLOBAL.APPS_INITIALIZE(user_id,responsibility_id,application_responsibility_id)
The values for the parameters can be queried from the tables, fnd_responsibility_tl and
fnd_user.
Ex: SELECT user_id FROM fnd_user WHERE user_name like 'OPERATIONS'
SELECT responsibility_id, application_id
FROM fnd_responsibility_tl
start_time The time at which the program should start executing (optional)
sub_request TRUE if the program is being submitted from any other program
Example:
declare
v_request_id nummber;
begin
FND_GLOBAL.APPS_INITIALIZE(1234,500126,20004);
v_request_id := FND_REQUEST.SUBMIT_REQUEST
(application=>'XX_TOP',
program=>'XXX_CONC_PROG',
argument1=>234);
else
end;
/
On the successful execution of function Submit_Request, it returns a unique number which will be the resultant request_id. This
request_id will be visible in the View Requests screen of the apps. If there occurs an error while execution, the function returns a 0.