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