DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_TDF_INS

Source


1 Package Body pay_tdf_ins as
2 /* $Header: pytdfrhi.pkb 120.4.12020000.2 2012/07/05 02:54:09 amnaraya ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_tdf_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_time_definition_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_time_definition_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_tdf_ins.g_time_definition_id_i := p_time_definition_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_tdf_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   pay_tdf_shd.g_api_dml := true;  -- Set the api dml status
134   --
135   -- Insert the row into: pay_time_definitions
136   --
137   insert into pay_time_definitions
138       (time_definition_id
139       ,short_name
140       ,definition_name
141       ,period_type
142       ,period_unit
143       ,day_adjustment
144       ,dynamic_code
145       ,business_group_id
146       ,legislation_code
147       ,definition_type
148       ,number_of_years
149       ,start_date
150       ,period_time_definition_id
151       ,creator_id
152       ,creator_type
153       ,object_version_number
154       )
155   Values
156     (p_rec.time_definition_id
157     ,p_rec.short_name
158     ,p_rec.definition_name
159     ,p_rec.period_type
160     ,p_rec.period_unit
161     ,p_rec.day_adjustment
162     ,p_rec.dynamic_code
163     ,p_rec.business_group_id
164     ,p_rec.legislation_code
165     ,p_rec.definition_type
166     ,p_rec.number_of_years
167     ,p_rec.start_date
168     ,p_rec.period_time_definition_id
169     ,p_rec.creator_id
170     ,p_rec.creator_type
171     ,p_rec.object_version_number
172     );
173   --
174   pay_tdf_shd.g_api_dml := false;   -- Unset the api dml status
175   --
176   hr_utility.set_location(' Leaving:'||l_proc, 10);
177 Exception
178   When hr_api.check_integrity_violated Then
179     -- A check constraint has been violated
180     pay_tdf_shd.g_api_dml := false;   -- Unset the api dml status
181     pay_tdf_shd.constraint_error
182       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
183   When hr_api.parent_integrity_violated Then
184     -- Parent integrity has been violated
185     pay_tdf_shd.g_api_dml := false;   -- Unset the api dml status
186     pay_tdf_shd.constraint_error
187       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
188   When hr_api.unique_integrity_violated Then
189     -- Unique integrity has been violated
190     pay_tdf_shd.g_api_dml := false;   -- Unset the api dml status
191     pay_tdf_shd.constraint_error
192       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
193   When Others Then
194     pay_tdf_shd.g_api_dml := false;   -- Unset the api dml status
195     Raise;
196 End insert_dml;
197 --
198 -- ----------------------------------------------------------------------------
199 -- |------------------------------< pre_insert >------------------------------|
200 -- ----------------------------------------------------------------------------
201 -- {Start Of Comments}
202 --
203 -- Description:
204 --   This private procedure contains any processing which is required before
205 --   the insert dml. Presently, if the entity has a corresponding primary
206 --   key which is maintained by an associating sequence, the primary key for
207 --   the entity will be populated with the next sequence value in
208 --   preparation for the insert dml.
209 --
210 -- Prerequisites:
211 --   This is an internal procedure which is called from the ins procedure.
212 --
213 -- In Parameters:
214 --   A Pl/Sql record structure.
215 --
216 -- Post Success:
217 --   Processing continues.
218 --
219 -- Post Failure:
220 --   If an error has occurred, an error message and exception will be raised
221 --   but not handled.
222 --
223 -- Developer Implementation Notes:
224 --   Any pre-processing required before the insert dml is issued should be
225 --   coded within this procedure. As stated above, a good example is the
226 --   generation of a primary key number via a corresponding sequence.
227 --   It is important to note that any 3rd party maintenance should be reviewed
228 --   before placing in this procedure.
229 --
230 -- Access Status:
231 --   Internal Row Handler Use Only.
232 --
233 -- {End Of Comments}
234 -- ----------------------------------------------------------------------------
235 Procedure pre_insert
236   (p_rec  in out nocopy pay_tdf_shd.g_rec_type
237   ) is
238 --
239   Cursor C_Sel1 is select pay_time_definitions_s.nextval from sys.dual;
240 --
241   Cursor C_Sel2 is
242     Select null
243       from pay_time_definitions
244      where time_definition_id =
245              pay_tdf_ins.g_time_definition_id_i;
246 --
247   l_proc   varchar2(72) := g_package||'pre_insert';
248   l_exists varchar2(1);
249 --
250 Begin
251   hr_utility.set_location('Entering:'||l_proc, 5);
252   --
253   If (pay_tdf_ins.g_time_definition_id_i is not null) Then
254     --
255     -- Verify registered primary key values not already in use
256     --
257     Open C_Sel2;
258     Fetch C_Sel2 into l_exists;
259     If C_Sel2%found Then
260        Close C_Sel2;
261        --
262        -- The primary key values are already in use.
263        --
264        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
265        fnd_message.set_token('TABLE_NAME','pay_time_definitions');
266        fnd_message.raise_error;
267     End If;
268     Close C_Sel2;
269     --
270     -- Use registered key values and clear globals
271     --
272     p_rec.time_definition_id :=
273       pay_tdf_ins.g_time_definition_id_i;
274     pay_tdf_ins.g_time_definition_id_i := null;
275   Else
276     --
277     -- No registerd key values, so select the next sequence number
278     --
279     --
280     -- Select the next sequence number
281     --
282     Open C_Sel1;
283     Fetch C_Sel1 Into p_rec.time_definition_id;
284     Close C_Sel1;
285   End If;
286   --
287   hr_utility.set_location(' Leaving:'||l_proc, 10);
288 End pre_insert;
289 --
290 -- ----------------------------------------------------------------------------
291 -- |-----------------------------< post_insert >------------------------------|
292 -- ----------------------------------------------------------------------------
293 -- {Start Of Comments}
294 --
295 -- Description:
296 --   This private procedure contains any processing which is required after
297 --   the insert dml.
298 --
299 -- Prerequisites:
300 --   This is an internal procedure which is called from the ins procedure.
301 --
302 -- In Parameters:
303 --   A Pl/Sql record structre.
304 --
305 -- Post Success:
306 --   Processing continues.
307 --
308 -- Post Failure:
309 --   If an error has occurred, an error message and exception will be raised
310 --   but not handled.
311 --
312 -- Developer Implementation Notes:
313 --   Any post-processing required after the insert dml is issued should be
314 --   coded within this procedure. It is important to note that any 3rd party
315 --   maintenance should be reviewed before placing in this procedure.
316 --
317 -- Access Status:
318 --   Internal Row Handler Use Only.
319 --
320 -- {End Of Comments}
321 -- ----------------------------------------------------------------------------
322 Procedure post_insert
323   (p_effective_date               in date
324   ,p_rec                          in pay_tdf_shd.g_rec_type
325   ) is
326 --
327   l_proc  varchar2(72) := g_package||'post_insert';
328 --
329 Begin
330   hr_utility.set_location('Entering:'||l_proc, 5);
331   begin
332     --
333     -- insert ownerships if applicable
334     create_app_ownerships
335       ('TIME_DEFINITION_ID', p_rec.time_definition_id
336       );
337     --
338     --
339     pay_tdf_rki.after_insert
340       (p_effective_date              => p_effective_date
341       ,p_time_definition_id
342       => p_rec.time_definition_id
343       ,p_short_name
344       => p_rec.short_name
345       ,p_definition_name
346       => p_rec.definition_name
347       ,p_period_type
348       => p_rec.period_type
349       ,p_period_unit
350       => p_rec.period_unit
351       ,p_day_adjustment
352       => p_rec.day_adjustment
353       ,p_dynamic_code
354       => p_rec.dynamic_code
355       ,p_business_group_id
356       => p_rec.business_group_id
357       ,p_legislation_code
358       => p_rec.legislation_code
359       ,p_definition_type
360       => p_rec.definition_type
361       ,p_number_of_years
362       => p_rec.number_of_years
363       ,p_start_date
364       => p_rec.start_date
365       ,p_period_time_definition_id
366       => p_rec.period_time_definition_id
367       ,p_creator_id
368       => p_rec.creator_id
369       ,p_creator_type
370       => p_rec.creator_type
371       ,p_object_version_number
372       => p_rec.object_version_number
373       );
374     --
375   exception
376     --
377     when hr_api.cannot_find_prog_unit then
378       --
379       hr_api.cannot_find_prog_unit_error
380         (p_module_name => 'PAY_TIME_DEFINITIONS'
381         ,p_hook_type   => 'AI');
382       --
383   end;
384   --
385   hr_utility.set_location(' Leaving:'||l_proc, 10);
386 End post_insert;
387 --
388 -- ----------------------------------------------------------------------------
389 -- |---------------------------------< ins >----------------------------------|
390 -- ----------------------------------------------------------------------------
391 Procedure ins
392   (p_effective_date               in date
393   ,p_rec                          in out nocopy pay_tdf_shd.g_rec_type
394   ) is
395 --
396   l_proc  varchar2(72) := g_package||'ins';
397 --
398 Begin
399   hr_utility.set_location('Entering:'||l_proc, 5);
400   --
401   -- Call the supporting insert validate operations
402   --
403   pay_tdf_bus.insert_validate
404      (p_effective_date
405      ,p_rec
406      );
407   --
408   -- Call to raise any errors on multi-message list
409   hr_multi_message.end_validation_set;
410   --
411   -- Call the supporting pre-insert operation
412   --
413   pay_tdf_ins.pre_insert(p_rec);
414   --
415   -- Insert the row
416   --
417   pay_tdf_ins.insert_dml(p_rec);
418   --
419   -- Call the supporting post-insert operation
420   --
421   pay_tdf_ins.post_insert
422      (p_effective_date
423      ,p_rec
424      );
425   --
426   -- Call to raise any errors on multi-message list
427   hr_multi_message.end_validation_set;
428   --
429   hr_utility.set_location('Leaving:'||l_proc, 20);
430 end ins;
431 --
432 -- ----------------------------------------------------------------------------
433 -- |---------------------------------< ins >----------------------------------|
434 -- ----------------------------------------------------------------------------
435 Procedure ins
436   (p_effective_date               in     date
437   ,p_short_name                     in     varchar2
438   ,p_definition_name                in     varchar2
439   ,p_period_type                    in     varchar2 default null
440   ,p_period_unit                    in     varchar2 default null
441   ,p_day_adjustment                 in     varchar2 default null
442   ,p_dynamic_code                   in     varchar2 default null
443   ,p_business_group_id              in     number   default null
444   ,p_legislation_code               in     varchar2 default null
445   ,p_definition_type                in     varchar2 default null
446   ,p_number_of_years                in     number   default null
447   ,p_start_date                     in     date     default null
448   ,p_period_time_definition_id      in     number   default null
449   ,p_creator_id                     in     number   default null
450   ,p_creator_type                   in     varchar2 default null
451   ,p_time_definition_id                out nocopy number
452   ,p_object_version_number             out nocopy number
453   ) is
454 --
455   l_rec   pay_tdf_shd.g_rec_type;
456   l_proc  varchar2(72) := g_package||'ins';
457 --
458 Begin
459   hr_utility.set_location('Entering:'||l_proc, 5);
460   --
461   -- Call conversion function to turn arguments into the
462   -- p_rec structure.
463   --
464   l_rec :=
465   pay_tdf_shd.convert_args
466     (null
467     ,p_short_name
468     ,p_definition_name
469     ,p_period_type
470     ,p_period_unit
471     ,p_day_adjustment
472     ,p_dynamic_code
473     ,p_business_group_id
474     ,p_legislation_code
475     ,p_definition_type
476     ,p_number_of_years
477     ,p_start_date
478     ,p_period_time_definition_id
479     ,p_creator_id
480     ,p_creator_type
481     ,null
482     );
483   --
484   -- Having converted the arguments into the pay_tdf_rec
485   -- plsql record structure we call the corresponding record business process.
486   --
487   pay_tdf_ins.ins
488      (p_effective_date
489      ,l_rec
490      );
491   --
492   -- As the primary key argument(s)
493   -- are specified as an OUT's we must set these values.
494   --
495   p_time_definition_id := l_rec.time_definition_id;
496   p_object_version_number := l_rec.object_version_number;
497   --
498   hr_utility.set_location(' Leaving:'||l_proc, 10);
499 End ins;
500 --
501 end pay_tdf_ins;