DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_RMN_INS

Source


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