1 Package Body pqh_rfe_ins as
2 /* $Header: pqrferhi.pkb 120.0 2005/10/06 14:54 srajakum noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pqh_rfe_ins.'; -- Global package name
9 --
10 -- The following global variables are only to be used by
11 -- the set_base_key_value and pre_insert procedures.
12 --
13 g_rate_factor_on_elmnt_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_rate_factor_on_elmnt_id in number) is
20 --
21 l_proc varchar2(72) := g_package||'set_base_key_value';
22 --
23 Begin
24 hr_utility.set_location('Entering:'||l_proc, 10);
25 --
26 pqh_rfe_ins.g_rate_factor_on_elmnt_id_i := p_rate_factor_on_elmnt_id;
27 --
28 hr_utility.set_location(' Leaving:'||l_proc, 20);
29 End set_base_key_value;
30 --
31 --
32 -- ----------------------------------------------------------------------------
33 -- |-----------------------< create_app_ownerships >--------------------------|
34 -- ----------------------------------------------------------------------------
35 --
36 -- Description:
37 -- This procedure inserts a row into the HR_APPLICATION_OWNERSHIPS table
38 -- when the row handler is called in the appropriate mode.
39 --
40 -- ----------------------------------------------------------------------------
41 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
42 ,p_pk_value IN varchar2) IS
43 --
44 CURSOR csr_definition IS
45 SELECT product_short_name
46 FROM hr_owner_definitions
47 WHERE session_id = hr_startup_data_api_support.g_session_id;
48 --
49 BEGIN
50 --
51 IF (hr_startup_data_api_support.return_startup_mode IN
52 ('STARTUP','GENERIC')) THEN
53 --
54 FOR c1 IN csr_definition LOOP
55 --
56 INSERT INTO hr_application_ownerships
57 (key_name
58 ,key_value
59 ,product_name
60 )
61 VALUES
62 (p_pk_column
63 ,fnd_number.number_to_canonical(p_pk_value)
64 ,c1.product_short_name
65 );
66 END LOOP;
67 END IF;
68 END create_app_ownerships;
69 --
70 -- ----------------------------------------------------------------------------
71 -- |-----------------------< create_app_ownerships >--------------------------|
72 -- ----------------------------------------------------------------------------
73 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
74 ,p_pk_value IN number) IS
75 --
76 BEGIN
77 create_app_ownerships(p_pk_column, to_char(p_pk_value));
78 END create_app_ownerships;
79 --
80 -- ----------------------------------------------------------------------------
81 -- |------------------------------< insert_dml >------------------------------|
82 -- ----------------------------------------------------------------------------
83 -- {Start Of Comments}
84 --
85 -- Description:
86 -- This procedure controls the actual dml insert logic. The processing of
87 -- this procedure are as follows:
88 -- 1) Initialise the object_version_number to 1 if the object_version_number
89 -- is defined as an attribute for this entity.
90 -- 2) To set and unset the g_api_dml status as required (as we are about to
91 -- perform dml).
92 -- 3) To insert the row into the schema.
93 -- 4) To trap any constraint violations that may have occurred.
94 -- 5) To raise any other errors.
95 --
96 -- Prerequisites:
97 -- This is an internal private procedure which must be called from the ins
98 -- procedure and must have all mandatory attributes set (except the
99 -- object_version_number which is initialised within this procedure).
100 --
101 -- In Parameters:
102 -- A Pl/Sql record structre.
103 --
104 -- Post Success:
105 -- The specified row will be inserted into the schema.
106 --
107 -- Post Failure:
108 -- On the insert dml failure it is important to note that we always reset the
109 -- g_api_dml status to false.
110 -- If a check, unique or parent integrity constraint violation is raised the
111 -- constraint_error procedure will be called.
112 -- If any other error is reported, the error will be raised after the
113 -- g_api_dml status is reset.
114 --
115 -- Developer Implementation Notes:
116 -- None.
117 --
118 -- Access Status:
119 -- Internal Row Handler Use Only.
120 --
121 -- {End Of Comments}
122 -- ----------------------------------------------------------------------------
123 Procedure insert_dml
124 (p_rec in out nocopy pqh_rfe_shd.g_rec_type
125 ) is
126 --
127 l_proc varchar2(72) := g_package||'insert_dml';
128 --
129 Begin
130 hr_utility.set_location('Entering:'||l_proc, 5);
131 p_rec.object_version_number := 1; -- Initialise the object version
132 --
133 --
134 --
135 -- Insert the row into: pqh_rate_factor_on_elmnts
136 --
137 insert into pqh_rate_factor_on_elmnts
138 (rate_factor_on_elmnt_id
139 ,criteria_rate_element_id
140 ,criteria_rate_factor_id
141 ,rate_factor_val_record_tbl
142 ,rate_factor_val_record_col
143 ,business_group_id
144 ,legislation_code
145 ,object_version_number
146 )
147 Values
148 (p_rec.rate_factor_on_elmnt_id
149 ,p_rec.criteria_rate_element_id
150 ,p_rec.criteria_rate_factor_id
151 ,p_rec.rate_factor_val_record_tbl
152 ,p_rec.rate_factor_val_record_col
153 ,p_rec.business_group_id
154 ,p_rec.legislation_code
155 ,p_rec.object_version_number
156 );
157 --
158 --
159 --
160 hr_utility.set_location(' Leaving:'||l_proc, 10);
161 Exception
162 When hr_api.check_integrity_violated Then
163 -- A check constraint has been violated
164 --
165 pqh_rfe_shd.constraint_error
166 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
167 When hr_api.parent_integrity_violated Then
168 -- Parent integrity has been violated
169 --
170 pqh_rfe_shd.constraint_error
171 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
172 When hr_api.unique_integrity_violated Then
173 -- Unique integrity has been violated
174 --
175 pqh_rfe_shd.constraint_error
176 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
177 When Others Then
178 --
179 Raise;
180 End insert_dml;
181 --
182 -- ----------------------------------------------------------------------------
183 -- |------------------------------< pre_insert >------------------------------|
184 -- ----------------------------------------------------------------------------
185 -- {Start Of Comments}
186 --
187 -- Description:
188 -- This private procedure contains any processing which is required before
189 -- the insert dml. Presently, if the entity has a corresponding primary
190 -- key which is maintained by an associating sequence, the primary key for
191 -- the entity will be populated with the next sequence value in
192 -- preparation for the insert dml.
193 --
194 -- Prerequisites:
195 -- This is an internal procedure which is called from the ins procedure.
196 --
197 -- In Parameters:
198 -- A Pl/Sql record structure.
199 --
200 -- Post Success:
201 -- Processing continues.
202 --
203 -- Post Failure:
204 -- If an error has occurred, an error message and exception will be raised
205 -- but not handled.
206 --
207 -- Developer Implementation Notes:
208 -- Any pre-processing required before the insert dml is issued should be
209 -- coded within this procedure. As stated above, a good example is the
210 -- generation of a primary key number via a corresponding sequence.
211 -- It is important to note that any 3rd party maintenance should be reviewed
212 -- before placing in this procedure.
213 --
214 -- Access Status:
215 -- Internal Row Handler Use Only.
216 --
217 -- {End Of Comments}
218 -- ----------------------------------------------------------------------------
219 Procedure pre_insert
220 (p_rec in out nocopy pqh_rfe_shd.g_rec_type
221 ) is
222 --
223 Cursor C_Sel1 is select pqh_rate_factor_on_elmnts_s.nextval from sys.dual;
224 --
225 Cursor C_Sel2 is
226 Select null
227 from pqh_rate_factor_on_elmnts
228 where rate_factor_on_elmnt_id =
229 pqh_rfe_ins.g_rate_factor_on_elmnt_id_i;
230 --
231 l_proc varchar2(72) := g_package||'pre_insert';
232 l_exists varchar2(1);
233 --
234 Begin
235 hr_utility.set_location('Entering:'||l_proc, 5);
236 --
237 If (pqh_rfe_ins.g_rate_factor_on_elmnt_id_i is not null) Then
238 --
239 -- Verify registered primary key values not already in use
240 --
241 Open C_Sel2;
242 Fetch C_Sel2 into l_exists;
243 If C_Sel2%found Then
244 Close C_Sel2;
245 --
246 -- The primary key values are already in use.
247 --
248 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
249 fnd_message.set_token('TABLE_NAME','pqh_rate_factor_on_elmnts');
250 fnd_message.raise_error;
251 End If;
252 Close C_Sel2;
253 --
254 -- Use registered key values and clear globals
255 --
256 p_rec.rate_factor_on_elmnt_id :=
257 pqh_rfe_ins.g_rate_factor_on_elmnt_id_i;
258 pqh_rfe_ins.g_rate_factor_on_elmnt_id_i := null;
259 Else
260 --
261 -- No registerd key values, so select the next sequence number
262 --
263 --
264 -- Select the next sequence number
265 --
266 Open C_Sel1;
267 Fetch C_Sel1 Into p_rec.rate_factor_on_elmnt_id;
268 Close C_Sel1;
269 End If;
270 --
271 hr_utility.set_location(' Leaving:'||l_proc, 10);
272 End pre_insert;
273 --
274 -- ----------------------------------------------------------------------------
275 -- |-----------------------------< post_insert >------------------------------|
276 -- ----------------------------------------------------------------------------
277 -- {Start Of Comments}
278 --
279 -- Description:
280 -- This private procedure contains any processing which is required after
281 -- the insert dml.
282 --
283 -- Prerequisites:
284 -- This is an internal procedure which is called from the ins procedure.
285 --
286 -- In Parameters:
287 -- A Pl/Sql record structre.
288 --
289 -- Post Success:
290 -- Processing continues.
291 --
292 -- Post Failure:
293 -- If an error has occurred, an error message and exception will be raised
294 -- but not handled.
295 --
296 -- Developer Implementation Notes:
297 -- Any post-processing required after the insert dml is issued should be
298 -- coded within this procedure. It is important to note that any 3rd party
299 -- maintenance should be reviewed before placing in this procedure.
300 --
301 -- Access Status:
302 -- Internal Row Handler Use Only.
303 --
304 -- {End Of Comments}
305 -- ----------------------------------------------------------------------------
306 Procedure post_insert
307 (p_effective_date in date
308 ,p_rec in pqh_rfe_shd.g_rec_type
309 ) is
310 --
311 l_proc varchar2(72) := g_package||'post_insert';
312 --
313 Begin
314 hr_utility.set_location('Entering:'||l_proc, 5);
315 begin
316 --
317 -- insert ownerships if applicable
318 create_app_ownerships
319 ('RATE_FACTOR_ON_ELMNT_ID', p_rec.rate_factor_on_elmnt_id
320 );
321 --
322 --
323 pqh_rfe_rki.after_insert
324 (p_effective_date => p_effective_date
325 ,p_rate_factor_on_elmnt_id
326 => p_rec.rate_factor_on_elmnt_id
327 ,p_criteria_rate_element_id
328 => p_rec.criteria_rate_element_id
329 ,p_criteria_rate_factor_id
330 => p_rec.criteria_rate_factor_id
331 ,p_rate_factor_val_record_tbl
332 => p_rec.rate_factor_val_record_tbl
333 ,p_rate_factor_val_record_col
334 => p_rec.rate_factor_val_record_col
335 ,p_business_group_id
336 => p_rec.business_group_id
337 ,p_legislation_code
338 => p_rec.legislation_code
339 ,p_object_version_number
340 => p_rec.object_version_number
341 );
342 --
343 exception
344 --
345 when hr_api.cannot_find_prog_unit then
346 --
347 hr_api.cannot_find_prog_unit_error
348 (p_module_name => 'PQH_RATE_FACTOR_ON_ELMNTS'
349 ,p_hook_type => 'AI');
350 --
351 end;
352 --
353 hr_utility.set_location(' Leaving:'||l_proc, 10);
354 End post_insert;
355 --
356 -- ----------------------------------------------------------------------------
357 -- |---------------------------------< ins >----------------------------------|
358 -- ----------------------------------------------------------------------------
359 Procedure ins
360 (p_effective_date in date
361 ,p_rec in out nocopy pqh_rfe_shd.g_rec_type
362 ) is
363 --
364 l_proc varchar2(72) := g_package||'ins';
365 --
366 Begin
367 hr_utility.set_location('Entering:'||l_proc, 5);
368 --
369 -- Call the supporting insert validate operations
370 --
371 pqh_rfe_bus.insert_validate
372 (p_effective_date
373 ,p_rec
374 );
375 --
376 -- Call to raise any errors on multi-message list
377 hr_multi_message.end_validation_set;
378 --
379 -- Call the supporting pre-insert operation
380 --
381 pqh_rfe_ins.pre_insert(p_rec);
382 --
383 -- Insert the row
384 --
385 pqh_rfe_ins.insert_dml(p_rec);
386 --
387 -- Call the supporting post-insert operation
388 --
389 pqh_rfe_ins.post_insert
390 (p_effective_date
391 ,p_rec
392 );
393 --
394 -- Call to raise any errors on multi-message list
395 hr_multi_message.end_validation_set;
396 --
397 hr_utility.set_location('Leaving:'||l_proc, 20);
398 end ins;
399 --
400 -- ----------------------------------------------------------------------------
401 -- |---------------------------------< ins >----------------------------------|
402 -- ----------------------------------------------------------------------------
403 Procedure ins
404 (p_effective_date in date
405 ,p_criteria_rate_element_id in number
406 ,p_criteria_rate_factor_id in number
407 ,p_rate_factor_val_record_tbl in varchar2
408 ,p_rate_factor_val_record_col in varchar2
409 ,p_business_group_id in number default null
410 ,p_legislation_code in varchar2 default null
411 ,p_rate_factor_on_elmnt_id out nocopy number
412 ,p_object_version_number out nocopy number
413 ) is
414 --
415 l_rec pqh_rfe_shd.g_rec_type;
416 l_proc varchar2(72) := g_package||'ins';
417 --
418 Begin
419 hr_utility.set_location('Entering:'||l_proc, 5);
420 --
421 -- Call conversion function to turn arguments into the
422 -- p_rec structure.
423 --
424 l_rec :=
425 pqh_rfe_shd.convert_args
426 (null
427 ,p_criteria_rate_element_id
428 ,p_criteria_rate_factor_id
429 ,p_rate_factor_val_record_tbl
430 ,p_rate_factor_val_record_col
431 ,p_business_group_id
432 ,p_legislation_code
433 ,null
434 );
435 --
436 -- Having converted the arguments into the pqh_rfe_rec
437 -- plsql record structure we call the corresponding record business process.
438 --
439 pqh_rfe_ins.ins
440 (p_effective_date
441 ,l_rec
442 );
443 --
444 -- As the primary key argument(s)
445 -- are specified as an OUT's we must set these values.
446 --
447 p_rate_factor_on_elmnt_id := l_rec.rate_factor_on_elmnt_id;
448 p_object_version_number := l_rec.object_version_number;
449 --
450 hr_utility.set_location(' Leaving:'||l_proc, 10);
451 End ins;
452 --
453 end pqh_rfe_ins;