DBA Data[Home] [Help]

PACKAGE BODY: APPS.PER_NAA_INS

Source


1 Package Body per_naa_ins as
2 /* $Header: penaarhi.pkb 120.1 2006/04/25 06:01:33 niljain noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  per_naa_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_absence_action_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_absence_action_id  in  number) is
23 Begin
20 --
21   l_proc       varchar2(72) := g_package||'set_base_key_value';
22 --
24   hr_utility.set_location('Entering:'||l_proc, 10);
25   --
26   per_naa_ins.g_absence_action_id_i := p_absence_action_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_naa_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   per_naa_shd.g_api_dml := true;  -- Set the api dml status
86   --
87   -- Insert the row into: per_nl_absence_actions
88   --
89   insert into per_nl_absence_actions
90       (absence_action_id
91       ,absence_attendance_id
92       ,expected_date
93       ,description
94       ,actual_start_date
95       ,actual_end_date
96       ,holder
97       ,comments
98       ,document_link
99       ,document_file_name
100       ,last_updated_by
101       ,object_version_number
102       ,enabled
103       )
104   Values
105     (p_rec.absence_action_id
106     ,p_rec.absence_attendance_id
107     ,p_rec.expected_date
108     ,p_rec.description
109     ,p_rec.actual_start_date
110     ,p_rec.actual_end_date
111     ,p_rec.holder
112     ,p_rec.comments
113     ,empty_blob()
114     ,p_rec.document_file_name
115     ,p_rec.last_updated_by
116     ,p_rec.object_version_number
117     ,p_rec.enabled
118     );
119   --
120   per_naa_shd.g_api_dml := false;   -- Unset the api dml status
121   --
122   hr_utility.set_location(' Leaving:'||l_proc, 10);
123 Exception
124   When hr_api.check_integrity_violated Then
125     -- A check constraint has been violated
126     per_naa_shd.g_api_dml := false;   -- Unset the api dml status
127     per_naa_shd.constraint_error
128       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
129   When hr_api.parent_integrity_violated Then
130     -- Parent integrity has been violated
131     per_naa_shd.g_api_dml := false;   -- Unset the api dml status
132     per_naa_shd.constraint_error
133       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
134   When hr_api.unique_integrity_violated Then
135     -- Unique integrity has been violated
136     per_naa_shd.g_api_dml := false;   -- Unset the api dml status
137     per_naa_shd.constraint_error
138       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
139   When Others Then
140     per_naa_shd.g_api_dml := false;   -- Unset the api dml status
141     Raise;
142 End insert_dml;
143 --
144 -- ----------------------------------------------------------------------------
145 -- |------------------------------< pre_insert >------------------------------|
146 -- ----------------------------------------------------------------------------
147 -- {Start Of Comments}
148 --
149 -- Description:
150 --   This private procedure contains any processing which is required before
151 --   the insert dml. Presently, if the entity has a corresponding primary
152 --   key which is maintained by an associating sequence, the primary key for
153 --   the entity will be populated with the next sequence value in
154 --   preparation for the insert dml.
155 --
156 -- Prerequisites:
157 --   This is an internal procedure which is called from the ins procedure.
158 --
159 -- In Parameters:
160 --   A Pl/Sql record structure.
161 --
162 -- Post Success:
166 --   If an error has occurred, an error message and exception will be raised
163 --   Processing continues.
164 --
165 -- Post Failure:
167 --   but not handled.
168 --
169 -- Developer Implementation Notes:
170 --   Any pre-processing required before the insert dml is issued should be
171 --   coded within this procedure. As stated above, a good example is the
172 --   generation of a primary key number via a corresponding sequence.
173 --   It is important to note that any 3rd party maintenance should be reviewed
174 --   before placing in this procedure.
175 --
176 -- Access Status:
177 --   Internal Row Handler Use Only.
178 --
179 -- {End Of Comments}
180 -- ----------------------------------------------------------------------------
181 Procedure pre_insert
182   (p_rec  in out nocopy per_naa_shd.g_rec_type
183   ) is
184 --
185   Cursor C_Sel1 is select per_nl_absence_actions_s.nextval from sys.dual;
186 --
187   Cursor C_Sel2 is
188     Select null
189       from per_nl_absence_actions
190      where absence_action_id =
191              per_naa_ins.g_absence_action_id_i;
192 --
193   l_proc   varchar2(72) := g_package||'pre_insert';
194   l_exists varchar2(1);
195 --
196 Begin
197   hr_utility.set_location('Entering:'||l_proc, 5);
198   --
199   If (per_naa_ins.g_absence_action_id_i is not null) Then
200     --
201     -- Verify registered primary key values not already in use
202     --
203     Open C_Sel2;
204     Fetch C_Sel2 into l_exists;
205     If C_Sel2%found Then
206        Close C_Sel2;
207        --
208        -- The primary key values are already in use.
209        --
210        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
211        fnd_message.set_token('TABLE_NAME','per_nl_absence_actions');
212        fnd_message.raise_error;
213     End If;
214     Close C_Sel2;
215     --
216     -- Use registered key values and clear globals
217     --
218     p_rec.absence_action_id :=
219       per_naa_ins.g_absence_action_id_i;
220     per_naa_ins.g_absence_action_id_i := null;
221   Else
222     --
223     -- No registerd key values, so select the next sequence number
224     --
225     --
226     -- Select the next sequence number
227     --
228     Open C_Sel1;
229     Fetch C_Sel1 Into p_rec.absence_action_id;
230     Close C_Sel1;
231   End If;
232   --
233   hr_utility.set_location(' Leaving:'||l_proc, 10);
234 End pre_insert;
235 --
236 -- ----------------------------------------------------------------------------
237 -- |-----------------------------< post_insert >------------------------------|
238 -- ----------------------------------------------------------------------------
239 -- {Start Of Comments}
240 --
241 -- Description:
242 --   This private procedure contains any processing which is required after
243 --   the insert dml.
244 --
245 -- Prerequisites:
246 --   This is an internal procedure which is called from the ins procedure.
247 --
248 -- In Parameters:
249 --   A Pl/Sql record structre.
250 --
251 -- Post Success:
252 --   Processing continues.
253 --
254 -- Post Failure:
255 --   If an error has occurred, an error message and exception will be raised
256 --   but not handled.
257 --
258 -- Developer Implementation Notes:
259 --   Any post-processing required after the insert dml is issued should be
260 --   coded within this procedure. It is important to note that any 3rd party
261 --   maintenance should be reviewed before placing in this procedure.
262 --
263 -- Access Status:
264 --   Internal Row Handler Use Only.
265 --
266 -- {End Of Comments}
267 -- ----------------------------------------------------------------------------
268 Procedure post_insert
269   (p_rec                          in per_naa_shd.g_rec_type
270   ) is
271 --
272   l_proc  varchar2(72) := g_package||'post_insert';
273 --
274 Begin
275   hr_utility.set_location('Entering:'||l_proc, 5);
276   begin
277     --
278     per_naa_rki.after_insert
279       (p_absence_action_id
280       => p_rec.absence_action_id
281       ,p_absence_attendance_id
282       => p_rec.absence_attendance_id
283       ,p_expected_date
284       => p_rec.expected_date
285       ,p_description
286       => p_rec.description
287       ,p_actual_start_date
288       => p_rec.actual_start_date
289       ,p_actual_end_date
290       => p_rec.actual_end_date
291       ,p_holder
292       => p_rec.holder
293       ,p_comments
294       => p_rec.comments
295       ,p_document_file_name
296       => p_rec.document_file_name
297       ,p_last_updated_by
298       => p_rec.last_updated_by
299       ,p_object_version_number
300       => p_rec.object_version_number
301       ,p_enabled
302       => p_rec.enabled
303       );
304     --
305   exception
306     --
307     when hr_api.cannot_find_prog_unit then
308       --
309       hr_api.cannot_find_prog_unit_error
310         (p_module_name => 'PER_NL_ABSENCE_ACTIONS'
311         ,p_hook_type   => 'AI');
312       --
313   end;
314   --
315   hr_utility.set_location(' Leaving:'||l_proc, 10);
316 End post_insert;
317 --
318 -- ----------------------------------------------------------------------------
319 -- |---------------------------------< ins >----------------------------------|
320 -- ----------------------------------------------------------------------------
321 Procedure ins
322   (p_rec                          in out nocopy per_naa_shd.g_rec_type
323   ) is
324 --
325   l_proc  varchar2(72) := g_package||'ins';
326 --
327 Begin
328   hr_utility.set_location('Entering:'||l_proc, 5);
329   --
330   -- Call the supporting insert validate operations
331   --
332   per_naa_bus.insert_validate
333      (p_rec
334      );
335   --
336   -- Call to raise any errors on multi-message list
337   hr_multi_message.end_validation_set;
338   --
339   -- Call the supporting pre-insert operation
340   --
341   per_naa_ins.pre_insert(p_rec);
342   --
343   -- Insert the row
344   --
345   per_naa_ins.insert_dml(p_rec);
346   --
347   -- Call the supporting post-insert operation
348   --
349   per_naa_ins.post_insert
350      (p_rec
351      );
352   --
353   -- Call to raise any errors on multi-message list
354   hr_multi_message.end_validation_set;
355   --
356   hr_utility.set_location('Leaving:'||l_proc, 20);
357 end ins;
358 --
359 -- ----------------------------------------------------------------------------
360 -- |---------------------------------< ins >----------------------------------|
361 -- ----------------------------------------------------------------------------
362 Procedure ins
363   (p_absence_attendance_id          in     number
364   ,p_expected_date                  in     date
365   ,p_description                    in     varchar2
366   ,p_actual_start_date              in     date
367   ,p_actual_end_date                in     date
368   ,p_holder                         in     varchar2
369   ,p_comments                       in     varchar2
370   ,p_document_file_name             in     varchar2
371   ,p_last_updated_by                 in     number
372   ,p_absence_action_id                 out nocopy number
373   ,p_object_version_number             out nocopy number
374   ,p_enabled                         in     varchar2
375   ) is
376 --
377   l_rec   per_naa_shd.g_rec_type;
378   l_proc  varchar2(72) := g_package||'ins';
379 --
380 Begin
381   hr_utility.set_location('Entering:'||l_proc, 5);
382   --
383   -- Call conversion function to turn arguments into the
384   -- p_rec structure.
385   --
386   l_rec :=
387   per_naa_shd.convert_args
388     (null
389     ,p_absence_attendance_id
390     ,p_expected_date
391     ,p_description
392     ,p_actual_start_date
393     ,p_actual_end_date
394     ,p_holder
395     ,p_comments
396     ,p_document_file_name
397     ,p_last_updated_by
398     ,null
399     ,p_enabled
400     );
401   --
402   -- Having converted the arguments into the per_naa_rec
403   -- plsql record structure we call the corresponding record business process.
404   --
405   per_naa_ins.ins
406      (l_rec
407      );
408   --
409   -- As the primary key argument(s)
410   -- are specified as an OUT's we must set these values.
411   --
412   p_absence_action_id := l_rec.absence_action_id;
413   p_object_version_number := l_rec.object_version_number;
414   --
415   hr_utility.set_location(' Leaving:'||l_proc, 10);
416 End ins;
417 --
418 end per_naa_ins;