DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_APR_INS

Source


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