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