1 Package Body per_osv_ins as
2 /* $Header: peosvrhi.pkb 120.0 2005/05/31 12:37:30 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' per_osv_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_org_structure_version_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_org_structure_version_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 per_osv_ins.g_org_structure_version_id_i := p_org_structure_version_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 per_osv_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 per_osv_shd.g_api_dml := true; -- Set the api dml status
86 --
87 -- Insert the row into: per_org_structure_versions
88 --
89 insert into per_org_structure_versions
90 (org_structure_version_id
91 ,business_group_id
92 ,organization_structure_id
93 ,date_from
94 ,version_number
95 ,copy_structure_version_id
96 ,date_to
97 ,request_id
98 ,program_application_id
99 ,program_id
100 ,program_update_date
101 ,object_version_number
102 ,topnode_pos_ctrl_enabled_flag
103 )
104 Values
105 (p_rec.org_structure_version_id
106 ,p_rec.business_group_id
107 ,p_rec.organization_structure_id
108 ,p_rec.date_from
109 ,p_rec.version_number
110 ,p_rec.copy_structure_version_id
111 ,p_rec.date_to
112 ,p_rec.request_id
113 ,p_rec.program_application_id
114 ,p_rec.program_id
115 ,p_rec.program_update_date
116 ,p_rec.object_version_number
117 ,p_rec.topnode_pos_ctrl_enabled_flag
118 );
119 --
120 per_osv_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 per_osv_shd.g_api_dml := false; -- Unset the api dml status
127 per_osv_shd.constraint_error
131 per_osv_shd.g_api_dml := false; -- Unset the api dml status
128 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
129 When hr_api.parent_integrity_violated Then
130 -- Parent integrity has been violated
132 per_osv_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 per_osv_shd.g_api_dml := false; -- Unset the api dml status
137 per_osv_shd.constraint_error
138 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
139 When Others Then
140 per_osv_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 per_osv_shd.g_rec_type
183 ) is
184 --
185 Cursor C_Sel1 is select per_org_structure_versions_s.nextval from sys.dual;
186 --
187 Cursor C_Sel2 is
188 Select null
189 from per_org_structure_versions
190 where org_structure_version_id =
191 per_osv_ins.g_org_structure_version_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 (per_osv_ins.g_org_structure_version_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','per_org_structure_versions');
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.org_structure_version_id :=
219 per_osv_ins.g_org_structure_version_id_i;
220 per_osv_ins.g_org_structure_version_id_i := null;
221 Else
222 --
223 -- No registerd key values, so select the next sequence number
224 --
225 --
226 -- Select the next sequence number
227 --
228 Open C_Sel1;
229 Fetch C_Sel1 Into p_rec.org_structure_version_id;
230 Close C_Sel1;
231
232 End If;
233 --
234 hr_utility.set_location(' Leaving:'||l_proc, 10);
235 End pre_insert;
236 --
237 -- ----------------------------------------------------------------------------
238 -- |-----------------------------< post_insert >------------------------------|
239 -- ----------------------------------------------------------------------------
240 -- {Start Of Comments}
241 --
242 -- Description:
243 -- This private procedure contains any processing which is required after
244 -- the insert dml.
245 --
246 -- Prerequisites:
247 -- This is an internal procedure which is called from the ins procedure.
248 --
249 -- In Parameters:
250 -- A Pl/Sql record structre.
251 --
252 -- Post Success:
253 -- Processing continues.
254 --
255 -- Post Failure:
256 -- If an error has occurred, an error message and exception will be raised
257 -- but not handled.
258 --
259 -- Developer Implementation Notes:
260 -- Any post-processing required after the insert dml is issued should be
261 -- coded within this procedure. It is important to note that any 3rd party
262 -- maintenance should be reviewed before placing in this procedure.
263 --
264 -- Access Status:
265 -- Internal Row Handler Use Only.
266 --
267 -- {End Of Comments}
268 -- ----------------------------------------------------------------------------
269 Procedure post_insert
270 (p_effective_date in date
271 ,p_rec in per_osv_shd.g_rec_type
272 ) is
273 --
277 hr_utility.set_location('Entering:'||l_proc, 5);
274 l_proc varchar2(72) := g_package||'post_insert';
275 --
276 Begin
278 begin
279 --
280 per_osv_rki.after_insert
281 (p_effective_date => p_effective_date
282 ,p_org_structure_version_id
283 => p_rec.org_structure_version_id
284 ,p_business_group_id
285 => p_rec.business_group_id
286 ,p_organization_structure_id
287 => p_rec.organization_structure_id
288 ,p_date_from
289 => p_rec.date_from
290 ,p_version_number
291 => p_rec.version_number
292 ,p_copy_structure_version_id
293 => p_rec.copy_structure_version_id
294 ,p_date_to
295 => p_rec.date_to
296 ,p_request_id
297 => p_rec.request_id
298 ,p_program_application_id
299 => p_rec.program_application_id
300 ,p_program_id
301 => p_rec.program_id
302 ,p_program_update_date
303 => p_rec.program_update_date
304 ,p_object_version_number
305 => p_rec.object_version_number
306 ,p_topnode_pos_ctrl_enabled_fla
307 => p_rec.topnode_pos_ctrl_enabled_flag
308 );
309 --
310 exception
311 --
312 when hr_api.cannot_find_prog_unit then
313 --
314 hr_api.cannot_find_prog_unit_error
315 (p_module_name => 'PER_ORG_STRUCTURE_VERSIONS'
316 ,p_hook_type => 'AI');
317 --
318 end;
319 --
320 hr_utility.set_location(' Leaving:'||l_proc, 10);
321 End post_insert;
322 --
323 -- ----------------------------------------------------------------------------
324 -- |---------------------------------< ins >----------------------------------|
325 -- ----------------------------------------------------------------------------
326 Procedure ins
327 (p_effective_date in date
328 ,p_rec in out nocopy per_osv_shd.g_rec_type
329 ,p_gap_warning out nocopy boolean
330 ) is
331 --
332 l_proc varchar2(72) := g_package||'ins';
333 --
334 Begin
335 hr_utility.set_location('Entering:'||l_proc, 5);
336 --
337 -- Call the supporting insert validate operations
338 --
339 per_osv_bus.insert_validate
340 (p_effective_date
341 ,p_rec
342 ,p_gap_warning);
343 --
344 -- Call the supporting pre-insert operation
345 --
346 per_osv_ins.pre_insert(p_rec);
347 --
348 -- Insert the row
349 --
350 per_osv_ins.insert_dml(p_rec);
351 --
352 -- Call the supporting post-insert operation
353 --
354 per_osv_ins.post_insert
355 (p_effective_date
356 ,p_rec
357 );
358 --
359 hr_utility.set_location('Leaving:'||l_proc, 20);
360 end ins;
361 --
362 -- ----------------------------------------------------------------------------
363 -- |---------------------------------< ins >----------------------------------|
364 -- ----------------------------------------------------------------------------
365 Procedure ins
366 (p_effective_date in date
367 ,p_organization_structure_id in number
368 ,p_date_from in date
369 ,p_version_number in number
370 ,p_copy_structure_version_id in number default null
371 ,p_date_to in date default null
372 ,p_request_id in number default null
373 ,p_program_application_id in number default null
374 ,p_program_id in number default null
375 ,p_program_update_date in date default null
376 ,p_topnode_pos_ctrl_enabled_fla in varchar2 default null
377 ,p_org_structure_version_id out nocopy number
378 ,p_object_version_number out nocopy number
379 ,p_gap_warning out nocopy boolean) is
380 --
381 l_rec per_osv_shd.g_rec_type;
382 l_proc varchar2(72) := g_package||'ins';
383 l_business_group_id number;
384 --
385 Begin
386 hr_utility.set_location('Entering:'||l_proc, 5);
387 --
388 -- Call conversion function to turn arguments into the
389 -- p_rec structure.
390 --
391
392 per_osv_bus.get_business_group_id
393 (p_organization_structure_id => p_organization_structure_id
394 ,p_business_group_id => l_business_group_id);
395
396 l_rec :=
397 per_osv_shd.convert_args
398 (null
399 ,l_business_group_id
400 ,p_organization_structure_id
401 ,p_date_from
402 ,p_version_number
403 ,p_copy_structure_version_id
404 ,p_date_to
405 ,p_request_id
406 ,p_program_application_id
407 ,p_program_id
408 ,p_program_update_date
409 ,null
410 ,p_topnode_pos_ctrl_enabled_fla
411 );
412 --
413 -- Having converted the arguments into the per_osv_rec
414 -- plsql record structure we call the corresponding record business process.
415 --
416 per_osv_ins.ins
417 (p_effective_date
418 ,l_rec
419 ,p_gap_warning
420 );
421 --
422 -- As the primary key argument(s)
423 -- are specified as an OUT's we must set these values.
424 --
425 p_org_structure_version_id := l_rec.org_structure_version_id;
426 p_object_version_number := l_rec.object_version_number;
427 --
428 hr_utility.set_location(' Leaving:'||l_proc, 10);
429 End ins;
430 --
431 end per_osv_ins;