DBA Data[Home] [Help]

PACKAGE BODY: APPS.PSP_RTD_INS

Source


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