1 Package Body pqh_del_ins as
2 /* $Header: pqdelrhi.pkb 115.7 2002/12/05 19:31:43 rpasapul noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' pqh_del_ins.'; -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------------------------------< insert_dml >------------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 -- This procedure controls the actual dml insert logic. The processing of
17 -- this procedure are as follows:
18 -- 1) Initialise the object_version_number to 1 if the object_version_number
19 -- is defined as an attribute for this entity.
20 -- 3) To insert the row into the schema.
21 -- 4) To trap any constraint violations that may have occurred.
22 -- 5) To raise any other errors.
23 --
24 -- Prerequisites:
25 -- This is an internal private procedure which must be called from the ins
26 -- procedure and must have all mandatory attributes set (except the
27 -- object_version_number which is initialised within this procedure).
28 --
29 -- In Parameters:
30 -- A Pl/Sql record structre.
31 --
32 -- Post Success:
33 -- The specified row will be inserted into the schema.
34 --
35 -- Post Failure:
36 -- If a check, unique or parent integrity constraint violation is raised the
37 -- constraint_error procedure will be called.
38 --
39 -- Developer Implementation Notes:
40 -- None.
41 --
42 -- Access Status:
43 -- Internal Row Handler Use Only.
44 --
45 -- {End Of Comments}
46 -- ----------------------------------------------------------------------------
47 Procedure insert_dml(p_rec in out nocopy pqh_del_shd.g_rec_type) is
48 --
49 l_proc varchar2(72) := g_package||'insert_dml';
50 --
51 Begin
52 hr_utility.set_location('Entering:'||l_proc, 5);
53 p_rec.object_version_number := 1; -- Initialise the object version
54 --
55 --
56 -- Insert the row into: pqh_dflt_budget_elements
57 --
58 insert into pqh_dflt_budget_elements
59 ( dflt_budget_element_id,
60 dflt_budget_set_id,
61 element_type_id,
62 dflt_dist_percentage,
63 object_version_number
64 )
65 Values
66 ( p_rec.dflt_budget_element_id,
67 p_rec.dflt_budget_set_id,
68 p_rec.element_type_id,
69 p_rec.dflt_dist_percentage,
70 p_rec.object_version_number
71 );
72 --
73 --
74 hr_utility.set_location(' Leaving:'||l_proc, 10);
75 Exception
76 When hr_api.check_integrity_violated Then
77 -- A check constraint has been violated
78 pqh_del_shd.constraint_error
79 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
80 When hr_api.parent_integrity_violated Then
81 -- Parent integrity has been violated
82 pqh_del_shd.constraint_error
83 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
84 When hr_api.unique_integrity_violated Then
85 -- Unique integrity has been violated
86 pqh_del_shd.constraint_error
87 (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
88 When Others Then
89 Raise;
90 End insert_dml;
91 --
92 -- ----------------------------------------------------------------------------
93 -- |------------------------------< pre_insert >------------------------------|
94 -- ----------------------------------------------------------------------------
95 -- {Start Of Comments}
96 --
97 -- Description:
98 -- This private procedure contains any processing which is required before
99 -- the insert dml. Presently, if the entity has a corresponding primary
100 -- key which is maintained by an associating sequence, the primary key for
101 -- the entity will be populated with the next sequence value in
102 -- preparation for the insert dml.
103 --
104 -- Prerequisites:
105 -- This is an internal procedure which is called from the ins procedure.
106 --
107 -- In Parameters:
108 -- A Pl/Sql record structre.
109 --
110 -- Post Success:
111 -- Processing continues.
112 --
113 -- Post Failure:
114 -- If an error has occurred, an error message and exception will be raised
115 -- but not handled.
116 --
117 -- Developer Implementation Notes:
118 -- Any pre-processing required before the insert dml is issued should be
119 -- coded within this procedure. As stated above, a good example is the
120 -- generation of a primary key number via a corresponding sequence.
121 -- It is important to note that any 3rd party maintenance should be reviewed
122 -- before placing in this procedure.
123 --
124 -- Access Status:
125 -- Internal Row Handler Use Only.
126 --
127 -- {End Of Comments}
128 -- ----------------------------------------------------------------------------
129 Procedure pre_insert(p_rec in out nocopy pqh_del_shd.g_rec_type) is
130 --
131 l_proc varchar2(72) := g_package||'pre_insert';
132 --
133 Cursor C_Sel1 is select pqh_dflt_budget_elements_s.nextval from sys.dual;
134 --
135 Begin
136 hr_utility.set_location('Entering:'||l_proc, 5);
137 --
138 --
139 -- Select the next sequence number
140 --
141 Open C_Sel1;
142 Fetch C_Sel1 Into p_rec.dflt_budget_element_id;
143 Close C_Sel1;
144 --
145 hr_utility.set_location(' Leaving:'||l_proc, 10);
146 End pre_insert;
147 --
148 -- ----------------------------------------------------------------------------
149 -- |-----------------------------< post_insert >------------------------------|
150 -- ----------------------------------------------------------------------------
151 -- {Start Of Comments}
152 --
153 -- Description:
154 -- This private procedure contains any processing which is required after the
155 -- insert dml.
156 --
157 -- Prerequisites:
158 -- This is an internal procedure which is called from the ins procedure.
159 --
160 -- In Parameters:
161 -- A Pl/Sql record structre.
162 --
163 -- Post Success:
164 -- Processing continues.
165 --
166 -- Post Failure:
167 -- If an error has occurred, an error message and exception will be raised
168 -- but not handled.
169 --
170 -- Developer Implementation Notes:
171 -- Any post-processing required after the insert dml is issued should be
172 -- coded within this procedure. It is important to note that any 3rd party
173 -- maintenance should be reviewed before placing in this procedure.
174 --
175 -- Access Status:
176 -- Internal Row Handler Use Only.
177 --
178 -- {End Of Comments}
179 -- ----------------------------------------------------------------------------
180 Procedure post_insert(p_rec in pqh_del_shd.g_rec_type) is
181 --
182 l_proc varchar2(72) := g_package||'post_insert';
183 --
184 --
185 l_sum number(15,2) := 0;
186
187 cursor csr_element(p_dflt_budget_set_id in number) is
188 select SUM(NVL(dflt_dist_percentage,0))
189 from pqh_dflt_budget_elements
190 where dflt_budget_set_id = p_dflt_budget_set_id;
191
192
193 --
194
195 Begin
196 hr_utility.set_location('Entering:'||l_proc, 5);
197 --
198 --
199 open csr_element(p_dflt_budget_set_id => p_rec.dflt_budget_set_id );
200 fetch csr_element into l_sum;
201 close csr_element;
202
203 if l_sum > 100 then
204 -- sum cannot be more then 100
205 --
206 hr_utility.set_message(8302,'PQH_WKS_INVALID_ELMNT_SUM');
207 hr_utility.raise_error;
208 --
209 end if;
210 --
211
212 --
213 -- Start of API User Hook for post_insert.
214 --
215 begin
216 --
217 pqh_del_rki.after_insert
218 (
219 p_dflt_budget_element_id =>p_rec.dflt_budget_element_id
220 ,p_dflt_budget_set_id =>p_rec.dflt_budget_set_id
221 ,p_element_type_id =>p_rec.element_type_id
222 ,p_dflt_dist_percentage =>p_rec.dflt_dist_percentage
223 ,p_object_version_number =>p_rec.object_version_number
224 );
225 --
226 exception
227 --
228 when hr_api.cannot_find_prog_unit then
229 --
230 hr_api.cannot_find_prog_unit_error
231 (p_module_name => 'pqh_dflt_budget_elements'
232 ,p_hook_type => 'AI');
233 --
234 end;
235 --
236 -- End of API User Hook for post_insert.
237 --
238 --
239 hr_utility.set_location(' Leaving:'||l_proc, 10);
240 End post_insert;
241 --
242 -- ----------------------------------------------------------------------------
243 -- |---------------------------------< ins >----------------------------------|
244 -- ----------------------------------------------------------------------------
245 Procedure ins
246 (
247 p_rec in out nocopy pqh_del_shd.g_rec_type
248 ) is
249 --
250 l_proc varchar2(72) := g_package||'ins';
251 --
252 Begin
253 hr_utility.set_location('Entering:'||l_proc, 5);
254 --
255 -- Call the supporting insert validate operations
256 --
257 pqh_del_bus.insert_validate(p_rec);
258 --
259 -- Call the supporting pre-insert operation
260 --
261 pre_insert(p_rec);
262 --
263 -- Insert the row
264 --
265 insert_dml(p_rec);
266 --
267 -- Call the supporting post-insert operation
268 --
269 post_insert(p_rec);
270 end ins;
271 --
272 -- ----------------------------------------------------------------------------
273 -- |---------------------------------< ins >----------------------------------|
274 -- ----------------------------------------------------------------------------
275 Procedure ins
276 (
277 p_dflt_budget_element_id out nocopy number,
278 p_dflt_budget_set_id in number,
279 p_element_type_id in number,
280 p_dflt_dist_percentage in number default null,
281 p_object_version_number out nocopy number
282 ) is
283 --
284 l_rec pqh_del_shd.g_rec_type;
285 l_proc varchar2(72) := g_package||'ins';
286 --
287 Begin
288 hr_utility.set_location('Entering:'||l_proc, 5);
289 --
290 -- Call conversion function to turn arguments into the
291 -- p_rec structure.
292 --
293 l_rec :=
294 pqh_del_shd.convert_args
295 (
296 null,
297 p_dflt_budget_set_id,
298 p_element_type_id,
299 p_dflt_dist_percentage,
300 null
301 );
302 --
303 -- Having converted the arguments into the pqh_del_rec
304 -- plsql record structure we call the corresponding record business process.
305 --
306 ins(l_rec);
307 --
308 -- As the primary key argument(s)
309 -- are specified as an OUT's we must set these values.
310 --
311 p_dflt_budget_element_id := l_rec.dflt_budget_element_id;
312 p_object_version_number := l_rec.object_version_number;
313 --
314 hr_utility.set_location(' Leaving:'||l_proc, 10);
315 End ins;
316 --
317 end pqh_del_ins;