[Home] [Help]
PACKAGE BODY: APPS.HRI_OLTP_CONC_SUPH_MASTER
Source
1 PACKAGE BODY hri_oltp_conc_suph_master AS
2 /* $Header: hriocshh.pkb 120.0 2005/05/29 07:27:23 appldev noship $ */
3
4 error_launching_thread EXCEPTION;
5 request_error EXCEPTION;
6
7 -- Write to log if debugging is set
8 PROCEDURE dbg(p_message IN VARCHAR2) IS
9
10 BEGIN
11 HRI_BPL_CONC_LOG.dbg(p_message);
12 END dbg;
13
14 FUNCTION get_stage RETURN VARCHAR2 IS
15
16 -- Used to store the return value of fnd_conc_global.request_data. If
17 -- it is non null then this indicates that the process has returned
18 -- from a paused state.
19 l_request_data VARCHAR2(240);
20
21 -- Variables to hold results of cursor
22 l_program_name VARCHAR2(240);
23 l_phase_code VARCHAR2(30);
24 l_status_code VARCHAR2(30);
25
26 -- Return variable holding process stage
27 l_child VARCHAR2(30);
28 l_status VARCHAR2(30);
29 l_process_stage VARCHAR2(240);
30
31 -- Get request name and status
32 CURSOR request_csr(v_request_id NUMBER) IS
33 SELECT
34 fcp.concurrent_program_name
35 ,fcr.phase_code
36 ,fcr.status_code
37 FROM
38 fnd_concurrent_requests fcr
39 ,fnd_concurrent_programs fcp
40 WHERE fcr.request_id = v_request_id
41 AND fcr.concurrent_program_id = fcp.concurrent_program_id
42 AND fcr.program_application_id = fcp.application_id;
43
44 BEGIN
45
46 -- Call fnd_conc_global.request_data, to see if this program is re-entering
47 -- after being paused.
48 l_request_data := fnd_conc_global.request_data;
49
50 -- Check whether a previous child request is completed
51 IF l_request_data IS NOT NULL THEN
52
53 -- A child request has just completed - get the details
54 OPEN request_csr(l_request_data);
55 FETCH request_csr INTO
56 l_program_name,
57 l_phase_code,
58 l_status_code;
59 CLOSE request_csr;
60
61 -- Check if error
62 IF (l_status_code = 'E') THEN
63 l_status := 'ERROR';
64 ELSE
65 l_status := 'COMPLETE';
66 END IF;
67
68 -- Check which child ran
69 IF (l_program_name = 'HRI_CS_ASGN_SUPH_EVENTS_CT') THEN
70 l_child := 'FIRST';
71 ELSE
72 l_child := 'SECOND';
73 END IF;
74
75 -- Set the return variable
76 l_process_stage := l_child || '_CHILD_' || l_status;
77
78 ELSE
79
80 -- Initial call
81 l_process_stage := 'INITIAL';
82
83 END IF;
84
85 RETURN l_process_stage;
86
87 END get_stage;
88
89 PROCEDURE launch_process(p_program_name IN VARCHAR2,
90 p_argument1 IN VARCHAR2 DEFAULT NULL,
91 p_argument2 IN VARCHAR2 DEFAULT NULL,
92 p_argument3 IN VARCHAR2 DEFAULT NULL,
93 p_argument4 IN VARCHAR2 DEFAULT NULL,
94 p_argument5 IN VARCHAR2 DEFAULT NULL) IS
95
96 l_request_id NUMBER;
97
98 BEGIN
99
100 l_request_id := fnd_request.submit_request
101 (application => 'HRI'
102 ,program => p_program_name
103 ,sub_request => TRUE
104 ,argument1 => p_argument1
105 ,argument2 => p_argument2
106 ,argument3 => p_argument3
107 ,argument4 => p_argument4
108 ,argument5 => p_argument5);
109
110 -- Raise exception if submission failed
111 IF l_request_id = 0 then
112 RAISE error_launching_thread;
113 END IF;
114
115 -- Wait for process to complete
116 fnd_conc_global.set_req_globals(conc_status => 'PAUSED',
117 request_data=> TO_CHAR(l_request_id));
118
119 END launch_process;
120
121 -- ----------------------------------------------------------------------------
122 -- Entry point to be called from the concurrent manager
123 -- ----------------------------------------------------------------------------
124 PROCEDURE load_all_managers(errbuf OUT NOCOPY VARCHAR2,
125 retcode OUT NOCOPY VARCHAR2,
126 p_chunk_size IN NUMBER,
127 p_start_date IN VARCHAR2,
128 p_end_date IN VARCHAR2,
129 p_full_refresh IN VARCHAR2) IS
130
131 l_business_group_id NUMBER;
132 l_stage VARCHAR2(30);
133
134 BEGIN
135
136 -- Initialize business group id
137 l_business_group_id := fnd_profile.value('PER_BUSINESS_GROUP_ID');
138
139 -- Get the process stage
140 l_stage := get_stage;
141
142 dbg('Procedure start - phase: ' || l_stage);
143
144 -- Take action corresponding to the process stage
145 IF (l_stage = 'INITIAL') THEN
146
147 -- Initial stage - submit first child process
148 launch_process
149 (p_program_name => 'HRI_CS_ASGN_SUPH_EVENTS_CT',
150 p_argument1 => 'HRI_OPL_SUPH_EVENTS',
151 p_argument2 => to_char(l_business_group_id),
152 p_argument3 => p_start_date,
153 p_argument4 => fnd_date.date_to_canonical(trunc(sysdate)),
154 p_argument5 => p_full_refresh);
155
156 dbg('Launched helper request');
157
158 ELSIF (l_stage = 'FIRST_CHILD_COMPLETE') THEN
159
160 -- First child process is complete - submit second
161 launch_process
162 (p_program_name => 'HRI_CS_SUPH',
163 p_argument1 => 'HRI_OPL_SUPH_HST',
164 p_argument2 => to_char(l_business_group_id),
165 p_argument3 => p_start_date,
166 p_argument4 => fnd_date.date_to_canonical(trunc(sysdate)),
167 p_argument5 => p_full_refresh);
168
169 dbg('Launched main request');
170
171 ELSIF (l_stage = 'SECOND_CHILD_COMPLETE') THEN
172
173 -- Both child processes complete - log success
174 null;
175
176 ELSE
177
178 -- An error occurred
179 RAISE request_error;
180
181 END IF;
182
183 EXCEPTION
184 --
185 WHEN OTHERS THEN
186 --
187 dbg('Exception');
188 errbuf := SQLERRM;
189 retcode := SQLCODE;
190 --
191 RAISE;
192 --
193 END load_all_managers;
194
195 END hri_oltp_conc_suph_master;