DBA Data[Home] [Help]

PACKAGE BODY: APPS.GHR_CST_INS

Source


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