DBA Data[Home] [Help]

PACKAGE BODY: APPS.HR_PFT_UPD

Source


1 Package Body hr_pft_upd as
2 /* $Header: hrpftrhi.pkb 120.0 2005/05/31 02:07:40 appldev noship $ */
3 --
4 -- ----------------------------------------------------------------------------
5 -- |                     Private Global Definitions                           |
6 -- ----------------------------------------------------------------------------
7 --
8 g_package  varchar2(33) := '  hr_pft_upd.';  -- Global package name
9 --
10 -- ----------------------------------------------------------------------------
11 -- |------------------------------< update_dml >------------------------------|
12 -- ----------------------------------------------------------------------------
13 -- {Start Of Comments}
14 --
15 -- Description:
16 --   This procedure controls the actual dml update logic. The processing of
17 --   this procedure is:
18 --   1) Increment the object_version_number by 1 if the object_version_number
19 --      is defined as an attribute for this entity.
20 --   2) To set and unset the g_api_dml status as required (as we are about to
21 --      perform dml).
22 --   3) To update the specified row in the schema using the primary key in
23 --      the predicates.
24 --   4) To trap any constraint violations that may have occurred.
25 --   5) To raise any other errors.
26 --
27 -- Prerequisites:
28 --   This is an internal private procedure which must be called from the upd
29 --   procedure.
30 --
31 -- In Parameters:
32 --   A Pl/Sql record structre.
33 --
34 -- Post Success:
35 --   The specified row will be updated in the schema.
36 --
37 -- Post Failure:
38 --   On the update dml failure it is important to note that we always reset the
39 --   g_api_dml status to false.
40 --   If a check, unique or parent integrity constraint violation is raised the
41 --   constraint_error procedure will be called.
42 --   If any other error is reported, the error will be raised after the
43 --   g_api_dml status is reset.
44 --
45 -- Developer Implementation Notes:
46 --   The update 'set' attribute list should be modified if any of your
47 --   attributes are not updateable.
48 --
49 -- Access Status:
50 --   Internal Row Handler Use Only.
51 --
52 -- {End Of Comments}
53 -- ----------------------------------------------------------------------------
54 Procedure update_dml
55   (p_rec in out nocopy hr_pft_shd.g_rec_type
56   ) is
57 --
58   l_proc  varchar2(72) := g_package||'update_dml';
59 --
60 Begin
61   hr_utility.set_location('Entering:'||l_proc, 5);
62   --
63   --
64   --
65   --
66   -- Update the hr_all_positions_f_tl Row
67   --
68   update hr_all_positions_f_tl
69     set
70      position_id                     = p_rec.position_id
71     ,language                        = p_rec.language
72     ,source_lang                     = p_rec.source_lang
73     ,name                            = p_rec.name
74     where position_id = p_rec.position_id
75     and language = p_rec.language;
76   --
77   --
78   --
79   hr_utility.set_location(' Leaving:'||l_proc, 10);
80 --
81 Exception
82   When hr_api.check_integrity_violated Then
83     -- A check constraint has been violated
84     --
85     hr_pft_shd.constraint_error
86       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
87   When hr_api.parent_integrity_violated Then
88     -- Parent integrity has been violated
89     --
90     hr_pft_shd.constraint_error
91       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
92   When hr_api.unique_integrity_violated Then
93     -- Unique integrity has been violated
94     --
95     hr_pft_shd.constraint_error
96       (p_constraint_name => hr_api.strip_constraint_name(SQLERRM));
97   When Others Then
98     --
99     Raise;
100 End update_dml;
101 --
102 -- ----------------------------------------------------------------------------
103 -- |------------------------------< pre_update >------------------------------|
104 -- ----------------------------------------------------------------------------
105 -- {Start Of Comments}
106 --
107 -- Description:
108 --   This private procedure contains any processing which is required before
109 --   the update dml.
110 --
111 -- Prerequisites:
112 --   This is an internal procedure which is called from the upd procedure.
113 --
114 -- In Parameters:
115 --   A Pl/Sql record structure.
116 --
117 -- Post Success:
118 --   Processing continues.
119 --
120 -- Post Failure:
121 --   If an error has occurred, an error message and exception wil be raised
122 --   but not handled.
123 --
124 -- Developer Implementation Notes:
125 --   Any pre-processing required before the update dml is issued should be
126 --   coded within this procedure. It is important to note that any 3rd party
127 --   maintenance should be reviewed before placing in this procedure.
128 --
129 -- Access Status:
130 --   Internal Row Handler Use Only.
131 --
132 -- {End Of Comments}
133 -- ----------------------------------------------------------------------------
134 Procedure pre_update
135   (p_rec in hr_pft_shd.g_rec_type
136   ) is
137 --
138   l_proc  varchar2(72) := g_package||'pre_update';
139 --
140 Begin
141   hr_utility.set_location('Entering:'||l_proc, 5);
142   --
143   hr_utility.set_location(' Leaving:'||l_proc, 10);
144 End pre_update;
145 --
146 -- ----------------------------------------------------------------------------
147 -- |-----------------------------< post_update >------------------------------|
148 -- ----------------------------------------------------------------------------
149 -- {Start Of Comments}
150 --
151 -- Description:
152 --   This private procedure contains any processing which is required after
153 --   the update dml.
154 --
155 -- Prerequisites:
156 --   This is an internal procedure which is called from the upd procedure.
157 --
158 -- In Parameters:
159 --   A Pl/Sql record structure.
160 --
161 -- Post Success:
162 --   Processing continues.
163 --
164 -- Post Failure:
165 --   If an error has occurred, an error message and exception will be raised
166 --   but not handled.
167 --
168 -- Developer Implementation Notes:
169 --   Any post-processing required after the update dml is issued should be
170 --   coded within this procedure. It is important to note that any 3rd party
171 --   maintenance should be reviewed before placing in this procedure.
172 --
173 -- Access Status:
174 --   Internal Row Handler Use Only.
175 --
176 -- {End Of Comments}
177 -- ----------------------------------------------------------------------------
178 Procedure post_update
179   (p_rec                          in hr_pft_shd.g_rec_type
180   ) is
181 --
182   l_proc  varchar2(72) := g_package||'post_update';
183 --
184 Begin
185   hr_utility.set_location('Entering:'||l_proc, 5);
186   begin
187     --
188     hr_pft_rku.after_update
189       (p_position_id
190       => p_rec.position_id
191       ,p_language
192       => p_rec.language
193       ,p_source_lang
194       => p_rec.source_lang
195       ,p_name
196       => p_rec.name
197       ,p_source_lang_o
198       => hr_pft_shd.g_old_rec.source_lang
199       ,p_name_o
200       => hr_pft_shd.g_old_rec.name
201       );
202     --
203   exception
204     --
205     when hr_api.cannot_find_prog_unit then
206       --
207       hr_api.cannot_find_prog_unit_error
208         (p_module_name => 'HR_ALL_POSITIONS_F_TL'
209         ,p_hook_type   => 'AU');
210       --
211   end;
212   --
213   hr_utility.set_location(' Leaving:'||l_proc, 10);
214 End post_update;
215 --
216 -- ----------------------------------------------------------------------------
217 -- |-----------------------------< convert_defs >-----------------------------|
218 -- ----------------------------------------------------------------------------
219 -- {Start Of Comments}
220 --
221 -- Description:
222 --   The Convert_Defs procedure has one very important function:
223 --   It must return the record structure for the row with all system defaulted
224 --   values converted into its corresponding parameter value for update. When
225 --   we attempt to update a row through the Upd process , certain
226 --   parameters can be defaulted which enables flexibility in the calling of
227 --   the upd process (e.g. only attributes which need to be updated need to be
228 --   specified). For the upd process to determine which attributes
229 --   have NOT been specified we need to check if the parameter has a reserved
230 --   system default value. Therefore, for all parameters which have a
231 --   corresponding reserved system default mechanism specified we need to
232 --   check if a system default is being used. If a system default is being
233 --   used then we convert the defaulted value into its corresponding attribute
234 --   value held in the g_old_rec data structure.
235 --
236 -- Prerequisites:
237 --   This private function can only be called from the upd process.
238 --
239 -- In Parameters:
240 --   A Pl/Sql record structure.
241 --
242 -- Post Success:
243 --   The record structure will be returned with all system defaulted parameter
244 --   values converted into its current row attribute value.
245 --
246 -- Post Failure:
247 --   No direct error handling is required within this function. Any possible
248 --   errors within this procedure will be a PL/SQL value error due to
249 --   conversion of datatypes or data lengths.
250 --
251 -- Developer Implementation Notes:
252 --   None.
253 --
254 -- Access Status:
255 --   Internal Row Handler Use Only.
256 --
257 -- {End Of Comments}
258 -- ----------------------------------------------------------------------------
259 Procedure convert_defs
260   (p_rec in out nocopy hr_pft_shd.g_rec_type
261   ) is
262 --
263 Begin
264   --
265   -- We must now examine each argument value in the
266   -- p_rec plsql record structure
267   -- to see if a system default is being used. If a system default
268   -- is being used then we must set to the 'current' argument value.
269   --
270   If (p_rec.source_lang = hr_api.g_varchar2) then
271     p_rec.source_lang :=
272     hr_pft_shd.g_old_rec.source_lang;
273   End If;
274   If (p_rec.name = hr_api.g_varchar2) then
275     p_rec.name :=
276     hr_pft_shd.g_old_rec.name;
277   End If;
278   --
279 End convert_defs;
280 --
281 -- ----------------------------------------------------------------------------
282 -- |---------------------------------< upd >----------------------------------|
283 -- ----------------------------------------------------------------------------
284 Procedure upd
285   (p_rec                          in out nocopy hr_pft_shd.g_rec_type
286   ) is
287 --
288   l_proc  varchar2(72) := g_package||'upd';
289 --
290 Begin
291   hr_utility.set_location('Entering:'||l_proc, 5);
292   --
293   -- We must lock the row which we need to update.
294   --
295   hr_pft_shd.lck
296     (p_rec.position_id
297     ,p_rec.language
298     );
299   --
300   -- 1. During an update system defaults are used to determine if
301   --    arguments have been defaulted or not. We must therefore
302   --    derive the full record structure values to be updated.
303   --
304   -- 2. Call the supporting update validate operations.
305   --
306   convert_defs(p_rec);
307   hr_pft_bus.update_validate
308      (p_rec
309      );
310   --
311   -- Call to raise any errors on multi-message list
312   hr_multi_message.end_validation_set;
313   --
314   -- Call the supporting pre-update operation
315   --
316   hr_pft_upd.pre_update(p_rec);
317   --
318   -- Update the row.
319   --
320   hr_pft_upd.update_dml(p_rec);
321   --
322   -- Call the supporting post-update operation
323   --
324   hr_pft_upd.post_update
325      (p_rec
326      );
327   --
328   -- Call to raise any errors on multi-message list
329   hr_multi_message.end_validation_set;
330 End upd;
331 --
332 -- ----------------------------------------------------------------------------
333 -- |---------------------------------< upd >----------------------------------|
334 -- ----------------------------------------------------------------------------
335 Procedure upd
336   (p_position_id                  in     number
337   ,p_language                     in     varchar2
338   ,p_source_lang                  in     varchar2  default hr_api.g_varchar2
339   ,p_name                         in     varchar2  default hr_api.g_varchar2
340   ) is
341 --
342   l_rec   hr_pft_shd.g_rec_type;
343   l_proc  varchar2(72) := g_package||'upd';
344 --
345 Begin
346   hr_utility.set_location('Entering:'||l_proc, 5);
347   --
348   -- Call conversion function to turn arguments into the
349   -- l_rec structure.
350   --
351   l_rec :=
352   hr_pft_shd.convert_args
353   (p_position_id
354   ,p_language
355   ,p_source_lang
356   ,p_name
357   );
358   --
359   -- Having converted the arguments into the
360   -- plsql record structure we call the corresponding record
361   -- business process.
362   --
363   hr_pft_upd.upd
364      (l_rec
365      );
366   --
367   --
368   hr_utility.set_location(' Leaving:'||l_proc, 10);
369 End upd;
370 --
371 -- ----------------------------------------------------------------------------
372 -- |------------------------------< upd_key_flex_meanings >-------------------|
373 -- ----------------------------------------------------------------------------
374 --
375 Procedure upd_key_flex_meanings
376   ( p_position_id                 in number --Primary key of base table
377   , p_position_definition_id      in number
378   ) IS
379   --
380   l_current_language_code  fnd_languages.nls_language%TYPE := userenv('LANG');
381   --
382   l_pft_rec                hr_pft_shd.g_rec_type;
383 
384   --
385   --Will return a cartesian set (we want every installed/base lang)
386   cursor c_languages IS
387   select l.language_code
388        , l.nls_language
389        , pd.id_flex_num
390     from fnd_languages l
391        , per_position_definitions pd
392    where pd.position_definition_id = p_position_definition_id
393      and l.installed_flag IN ('B', 'I');
394 
395   begin
396 
397     for l_language IN c_languages LOOP
398 
399        -- Lock the existing record (which may already be updated)
400        hr_pft_shd.lck
401          ( p_position_id
402          , l_language.language_code
403          );
404 
405        --Get the local record values from the locked record
406        l_pft_rec := hr_pft_shd.g_old_rec;
407 
408        --Set the session language (this also clears the key flex cache)
409        hr_kflex_utility.set_session_nls_language(l_language.nls_language);
410 
411        --Populate the local record with translated key flex meanings
412        l_pft_rec.name := fnd_flex_ext.get_segs( 'PER'
413                                               , 'POS'
414                                               , l_language.id_flex_num
415                                               , p_position_definition_id
416                                               );
417 
418        --When generated name is null, use hr_all_positions_f.name
419        if l_pft_rec.name is null then
420          begin
421            select psf.name into  l_pft_rec.name
422            from hr_all_positions_f psf
423            where psf.position_id = p_position_id
424            and psf.effective_end_date = hr_general.end_of_time;
425          exception
426            when others then
427              null;
428          end;
429        end if;
430 
431        --Update the record
432        update_dml(l_pft_rec);
433 
434     end loop;
435 
436     -- Set the session language back to original (this also clears the key flex cache)
437     hr_kflex_utility.set_session_language_code(l_current_language_code);
438   exception
439     when others then
440       if ( l_current_language_code IS NOT NULL ) then
441         hr_kflex_utility.set_session_language_code(l_current_language_code);
442       end if;
443     raise;
444   end;
445 --
446 -- ----------------------------------------------------------------------------
447 -- |------------------------------< upd_tl >----------------------------------|
448 -- ----------------------------------------------------------------------------
449 Procedure upd_tl
450   (p_language_code                 in varchar2
451   ,p_position_id                  in number
452   ,p_position_definition_id       in number
453   ) is
454   --
455   -- Cursor to obtain the translation rows where the language or
456   -- source_lang match the specified language.
457   --
458   cursor csr_upd_langs is
459     select pft.language
460       from hr_all_positions_f_tl pft
461      where pft.position_id = p_position_id
462        and p_language_code in (pft.language
463                               ,pft.source_lang);
464   --
465   l_proc  varchar2(72) := g_package||'upd_tl';
466   --
467 Begin
468   hr_utility.set_location('Entering:'||l_proc,10);
469   --
470   -- Update the translated values for every matching row
471   -- setting SOURCE_LANG to the specified language.
472   --
473   -- PMFLETCH Only need to do this update if there are additional
474   -- translated columns (i.e. more than just the key flex values)
475   --for l_lang in csr_upd_langs loop
476   --  hr_pft_upd.upd
477   --    (p_position_id                 => p_position_id
478   --    ,p_language                    => l_lang.language
479   --    ,p_source_lang                 => p_language_code
480   --    ,p_name                        => p_name
481   --    );
482   --end loop;
483   --
484   -- PMFLETCH Update the key flex meanings
485   upd_key_flex_meanings( p_position_id
486                        , p_position_definition_id
487                        );
488   --
489   hr_utility.set_location(' Leaving:'||l_proc,20);
490 End upd_tl;
491 --
492 end hr_pft_upd;