1 package body hr_dt_attribute_support as
2 /* $Header: dtattsup.pkb 120.0 2005/05/27 23:09:57 appldev noship $ */
3 -- ----------------------------------------------------------------------------
4 -- | Private Package Body Global Specifications |
5 -- ----------------------------------------------------------------------------
6 g_package varchar2(33) := ' hr_dt_attribute_support.';
7 --
8 type l_varchar32767_tab is table of varchar2(32767)
9 index by binary_integer;
10 type l_varchar30_tab is table of varchar2(30)
11 index by binary_integer;
12 type l_boolean_tab is table of boolean
13 index by binary_integer;
14 --
15 g_parameter_name l_varchar30_tab;
16 g_old_value l_varchar32767_tab; -- holds the 1st row values
17 g_new_value l_varchar32767_tab; -- holds the new datetrack values
18 g_parameter_status l_boolean_tab; -- determines the attribute status
19 g_date_format varchar2(10) := 'dd/mm/yyyy';
20 g_index binary_integer;
21 g_reset_index boolean := true;
22 -- ----------------------------------------------------------------------------
23 -- |-----------------------------< add_parameter >----------------------------|
24 -- ----------------------------------------------------------------------------
25 -- {Start Of Comments}
26 --
27 -- Description:
28 -- This private function adds the parameter and its properties to the pl/sql
29 -- data structures if the parameter is changing.
30 --
31 -- Pre-Requisities:
32 -- Should only be called for the row which is active of the effective date.
33 --
34 -- In Parameters:
35 -- p_parameter_name --> the parameter name
36 -- p_new_value --> as on the first row then specifies the new
37 -- value to be used
38 -- p_current_value --> specifies the current row value which is
39 -- as of the effective date
40 --
41 -- Post Success:
42 -- If the parameter is being modified then it is added to the internal
43 -- pl/sql table datastructures and the value returned is the new value.
44 -- if the parameter is not being modified then the fuction returns the
45 -- current value passed in.
46 --
47 -- Post Failure:
48 -- None.
49 --
50 -- Developer Implementation Notes:
51 -- None
52 --
53 -- Access Status:
54 -- Private.
55 --
56 -- {End Of Comments}
57 -- ----------------------------------------------------------------------------
58 function add_parameter
59 (p_parameter_name in varchar2
60 ,p_new_value in varchar2
61 ,p_current_value in varchar2) return varchar2 is
62 --
63 l_proc varchar2(72) := g_package||'add_parameter';
64 l_current_value varchar2(32767);
65 --
66 begin
67 hr_utility.set_location('Entering:'|| l_proc, 5);
68 -- check to see if the attribute is changing. we only add
69 -- to the pl/sql table structures when values are changing.
70 if nvl(p_new_value, hr_api.g_varchar2) =
71 nvl(p_current_value, hr_api.g_varchar2) then
72 -- the new value is the same as the current value therefore
73 -- we cannot be updating the attribute. set the return value
74 -- to the current value.
75 l_current_value := p_current_value;
76 else
77 -- determine if we have to reset the index
78 if g_reset_index then
79 g_reset_index := false;
80 g_index := 0;
81 end if;
82 -- as the attribute is changing add to the pl/sql table
83 -- structures for further comparisons at the index position
84 g_parameter_name(g_index) := p_parameter_name;
85 g_old_value(g_index) := p_current_value;
86 g_new_value(g_index) := p_new_value;
87 g_parameter_status(g_index) := true;
88 l_current_value := p_new_value;
89 -- increment the index counter
90 g_index := g_index + 1;
91 end if;
92 return(l_current_value);
93 hr_utility.set_location(' Leaving:'|| l_proc, 10);
94 end add_parameter;
95 -- ----------------------------------------------------------------------------
96 -- |-------------------------< get_parameter_index >--------------------------|
97 -- ----------------------------------------------------------------------------
98 -- {Start Of Comments}
99 --
100 -- Description:
101 -- This private function returns the index position within the pl/sql table
102 -- structures for a given parameter name.
103 --
104 -- Pre-Requisities:
105 -- None.
106 --
107 -- In Parameters:
108 -- p_parameter_name -> the parameter name
109 --
110 -- Post Success:
111 -- Index position is returned as a binary_integer.
112 --
113 -- Post Failure:
114 -- An error will be raised if the parameter name does not exist.
115 --
116 -- Developer Implementation Notes:
117 -- None
118 --
119 -- Access Status:
120 -- Private.
121 --
122 -- {End Of Comments}
123 -- ----------------------------------------------------------------------------
124 procedure is_parameter_changing
125 (p_parameter_name in varchar2
126 ,p_changing out nocopy boolean
127 ,p_index out nocopy binary_integer) is
128 --
129 l_proc varchar2(72) := g_package||'is_parameter_changing';
130 l_index binary_integer;
131 l_found_name boolean := false;
132 --
133 begin
134 --
135 hr_utility.set_location('Entering:'|| l_proc, 5);
136 -- ensure at least one element exists
137 if g_index > 0 then
138 -- determine index position of the parameter
139 for i in 0..(g_index - 1) loop
140 if g_parameter_name(i) = p_parameter_name then
141 l_found_name := true;
142 l_index := i;
143 exit;
144 end if;
145 end loop;
146 end if;
147 --
148 if l_found_name then
149 -- a parameter has been found
150 p_changing := true;
151 p_index := l_index;
152 else
153 -- parameter does not exist
154 p_changing := false;
155 p_index := null;
156 end if;
157 hr_utility.set_location(' Leaving:'|| l_proc, 10);
158 end is_parameter_changing;
159 -- ----------------------------------------------------------------------------
160 -- |------------------------< get_parameter_char >----------------------------|
161 -- ----------------------------------------------------------------------------
162 function get_parameter_char
163 (p_effective_date_row in boolean default false
164 ,p_parameter_name in varchar2
165 ,p_new_value in varchar2 default null
166 ,p_current_value in varchar2) return varchar2 is
167 --
168 l_proc varchar2(72) := g_package||'get_parameter_char';
169 l_index binary_integer := 0;
170 l_new_value varchar2(32767);
171 l_current_value varchar2(32767);
172 l_changing boolean;
173 --
174 begin
175 --
176 hr_utility.set_location('Entering:'|| l_proc, 5);
177 -- if on first row add the parameter
178 if p_effective_date_row then
179 -- determine if the user value is using a system default
180 if p_new_value = hr_api.g_varchar2 then
181 -- value is using a system default, set to the current row value
182 l_new_value := p_current_value;
183 else
184 -- value is not using a system default
185 l_new_value := p_new_value;
186 end if;
187 -- add the parameter to the pl/sql structures
188 l_current_value := add_parameter
189 (p_parameter_name => p_parameter_name
190 ,p_new_value => l_new_value
191 ,p_current_value => p_current_value);
192 else
193 -- because we are replacing current values set the reset indicator
194 -- to true
195 g_reset_index := true;
196 -- determine if the parameter is changing
197 is_parameter_changing
198 (p_parameter_name => p_parameter_name
199 ,p_changing => l_changing
200 ,p_index => l_index);
201 --
202 if l_changing then
203 if nvl(p_current_value, hr_api.g_varchar2) =
204 nvl(g_old_value(l_index), hr_api.g_varchar2) and
205 g_parameter_status(l_index) then
206 l_current_value := g_new_value(l_index);
207 else
208 g_parameter_status(l_index) := false;
209 l_current_value := p_current_value;
210 end if;
211 else
212 -- set the return value to the current value
213 l_current_value := p_current_value;
214 end if;
215 end if;
216 return(l_current_value);
217 hr_utility.set_location(' Leaving:'|| l_proc, 10);
218 end get_parameter_char;
219 -- ----------------------------------------------------------------------------
220 -- |----------------------< get_parameter_number >----------------------------|
221 -- ----------------------------------------------------------------------------
222 function get_parameter_number
223 (p_effective_date_row in boolean default false
224 ,p_parameter_name in varchar2
225 ,p_new_value in number default null
226 ,p_current_value in number) return number is
227 --
228 l_proc varchar2(72) := g_package||'get_parameter_number';
229 l_new_value number := p_new_value;
230 --
231 begin
232 --
233 hr_utility.set_location('Entering:'|| l_proc, 5);
234 --
235 if p_effective_date_row then
236 -- determine if the user value is using a system default
237 if l_new_value = hr_api.g_number then
238 -- value is using a system default, set to the current row value
239 l_new_value := p_current_value;
240 end if;
241 end if;
242 --
243 return(to_number(get_parameter_char
244 (p_effective_date_row => p_effective_date_row
245 ,p_parameter_name => p_parameter_name
246 ,p_new_value => to_char(l_new_value)
247 ,p_current_value => p_current_value)));
248 --
249 hr_utility.set_location(' Leaving:'|| l_proc, 10);
250 end get_parameter_number;
251 -- ----------------------------------------------------------------------------
252 -- |-------------------------< get_parameter_date >---------------------------|
253 -- ----------------------------------------------------------------------------
254 function get_parameter_date
255 (p_effective_date_row in boolean default false
256 ,p_parameter_name in varchar2
257 ,p_new_value in date default null
258 ,p_current_value in date) return date is
259 --
260 l_proc varchar2(72) := g_package||'get_parameter_date';
261 l_new_value date := trunc(p_new_value);
262 l_current_value varchar2(30) := to_char(trunc(p_current_value), g_date_format);
263 --
264 begin
265 --
266 hr_utility.set_location('Entering:'|| l_proc, 5);
267 --
268 if p_effective_date_row then
269 -- determine if the user value is using a system default
270 if trunc(p_new_value) = hr_api.g_date then
271 -- value is using a system default, set to the current row value
272 l_new_value := trunc(p_current_value);
273 end if;
274 end if;
275 --
276 return(to_date(get_parameter_char
277 (p_effective_date_row => p_effective_date_row
278 ,p_parameter_name => p_parameter_name
279 ,p_new_value => to_char(l_new_value, g_date_format)
280 ,p_current_value => l_current_value), g_date_format));
281 --
282 hr_utility.set_location(' Leaving:'|| l_proc, 10);
283 end get_parameter_date;
284 -- ----------------------------------------------------------------------------
285 -- |-----------------------< is_current_row_changing >------------------------|
286 -- ----------------------------------------------------------------------------
287 function is_current_row_changing return boolean is
288 --
289 l_proc varchar2(72) := g_package||'is_current_row_changing';
290 l_index binary_integer;
291 l_found boolean := false;
292 --
293 begin
294 --
295 hr_utility.set_location('Entering:'|| l_proc, 5);
296 -- only process if at least one element has been set
297 if g_index > 0 then
298 -- determine if at least one parameter change exists
299 for l_index in 0..(g_index - 1) loop
300 if g_parameter_status(l_index) then
301 l_found := true;
302 exit;
303 end if;
304 end loop;
305 end if;
306 hr_utility.set_location(' Leaving:'|| l_proc, 10);
307 return(l_found);
308 end is_current_row_changing;
309 -- ----------------------------------------------------------------------------
310 -- |---------------------< reset_parameter_statuses >-------------------------|
311 -- ----------------------------------------------------------------------------
312 procedure reset_parameter_statuses is
313 --
314 l_proc varchar2(72) := g_package||'reset_parameter_statuses';
315 l_index binary_integer;
316 --
317 begin
318 hr_utility.set_location('Entering:'|| l_proc, 5);
319 -- only process if at least one element has been set
320 if g_index > 0 then
321 for l_index in 0..(g_index - 1) loop
322 g_parameter_status(l_index) := true;
323 end loop;
324 end if;
325 hr_utility.set_location(' Leaving:'|| l_proc, 10);
326 end reset_parameter_statuses;
327 --
328 end hr_dt_attribute_support;