DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_QSN_INS

Source


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