DBA Data[Home] [Help]

PACKAGE BODY: APPS.BEN_BCD_INS

Source


1 Package Body ben_bcd_ins as
2 /* $Header: bebcdrhi.pkb 120.0 2005/05/28 00:34:41 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ben_bcd_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_cwb_matrix_dtl_id_i  number   default null;
14 --
15 -- ----------------------------------------------------------------------------
16 -- |------------------------< set_base_key_value >----------------------------|
17 -- ----------------------------------------------------------------------------
18 procedure set_base_key_value
19   (p_cwb_matrix_dtl_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   ben_bcd_ins.g_cwb_matrix_dtl_id_i := p_cwb_matrix_dtl_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 ben_bcd_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: ben_cwb_matrix_dtl
88   --
89   insert into ben_cwb_matrix_dtl
90       (cwb_matrix_dtl_id
91       ,cwb_matrix_id
92       ,row_crit_val
93       ,col_crit_val
94       ,pct_emp_cndr
95       ,pct_val
96       ,emp_amt
97       ,business_group_id
98       ,object_version_number
99       )
100   Values
101     (p_rec.cwb_matrix_dtl_id
102     ,p_rec.cwb_matrix_id
103     ,p_rec.row_crit_val
104     ,p_rec.col_crit_val
105     ,p_rec.pct_emp_cndr
106     ,p_rec.pct_val
107     ,p_rec.emp_amt
108     ,p_rec.business_group_id
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     ben_bcd_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     ben_bcd_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     ben_bcd_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 ben_bcd_shd.g_rec_type
175   ) is
176 --
177   Cursor C_Sel1 is select ben_cwb_matrix_dtl_s.nextval from sys.dual;
178 --
179   Cursor C_Sel2 is
180     Select null
181       from ben_cwb_matrix_dtl
182      where cwb_matrix_dtl_id =
183              ben_bcd_ins.g_cwb_matrix_dtl_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 (ben_bcd_ins.g_cwb_matrix_dtl_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','ben_cwb_matrix_dtl');
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.cwb_matrix_dtl_id :=
211       ben_bcd_ins.g_cwb_matrix_dtl_id_i;
212     ben_bcd_ins.g_cwb_matrix_dtl_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.cwb_matrix_dtl_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_rec                          in ben_bcd_shd.g_rec_type
262   ) is
263 --
264   l_proc  varchar2(72) := g_package||'post_insert';
265 --
266 Begin
267   hr_utility.set_location('Entering:'||l_proc, 5);
268   begin
269     --
270     ben_bcd_rki.after_insert
271       (p_cwb_matrix_dtl_id
272       => p_rec.cwb_matrix_dtl_id
273       ,p_cwb_matrix_id
274       => p_rec.cwb_matrix_id
275       ,p_row_crit_val
276       => p_rec.row_crit_val
277       ,p_col_crit_val
278       => p_rec.col_crit_val
279       ,p_pct_emp_cndr
280       => p_rec.pct_emp_cndr
281       ,p_pct_val
282       => p_rec.pct_val
283       ,p_emp_amt
284       => p_rec.emp_amt
285       ,p_business_group_id
286       => p_rec.business_group_id
287       ,p_object_version_number
288       => p_rec.object_version_number
289       );
290     --
291   exception
292     --
293     when hr_api.cannot_find_prog_unit then
294       --
295       hr_api.cannot_find_prog_unit_error
296         (p_module_name => 'BEN_CWB_MATRIX_DTL'
297         ,p_hook_type   => 'AI');
298       --
299   end;
300   --
301   hr_utility.set_location(' Leaving:'||l_proc, 10);
302 End post_insert;
303 --
304 -- ----------------------------------------------------------------------------
305 -- |---------------------------------< ins >----------------------------------|
306 -- ----------------------------------------------------------------------------
307 Procedure ins
308   (p_rec                          in out nocopy ben_bcd_shd.g_rec_type
309   ) is
310 --
311   l_proc  varchar2(72) := g_package||'ins';
312 --
313 Begin
314   hr_utility.set_location('Entering:'||l_proc, 5);
315   --
316   -- Call the supporting insert validate operations
317   --
318   ben_bcd_bus.insert_validate
319      (p_rec
320      );
321   --
322   -- Call to raise any errors on multi-message list
323   hr_multi_message.end_validation_set;
324   --
325   -- Call the supporting pre-insert operation
326   --
327   ben_bcd_ins.pre_insert(p_rec);
328   --
329   -- Insert the row
330   --
331   ben_bcd_ins.insert_dml(p_rec);
332   --
333   -- Call the supporting post-insert operation
334   --
335   ben_bcd_ins.post_insert
336      (p_rec
337      );
338   --
339   -- Call to raise any errors on multi-message list
340   hr_multi_message.end_validation_set;
341   --
342   hr_utility.set_location('Leaving:'||l_proc, 20);
343 end ins;
344 --
345 -- ----------------------------------------------------------------------------
346 -- |---------------------------------< ins >----------------------------------|
347 -- ----------------------------------------------------------------------------
348 Procedure ins
349   (p_cwb_matrix_id                  in     number
350   ,p_row_crit_val                   in     varchar2
351   ,p_business_group_id              in     number
352   ,p_col_crit_val                   in     varchar2 default null
353   ,p_pct_emp_cndr                   in     number   default null
354   ,p_pct_val                        in     number   default null
355   ,p_emp_amt                        in     number   default null
356   ,p_cwb_matrix_dtl_id                 out nocopy number
357   ,p_object_version_number             out nocopy number
358   ) is
359 --
360   l_rec   ben_bcd_shd.g_rec_type;
361   l_proc  varchar2(72) := g_package||'ins';
362 --
363 Begin
364   hr_utility.set_location('Entering:'||l_proc, 5);
365   --
366   -- Call conversion function to turn arguments into the
367   -- p_rec structure.
368   --
369   l_rec :=
370   ben_bcd_shd.convert_args
371     (null
372     ,p_cwb_matrix_id
373     ,p_row_crit_val
374     ,p_col_crit_val
375     ,p_pct_emp_cndr
376     ,p_pct_val
377     ,p_emp_amt
378     ,p_business_group_id
379     ,null
380     );
381   --
382   -- Having converted the arguments into the ben_bcd_rec
383   -- plsql record structure we call the corresponding record business process.
384   --
385   ben_bcd_ins.ins
386      (l_rec
387      );
388   --
389   -- As the primary key argument(s)
390   -- are specified as an OUT's we must set these values.
391   --
392   p_cwb_matrix_dtl_id := l_rec.cwb_matrix_dtl_id;
393   p_object_version_number := l_rec.object_version_number;
394   --
395   hr_utility.set_location(' Leaving:'||l_proc, 10);
396 End ins;
397 --
398 end ben_bcd_ins;