DBA Data[Home] [Help]

PACKAGE BODY: APPS.PQH_TCD_INS

Source


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