[Home] [Help]
PACKAGE BODY: APPS.AME_ATR_SHD
Source
1 Package Body ame_atr_shd as
2 /* $Header: amatrrhi.pkb 120.3 2005/11/22 03:14 santosin noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- | Private Global Definitions |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package varchar2(33) := ' ame_atr_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_ATTRIBUTES_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_attribute_id in number
41 ,p_object_version_number in number
42 ) Return Boolean Is
43 --
44 -- Cursor selects the 'current' row from the HR Schema
45 --
46 Cursor C_Sel1 is
47 select
48 attribute_id
49 ,name
50 ,attribute_type
51 ,line_item
52 ,start_date
53 ,end_date
54 ,description
55 ,security_group_id
56 ,approver_type_id
57 ,item_class_id
58 ,object_version_number
59 ,created_by
60 from ame_attributes
61 where attribute_id = p_attribute_id
62 and p_effective_date
63 between start_date
64 and nvl(end_date - ame_util.oneSecond,p_effective_date);
65 --
66 l_fct_ret boolean;
67 --
68 Begin
69 --
70 If (p_effective_date is null or
71 p_attribute_id is null or
72 p_object_version_number is null) Then
73 --
74 -- One of the primary key arguments is null therefore we must
75 -- set the returning function value to false
76 --
77 l_fct_ret := false;
78 Else
79 If (p_attribute_id =
80 ame_atr_shd.g_old_rec.attribute_id and
81 p_object_version_number =
82 ame_atr_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_atr_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_atr_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_attribute_id in number
121 ,p_new_end_date in date
122 ,p_object_version_number out nocopy number
123 ) is
124 --
125 l_proc varchar2(72) := g_package||'upd_end_date';
126 l_object_version_number number;
127 --
128 Begin
129 hr_utility.set_location('Entering:'||l_proc, 5);
130 --
131 -- Because we are updating a row we must get the next object
132 -- version number.
133 --
134 l_object_version_number :=
135 ame_atr_shd.get_object_version_number
136 (p_attribute_id => p_attribute_id
137 );
138 --
139 hr_utility.set_location(l_proc, 10);
140 --
141 --
142 -- Update the specified datetrack row setting the effective
143 -- end date to the specified new effective end date.
144 --
145 update ame_attributes t
146 set t.end_date = p_new_end_date
147 , t.object_version_number = l_object_version_number
148 where t.attribute_id = p_attribute_id
149 and p_effective_date
150 between t.start_date and nvl(t.end_date - ame_util.oneSecond,p_effective_date)
151 ;
152 --
153 --
154 p_object_version_number := l_object_version_number;
155 hr_utility.set_location(' Leaving:'||l_proc, 15);
156 --
157 End upd_end_date;
158 --
159 -- ----------------------------------------------------------------------------
160 -- |---------------------------------< lck >----------------------------------|
161 -- ----------------------------------------------------------------------------
162 Procedure lck
163 (p_effective_date in date
164 ,p_datetrack_mode in varchar2
165 ,p_attribute_id in number
166 ,p_object_version_number in number
167 ,p_validation_start_date out nocopy date
168 ,p_validation_end_date out nocopy date
169 ) is
170 --
171 l_proc varchar2(72) := g_package||'lck';
172 l_validation_start_date date;
173 l_validation_end_date date;
174 l_argument varchar2(30);
175 --
176 -- Cursor C_Sel1 selects the current locked row as of session date
177 -- ensuring that the object version numbers match.
178 --
179 Cursor C_Sel1 is
180 select
181 attribute_id
182 ,name
183 ,attribute_type
184 ,line_item
185 ,start_date
186 ,end_date
187 ,description
188 ,security_group_id
189 ,approver_type_id
190 ,item_class_id
191 ,object_version_number
192 ,created_by
193 from ame_attributes
194 where attribute_id = p_attribute_id
195 and p_effective_date
196 between start_date and nvl(end_date - ame_util.oneSecond, p_effective_date)
197 for update nowait;
198 --
199 --
200 --
201 Begin
202 hr_utility.set_location('Entering:'||l_proc, 5);
203 --
204 -- Ensure that all the mandatory arguments are not null
205 --
209 );
206 hr_api.mandatory_arg_error(p_api_name => l_proc
207 ,p_argument => 'effective_date'
208 ,p_argument_value => p_effective_date
210 --
211 hr_api.mandatory_arg_error(p_api_name => l_proc
212 ,p_argument => 'datetrack_mode'
213 ,p_argument_value => p_datetrack_mode
214 );
215 --
216 hr_api.mandatory_arg_error(p_api_name => l_proc
217 ,p_argument => 'attribute_id'
218 ,p_argument_value => p_attribute_id
219 );
220 --
221 hr_api.mandatory_arg_error(p_api_name => l_proc
222 ,p_argument => 'object_version_number'
223 ,p_argument_value => p_object_version_number
224 );
225 --
226 -- Check to ensure the datetrack mode is not INSERT.
227 --
228 If (p_datetrack_mode <> hr_api.g_insert) then
229 --
230 -- We must select and lock the current row.
231 --
232 Open C_Sel1;
233 Fetch C_Sel1 Into ame_atr_shd.g_old_rec;
234 If C_Sel1%notfound then
235 Close C_Sel1;
236 --
237 -- The primary key is invalid therefore we must error
238 --
239 fnd_message.set_name('PAY', 'HR_7220_INVALID_PRIMARY_KEY');
240 fnd_message.raise_error;
241 End If;
242 Close C_Sel1;
243 If (p_object_version_number
244 <> ame_atr_shd.g_old_rec.object_version_number) Then
245 fnd_message.set_name('PAY', 'HR_7155_OBJECT_INVALID');
246 fnd_message.raise_error;
247 End If;
248 --
249 --
250 --
251 Else
252 --
253 -- We are doing a datetrack 'INSERT' which is illegal within this
254 -- procedure therefore we must error (note: to lck on insert the
255 -- private procedure ins_lck should be called).
256 --
257 fnd_message.set_name('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
258 fnd_message.set_token('PROCEDURE', l_proc);
259 fnd_message.set_token('STEP','20');
260 fnd_message.raise_error;
261 End If;
262 --
263 -- Set the validation start and end date OUT arguments
264 --
265 if (p_datetrack_mode = hr_api.g_update) then
266 p_validation_start_date := p_effective_date;
267 p_validation_end_date := ame_atr_shd.g_old_rec.end_date;
268 elsif (p_datetrack_mode = hr_api.g_delete) then
269 p_validation_start_date := p_effective_date;
270 p_validation_end_date := p_effective_date;
271 end if;
272 --
273 hr_utility.set_location(' Leaving:'||l_proc, 30);
274 --
275 -- We need to trap the ORA LOCK exception
276 --
277 Exception
278 When HR_Api.Object_Locked then
279 --
280 -- The object is locked therefore we need to supply a meaningful
281 -- error message.
282 --
283 fnd_message.set_name('PAY', 'HR_7165_OBJECT_LOCKED');
284 fnd_message.set_token('TABLE_NAME', 'ame_attributes');
285 fnd_message.raise_error;
286 End lck;
287 --
288 -- ----------------------------------------------------------------------------
289 -- |-----------------------------< convert_args >-----------------------------|
290 -- ----------------------------------------------------------------------------
291 Function convert_args
292 (p_attribute_id in number
293 ,p_name in varchar2
294 ,p_attribute_type in varchar2
295 ,p_line_item in varchar2
296 ,p_start_date in date
297 ,p_end_date in date
298 ,p_description in varchar2
299 ,p_security_group_id in number
300 ,p_approver_type_id in number
301 ,p_item_class_id in number
302 ,p_object_version_number in number
303 )
304 Return g_rec_type is
305 --
306 l_rec g_rec_type;
307 --
308 Begin
309 --
310 -- Convert arguments into local l_rec structure.
311 --
312 l_rec.attribute_id := p_attribute_id;
313 l_rec.name := p_name;
314 l_rec.attribute_type := p_attribute_type;
315 l_rec.line_item := p_line_item;
316 l_rec.start_date := p_start_date;
317 l_rec.end_date := p_end_date;
318 l_rec.description := p_description;
319 l_rec.security_group_id := p_security_group_id;
320 l_rec.approver_type_id := p_approver_type_id;
321 l_rec.item_class_id := p_item_class_id;
322 l_rec.object_version_number := p_object_version_number;
323 --
324 -- Return the plsql record structure.
325 --
326 Return(l_rec);
327 --
328 End convert_args;
329 --
330 -- ----------------------------------------------------------------------------
331 -- |------------------------< get_object_version_number >----------------------|
332 -- ----------------------------------------------------------------------------
333 Function get_object_version_number
334 (p_attribute_id in number
335 )
336 Return number is
337 --
338 l_ovn number;
339 --
340 Begin
341 --
342 -- get the next ovn
343 --
344 select nvl(max(t.object_version_number),0) + 1
345 into l_ovn
346 from ame_attributes t
347 where t.attribute_id = p_attribute_id;
348 --
349 -- Return the new object_version_number.
350 --
351 Return(l_ovn);
352 --
353 End get_object_version_number;
354 --
355 end ame_atr_shd;