1 Package Body ff_ffn_ins as
2 /* $Header: ffffnrhi.pkb 120.1 2005/10/05 01:50 adkumar noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ff_ffn_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_function_id_i number default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19 (p_function_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 ff_ffn_ins.g_function_id_i := p_function_id;
27 --
28 hr_utility.set_location(' Leaving:'||l_proc, 20);
29 End set_base_key_value;
30 --
31 --
32 -- ----------------------------------------------------------------------------
33 -- |-----------------------< create_app_ownerships >--------------------------|
34 -- ----------------------------------------------------------------------------
35 --
36 -- Description:
37 -- This procedure inserts a row into the HR_APPLICATION_OWNERSHIPS table
38 -- when the row handler is called in the appropriate mode.
39 --
40 -- ----------------------------------------------------------------------------
41 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
42 ,p_pk_value IN varchar2) IS
43 --
44 CURSOR csr_definition IS
45 SELECT product_short_name
46 FROM hr_owner_definitions
47 WHERE session_id = hr_startup_data_api_support.g_session_id;
48 --
49 BEGIN
50 --
51 IF (hr_startup_data_api_support.return_startup_mode IN
52 ('STARTUP','GENERIC')) THEN
53 --
54 FOR c1 IN csr_definition LOOP
55 --
56 INSERT INTO hr_application_ownerships
57 (key_name
58 ,key_value
59 ,product_name
60 )
61 VALUES
62 (p_pk_column
63 ,fnd_number.number_to_canonical(p_pk_value)
64 ,c1.product_short_name
65 );
66 END LOOP;
67 END IF;
68 END create_app_ownerships;
69 --
70 -- ----------------------------------------------------------------------------
71 -- |-----------------------< create_app_ownerships >--------------------------|
72 -- ----------------------------------------------------------------------------
73 PROCEDURE create_app_ownerships(p_pk_column IN varchar2
74 ,p_pk_value IN number) IS
75 --
76 BEGIN
77 create_app_ownerships(p_pk_column, to_char(p_pk_value));
78 END create_app_ownerships;
79 --
80 -- ----------------------------------------------------------------------------
81 -- |------------------------------< insert_dml >------------------------------|
82 -- ----------------------------------------------------------------------------
83 -- {Start Of Comments}
84 --
85 -- Description:
86 -- This procedure controls the actual dml insert logic. The processing of
87 -- this procedure are as follows:
88 -- 1) Initialise the object_version_number to 1 if the object_version_number
89 -- is defined as an attribute for this entity.
90 -- 2) To set and unset the g_api_dml status as required (as we are about to
91 -- perform dml).
92 -- 3) To insert the row into the schema.
93 -- 4) To trap any constraint violations that may have occurred.
94 -- 5) To raise any other errors.
95 --
96 -- Prerequisites:
97 -- This is an internal private procedure which must be called from the ins
98 -- procedure and must have all mandatory attributes set (except the
99 -- object_version_number which is initialised within this procedure).
100 --
101 -- In Parameters:
102 -- A Pl/Sql record structre.
103 --
104 -- Post Success:
105 -- The specified row will be inserted into the schema.
106 --
107 -- Post Failure:
108 -- On the insert dml failure it is important to note that we always reset the
109 -- g_api_dml status to false.
110 -- If a check, unique or parent integrity constraint violation is raised the
111 -- constraint_error procedure will be called.
112 -- If any other error is reported, the error will be raised after the
113 -- g_api_dml status is reset.
114 --
115 -- Developer Implementation Notes:
116 -- None.
117 --
118 -- Access Status:
119 -- Internal Row Handler Use Only.
120 --
121 -- {End Of Comments}
122 -- ----------------------------------------------------------------------------
123 Procedure insert_dml
124 (p_rec in out nocopy ff_ffn_shd.g_rec_type
125 ) is
126 --
127 l_proc varchar2(72) := g_package||'insert_dml';
128 --
129 Begin
130 hr_utility.set_location('Entering:'||l_proc, 5);
131 p_rec.object_version_number := 1; -- Initialise the object version
132 --
133 ff_ffn_shd.g_api_dml := true; -- Set the api dml status
134 --
135 -- Insert the row into: ff_functions
136 --
137 insert into ff_functions
138 (function_id
139 ,business_group_id
140 ,legislation_code
141 ,class
142 ,name
143 ,alias_name
144 ,data_type
145 ,definition
146 ,description
147 ,object_version_number
148 )
149 Values
150 (p_rec.function_id
151 ,p_rec.business_group_id
152 ,p_rec.legislation_code
153 ,p_rec.class
154 ,p_rec.name
155 ,p_rec.alias_name
156 ,p_rec.data_type
157 ,p_rec.definition
158 ,p_rec.description
159 ,p_rec.object_version_number
160 );
161 --
162 ff_ffn_shd.g_api_dml := false; -- Unset the api dml status
163 --
164 hr_utility.set_location(' Leaving:'||l_proc, 10);
165 Exception
166 When hr_api.check_integrity_violated Then
167 -- A check constraint has been violated
168 ff_ffn_shd.g_api_dml := false; -- Unset the api dml status
169 ff_ffn_shd.constraint_error
170 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
171 When hr_api.parent_integrity_violated Then
172 -- Parent integrity has been violated
173 ff_ffn_shd.g_api_dml := false; -- Unset the api dml status
174 ff_ffn_shd.constraint_error
175 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
176 When hr_api.unique_integrity_violated Then
177 -- Unique integrity has been violated
178 ff_ffn_shd.g_api_dml := false; -- Unset the api dml status
179 ff_ffn_shd.constraint_error
180 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
181 When Others Then
182 ff_ffn_shd.g_api_dml := false; -- Unset the api dml status
183 Raise;
184 End insert_dml;
185 --
186 -- ----------------------------------------------------------------------------
187 -- |------------------------------< pre_insert >------------------------------|
188 -- ----------------------------------------------------------------------------
189 -- {Start Of Comments}
190 --
191 -- Description:
192 -- This private procedure contains any processing which is required before
193 -- the insert dml. Presently, if the entity has a corresponding primary
194 -- key which is maintained by an associating sequence, the primary key for
195 -- the entity will be populated with the next sequence value in
196 -- preparation for the insert dml.
197 --
198 -- Prerequisites:
199 -- This is an internal procedure which is called from the ins procedure.
200 --
201 -- In Parameters:
202 -- A Pl/Sql record structure.
203 --
204 -- Post Success:
205 -- Processing continues.
206 --
207 -- Post Failure:
208 -- If an error has occurred, an error message and exception will be raised
209 -- but not handled.
210 --
211 -- Developer Implementation Notes:
212 -- Any pre-processing required before the insert dml is issued should be
213 -- coded within this procedure. As stated above, a good example is the
214 -- generation of a primary key number via a corresponding sequence.
215 -- It is important to note that any 3rd party maintenance should be reviewed
216 -- before placing in this procedure.
217 --
218 -- Access Status:
219 -- Internal Row Handler Use Only.
220 --
221 -- {End Of Comments}
222 -- ----------------------------------------------------------------------------
223 Procedure pre_insert
224 (p_rec in out nocopy ff_ffn_shd.g_rec_type
225 ) is
226 --
227 Cursor C_Sel1 is select ff_functions_s.nextval from sys.dual;
228 --
229 Cursor C_Sel2 is
230 Select null
231 from ff_functions
232 where function_id =
233 ff_ffn_ins.g_function_id_i;
234 --
235 l_proc varchar2(72) := g_package||'pre_insert';
236 l_exists varchar2(1);
237 --
238 Begin
239 hr_utility.set_location('Entering:'||l_proc, 5);
240 --
241 If (ff_ffn_ins.g_function_id_i is not null) Then
242 --
243 -- Verify registered primary key values not already in use
244 --
245 Open C_Sel2;
246 Fetch C_Sel2 into l_exists;
247 If C_Sel2%found Then
248 Close C_Sel2;
249 --
250 -- The primary key values are already in use.
251 --
252 fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
253 fnd_message.set_token('TABLE_NAME','ff_functions');
254 fnd_message.raise_error;
255 End If;
256 Close C_Sel2;
257 --
258 -- Use registered key values and clear globals
259 --
260 p_rec.function_id :=
261 ff_ffn_ins.g_function_id_i;
262 ff_ffn_ins.g_function_id_i := null;
263 Else
264 --
265 -- No registerd key values, so select the next sequence number
266 --
267 --
268 -- Select the next sequence number
269 --
270 Open C_Sel1;
271 Fetch C_Sel1 Into p_rec.function_id;
272 Close C_Sel1;
273 End If;
274 --
275 hr_utility.set_location(' Leaving:'||l_proc, 10);
276 End pre_insert;
277 --
278 -- ----------------------------------------------------------------------------
279 -- |-----------------------------< post_insert >------------------------------|
280 -- ----------------------------------------------------------------------------
281 -- {Start Of Comments}
282 --
283 -- Description:
284 -- This private procedure contains any processing which is required after
285 -- the insert dml.
286 --
287 -- Prerequisites:
288 -- This is an internal procedure which is called from the ins procedure.
289 --
290 -- In Parameters:
291 -- A Pl/Sql record structre.
292 --
293 -- Post Success:
294 -- Processing continues.
295 --
296 -- Post Failure:
297 -- If an error has occurred, an error message and exception will be raised
298 -- but not handled.
299 --
300 -- Developer Implementation Notes:
301 -- Any post-processing required after the insert dml is issued should be
302 -- coded within this procedure. It is important to note that any 3rd party
303 -- maintenance should be reviewed before placing in this procedure.
304 --
305 -- Access Status:
306 -- Internal Row Handler Use Only.
307 --
308 -- {End Of Comments}
309 -- ----------------------------------------------------------------------------
310 Procedure post_insert
311 (p_effective_date in date
312 ,p_rec in ff_ffn_shd.g_rec_type
313 ) is
314 --
315 l_proc varchar2(72) := g_package||'post_insert';
316 --
317 Begin
318 hr_utility.set_location('Entering:'||l_proc, 5);
319 begin
320 --
321 -- insert ownerships if applicable
322 create_app_ownerships
323 ('FUNCTION_ID', p_rec.function_id
324 );
325 --
326 --
327 ff_ffn_rki.after_insert
328 (p_effective_date => p_effective_date
329 ,p_function_id => p_rec.function_id
330 ,p_business_group_id => p_rec.business_group_id
331 ,p_legislation_code => p_rec.legislation_code
332 ,p_class => p_rec.class
333 ,p_name => p_rec.name
334 ,p_alias_name => p_rec.alias_name
335 ,p_data_type => p_rec.data_type
336 ,p_definition => p_rec.definition
337 ,p_description => p_rec.description
338 ,p_object_version_number => p_rec.object_version_number
339 );
340 --
341 exception
342 --
343 when hr_api.cannot_find_prog_unit then
344 --
345 hr_api.cannot_find_prog_unit_error
346 (p_module_name => 'FF_FUNCTIONS'
347 ,p_hook_type => 'AI');
348 --
349 end;
350 --
351 hr_utility.set_location(' Leaving:'||l_proc, 10);
352 End post_insert;
353 --
354 -- ----------------------------------------------------------------------------
355 -- |---------------------------------< ins >----------------------------------|
356 -- ----------------------------------------------------------------------------
357 Procedure ins
358 (p_effective_date in date
359 ,p_rec in out nocopy ff_ffn_shd.g_rec_type
360 ) is
361 --
362 l_proc varchar2(72) := g_package||'ins';
363 --
364 Begin
365 hr_utility.set_location('Entering:'||l_proc, 5);
366 --
367 -- Call the supporting insert validate operations
368 --
369 ff_ffn_bus.insert_validate
370 (p_effective_date
371 ,p_rec
372 );
373 --
374 -- Call to raise any errors on multi-message list
375 hr_multi_message.end_validation_set;
376 --
377 -- Call the supporting pre-insert operation
378 --
379 ff_ffn_ins.pre_insert(p_rec);
380 --
381 -- Insert the row
382 --
383 ff_ffn_ins.insert_dml(p_rec);
384 --
385 -- Call the supporting post-insert operation
386 --
387 ff_ffn_ins.post_insert
388 (p_effective_date
389 ,p_rec
390 );
391 --
392 -- Call to raise any errors on multi-message list
393 hr_multi_message.end_validation_set;
394 --
395 hr_utility.set_location('Leaving:'||l_proc, 20);
396 end ins;
397 --
398 -- ----------------------------------------------------------------------------
399 -- |---------------------------------< ins >----------------------------------|
400 -- ----------------------------------------------------------------------------
401 Procedure ins
402 (p_effective_date in date
403 ,p_class in varchar2
404 ,p_name in varchar2
405 ,p_business_group_id in number default null
406 ,p_legislation_code in varchar2 default null
407 ,p_alias_name in varchar2 default null
408 ,p_data_type in varchar2 default null
409 ,p_definition in varchar2 default null
410 ,p_description in varchar2 default null
411 ,p_function_id out nocopy number
412 ,p_object_version_number out nocopy number
413 ) is
414 --
415 l_rec ff_ffn_shd.g_rec_type;
416 l_proc varchar2(72) := g_package||'ins';
417 --
418 Begin
419 hr_utility.set_location('Entering:'||l_proc, 5);
420 --
421 -- Call conversion function to turn arguments into the
422 -- p_rec structure.
423 --
424 l_rec :=
425 ff_ffn_shd.convert_args
426 (null
427 ,p_business_group_id
428 ,p_legislation_code
429 ,p_class
430 ,p_name
431 ,p_alias_name
432 ,p_data_type
433 ,p_definition
434 ,p_description
435 ,null
436 );
437 --
438 -- Having converted the arguments into the ff_ffn_rec
439 -- plsql record structure we call the corresponding record business process.
440 --
441 ff_ffn_ins.ins
442 (p_effective_date
443 ,l_rec
444 );
445 --
446 -- As the primary key argument(s)
447 -- are specified as an OUT's we must set these values.
448 --
449 p_function_id := l_rec.function_id;
450 p_object_version_number := l_rec.object_version_number;
451 --
452 hr_utility.set_location(' Leaving:'||l_proc, 10);
453 End ins;
454 --
455 end ff_ffn_ins;