DBA Data[Home] [Help]

PACKAGE BODY: APPS.AME_ACU_SHD

Source


1 Package Body ame_acu_shd as
2 /* $Header: amacurhi.pkb 120.4 2005/11/22 03:13 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  ame_acu_shd.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |---------------------------< constraint_error >---------------------------|
12 -- ----------------------------------------------------------------------------
13 Procedure constraint_error
14   (p_constraint_name in all_constraints.constraint_name%TYPE
15   ) Is
16 --
17   l_proc        varchar2(72) := g_package||'constraint_error';
18 --
19 Begin
20   --
21   If (p_constraint_name = 'AME_ACTION_USAGES_PK') Then
22     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
23     fnd_message.set_token('PROCEDURE', l_proc);
24     fnd_message.set_token('STEP','5');
25     fnd_message.raise_error;
26   Else
27     fnd_message.set_name('PAY', 'HR_7877_API_INVALID_CONSTRAINT');
28     fnd_message.set_token('PROCEDURE', l_proc);
29     fnd_message.set_token('CONSTRAINT_NAME', p_constraint_name);
30     fnd_message.raise_error;
31   End If;
32   --
33 End constraint_error;
34 --
35 -- ----------------------------------------------------------------------------
36 -- |-----------------------------< api_updating >-----------------------------|
37 -- ----------------------------------------------------------------------------
38 Function api_updating
39   (p_effective_date                   in date
40   ,p_rule_id                          in number
41   ,p_action_id                        in number
42   ,p_object_version_number            in number
43   ) Return Boolean Is
44   --
45   -- Cursor selects the 'current' row from the HR Schema
46   --
47   Cursor C_Sel1 is
48     select
49      rule_id
50     ,action_id
51     ,start_date
52     ,end_date
53     ,object_version_number
54     from        ame_action_usages
55     where       action_id = p_action_id
56       and    rule_id = p_rule_id
57       and    ( p_effective_date
58         between start_date and nvl(end_date - ame_util.oneSecond,p_effective_date)
59           or
60          (p_effective_date < start_date and
61             start_date < nvl(end_date,start_date + ame_util.oneSecond)));
62 --
63   l_fct_ret     boolean;
64 --
65 Begin
66   --
67   If (p_effective_date is null or
68       p_action_id is null or
69       p_rule_id is null or
70       p_object_version_number is null) Then
71     --
72     -- One of the primary key arguments is null therefore we must
73     -- set the returning function value to false
74     --
75     l_fct_ret := false;
76   Else
77     If (p_action_id =
78         ame_acu_shd.g_old_rec.action_id and
79       p_rule_id =
80         ame_acu_shd.g_old_rec.rule_id and
81         p_object_version_number =
82         ame_acu_shd.g_old_rec.object_version_number) Then
83       --
84       -- The g_old_rec is current therefore we must
85       -- set the returning function to true
86       --
87       l_fct_ret := true;
88     Else
89       --
90       -- Select the current row
91       --
92       Open C_Sel1;
93       Fetch C_Sel1 Into ame_acu_shd.g_old_rec;
94       If C_Sel1%notfound Then
95         Close C_Sel1;
96         --
97         -- The primary key is invalid therefore we must error
98         --
99         fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
100         fnd_message.raise_error;
101       End If;
102       Close C_Sel1;
103       If (p_object_version_number
104           <> ame_acu_shd.g_old_rec.object_version_number) Then
105         fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
106         fnd_message.raise_error;
107       End If;
108       l_fct_ret := true;
109     End If;
110   End If;
111   Return (l_fct_ret);
112 --
113 End api_updating;
114 --
115 -- ----------------------------------------------------------------------------
116 -- |----------------------------< upd_end_date >------------------------------|
117 -- ----------------------------------------------------------------------------
118 Procedure upd_end_date
119   (p_effective_date                   in date
120   ,p_rule_id                          in number
121   ,p_action_id                        in number
122   ,p_new_end_date                     in date
123   ,p_object_version_number            out nocopy number
124   ) is
125 --
126   l_proc                  varchar2(72) := g_package||'upd_end_date';
127   l_current_user_id       integer;
128   l_object_version_number number;
129 --
130 Begin
131   hr_utility.set_location('Entering:'||l_proc, 5);
132   --
133   l_current_user_id := fnd_global.user_id;
134   --
135   -- Because we are updating a row we must get the next object
136   -- version number.
137   --
138   l_object_version_number :=
139     ame_acu_shd.get_object_version_number
140       (p_action_id =>  p_action_id
141  ,p_rule_id =>  p_rule_id
142       );
143   --
144   hr_utility.set_location(l_proc, 10);
145   --
146 --
147   -- Update the specified datetrack row setting the effective
148   -- end date to the specified new effective end date.
149   --
150   update  ame_action_usages t
151   set     t.end_date          = p_new_end_date
152          ,t.last_updated_by   = l_current_user_id
153          ,t.last_update_date  = p_new_end_date
154          ,t.last_update_login = l_current_user_id
155     ,     t.object_version_number = l_object_version_number
156   where   t.action_id = p_action_id
157  and    t.rule_id = p_rule_id
158    and    ( p_effective_date
159            between t.start_date and nvl(t.end_date - ame_util.oneSecond,p_effective_date)
160           or
161          (p_effective_date < t.start_date and
162             t.start_date < nvl(t.end_date,t.start_date + ame_util.oneSecond)));
163   --
164   --
165   p_object_version_number := l_object_version_number;
166   hr_utility.set_location(' Leaving:'||l_proc, 15);
167 --
168 End upd_end_date;
169 --
170 -- ----------------------------------------------------------------------------
171 -- |---------------------------------< lck >----------------------------------|
172 -- ----------------------------------------------------------------------------
173 Procedure lck
174   (p_effective_date                   in date
175   ,p_datetrack_mode                   in varchar2
176   ,p_rule_id                          in number
177   ,p_action_id                        in number
178   ,p_object_version_number            in number
179   ,p_validation_start_date            out nocopy date
180   ,p_validation_end_date              out nocopy date
181   ) is
182 --
183   l_proc                  varchar2(72) := g_package||'lck';
184   l_validation_start_date date;
185   l_validation_end_date   date;
186   l_argument              varchar2(30);
187   l_dummy                 varchar2(10);
188   --
189   -- Cursor C_Sel1 selects the current locked row as of session date
190   -- ensuring that the object version numbers match.
191   --
192   Cursor C_Sel1 is
193     select
194      rule_id
195     ,action_id
196     ,start_date
197     ,end_date
198     ,object_version_number
199     from    ame_action_usages
200     where   action_id = p_action_id
201    and    rule_id = p_rule_id
202    and    ( p_effective_date
203            between start_date and nvl(end_date - ame_util.oneSecond,p_effective_date)
204           or
205          (p_effective_date < start_date and
206             start_date < nvl(end_date,start_date + ame_util.oneSecond)))
207     for update nowait;
208   --
209   --
210   --
211 Begin
212   hr_utility.set_location('Entering:'||l_proc, 5);
213   --
214   -- Ensure that all the mandatory arguments are not null
215   --
216   hr_api.mandatory_arg_error(p_api_name       => l_proc
217                             ,p_argument       => 'effective_date'
218                             ,p_argument_value => p_effective_date
219                             );
220   --
221   hr_api.mandatory_arg_error(p_api_name       => l_proc
222                             ,p_argument       => 'datetrack_mode'
223                             ,p_argument_value => p_datetrack_mode
224                             );
225   --
226   hr_api.mandatory_arg_error(p_api_name       => l_proc
227                             ,p_argument       => 'action_id'
228                             ,p_argument_value => p_action_id
229                             );
230   --
231     hr_api.mandatory_arg_error(p_api_name       => l_proc
232                             ,p_argument       => 'object_version_number'
233                             ,p_argument_value => p_object_version_number
234                             );
235   --
236   -- Check to ensure the datetrack mode is not INSERT.
237   --
238   If (p_datetrack_mode <> hr_api.g_insert) then
239     --
240     -- We must select and lock the current row.
241     --
242     Open  C_Sel1;
243     Fetch C_Sel1 Into ame_acu_shd.g_old_rec;
244     If C_Sel1%notfound then
245       Close C_Sel1;
246       --
247       -- The primary key is invalid therefore we must error
248       --
249       fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
250       fnd_message.raise_error;
251     End If;
252     Close C_Sel1;
253     If (p_object_version_number
254           <> ame_acu_shd.g_old_rec.object_version_number) Then
255         fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
256         fnd_message.raise_error;
257     End If;
258     --
259     --
260     --
261   Else
262     --
263     -- We are doing a datetrack 'INSERT' which is illegal within this
264     -- procedure therefore we must error (note: to lck on insert the
265     -- private procedure ins_lck should be called).
266     --
267     fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
268     fnd_message.set_token('PROCEDURE', l_proc);
269     fnd_message.set_token('STEP','20');
270     fnd_message.raise_error;
271   End If;
272   --
273   -- Set the validation start and end date OUT arguments
274   --
275   if (p_datetrack_mode = hr_api.g_update) then
276     p_validation_start_date := p_effective_date;
277     p_validation_end_date   := ame_acu_shd.g_old_rec.end_date;
278   elsif (p_datetrack_mode = hr_api.g_delete) then
279     p_validation_start_date := p_effective_date;
280     p_validation_end_date   := p_effective_date;
281   end if;
282   --
283   hr_utility.set_location(' Leaving:'||l_proc, 30);
284 --
285 -- We need to trap the 2 parent objects viz. ame_rules and ame_actions
286 --
287   begin
288     select null
289       into l_dummy
290       from ame_actions
291       where action_id = p_action_id
292        and  p_effective_date between start_date and
293                  nvl(end_date - ame_util.oneSecond, p_effective_date)
294        for update of end_date nowait;
295    /*select null
296       into l_dummy
297       from ame_rules
298       where rule_id = p_rule_id and
299        ((p_effective_date between start_date and
300             nvl(end_date - ame_util.oneSecond, p_effective_date)) or
301         (p_effective_date < start_date and
302             start_date < nvl(end_date,start_date + ame_util.oneSecond)))
303        for update of end_date nowait;*/
304   exception
305     when others then
306     --
307     fnd_message.set_name('PER', 'AME_99999_CANT_LOCK_PARENT');
308     fnd_message.set_token('PROCEDURE', l_proc);
309     fnd_message.set_token('STEP','40');
310     fnd_message.raise_error;
311   end;
312 --
313 -- We need to trap the ORA LOCK exception
314 --
315 Exception
316   When HR_Api.Object_Locked then
317     --
318     -- The object is locked therefore we need to supply a meaningful
319     -- error message.
320     --
321     fnd_message.set_name('PAY', 'HR_7165_OBJECT_LOCKED');
322     fnd_message.set_token('TABLE_NAME', 'ame_action_usages');
323     fnd_message.raise_error;
324 End lck;
325 --
326 -- ----------------------------------------------------------------------------
327 -- |-----------------------------< convert_args >-----------------------------|
328 -- ----------------------------------------------------------------------------
329 Function convert_args
330   (p_rule_id                        in number
331   ,p_action_id                      in number
332   ,p_start_date                     in date
333   ,p_end_date                       in date
334   ,p_object_version_number          in number
335   )
336   Return g_rec_type is
337 --
338   l_rec   g_rec_type;
339 --
340 Begin
341   --
342   -- Convert arguments into local l_rec structure.
343   --
344   l_rec.rule_id                          := p_rule_id;
345   l_rec.action_id                        := p_action_id;
346   l_rec.start_date                       := p_start_date;
347   l_rec.end_date                         := p_end_date;
348   l_rec.object_version_number            := p_object_version_number;
349   --
350   -- Return the plsql record structure.
351   --
352   Return(l_rec);
353 --
354 End convert_args;
355 --
356 -- ----------------------------------------------------------------------------
357 -- |------------------------< get_object_version_number >----------------------|
358 -- ----------------------------------------------------------------------------
359 Function get_object_version_number
360   (p_rule_id  in  number
361   ,p_action_id  in  number
362   )
363   Return number is
364 --
365   l_ovn   number;
366 --
367 Begin
368   --
369   -- get the next ovn
370   --
371   select nvl(max(t.object_version_number),0) + 1
372     into l_ovn
373     from ame_action_usages t
374    where t.action_id = p_action_id
375  and    t.rule_id = p_rule_id;
376   --
377   -- Return the new object_version_number.
378   --
379   Return(l_ovn);
380 --
381 End get_object_version_number;
382   --
383 --
384 end ame_acu_shd;