DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_QSN_INS

Source


1 Package Body hr_qsn_ins as
2 /* $Header: hrqsnrhi.pkb 120.4.12010000.3 2008/11/05 09:57:56 rsykam ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)  := '  hr_qsn_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_questionnaire_template_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_questionnaire_template_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   hr_qsn_ins.g_questionnaire_template_id_i := p_questionnaire_template_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(p_rec in out nocopy hr_qsn_shd.g_rec_type) is
76 --
77   l_proc  varchar2(72) := g_package||'insert_dml';
78 --
79 Begin
80   hr_utility.set_location('Entering:'||l_proc, 5);
81   p_rec.object_version_number := 1;  -- Initialise the object version
82   --
83   -- Insert the row into: hr_questionnaires
84   --
85   insert into hr_questionnaires
86   (  questionnaire_template_id,
87   name,
88   text,
89   available_flag,
90   business_group_id,
91   object_version_number
92   )
93   Values
94   (  p_rec.questionnaire_template_id,
95   p_rec.name,
96   p_rec.text,
97   p_rec.available_flag,
98   p_rec.business_group_id,
99   p_rec.object_version_number
100   );
101   --
102   hr_utility.set_location(' Leaving:'||l_proc, 10);
103 Exception
104   When hr_api.check_integrity_violated Then
105     -- A check constraint has been violated
106     hr_qsn_shd.constraint_error
107       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
108   When hr_api.parent_integrity_violated Then
109     -- Parent integrity has been violated
110     hr_qsn_shd.constraint_error
111       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
112   When hr_api.unique_integrity_violated Then
113     -- Unique integrity has been violated
114     hr_qsn_shd.constraint_error
115       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
116   When Others Then
117     Raise;
118 End insert_dml;
119 --
120 -- ----------------------------------------------------------------------------
121 -- |------------------------------< pre_insert >------------------------------|
122 -- ----------------------------------------------------------------------------
123 -- {Start Of Comments}
124 --
125 -- Description:
126 --   This private procedure contains any processing which is required before
127 --   the insert dml. Presently, if the entity has a corresponding primary
128 --   key which is maintained by an associating sequence, the primary key for
129 --   the entity will be populated with the next sequence value in
130 --   preparation for the insert dml.
131 --
132 -- Prerequisites:
133 --   This is an internal procedure which is called from the ins procedure.
134 --
135 -- In Parameters:
136 --   A Pl/Sql record structre.
137 --
138 -- Post Success:
139 --   Processing continues.
140 --
141 -- Post Failure:
142 --   If an error has occurred, an error message and exception will be raised
143 --   but not handled.
144 --
145 -- Developer Implementation Notes:
146 --   Any pre-processing required before the insert dml is issued should be
147 --   coded within this procedure. As stated above, a good example is the
148 --   generation of a primary key number via a corresponding sequence.
149 --   It is important to note that any 3rd party maintenance should be reviewed
150 --   before placing in this procedure.
151 --
152 -- Access Status:
153 --   Internal Row Handler Use Only.
154 --
155 -- {End Of Comments}
156 -- ----------------------------------------------------------------------------
157 Procedure pre_insert(p_rec  in out nocopy hr_qsn_shd.g_rec_type) is
158 --
159   l_proc  varchar2(72) := g_package||'pre_insert';
160   l_exists varchar2(1);
161 --
162   Cursor C_Sel1 is select hr_questionnaires_s.nextval from sys.dual;
163 --
164   Cursor C_Sel2 is
165          select null
166                 from hr_questionnaires
167                 where questionnaire_template_id = hr_qsn_ins.g_questionnaire_template_id_i;
168 --
169 Begin
170   hr_utility.set_location('Entering:'||l_proc, 5);
171   --
172   if hr_qsn_ins.g_questionnaire_template_id_i is not null then
173     --
174     -- Verify registered primary key values not already in use
175     --
176     Open C_Sel2;
177     Fetch C_Sel2 into l_exists;
178     If C_Sel2%found then
179       Close C_Sel2;
180       --
181       -- The primary key values are already in use.
182       --
183       fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
184       fnd_message.set_token('TABLE_NAME','hr_questionnaires');
185       fnd_message.raise_error;
186     end if;
187     Close C_Sel2;
188     --
189     -- Use registered key values and clear globals
190     --
191     p_rec.questionnaire_template_id := hr_qsn_ins.g_questionnaire_template_id_i;
192     hr_qsn_ins.g_questionnaire_template_id_i := null;
193     --
194   else
195     --
196   -- Select the next sequence number
197   --
198   Open C_Sel1;
199   Fetch C_Sel1 Into p_rec.questionnaire_template_id;
200   Close C_Sel1;
201   end if;
202   --
203   hr_utility.set_location(' Leaving:'||l_proc, 10);
204 End pre_insert;
205 --
206 -- ----------------------------------------------------------------------------
207 -- |-----------------------------< post_insert >------------------------------|
208 -- ----------------------------------------------------------------------------
209 -- {Start Of Comments}
210 --
211 -- Description:
212 --   This private procedure contains any processing which is required after the
213 --   insert dml.
214 --
215 -- Prerequisites:
216 --   This is an internal procedure which is called from the ins procedure.
217 --
218 -- In Parameters:
219 --   A Pl/Sql record structre.
220 --
221 -- Post Success:
222 --   Processing continues.
223 --
224 -- Post Failure:
225 --   If an error has occurred, an error message and exception will be raised
226 --   but not handled.
227 --
228 -- Developer Implementation Notes:
229 --   Any post-processing required after the insert dml is issued should be
230 --   coded within this procedure. It is important to note that any 3rd party
231 --   maintenance should be reviewed before placing in this procedure.
232 --
233 -- Access Status:
234 --   Internal Row Handler Use Only.
235 --
236 -- {End Of Comments}
237 -- ----------------------------------------------------------------------------
238 Procedure post_insert(p_rec in hr_qsn_shd.g_rec_type
239          ,p_effective_date in date) is
240 --
241   l_proc  varchar2(72) := g_package||'post_insert';
242 --
243 Begin
244   hr_utility.set_location('Entering:'||l_proc, 5);
245   --
246   begin
247     hr_qsn_rki.after_insert
248        (p_questionnaire_template_id  => p_rec.questionnaire_template_id
249        ,p_name        => p_rec.name
250    --    ,p_text        => p_rec.text
251        ,p_available_flag    => p_rec.available_flag
252        ,p_business_group_id    => p_rec.business_group_id
253        ,p_object_version_number    => p_rec.object_version_number
254        ,p_effective_date    => p_effective_date
255        );
256   exception
257     when hr_api.cannot_find_prog_unit then
258       hr_api.cannot_find_prog_unit_error
259    (p_module_name => 'HR_QUESTIONNAIRES'
260    ,p_hook_type   => 'AI'
261    );
262   end;
263   hr_utility.set_location(' Leaving:'||l_proc, 10);
264 End post_insert;
265 --
266 -- ----------------------------------------------------------------------------
267 -- |---------------------------------< ins >----------------------------------|
268 -- ----------------------------------------------------------------------------
269 Procedure ins
270   (
271   p_rec        in out nocopy hr_qsn_shd.g_rec_type,
272   p_effective_date in date
273   ) is
274 --
275   l_proc  varchar2(72) := g_package||'ins';
276 --
277 Begin
278   hr_utility.set_location('Entering:'||l_proc, 5);
279   --
280   -- Call the supporting insert validate operations
281   --
282   hr_qsn_bus.insert_validate(p_rec, p_effective_date);
283   --
284   -- Call to raise any errors on multi-message list
285   hr_multi_message.end_validation_set;
286   --
287   -- Call the supporting pre-insert operation
288   --
289   pre_insert(p_rec);
290   --
291   -- Insert the row
292   --
293   insert_dml(p_rec);
294   --
295   -- Call the supporting post-insert operation
296   --
297   post_insert(p_rec, p_effective_date);
298   -- Call to raise any errors on multi-message list
299   hr_multi_message.end_validation_set;
300   --
301 end ins;
302 --
303 -- ----------------------------------------------------------------------------
304 -- |---------------------------------< ins >----------------------------------|
305 -- ----------------------------------------------------------------------------
306 Procedure ins
307   (
308   p_questionnaire_template_id    out nocopy number,
309   p_name                         in varchar2,
310   p_text                         in CLOB,
311   p_available_flag               in varchar2,
312   p_business_group_id            in number,
313   p_object_version_number        out nocopy number,
314   p_effective_date     in date
315   ) is
316 --
317   l_rec    hr_qsn_shd.g_rec_type;
318   l_proc  varchar2(72) := g_package||'ins';
319 --
320 Begin
321   hr_utility.set_location('Entering:'||l_proc, 5);
322   --
323   -- Call conversion function to turn arguments into the
324   -- p_rec structure.
325   --
326   l_rec :=
327   hr_qsn_shd.convert_args
328   (
329   null,
330   p_name,
331   p_text,
332   p_available_flag,
333   p_business_group_id,
334   null
335   );
336   --
337   -- Having converted the arguments into the hr_qsn_rec
338   -- plsql record structure we call the corresponding record business process.
339   --
340   ins(l_rec, p_effective_date);
341   --
342   -- As the primary key argument(s)
343   -- are specified as an OUT's we must set these values.
344   --
345   p_questionnaire_template_id := l_rec.questionnaire_template_id;
346   p_object_version_number := l_rec.object_version_number;
347   --
348   hr_utility.set_location(' Leaving:'||l_proc, 10);
349 End ins;
350 --
351 end hr_qsn_ins;