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