DBA Data[Home] [Help]

PACKAGE BODY: APPS.FND_JOBS_PKG

Source


1 package body FND_JOBS_PKG as
2 /* $Header: AFJOBPKB.pls 120.1 2005/07/02 04:08:45 appldev noship $ */
3   C_LOG_HEAD 	CONSTANT VARCHAR2(30) := 'fnd.plsql.FND_JOBS_PKG.';
4 --
5   procedure APPS_INITIALIZE_SYSADMIN is
6     L_USER_ID      number;
7     L_RESP_ID      number;
8     L_RESP_APPL_ID number;
9   begin
10     begin
11       select USER_ID into L_USER_ID from FND_USER where USER_NAME = 'SYSADMIN';
12     exception when OTHERS then
13       L_USER_ID := 0;
14     end;
15     begin
16       select R.APPLICATION_ID, R.RESPONSIBILITY_ID
17         into L_RESP_APPL_ID, L_RESP_ID
18         from FND_APPLICATION A, FND_RESPONSIBILITY R
19        where R.APPLICATION_ID = A.APPLICATION_ID
20          and A.APPLICATION_SHORT_NAME = 'SYSADMIN'
21          and R.RESPONSIBILITY_KEY = 'SYSTEM_ADMINISTRATOR';
22     exception when OTHERS then
23       L_RESP_APPL_ID := 1;
24       L_RESP_ID := 20420;
25     end;
26     FND_GLOBAL.APPS_INITIALIZE(USER_ID      => L_USER_ID,
27                                RESP_ID      => L_RESP_ID,
28                                RESP_APPL_ID => L_RESP_APPL_ID);
29   end APPS_INITIALIZE_SYSADMIN;
30 --
31   /*
32   ** No AOL equivalent - replace with body of code that combines
33   ** calls to FND_CONC_MAINTAIN.APPS_INITIALIZE_FOR_MGR,
34   **          FND_CONC_MAINTAIN.GET_PENDING_REQUEST_ID,
35   **      and FND_REQUEST.SUBMIT_REQUEST
36   */
37   function SUBMIT_JOB(P_APPLICATION_SHORT_NAME  in varchar2,
38                       P_CONCURRENT_PROGRAM_NAME in varchar2,
39                       P_ALTERNATE_PROGRAM       in varchar2)
40     return number is
41     JOB_NUMBER number;
42     JOB_BROKEN varchar2(30);
43     JOB_SID    number;
44     JOB_STRING varchar2(4000);
45   begin
46     JOB_STRING := P_ALTERNATE_PROGRAM||';';
47     begin
48 /*
49       select J.JOB, J.BROKEN, R.SID
50         into JOB_NUMBER, JOB_BROKEN, JOB_SID
51         from DBA_JOBS J, DBA_JOBS_RUNNING R
52        where J.WHAT = JOB_STRING
53          and J.JOB = R.JOB(+);
54 */
55       if (JOB_BROKEN = 'Y') then
56         -- If the job is broken, remove it (### and resubmit ###)
57         DBMS_JOB.REMOVE(JOB_NUMBER);
58       elsif (JOB_SID is null) then
59         return(null); -- Job is pending but not running
60       end if;
61     exception when NO_DATA_FOUND then
62       JOB_NUMBER := null;
63     end;
64     /* Job is either running or doesn't exist, so submit it */
65     DBMS_JOB.SUBMIT(JOB_NUMBER, JOB_STRING);
66     return(JOB_NUMBER);
67   exception when OTHERS then
68     return(0); -- Job submission failed for some reason
69   end SUBMIT_JOB;
70 --
71   function SUBMIT_MENU_COMPILE return varchar2 is
72     l_api_name CONSTANT VARCHAR2(30) := 'SUBMIT_MENU_COMPILE';
73     request_id number;
74     phase varchar2(80);
75     status varchar2(80);
76     dev_phase varchar2(30);
77     dev_status varchar2(30);
78     message varchar2(255);
79     result boolean;
80   begin
81     /* Submit a concurrent request to compile the marked menus. */
82     --
83     /*
84     ** Make sure that we are intialized as the special user
85     ** that will submit the request
86     */
87     begin
88       FND_CONC_MAINTAIN.apps_initialize_for_mgr;
89     exception
90       when others then
91        if ((FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL)) then
92          fnd_log.string(FND_LOG.LEVEL_EXCEPTION,
93                         c_log_head || l_api_name || '.init_failed',
94             'A Failure occurred in FND_CONC_MAINTAIN.apps_initialize_for_mgr');
95        end if;
96        return 'E';
97     end;
98     --
99     /* First check if the request is already about to be run */
100     request_id := FND_CONC_MAINTAIN.get_pending_request_id('FND', 'FNDSCMPI');
101     if ((FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL)) then
102       fnd_log.string(FND_LOG.LEVEL_STATEMENT,
103                      c_log_head || l_api_name || '.get_req_status',
104                      'Checked request status. request_id:' || request_id);
105     end if;
106     /* If it is about to be run then there will be a request id. */
107     if ((request_id is not NULL) and (request_id = 0)) then
108       /* Submit the recompile request since it isn't about to be run */
109       request_id := fnd_request.submit_request (application => 'FND',
110                                                 program     => 'FNDSCMPI',
111                                                 argument1   => 'N');
112       if ((FND_LOG.LEVEL_STATEMENT >= FND_LOG.G_CURRENT_RUNTIME_LEVEL)) then
113         fnd_log.string(FND_LOG.LEVEL_STATEMENT,
114                        c_log_head || l_api_name || '.submit',
115                    'to recompile, Submitted FNDSCMPI request id:'||request_id);
116       end if;
117       if (request_id = 0) then
118         if ((FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL)) then
119           fnd_log.string(FND_LOG.LEVEL_EXCEPTION,
120                          c_log_head || l_api_name || '.submit_failed',
121                       'Request ID zero means submission failed.  Msg on stack:'
122                          || fnd_message.get);
123         end if;
124         return 'E';
125       end if;
126       return 'S';
127     end if;
128     return 'P';
129   exception
130     when others then /* If we can't submit the request.*/
131       if ((FND_LOG.LEVEL_EXCEPTION >= FND_LOG.G_CURRENT_RUNTIME_LEVEL)) then
132         fnd_log.string(FND_LOG.LEVEL_EXCEPTION,
133                        c_log_head || l_api_name || '.req_submit_fail',
134             'Could not submit concurrent request FNDSCMPI to recompile menus');
135       end if;
136       return 'E';
137   end SUBMIT_MENU_COMPILE;
138 --
139   procedure SUBMIT_MENU_COMPILE is
140     /* Submit a concurrent request to compile the marked menus. */
141     l_api_name CONSTANT VARCHAR2(30) := 'SUBMIT_MENU_COMPILE';
142     request_id number;
143     phase varchar2(80);
144     status varchar2(80);
145     dev_phase varchar2(30);
146     dev_status varchar2(30);
147     message varchar2(255);
148     result boolean;
149   begin
150     /* First check if the request is already about to be run */
151     request_id := NULL;
152     result := fnd_concurrent.get_request_status(request_id, 'FND', 'FNDSCMPI',
153                                                 phase, status, dev_phase,
154                                                 dev_status, message);
155     /* Log result */
156     if (fnd_log.LEVEL_STATEMENT >= fnd_log.g_current_runtime_level) then
157       fnd_log.string(FND_LOG.LEVEL_STATEMENT,
158                      c_log_head || l_api_name || '.get_req_status',
159                      'Checked request status. dev_phase:'
160                      || dev_phase ||' dev_status:'||dev_status);
161     end if;
162     /* If it is about to be run then phase will be 'PENDING'  */
163     /* and status will be 'NORMAL' (not scheduled or standby) */
164     if ((dev_phase <> 'PENDING') or
165         (dev_status <> 'NORMAL') or
166         (dev_status is null)) then
167       /* Submit the recompile request since it isn't about to be run */
168       request_id := fnd_request.submit_request(application => 'FND',
169                                                program     => 'FNDSCMPI',
170                                                argument1   => 'N');
171       /* Log result */
172       if (fnd_log.LEVEL_STATEMENT >= fnd_log.g_current_runtime_level) then
173         fnd_log.string(FND_LOG.LEVEL_STATEMENT,
174                        c_log_head || l_api_name || '.submit',
175                    'to recompile, Submitted FNDSCMPI request id:'||request_id);
176       end if;
177     end if;
178   exception
179     when others then /* Don't error out if we can't submit the request.*/
180       if (fnd_log.LEVEL_EXCEPTION >= fnd_log.g_current_runtime_level) then
181         fnd_log.string(FND_LOG.LEVEL_EXCEPTION,
182                        c_log_head || l_api_name || '.req_submit_fail',
183             'Could not submit concurrent request FNDSCMPI to recompile menus');
184         end if;
185   end SUBMIT_MENU_COMPILE;
186 --
187 end FND_JOBS_PKG;