DBA Data[Home] [Help]

PACKAGE BODY: APPS.PAY_SPR_INS

Source


1 Package Body pay_spr_ins as
2 /* $Header: pysprrhi.pkb 120.0 2005/05/29 08:54:06 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  pay_spr_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_security_profile_id_i  number   default null;
14 g_payroll_id_i  number   default null;
15 --
16 -- ----------------------------------------------------------------------------
17 -- |------------------------< set_base_key_value >----------------------------|
18 -- ----------------------------------------------------------------------------
19 procedure set_base_key_value
20   (p_security_profile_id  in  number
21   ,p_payroll_id  in  number) is
22 --
23   l_proc       varchar2(72) := g_package||'set_base_key_value';
24 --
25 Begin
26   hr_utility.set_location('Entering:'||l_proc, 10);
27   --
28   pay_spr_ins.g_security_profile_id_i := p_security_profile_id;
29   pay_spr_ins.g_payroll_id_i := p_payroll_id;
30   --
31   hr_utility.set_location(' Leaving:'||l_proc, 20);
32 End set_base_key_value;
33 --
34 --
35 -- ----------------------------------------------------------------------------
36 -- |------------------------------< insert_dml >------------------------------|
37 -- ----------------------------------------------------------------------------
38 -- {Start Of Comments}
39 --
40 -- Description:
41 --   This procedure controls the actual dml insert logic. The processing of
42 --   this procedure are as follows:
43 --   1) Initialise the object_version_number to 1 if the object_version_number
44 --      is defined as an attribute for this entity.
45 --   2) To set and unset the g_api_dml status as required (as we are about to
46 --      perform dml).
47 --   3) To insert the row into the schema.
48 --   4) To trap any constraint violations that may have occurred.
49 --   5) To raise any other errors.
50 --
51 -- Prerequisites:
52 --   This is an internal private procedure which must be called from the ins
53 --   procedure and must have all mandatory attributes set (except the
54 --   object_version_number which is initialised within this procedure).
55 --
56 -- In Parameters:
57 --   A Pl/Sql record structre.
58 --
59 -- Post Success:
60 --   The specified row will be inserted into the schema.
61 --
62 -- Post Failure:
63 --   On the insert dml failure it is important to note that we always reset the
64 --   g_api_dml status to false.
65 --   If a check, unique or parent integrity constraint violation is raised the
66 --   constraint_error procedure will be called.
67 --   If any other error is reported, the error will be raised after the
68 --   g_api_dml status is reset.
69 --
70 -- Developer Implementation Notes:
71 --   None.
72 --
73 -- Access Status:
74 --   Internal Row Handler Use Only.
75 --
76 -- {End Of Comments}
77 -- ----------------------------------------------------------------------------
78 Procedure insert_dml
79   (p_rec in out nocopy pay_spr_shd.g_rec_type
80   ) is
81 --
82   l_proc  varchar2(72) := g_package||'insert_dml';
83 --
84 Begin
85   hr_utility.set_location('Entering:'||l_proc, 5);
86   p_rec.object_version_number := 1;  -- Initialise the object version
87   --
88   pay_spr_shd.g_api_dml := true;  -- Set the api dml status
89   --
90   -- Insert the row into: pay_security_payrolls
91   --
92   hr_utility.set_location(to_char(p_rec.payroll_id),10);
93   insert into pay_security_payrolls
94       (business_group_id
95       ,security_profile_id
96       ,payroll_id
97       ,request_id
98       ,program_application_id
99       ,program_id
100       ,program_update_date
101       ,object_version_number
102       )
103   Values
104     (p_rec.business_group_id
105     ,p_rec.security_profile_id
106     ,p_rec.payroll_id
107     ,p_rec.request_id
108     ,p_rec.program_application_id
109     ,p_rec.program_id
110     ,p_rec.program_update_date
111     ,p_rec.object_version_number
112     );
113   --
114   pay_spr_shd.g_api_dml := false;   -- Unset the api dml status
115   --
116   hr_utility.set_location(' Leaving:'||l_proc, 10);
117 Exception
118   When hr_api.check_integrity_violated Then
119     -- A check constraint has been violated
120     pay_spr_shd.g_api_dml := false;   -- Unset the api dml status
121     pay_spr_shd.constraint_error
122       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
123   When hr_api.parent_integrity_violated Then
124     -- Parent integrity has been violated
125     pay_spr_shd.g_api_dml := false;   -- Unset the api dml status
126     pay_spr_shd.constraint_error
127       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
128   When hr_api.unique_integrity_violated Then
129     -- Unique integrity has been violated
130     pay_spr_shd.g_api_dml := false;   -- Unset the api dml status
131     pay_spr_shd.constraint_error
132       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
133   When Others Then
134     pay_spr_shd.g_api_dml := false;   -- Unset the api dml status
135     Raise;
136 End insert_dml;
137 --
138 -- ----------------------------------------------------------------------------
139 -- |------------------------------< pre_insert >------------------------------|
140 -- ----------------------------------------------------------------------------
141 -- {Start Of Comments}
142 --
143 -- Description:
144 --   This private procedure contains any processing which is required before
145 --   the insert dml. Presently, if the entity has a corresponding primary
146 --   key which is maintained by an associating sequence, the primary key for
147 --   the entity will be populated with the next sequence value in
148 --   preparation for the insert dml.
149 --
150 -- Prerequisites:
151 --   This is an internal procedure which is called from the ins procedure.
152 --
153 -- In Parameters:
154 --   A Pl/Sql record structure.
155 --
156 -- Post Success:
157 --   Processing continues.
158 --
159 -- Post Failure:
160 --   If an error has occurred, an error message and exception will be raised
161 --   but not handled.
162 --
163 -- Developer Implementation Notes:
164 --   Any pre-processing required before the insert dml is issued should be
165 --   coded within this procedure. As stated above, a good example is the
166 --   generation of a primary key number via a corresponding sequence.
167 --   It is important to note that any 3rd party maintenance should be reviewed
168 --   before placing in this procedure.
169 --
170 -- Access Status:
171 --   Internal Row Handler Use Only.
172 --
173 -- {End Of Comments}
174 -- ----------------------------------------------------------------------------
175 Procedure pre_insert
176   (p_rec  in out nocopy pay_spr_shd.g_rec_type
177   ) is
178 --
179 --
180   Cursor C_Sel2 is
181     Select null
182       from pay_security_payrolls
183      where security_profile_id =
184              pay_spr_ins.g_security_profile_id_i
185        and payroll_id =
186              pay_spr_ins.g_payroll_id_i;
187 --
188   l_proc   varchar2(72) := g_package||'pre_insert';
189   l_exists varchar2(1);
190 --
191 Begin
192   hr_utility.set_location('Entering:'||l_proc, 5);
193   --
194   If (pay_spr_ins.g_security_profile_id_i is not null and
195       pay_spr_ins.g_payroll_id_i is not null) Then
196     --
197     -- Verify registered primary key values not already in use
198     --
199     Open C_Sel2;
200     Fetch C_Sel2 into l_exists;
201     If C_Sel2%found Then
202        Close C_Sel2;
203        --
204        -- The primary key values are already in use.
205        --
206        fnd_message.set_name('PER','PER_289391_KEY_ALREADY_USED');
207        fnd_message.set_token('TABLE_NAME','pay_security_payrolls');
208        fnd_message.raise_error;
209     End If;
210     Close C_Sel2;
211     --
212     -- Use registered key values and clear globals
213     --
214     p_rec.security_profile_id :=
215       pay_spr_ins.g_security_profile_id_i;
216     pay_spr_ins.g_security_profile_id_i := null;
217     p_rec.payroll_id :=
218       pay_spr_ins.g_payroll_id_i;
219     pay_spr_ins.g_payroll_id_i := null;
220 
221   End If;
222   --
223   hr_utility.set_location(' Leaving:'||l_proc, 10);
224 End pre_insert;
225 --
226 -- ----------------------------------------------------------------------------
227 -- |-----------------------------< post_insert >------------------------------|
228 -- ----------------------------------------------------------------------------
229 -- {Start Of Comments}
230 --
231 -- Description:
232 --   This private procedure contains any processing which is required after
233 --   the insert dml.
234 --
235 -- Prerequisites:
236 --   This is an internal procedure which is called from the ins procedure.
237 --
238 -- In Parameters:
239 --   A Pl/Sql record structre.
240 --
241 -- Post Success:
242 --   Processing continues.
243 --
244 -- Post Failure:
245 --   If an error has occurred, an error message and exception will be raised
246 --   but not handled.
247 --
248 -- Developer Implementation Notes:
249 --   Any post-processing required after the insert dml is issued should be
250 --   coded within this procedure. It is important to note that any 3rd party
251 --   maintenance should be reviewed before placing in this procedure.
252 --
253 -- Access Status:
254 --   Internal Row Handler Use Only.
255 --
256 -- {End Of Comments}
257 -- ----------------------------------------------------------------------------
258 Procedure post_insert
259   (p_effective_date               in date
260   ,p_rec                          in pay_spr_shd.g_rec_type
261   ) is
262 --
263   l_proc  varchar2(72) := g_package||'post_insert';
264 --
265 Begin
266   hr_utility.set_location('Entering:'||l_proc, 5);
267   begin
268     --
269     pay_spr_rki.after_insert
270       (p_effective_date              => p_effective_date
271       ,p_business_group_id
272       => p_rec.business_group_id
273       ,p_security_profile_id
274       => p_rec.security_profile_id
275       ,p_payroll_id
276       => p_rec.payroll_id
277       ,p_object_version_number
278       => p_rec.object_version_number
279       );
280     --
281   exception
282     --
283     when hr_api.cannot_find_prog_unit then
284       --
285       hr_api.cannot_find_prog_unit_error
286         (p_module_name => 'PAY_SECURITY_PAYROLLS'
287         ,p_hook_type   => 'AI');
288       --
289   end;
290   --
291   hr_utility.set_location(' Leaving:'||l_proc, 10);
292 End post_insert;
293 --
294 -- ----------------------------------------------------------------------------
295 -- |---------------------------------< ins >----------------------------------|
296 -- ----------------------------------------------------------------------------
297 Procedure ins
298   (p_effective_date               in            date
299   ,p_rec                          in out nocopy pay_spr_shd.g_rec_type
300   ) is
301 --
302   l_proc  varchar2(72) := g_package||'ins';
303 --
304 Begin
305   hr_utility.set_location('Entering:'||l_proc, 5);
306   --
307   -- Call the supporting insert validate operations
308   --
309   pay_spr_bus.insert_validate
310      (p_effective_date
311      ,p_rec
312      );
313   --
314   -- Call to raise any errors on multi-message list
315   hr_multi_message.end_validation_set;
316   --
317   -- Call the supporting pre-insert operation
318   --
319   pay_spr_ins.pre_insert(p_rec);
320   --
321   -- Insert the row
322   --
323   pay_spr_ins.insert_dml(p_rec);
324   --
325   -- Call the supporting post-insert operation
326   --
327   pay_spr_ins.post_insert
328      (p_effective_date
329      ,p_rec
330      );
331   --
332   -- Call to raise any errors on multi-message list
333   hr_multi_message.end_validation_set;
334   --
335   hr_utility.set_location('Leaving:'||l_proc, 20);
336 end ins;
337 --
338 -- ----------------------------------------------------------------------------
339 -- |---------------------------------< ins >----------------------------------|
340 -- ----------------------------------------------------------------------------
341 Procedure ins
342   (p_effective_date                 in     	 date
343   ,p_security_profile_id            in     	 number
344   ,p_payroll_id                     in     	 number
345   ,p_object_version_number          out  nocopy  number
346   ) is
347 --
348   l_rec   pay_spr_shd.g_rec_type;
349   l_proc  varchar2(72) := g_package||'ins';
350   l_business_group_id number;
351 --
352 Begin
353   hr_utility.set_location('Entering:'||l_proc, 5);
354   --
355   -- Call the chk procedures that will return the business group id
356 
357   --  This two procedures are being called here instead of in
358   --  insert_validate beacause the business group id is being derived here
359   --  to set l_rec. And the payroll_id and the security_profile_id has to
360   --  be valid.
361 
362   -- Call to validate the business group id is not global
363 
364   pay_spr_bus.chk_security_profile
365     (p_security_profile_id => p_security_profile_id
366     ,p_business_group_id   => l_business_group_id);
367 
368   -- Call to Validate security profile id and payroll id belong to the
369   --  same business group.
370 
371   pay_spr_bus.chk_payroll_id
372     (p_payroll_id           => p_payroll_id
373     ,p_security_profile_id  => p_security_profile_id
374     ,p_business_group_id    => l_business_group_id);
375 
376   hr_utility.set_location(l_proc, 7);
377   --
378   -- Call conversion function to turn arguments into the
379   -- p_rec structure.
380   --
381   l_rec :=
382   pay_spr_shd.convert_args
383     (l_business_group_id
384     ,p_security_profile_id
385     ,p_payroll_id
386     ,p_object_version_number
387     );
388   --
389   -- Having converted the arguments into the pay_spr_rec
390   -- plsql record structure we call the corresponding record business process.
391   --
392   pay_spr_ins.ins
393      (p_effective_date
394      ,l_rec
395      );
396   --
397       p_object_version_number := l_rec.object_version_number;
398   --
399     hr_utility.set_location(' Leaving:'||l_proc, 10);
400 End ins;
401 --
402 end pay_spr_ins;