DBA Data[Home] [Help]

PACKAGE BODY: APPS.OTA_TSR_INS

Source


1 Package Body ota_tsr_ins as
2 /* $Header: ottsr01t.pkb 120.3.12020000.3 2012/12/14 09:48:09 atadepal ship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33)	:= '  ota_tsr_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_supplied_resource_id_i  number   default null;
14 
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_supplied_resource_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   ota_tsr_ins.g_supplied_resource_id_i := p_supplied_resource_id;
27   --
28   hr_utility.set_location(' Leaving:'||l_proc, 20);
29 End set_base_key_value;
30 --
31 -- ----------------------------------------------------------------------------
32 -- |------------------------------< insert_dml >------------------------------|
33 -- ----------------------------------------------------------------------------
34 -- {Start Of Comments}
35 --
36 -- Description:
37 --   This procedure controls the actual dml insert logic. The functions of this
38 --   procedure are as follows:
39 --   1) Initialise the object_version_number to 1 if the object_version_number
40 --      is defined as an attribute for this entity.
41 --   2) To set and unset the g_api_dml status as required (as we are about to
42 --      perform dml).
43 --   3) To insert the row into the schema.
44 --   4) To trap any constraint violations that may have occurred.
45 --   5) To raise any other errors.
46 --
47 -- Pre Conditions:
48 --   This is an internal private procedure which must be called from the ins
49 --   procedure and must have all mandatory arguments set (except the
50 --   object_version_number which is initialised within this procedure).
51 --
52 -- In Arguments:
53 --   A Pl/Sql record structre.
54 --
55 -- Post Success:
56 --   The specified row will be inserted into the schema.
57 --
58 -- Post Failure:
59 --   On the insert dml failure it is important to note that we always reset the
60 --   g_api_dml status to false.
61 --   If a check, unique or parent integrity constraint violation is raised the
62 --   constraint_error procedure will be called.
63 --   If any other error is reported, the error will be raised after the
64 --   g_api_dml status is reset.
65 --
66 -- Developer Implementation Notes:
67 --   None.
68 --
69 -- Access Status:
70 --   Internal Development Use Only.
71 --
72 -- {End Of Comments}
73 -- ----------------------------------------------------------------------------
74 Procedure insert_dml(p_rec in out nocopy ota_tsr_shd.g_rec_type) is
75 --
76   l_proc  varchar2(72) := g_package||'insert_dml';
77 --
78 Begin
79   hr_utility.set_location('Entering:'||l_proc, 5);
80   p_rec.object_version_number := 1;  -- Initialise the object version
81   --
82   ota_tsr_shd.g_api_dml := true;  -- Set the api dml status
83   --
84   -- Insert the row into: ota_suppliable_resources
85   --
86   insert into ota_suppliable_resources
87   (	supplied_resource_id,
88 	vendor_id,
89 	business_group_id,
90 	resource_definition_id,
91 	consumable_flag,
92 	object_version_number,
93 	resource_type,
94 	start_date,
95 	comments,
96 	cost,
97 	cost_unit,
98 	currency_code,
99 	end_date,
100 	internal_address_line,
101 	lead_time,
102 	name,
103 	supplier_reference,
104 	tsr_information_category,
105 	tsr_information1,
106 	tsr_information2,
107 	tsr_information3,
108 	tsr_information4,
109 	tsr_information5,
110 	tsr_information6,
111 	tsr_information7,
112 	tsr_information8,
113 	tsr_information9,
114 	tsr_information10,
115 	tsr_information11,
116 	tsr_information12,
117 	tsr_information13,
118 	tsr_information14,
119 	tsr_information15,
120 	tsr_information16,
121 	tsr_information17,
122 	tsr_information18,
123 	tsr_information19,
124 	tsr_information20,
125       training_center_id,
126       location_id,
127       trainer_id,
128       special_instruction
129   )
130   Values
131   (	p_rec.supplied_resource_id,
132 	p_rec.vendor_id,
133 	p_rec.business_group_id,
134 	p_rec.resource_definition_id,
135 	p_rec.consumable_flag,
136 	p_rec.object_version_number,
137 	p_rec.resource_type,
138 	p_rec.start_date,
139 	p_rec.comments,
140 	p_rec.cost,
141 	p_rec.cost_unit,
142 	p_rec.currency_code,
143 	p_rec.end_date,
144 	p_rec.internal_address_line,
145 	p_rec.lead_time,
146 	p_rec.name,
147 	p_rec.supplier_reference,
148 	p_rec.tsr_information_category,
149 	p_rec.tsr_information1,
150 	p_rec.tsr_information2,
151 	p_rec.tsr_information3,
152 	p_rec.tsr_information4,
153 	p_rec.tsr_information5,
154 	p_rec.tsr_information6,
155 	p_rec.tsr_information7,
156 	p_rec.tsr_information8,
157 	p_rec.tsr_information9,
158 	p_rec.tsr_information10,
159 	p_rec.tsr_information11,
160 	p_rec.tsr_information12,
161 	p_rec.tsr_information13,
162 	p_rec.tsr_information14,
163 	p_rec.tsr_information15,
164 	p_rec.tsr_information16,
165 	p_rec.tsr_information17,
166 	p_rec.tsr_information18,
167 	p_rec.tsr_information19,
168 	p_rec.tsr_information20,
169       p_rec.training_center_id,
170       p_rec.location_id,
171       p_rec.trainer_id,
172       p_rec.special_instruction
173   );
174   --
175   ota_tsr_shd.g_api_dml := false;   -- Unset the api dml status
176   --
177   hr_utility.set_location(' Leaving:'||l_proc, 10);
178 Exception
179   When hr_api.check_integrity_violated Then
180     -- A check constraint has been violated
181     ota_tsr_shd.g_api_dml := false;   -- Unset the api dml status
182     ota_tsr_shd.constraint_error
183       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
184   When hr_api.parent_integrity_violated Then
185     -- Parent integrity has been violated
186     ota_tsr_shd.g_api_dml := false;   -- Unset the api dml status
187     ota_tsr_shd.constraint_error
188       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
189   When hr_api.unique_integrity_violated Then
190     -- Unique integrity has been violated
191     ota_tsr_shd.g_api_dml := false;   -- Unset the api dml status
192     ota_tsr_shd.constraint_error
193       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
194   When Others Then
195     ota_tsr_shd.g_api_dml := false;   -- Unset the api dml status
196     Raise;
197 End insert_dml;
198 --
199 -- ----------------------------------------------------------------------------
200 -- |------------------------------< pre_insert >------------------------------|
201 -- ----------------------------------------------------------------------------
202 -- {Start Of Comments}
203 --
204 -- Description:
205 --   This private procedure contains any processing which is required before
206 --   the insert dml. Presently, if the entity has a corresponding primary
207 --   key which is maintained by an associating sequence, the primary key for
208 --   the entity will be populated with the next sequence value in
209 --   preparation for the insert dml.
210 --
211 -- Pre Conditions:
212 --   This is an internal procedure which is called from the ins procedure.
213 --
214 -- In Arguments:
215 --   A Pl/Sql record structre.
216 --
217 -- Post Success:
218 --   Processing continues.
219 --
220 -- Post Failure:
221 --   If an error has occurred, an error message and exception will be raised
222 --   but not handled.
223 --
224 -- Developer Implementation Notes:
225 --   Any pre-processing required before the insert dml is issued should be
226 --   coded within this procedure. As stated above, a good example is the
227 --   generation of a primary key number via a corresponding sequence.
228 --   It is important to note that any 3rd party maintenance should be reviewed
229 --   before placing in this procedure.
230 --
231 -- Access Status:
232 --   Internal Development Use Only.
233 --
234 -- {End Of Comments}
235 -- ----------------------------------------------------------------------------
236 Procedure pre_insert(p_rec  in out nocopy ota_tsr_shd.g_rec_type) is
237 --
238   l_proc  varchar2(72) := g_package||'pre_insert';
239 --
240   Cursor C_Sel1 is select ota_suppliable_resources_s.nextval from sys.dual;
241 --
242   Cursor C_Sel2 is
243     Select null
244       from ota_suppliable_resources
245      where supplied_resource_id =
246              ota_tsr_ins.g_supplied_resource_id_i;
247 --
248 
249   l_exists varchar2(1);
250 --
251 Begin
252   hr_utility.set_location('Entering:'||l_proc, 5);
253    If (ota_tsr_ins.g_supplied_resource_id_i is not null) Then
254     --
255     -- Verify registered primary key values not already in use
256     --
257     Open C_Sel2;
258     Fetch C_Sel2 into l_exists;
259     If C_Sel2%found Then
260        Close C_Sel2;
261        --
262        -- The primary key values are already in use.
263        --
264        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
265        fnd_message.set_token('TABLE_NAME','ota_suppliable_resources');
266        fnd_message.raise_error;
267     End If;
268     Close C_Sel2;
269     --
270     -- Use registered key values and clear globals
271     --
272     p_rec.supplied_resource_id :=
273       ota_tsr_ins.g_supplied_resource_id_i;
274     ota_tsr_ins.g_supplied_resource_id_i := null;
275   Else
276     --
277     --
278     -- Select the next sequence number
279     --
280     Open C_Sel1;
281     Fetch C_Sel1 Into p_rec.supplied_resource_id;
282     Close C_Sel1;
283   End If;
284   --
285   hr_utility.set_location(' Leaving:'||l_proc, 10);
286 End pre_insert;
287 --
288 -- ----------------------------------------------------------------------------
289 -- |-----------------------------< post_insert >------------------------------|
290 -- ----------------------------------------------------------------------------
291 -- {Start Of Comments}
292 --
293 -- Description:
294 --   This private procedure contains any processing which is required after the
295 --   insert dml.
296 --
297 -- Pre Conditions:
298 --   This is an internal procedure which is called from the ins procedure.
299 --
300 -- In Arguments:
301 --   A Pl/Sql record structre.
302 --
303 -- Post Success:
304 --   Processing continues.
305 --
306 -- Post Failure:
307 --   If an error has occurred, an error message and exception will be raised
308 --   but not handled.
309 --
310 -- Developer Implementation Notes:
311 --   Any post-processing required after the insert dml is issued should be
312 --   coded within this procedure. It is important to note that any 3rd party
313 --   maintenance should be reviewed before placing in this procedure.
314 --
315 -- Access Status:
316 --   Internal Development Use Only.
317 --
318 -- {End Of Comments}
319 -- ----------------------------------------------------------------------------
320 Procedure post_insert(p_rec in ota_tsr_shd.g_rec_type) is
321 --
322   l_proc  varchar2(72) := g_package||'post_insert';
323 --
324 Begin
325   hr_utility.set_location('Entering:'||l_proc, 5);
326   --
327   hr_utility.set_location(' Leaving:'||l_proc, 10);
328 End post_insert;
329 --
330 -- ----------------------------------------------------------------------------
331 -- |---------------------------------< ins >----------------------------------|
332 -- ----------------------------------------------------------------------------
333 Procedure ins
334   (
335   p_rec        in out nocopy ota_tsr_shd.g_rec_type,
336   p_validate   in     boolean
337   ) is
338 --
339   l_proc  varchar2(72) := g_package||'ins';
340 --
341 Begin
342   hr_utility.set_location('Entering:'||l_proc, 5);
343   --
344   -- Determine if the business process is to be validated.
345   --
346   If p_validate then
347     --
348     -- Issue the savepoint.
349     --
350     SAVEPOINT ins_ota_tsr;
351   End If;
352   --
353   -- Call the supporting insert validate operations
354   --
355   ota_tsr_bus.insert_validate(p_rec);
356   --
357   -- Call the supporting pre-insert operation
358   --
359   pre_insert(p_rec);
360   --
361   -- Insert the row
362   --
363   insert_dml(p_rec);
364   --
365   -- Call the supporting post-insert operation
366   --
367   post_insert(p_rec);
368   --
369   -- If we are validating then raise the Validate_Enabled exception
370   --
371   If p_validate then
372     Raise HR_Api.Validate_Enabled;
373   End If;
374   --
375   hr_utility.set_location(' Leaving:'||l_proc, 10);
376 Exception
377   When HR_Api.Validate_Enabled Then
378     --
379     -- As the Validate_Enabled exception has been raised
380     -- we must rollback to the savepoint
381     --
382     ROLLBACK TO ins_ota_tsr;
383 end ins;
384 --
385 -- ----------------------------------------------------------------------------
386 -- |---------------------------------< ins >----------------------------------|
387 -- ----------------------------------------------------------------------------
388 Procedure ins
389   (
390   p_supplied_resource_id         out nocopy number,
391   p_vendor_id                    in number,
392   p_business_group_id            in number,
393   p_resource_definition_id       in number,
394   p_consumable_flag              in varchar2,
395   p_object_version_number        out nocopy number,
396   p_resource_type                in varchar2,
397   p_start_date                   in date,
398   p_comments                     in varchar2,
399   p_cost                         in number,
400   p_cost_unit                    in varchar2,
401   p_currency_code                in varchar2,
402   p_end_date                     in date    ,
403   p_internal_address_line        in varchar2,
404   p_lead_time                    in number  ,
405   p_name                         in varchar2,
406   p_supplier_reference           in varchar2,
407   p_tsr_information_category     in varchar2,
408   p_tsr_information1             in varchar2,
409   p_tsr_information2             in varchar2,
410   p_tsr_information3             in varchar2,
411   p_tsr_information4             in varchar2,
412   p_tsr_information5             in varchar2,
413   p_tsr_information6             in varchar2,
414   p_tsr_information7             in varchar2,
415   p_tsr_information8             in varchar2,
416   p_tsr_information9             in varchar2,
417   p_tsr_information10            in varchar2,
418   p_tsr_information11            in varchar2,
419   p_tsr_information12            in varchar2,
420   p_tsr_information13            in varchar2,
421   p_tsr_information14            in varchar2,
422   p_tsr_information15            in varchar2,
423   p_tsr_information16            in varchar2,
424   p_tsr_information17            in varchar2,
425   p_tsr_information18            in varchar2,
426   p_tsr_information19            in varchar2,
427   p_tsr_information20            in varchar2,
428   p_training_center_id           in number,
429   p_location_id			   in number,
430   p_trainer_id                   in number,
431   p_special_instruction          in varchar2,
432   p_validate                     in boolean
433   ) is
434 --
435   l_rec	  ota_tsr_shd.g_rec_type;
436   l_proc  varchar2(72) := g_package||'ins';
437 --
438 Begin
439   hr_utility.set_location('Entering:'||l_proc, 5);
440   --
441   -- Call conversion function to turn arguments into the
442   -- p_rec structure.
443   --
444   l_rec :=
445   ota_tsr_shd.convert_args
446   (
447   null,
448   p_vendor_id,
449   p_business_group_id,
450   p_resource_definition_id,
451   p_consumable_flag,
452   null,
453   p_resource_type,
454   p_start_date,
455   p_comments,
456   p_cost,
457   p_cost_unit,
458   p_currency_code,
459   p_end_date,
460   p_internal_address_line,
461   p_lead_time,
462   p_name,
463   p_supplier_reference,
464   p_tsr_information_category,
465   p_tsr_information1,
466   p_tsr_information2,
467   p_tsr_information3,
468   p_tsr_information4,
469   p_tsr_information5,
470   p_tsr_information6,
471   p_tsr_information7,
472   p_tsr_information8,
473   p_tsr_information9,
474   p_tsr_information10,
475   p_tsr_information11,
476   p_tsr_information12,
477   p_tsr_information13,
478   p_tsr_information14,
479   p_tsr_information15,
480   p_tsr_information16,
481   p_tsr_information17,
482   p_tsr_information18,
483   p_tsr_information19,
484   p_tsr_information20,
485   p_training_center_id,
486   p_location_id,
487   p_trainer_id,
488   p_special_instruction
489   );
490   --
491   -- Having converted the arguments into the ota_tsr_rec
492   -- plsql record structure we call the corresponding record business process.
493   --
494   ins(l_rec, p_validate);
495   --
496   -- As the primary key argument(s)
497   -- are specified as an OUT's we must set these values.
498   --
499   p_supplied_resource_id := l_rec.supplied_resource_id;
500   p_object_version_number := l_rec.object_version_number;
501   --
502   hr_utility.set_location(' Leaving:'||l_proc, 10);
503 End ins;
504 --
505 end ota_tsr_ins;