1 Package Body pay_pbd_ins as
2 /* $Header: pypbdrhi.pkb 115.1 2002/12/11 15:12:08 exjones noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pay_pbd_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_bal_attribute_default_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_bal_attribute_default_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 pay_pbd_ins.g_bal_attribute_default_id_i := p_bal_attribute_default_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 pay_pbd_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 --
132 --
133 --
134 -- Insert the row into: pay_bal_attribute_defaults
135 --
136 insert into pay_bal_attribute_defaults
137 (bal_attribute_default_id
138 ,attribute_id
139 ,balance_dimension_id
140 ,balance_category_id
141 ,legislation_code
142 ,business_group_id
143 )
144 Values
145 (p_rec.bal_attribute_default_id
146 ,p_rec.attribute_id
147 ,p_rec.balance_dimension_id
148 ,p_rec.balance_category_id
149 ,p_rec.legislation_code
150 ,p_rec.business_group_id
151 );
152 --
153 --
154 --
155 hr_utility.set_location(' Leaving:'||l_proc, 10);
156 Exception
157 When hr_api.check_integrity_violated Then
158 -- A check constraint has been violated
159 --
160 pay_pbd_shd.constraint_error
161 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
162 When hr_api.parent_integrity_violated Then
163 -- Parent integrity has been violated
164 --
165 pay_pbd_shd.constraint_error
166 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
167 When hr_api.unique_integrity_violated Then
168 -- Unique integrity has been violated
169 --
170 pay_pbd_shd.constraint_error
171 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
172 When Others Then
173 --
174 Raise;
175 End insert_dml;
176 --
177 -- ----------------------------------------------------------------------------
178 -- |------------------------------< pre_insert >------------------------------|
179 -- ----------------------------------------------------------------------------
180 -- {Start Of Comments}
181 --
182 -- Description:
183 -- This private procedure contains any processing which is required before
184 -- the insert dml. Presently, if the entity has a corresponding primary
185 -- key which is maintained by an associating sequence, the primary key for
186 -- the entity will be populated with the next sequence value in
187 -- preparation for the insert dml.
188 --
189 -- Prerequisites:
190 -- This is an internal procedure which is called from the ins procedure.
191 --
192 -- In Parameters:
193 -- A Pl/Sql record structure.
194 --
195 -- Post Success:
196 -- Processing continues.
197 --
198 -- Post Failure:
199 -- If an error has occurred, an error message and exception will be raised
200 -- but not handled.
201 --
202 -- Developer Implementation Notes:
203 -- Any pre-processing required before the insert dml is issued should be
204 -- coded within this procedure. As stated above, a good example is the
205 -- generation of a primary key number via a corresponding sequence.
206 -- It is important to note that any 3rd party maintenance should be reviewed
207 -- before placing in this procedure.
208 --
209 -- Access Status:
210 -- Internal Row Handler Use Only.
211 --
212 -- {End Of Comments}
213 -- ----------------------------------------------------------------------------
214 Procedure pre_insert
215 (p_rec in out nocopy pay_pbd_shd.g_rec_type
216 ) is
217 --
218 Cursor C_Sel1 is select pay_bal_attribute_defaults_s.nextval from sys.dual;
219 --
220 Cursor C_Sel2 is
221 Select null
222 from pay_bal_attribute_defaults
223 where bal_attribute_default_id =
224 pay_pbd_ins.g_bal_attribute_default_id_i;
225 --
226 l_proc varchar2(72) := g_package||'pre_insert';
227 l_exists varchar2(1);
228 --
229 Begin
230 hr_utility.set_location('Entering:'||l_proc, 5);
231 --
232 If (pay_pbd_ins.g_bal_attribute_default_id_i is not null) Then
233 --
234 -- Verify registered primary key values not already in use
235 --
236 Open C_Sel2;
237 Fetch C_Sel2 into l_exists;
238 If C_Sel2%found Then
239 Close C_Sel2;
240 --
241 -- The primary key values are already in use.
242 --
243 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
244 fnd_message.set_token('TABLE_NAME','pay_bal_attribute_defaults');
245 fnd_message.raise_error;
246 End If;
247 Close C_Sel2;
248 --
249 -- Use registered key values and clear globals
250 --
251 p_rec.bal_attribute_default_id :=
252 pay_pbd_ins.g_bal_attribute_default_id_i;
253 pay_pbd_ins.g_bal_attribute_default_id_i := null;
254 Else
255 --
256 -- No registerd key values, so select the next sequence number
257 --
258 --
259 -- Select the next sequence number
260 --
261 Open C_Sel1;
262 Fetch C_Sel1 Into p_rec.bal_attribute_default_id;
263 Close C_Sel1;
264 End If;
265 --
266 hr_utility.set_location(' Leaving:'||l_proc, 10);
267 End pre_insert;
268 --
269 -- ----------------------------------------------------------------------------
270 -- |-----------------------------< post_insert >------------------------------|
271 -- ----------------------------------------------------------------------------
272 -- {Start Of Comments}
273 --
274 -- Description:
275 -- This private procedure contains any processing which is required after
276 -- the insert dml.
277 --
278 -- Prerequisites:
279 -- This is an internal procedure which is called from the ins procedure.
280 --
281 -- In Parameters:
282 -- A Pl/Sql record structre.
283 --
284 -- Post Success:
285 -- Processing continues.
286 --
287 -- Post Failure:
288 -- If an error has occurred, an error message and exception will be raised
289 -- but not handled.
290 --
291 -- Developer Implementation Notes:
292 -- Any post-processing required after the insert dml is issued should be
293 -- coded within this procedure. It is important to note that any 3rd party
294 -- maintenance should be reviewed before placing in this procedure.
295 --
296 -- Access Status:
297 -- Internal Row Handler Use Only.
298 --
299 -- {End Of Comments}
300 -- ----------------------------------------------------------------------------
301 Procedure post_insert
302 (p_rec in pay_pbd_shd.g_rec_type
303 ) is
304 --
305 l_proc varchar2(72) := g_package||'post_insert';
306 --
307 Begin
308 hr_utility.set_location('Entering:'||l_proc, 5);
309 begin
310 --
311 -- insert ownerships if applicable
312 create_app_ownerships
313 ('BAL_ATTRIBUTE_DEFAULT_ID', p_rec.bal_attribute_default_id
314 );
315 --
316 --
317 pay_pbd_rki.after_insert
318 (p_bal_attribute_default_id
319 => p_rec.bal_attribute_default_id
320 ,p_attribute_id
321 => p_rec.attribute_id
322 ,p_balance_dimension_id
323 => p_rec.balance_dimension_id
324 ,p_balance_category_id
325 => p_rec.balance_category_id
326 ,p_legislation_code
327 => p_rec.legislation_code
328 ,p_business_group_id
329 => p_rec.business_group_id
330 );
331 --
332 exception
333 --
334 when hr_api.cannot_find_prog_unit then
335 --
336 hr_api.cannot_find_prog_unit_error
337 (p_module_name => 'PAY_BAL_ATTRIBUTE_DEFAULTS'
338 ,p_hook_type => 'AI');
339 --
340 end;
341 --
342 hr_utility.set_location(' Leaving:'||l_proc, 10);
343 End post_insert;
344 --
345 -- ----------------------------------------------------------------------------
346 -- |---------------------------------< ins >----------------------------------|
347 -- ----------------------------------------------------------------------------
348 Procedure ins
349 (p_rec in out nocopy pay_pbd_shd.g_rec_type
350 ) is
351 --
352 l_proc varchar2(72) := g_package||'ins';
353 --
354 Begin
355 hr_utility.set_location('Entering:'||l_proc, 5);
356 --
357 -- Call the supporting insert validate operations
358 --
359 pay_pbd_bus.insert_validate
360 (p_rec
361 );
362 --
363 -- Call to raise any errors on multi-message list
364 hr_multi_message.end_validation_set;
365 --
366 -- Call the supporting pre-insert operation
367 --
368 pay_pbd_ins.pre_insert(p_rec);
369 --
370 -- Insert the row
371 --
372 pay_pbd_ins.insert_dml(p_rec);
373 --
374 -- Call the supporting post-insert operation
375 --
376 pay_pbd_ins.post_insert
377 (p_rec
378 );
379 --
380 -- Call to raise any errors on multi-message list
381 hr_multi_message.end_validation_set;
382 --
383 hr_utility.set_location('Leaving:'||l_proc, 20);
384 end ins;
385 --
386 -- ----------------------------------------------------------------------------
387 -- |---------------------------------< ins >----------------------------------|
388 -- ----------------------------------------------------------------------------
389 Procedure ins
390 (p_attribute_id in number
391 ,p_balance_dimension_id in number
392 ,p_balance_category_id in number
393 ,p_legislation_code in varchar2 default null
394 ,p_business_group_id in number default null
395 ,p_bal_attribute_default_id out nocopy number
396 ) is
397 --
398 l_rec pay_pbd_shd.g_rec_type;
399 l_proc varchar2(72) := g_package||'ins';
400 --
401 Begin
402 hr_utility.set_location('Entering:'||l_proc, 5);
403 --
404 -- Call conversion function to turn arguments into the
405 -- p_rec structure.
406 --
407 l_rec :=
408 pay_pbd_shd.convert_args
409 (null
410 ,p_attribute_id
411 ,p_balance_dimension_id
412 ,p_balance_category_id
413 ,p_legislation_code
414 ,p_business_group_id
415 );
416 --
417 -- Having converted the arguments into the pay_pbd_rec
418 -- plsql record structure we call the corresponding record business process.
419 --
420 pay_pbd_ins.ins
421 (l_rec
422 );
423 --
424 -- As the primary key argument(s)
425 -- are specified as an OUT's we must set these values.
426 --
427 p_bal_attribute_default_id := l_rec.bal_attribute_default_id;
428 --
429 hr_utility.set_location(' Leaving:'||l_proc, 10);
430 End ins;
431 --
432 end pay_pbd_ins;