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