DBA Data[Home] [Help]

PACKAGE BODY: APPS.PER_ENT_INS

Source


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