DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_CRF_INS

Source


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