DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_BAD_INS

Source


1 Package Body pay_bad_ins as
2 /* $Header: pybadrhi.pkb 115.3 2003/05/28 18:43:28 rthirlby noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_bad_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_attribute_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_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_bad_ins.g_attribute_id_i := p_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_bad_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_definitions
135   --
136   insert into pay_bal_attribute_definitions
137       (attribute_id
138       ,attribute_name
139       ,alterable
140       ,legislation_code
141       ,business_group_id
142       ,user_attribute_name
143       )
144   Values
145     (p_rec.attribute_id
146     ,p_rec.attribute_name
147     ,p_rec.alterable
148     ,p_rec.legislation_code
149     ,p_rec.business_group_id
150     ,p_rec.user_attribute_name
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_bad_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_bad_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_bad_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_bad_shd.g_rec_type
216   ) is
217 --
218   Cursor C_Sel1 is select pay_bal_attribute_definition_s.nextval from sys.dual;
219 --
220   Cursor C_Sel2 is
221     Select null
222       from pay_bal_attribute_definitions
223      where attribute_id =
224              pay_bad_ins.g_attribute_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_bad_ins.g_attribute_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_definitions');
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.attribute_id :=
252       pay_bad_ins.g_attribute_id_i;
253     pay_bad_ins.g_attribute_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.attribute_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_effective_date               in date
303   ,p_rec                          in pay_bad_shd.g_rec_type
304   ) is
305 --
306   l_proc  varchar2(72) := g_package||'post_insert';
307 --
308 Begin
309   hr_utility.set_location('Entering:'||l_proc, 5);
310   begin
311     --
312     -- insert ownerships if applicable
313     create_app_ownerships
314       ('ATTRIBUTE_ID', p_rec.attribute_id
315       );
316     --
317     --
318     pay_bad_rki.after_insert
319       (p_effective_date              => p_effective_date
320       ,p_attribute_id
321       => p_rec.attribute_id
322       ,p_attribute_name
323       => p_rec.attribute_name
324       ,p_alterable
325       => p_rec.alterable
326       ,p_legislation_code
327       => p_rec.legislation_code
328       ,p_business_group_id
329       => p_rec.business_group_id
330       ,p_user_attribute_name
331       => p_rec.user_attribute_name
332       );
333     --
334   exception
335     --
336     when hr_api.cannot_find_prog_unit then
337       --
338       hr_api.cannot_find_prog_unit_error
339         (p_module_name => 'PAY_BAL_ATTRIBUTE_DEFINITIONS'
340         ,p_hook_type   => 'AI');
341       --
342   end;
343   --
344   hr_utility.set_location(' Leaving:'||l_proc, 10);
345 End post_insert;
346 --
347 -- ----------------------------------------------------------------------------
348 -- |---------------------------------< ins >----------------------------------|
349 -- ----------------------------------------------------------------------------
350 Procedure ins
351   (p_effective_date               in date
352   ,p_rec                          in out nocopy pay_bad_shd.g_rec_type
353   ) is
354 --
355   l_proc  varchar2(72) := g_package||'ins';
356 --
357 Begin
358   hr_utility.set_location('Entering:'||l_proc, 5);
359   --
360   -- Call the supporting insert validate operations
361   --
362   pay_bad_bus.insert_validate
363      (p_effective_date
364      ,p_rec
365      );
366   --
367   -- Call to raise any errors on multi-message list
368   hr_multi_message.end_validation_set;
369   --
370   -- Call the supporting pre-insert operation
371   --
372   pay_bad_ins.pre_insert(p_rec);
373   --
374   -- Insert the row
375   --
376   pay_bad_ins.insert_dml(p_rec);
377   --
378   -- Call the supporting post-insert operation
379   --
380   pay_bad_ins.post_insert
381      (p_effective_date
382      ,p_rec
383      );
384   --
385   -- Call to raise any errors on multi-message list
386   hr_multi_message.end_validation_set;
387   --
388   hr_utility.set_location('Leaving:'||l_proc, 20);
389 end ins;
390 --
391 -- ----------------------------------------------------------------------------
392 -- |---------------------------------< ins >----------------------------------|
393 -- ----------------------------------------------------------------------------
394 Procedure ins
395   (p_effective_date                 in     date
396   ,p_attribute_name                 in     varchar2
397   ,p_alterable                      in     varchar2 default null
398   ,p_legislation_code               in     varchar2 default null
399   ,p_business_group_id              in     number   default null
400   ,p_user_attribute_name            in     varchar2 default null
401   ,p_attribute_id                      out nocopy number
402   ) is
403 --
404   l_rec   pay_bad_shd.g_rec_type;
405   l_proc  varchar2(72) := g_package||'ins';
406 --
407 Begin
408   hr_utility.set_location('Entering:'||l_proc, 5);
409   --
410   -- Call conversion function to turn arguments into the
411   -- p_rec structure.
412   --
413   l_rec :=
414   pay_bad_shd.convert_args
415     (null
416     ,p_attribute_name
417     ,p_alterable
418     ,p_legislation_code
419     ,p_business_group_id
420     ,p_user_attribute_name
421     );
422   --
423   -- Having converted the arguments into the pay_bad_rec
424   -- plsql record structure we call the corresponding record business process.
425   --
426   pay_bad_ins.ins
427      (p_effective_date
428      ,l_rec
429      );
430   --
431   -- As the primary key argument(s)
432   -- are specified as an OUT's we must set these values.
433   --
434   p_attribute_id := l_rec.attribute_id;
435   --
436   hr_utility.set_location(' Leaving:'||l_proc, 10);
437 End ins;
438 --
439 end pay_bad_ins;