DBA Data[Home] [Help]

PACKAGE BODY: APPS.HRDYNDBI

Source


1 package body hrdyndbi as
2 /* $Header: pydyndbi.pkb 120.27.12010000.2 2008/08/06 07:08:23 ubhat ship $ */
3 --
4 /*
5 --
6 -- Copyright (c) Oracle Corporation 1991,1992,1993. All rights reserved
7 /*
8 PRODUCT
9     Oracle*Payroll
10 --
11 NAME
12     pydyndbi.pkb  - procedures for creating/ deleting DYNamic DataBase Items.
13 --
14 DESCRIPTION
15     This package contains a collection of routines for generating and
16     deleting dynamic database item.  The routes must already be in the
17     database for these routines to work.
18     The following database items are created/ deleted using procedures in
19     this file:
20     balances
21     element types
22     input values
23     grade rates
24     descriptive flexs
25     key flexs
26     absence types
27 NOTES
28     User Defined Data:
29     -----------------
30     User defined data may either be owned by a          ---------------------
31     business group OR by a legislation. Since           | User Defined Data |
32     a business group belongs to a legislation,          ---------------------
33     the legislation code for data that has a                Y         Y
34     business group id may always be derived.                |         |
35                                                          \  |         |   /
36                                                           \ |         |  /
37     The effect on the entity horizon is that               \------------/
38     either the legislation code OR the                      |         |
39     business group id may be specified.  The           ------------   |
40     columns on the table ff_user_entities should       | Business |   |
41     not BOTH be populated.                             |  group   |   |
42                                                        ------------   |
43     The allowed combinations for these 2 columns            Y         |
44     are shown in the table below.  This is now the          |         |
45     same model for Payroll and Formula.                     |         |
46                                                             |         |
47                                                           ---------------
48                                                           | Legislation |
49                                                           ---------------
50     --
51       --------------------------------------------------------------------
52       |                              Legislation            Business     |
53       |                                 Code                Group id     |
54       |                                                                  |
55       | Generic Startup Data     :      null                  null       |
56       |                                                                  |
57       | Legislation Specific     :    not null                null       |
58       | Startup Data                                                     |
59       |                                                                  |
60       | User Defined Data        :      null                not null     |
61       |                                                                  |
62       --------------------------------------------------------------------
63     --
64     (Previously Formula used the same model, EXCEPT that User Defined Data had
65      both columns as not null).
66     --
67     --
68     Creating DB Items:
69     -----------------
70     The main procedures that create/ delete database items are named xxx_dict.
71     These procedures share some general purpose routines to simplify the
72     process of creating DB items.  These procedures are called:
73     --
74     insert_user_entity
75     insert_parameter_value
76     insert_database_item
77     --
78     Since they are declared in the package header, other routines that may
79     be written in the future to generate DB items may also reference them.
80     Each of the database creation procedures follow a similar layout:
81     --
82     The procedure (xxx_dict) is called with the relevent parameters (for
83     example the procedure to generate Element DB items is passed an element
84     type id and an effective date).  The procedure may then retrieve further
85     information from the database.  Then the entity is created with a call
86     to: 'insert_user_entity'.  This defines what route the database items will
87     be attached to.  If the route uses any where clause fillers (written as
88     (Ux in the route) then the procedure 'insert_parameter_value' is called
89     next.  (If the route does not use any where clause fillers, this call is
90     omitted).  Finally the procedure calls 'insert_database_item' for every
91     datbase item that is to be attached to the entity (and hence the route).
92     When several database items are to be created each with a different route,
93     then the main procedure (xxx_dict) calls the 3 routines in order, ie:
94     --
95     procedure xxx_dict (..)   -- create some DB items
96     begin
97       -- get some information from the database
98       insert_user_entity (..);
99       insert_parameter_value (..);    -- if the route uses where clause fillers
100       --
101       -- now create all the DB items for the above entity (and hence route)
102       --
103       insert_database_item (..);
104       insert_database_item (..);
105       insert_database_item (..);
106       --
107       -- another route is required, so declare a new user entity:
108       --
109       insert_user_entity (..);
110       insert_parameter_value (..);
111       --
112       -- now create all the DB items for the above entity (and hence route)
113       --
114       insert_database_item (..);
115       insert_database_item (..);
116       insert_database_item (..);
117     end;
118     --
119     Refer to the procedure headers for more information on each procedure.
120 --
121    Name   Ver    DD-MON-YYYY BugNo. and text
122    -----------------------------------------
123    ckesanap 115.148 25-Apr-2008    Bug 6955080. In delete_keyflex_dict, chaged the
124                                    where condition clause for deleting the
125 				   existing user_entity from ff_user_entities.
126    ckesanap 115.147 07-Aug-2007    Bug 5930272. Added fnd_message.retrieve() in
127                                    insert_user_entity_main() to clear the message
128 				   in the FND message queue as the error raised
129 				   in checkformat() is being handled.
130    ckesanap 115.146 18-Jul-2007    Bug 6215173. Passed null for l_legislation_code
131                                    parameter to create_key_flex() in
132 				   create_keyflex_dict() procedure.
133    divicker 115.145 22-MAY-2007    Merge exists for check_for_(tl)_dbi_clash
134    divicker 115.144 16-MAY-2007    Optimizer hints added for procedures
135                                    check_for_(tl)_dbi_clash
136    arashid  115.143 24-NOV-2006    Make dbi2ueid error message give out
137                                    more information. Also, catch
138                                    exceptions from update_xxx calls
139                                    in pay_process_dyndbi_changes and
140                                    log the errors.
141                                    Set the g_security_group_id for the
142                                    NAME_TRANSLATIONS lookup in
143                                    pay_process_dyndbi_changes, otherwise
144                                    the meaning is not translated.
145                                    Only delete PAY_DYNDBI_CHANGES row if
146                                    no errors occurred.
147    arashid  115.142 10-NOV-2006    Bug5464970 fix for changed
148                                    pay_dbitl_update_errors_pkg.fetch_all_rows
149                                    interface. Also, use dbms_sql.varchar_table
150                                    in process_leg_translations.
151    arashid  115.141 22-SEP-2006    Bug 5556728: in the MLS dbi case,
152                                    'Pay Value' was passed into
153                                    replace_code_name so the replacement was
154                                    not taking place.
155    divicker 115.140 01-JUN-2006    11511 branch merge
156    arashid  115.139 11-MAY-2006    Add code for running legislation-specific
157                                    database item translation from
158                                    process_pay_dyndbi_changes.
159    arashid  115.138 09-MAY-2006    Don't disable ff_user_entities delete
160                                    triggers as thay are required to delete
161                                    ff_database_items_tl rows (other child
162                                    rows are cascade deleted).
163    arashid  115.137 05-MAY-2006    Use substr to restrict names to 80
164                                    characters in routines that generate base
165                                    dbi names  - this is to match the main
166                                    dynamic dbi name generation code. The
167                                    changes are in:
168                                    GEN_ET_BASE_DBI_NAME
169                                    GEN_DB_BASE_DBI_NAME
170                                    GEN_EIV_BASE_DBI_NAME
171    arashid  115.136 04-MAY-2006    Fixed infinitely looping code for
172                                    translating DATE_PAID and non-DATE_PAID
173                                    ELEMENT TYPE / INPUT VALUE database items.
174                                    Put debug into PROCESS_PAY_DYNDBI_CHANGES,
175                                    and tidied up the update error logging
176                                    code therein.
177    arashid  115.135 27-APR-2006    The following changes were made:
178                                    - process date-paid and non-date-paid
179                                      database items when updating _TL names.
180                                    - process_pay_dyndbi_changes code now calls
181                                      FF_DATABASE_ITEMS_PKG.UPDATE_SEEDED_TL_ROWS
182                                      and writes messages to the concurrent
183                                      processing log file.
184    arashid  115.134 31-MAR-2006    Changed  process_pay_dyndbi_changes to not
185                                    raise assertions when entities are missing.
186                                    Instead, the condition is traced and the
187                                    PAY_DYNDBI_CHANGES row deleted.
188    arashid  115.133 27-JAN-2006    Changed  process_pay_dyndbi_changes to a
189                                    concurrent processing interface with VARCHAR2
190                                    parameters.
191    arashid  115.132 11-NOV-2005    Fixed bug in new_defined_balance whereby
192                                    p_defined_balance_id was being passed
193                                    as p_balance_type_id in GEN_DB_TL_DBI_NAME.
194    arashid  115.131 01-NOV-2005    Made process_pay_dyndbi_changes multi-threaded.
195    arashid  115.130 31-OCT-2005    Changed PROCESS_PAY_DYNDBI_CHANGES to COMMIT
196                                    every 50 rows.
197    arashid  115.129 19-OCT-2005    Added support for fully translated dynamic
198                                    database items.
199                                    1. Added internal insert_database_item
200                                       interface with extra parameters to
201                                       help with fully translated database
202                                       items.
203                                    2. Tightened up validation for 'SEED'
204                                       condition to check against business
205                                       groups with the same legislation code.
206                                    3. Extracted code into functions for reuse:
207                                       check_for_dbi_clash
208                                       replace_code_name
209                                       uom_requires_dbis
210                                    4. Changed insert_database_item to handle
211                                       full MLS and pseudo-MLS as separate
212                                       cases. For full MLS, only a single
213                                       base DBI in ff_database_items is
214                                       generated.
215                                    5. Changed code for generating element,
216                                       input, and defined balance DBIs to
217                                       handle full MLS where it is supported.
218                                    6. Added update_xxx calls for MLS updates
219                                       to FF_DATABASE_ITEMS_TL.
220                                    Updates to FP.K and earlier should be
221                                    branched on 115.28.
222    alogue   115.128 07-OCT-2005    Performance fix to sel_ffci in
223                                    create_alternative_dbis. Bug 4658377.
224    nbristow 115.126 01-AUG-2005    Added support for OTL balances.
225    divicker 115.125 27-JUL-2005    add sleep for all workers bar first when
226                                    altering trigger states to prevent ora 4061
227    divicker 115.124 27-JUN-2005    add delimiting quotes to a text type
228                                    route parameter value 4431372
229    divicker 115.123 23-JUN-2005    hint update
230    divicker 115.122 22-JUN-2005    Add ordered hints for 2 stmts that speed up
231                                    fresh installs of hrglobal
232    divicker 115.121 09-JUN-2005    4363933 Add sleep to prevent too many
233                                    executions of worker complete loop
234    arashid  115.120 25-MAY-2005    4387272
235                                    Fixed FF_COMPILED_INFO_F delete code so
236                                    that all the affected FF_COMPILED_INFO_F
237                                    rows are deleted. The changes are made
238                                    for the partial delete cases:
239                                    delete_compiled_formula
240                                    delete_compiled_formula_priv
241                                    legislative rebuild_ele_input_bal
242    divicker 115.119 17-MAY-2005    Pre delete formula usages compiled info
243                                    by legislation or all if core
244    divicker 115.118 13-MAY-2005    Add commit points per 100 rows
245                                    Trace the worker for each main loop
246    divicker 115.117 12-MAY-2005    Regress back to fail and quit mode
247    divicker 115.116 11-MAY-2005    Fix duplicate RB user entity creation
248    divicker 115.115 05-MAY-2005    Add name delete for RB ue as well
249    divicker 115.114 21-APR-2005    add hint to del_comp_form_priv cursor
250    divicker 115.113 21-APR-2005    make internal calls to del_comp_form
251                                    call a more performant del_comp_form_priv
252                                    version instead when we can guarantee internal
253                                    calls will have a non-null creator id so we
254                                    can exploit the index by removing the nvl
255    divicker 115.112 20-APR-2005    fix issue with RB only def bal creation
256    divicker 115.111 31-MAR-2005    refresh def bal cursor addition and
257                                    and get_alt_route addition for 4273939
258    divicker 115.110 29-MAR-2005    fix to delete_compiled_formula when passed
259                                    leg_code is null even though formulae
260                                    may not be null 4262658
261    divicker 115.109 10-MAR-2005    fix an incorrect trace stmt
262    divicker 115.108 10-MAR-2005    dont eenable triggers in exception blk of
263                                    reib in order to avoid red herring mutation
264                                    erros in other drivers. instead do it in
265                                    hrrbdeib caller. Do it at beginning so both
266                                    are initially enabled if calling reib
267                                    manually
268    divicker 115.107 24-FEB-2005    comment change
269    divicker 115.106 23-FEB-2005    trace each main ID being processed
270                                    allows for much faster tracing
271                                    format is:
272                                    RDB:B,RB:leg_code.bg.defbalid,baldimid,baltype,srunbal
273                                    RELE:element_type_id.date
274                                    RELI:input_value_id.date
275                                    To rerun hrrbdeib for just one piece of data call the following
276                                    call disable trigger procs
277                                    set boolean hrdyndbi.g_triggers_altered true
278                                    for RDB: hrdyndbi.refresh_defined_balances(defbalid, 1);
279                                    for RELE: hrdyndbi.create_element_type_dict(element_type_id,dt);
280                                    for RELI: hrdyndbi.create_input_value_dict(input_value_id,dt);
281                                    <dt is to_date(<date>,'DD-MM-YYYY')> or null
282    divicker 115.105 23-FEB-2005    deliver better restricted tracing data
283    divicker 115.104 17-FEB-2005    mod to dcf
284    divicker 115.103 15-FEB-2005    decompile formula on leg code
285    divicker 115.102 10-FEB-2005    Add applied date to see when each worker is
286                                    started
287    divicker 115.101 09-FEB-2005    mthread fix
288    divicker 115.100 01-FEB-2005    Add proc reib_all
289    divicker 115.99 28-JAN-2005     form id pick fix and perf improvements
290    divicker 115.98 26-JAN-2005     del_comp_form E takes null leg_code not %
291                                    use l_entity_name in del_c_f KF
292    divicker 115.97 24-JAN-2005     Put back mod for refresh_element_types
293    divicker 115.96 21-JAN-2005     Be more selective on the formulae to
294                                    uncompile so FFXBPC can run faster
295    divicker 115.95 21-JAN-2005     Remove sho err
296    divicker 115.94 19-JAN-2005     Performance improvements
297    divicker 115.93 18-NOV-2004     Multithread
298    alogue   115.92 28-JUL-2004     Ensure quoted dbitems front last change
299                                    do not exceed 80 characters.  Bug 3797888.
300    alogue   115.88 06-JUL-2004     Quote dbitem names that would have failed
301                                    with illegal characters. Bug 3723715.
302    divicker 115.87 24-JUN-2004     More mods to debug for insert route param
303    divicker 115.86 12-MAY-2004     Fix for 8i
304    divicker 115.84 06-MAY-2004     More debug info for input value
305    divicker 115.83                 Add a load of additional debug info.
306                                    PYUPIP apps/apps HRDYNDBI
307    divicker 115.81 09-DEC-2003     No multi-thread
308                                    Merge changes in 115.79
309                                    Merge changes in 115.80
310    divicker 115.76 24-SEP-2003     Same as 115.74 (back out mthread routines)
311    alogue   115.74 31-JUL-2003     Bug 3073514. Replace hyphens with underscores
312                                    from flex segment names before creating
313                                    their dbitems.  Change to dflex_c2.
314    alogue   115.73 28-MAY-2003     Bug 2977644. Fix delete_compiled_formula
315                                    to correctlt delete formula.
316    alogue   115.72 02-MAY-2003     Bug 2936561. Remove full stops from input
317                                    value names before ue and dbi creation.
318                                    GUI should have avoided full stops being in
319                                    input value names, but transpires accrual
320                                    code creates elements and input values
321                                    without running checkformat check. This is
322                                    really a workaround to that issue.
323    alogue   115.71 02-MAY-2003     Bug 2936750. Remove full stops from flex
324                                    segment names before creating their dbitems.
325                                    Change to dflex_c2;
326    scchakra 115.70 30-APR-2003     Created procedure recreate_defined_balance.
327                                    Bug - 2450195.
328    alogue   115.69 28-MAR-2003     Bug 2865665. Change behaviour for
329                                    so always set to Y if on db less than 9i.
330    divicker 115.68 17-MAR-2003     Modify leg code specific version of
331                                    refresh_element_types to only pick up
332                                    IVs that are deemed for dbi generation
333    alogue   115.67 10-MAR-2003     Bug 2836076. Change LOW_VOLUME behaviour
334                                    so defaults to TRUE for dbs earlier
335                                    than 9i.
336    alogue   115.66 06-MAR-2003     Bug 2835806. Fix to legislative
337                                    rebuild_ele_input_bal to ensure only
338                                    Balance user entities get deleted.
339    scchakra 115.65 20-FEB-2003     Bug 2813405. Removed code to raise error
340                                    PAY_34166_DF_DBI_MULTI_OCCUR from procedures
341 				   create_dev_desc_flex_dict and
342 				   get_legislation_code.
343    scchakra 115.64 11-FEB-2003     Bug 2637573. Modified
344                                    create_dev_desc_flex_dict to create DB items
345                                    for routes defined in table
346                                    pay_route_to_descr_flexs. Created a new
347                                    function get_legislation_code.
348    divicker 115.63 03-FEB-2003     bugfix 2782128
349    divicker 115.62 31-JAN-2003     Ensure BG items related to legcode are also picked
350                                    up for processing in legislative striping mode
351    alogue   115.61 18-DEC-2002     NOCOPY changes. Bug 2692195.
352                                    Support of Competencies dbitem creation in
353                                    create_keyflex_dict.
354    alogue   115.60 15-NOV-2002     Changed balance dbitem definition strategy so
355                                    now only use RULE hint when LOW_VOLUME
356                                    pay_action_parameter is set to Y.  Thus default
357                                    behaviour is now that balances won't have this hint.
358    RThirlby 115.59 15-OCT-2002     Changed new_defined_balance to default the
359                                    save_run_balance flag is it is not alreaady
360                                    set, and if a default is available.
361    nbristow 115.58 03-OCT-2002     Changed new_defined_balance to allow calls to
362                                    get_value.
363    mkandasa 115.57 03-OCT-2002     Removed the error which is raised if p_record_inserted
364                                    returns false in insert_user_entity.
365    mkandasa 115.56 01-OCT-2002     Substr'd user entity name to 80 chars.Raised
366                                    Error in case of duplication of user entity name.
367                                    Bug no 2073022.
368    divicker 115.55 24-SEP-2002     H_ instead of H_DEC
369    divicker 115.54 20-SEP-2002     Slight fix to change in 115.53
370    divicker 115.53 19-SEP-2002     Change UOM H_ support to use H_DEC%. Tidy up of string
371    alogue   115.51 11-SEP-2002     Remove full stops from potential dbitems. Bug 2557062.
372    alogue   115.50 22-AUG-2002     Remove brackets from potential dbitems. Bug 2377726.
373    divicker 115.49 29-JUL-2002     Leg code striping for formula
374    mreid    115.48 18-JUL-2002     Modify creation of rpv for Entry DDF
375    alogue   115.47 16-JUL-2002     Handle user entities owned by old
376                                    values of SCL legislation rule
377                                    in create_scl_flex_dict.
378    divicker 115.46 26-JUN-2002     Added call in create_desc_flex_main to
379                                    insert rpv for ENTRY_DESC_FLEX_ROUTE
380    divicker 115.45 17-JUN-2002     Added back H_% UOM support
381                                    Added route parameter for ENTRY_DESC_FLEX
382                                    route
383    mreid    115.44 11-JUN-2002     Added support for Entry DDF
384    divicker 115.43 22-MAY-2002     Back out 115.41 change until July MP
385    rthirlby 115.42 13-MAY-2002     Corrected delete of SRB user entities to
386                                    delete of RB user entities.
387    divicker 115.41 01-MAY-2002     Added H_% UOM to generate fffunc.cn calls
388    rthirlby 115.40 01-MAR-2002     Added procedure create_alternative_dbis, to
389                                    create user entites for run balances. NB, no
390                                    dbi is created, to avoid the possibility of
391                                    people using the wrong dbi in formulas.
392                                    Added delete of SRB balances to rebuild_ele_
393                                    input_bal procedure.
394    alogue          08-MAR-2001     Fix insert_database_item when passed in
395                                    user_entity_id.
396    alogue           12-DEC-2000    Suport of creation of dbitems in
397                                    create_dev_desc_flex_dict for Extra Location Info
398                                    DDF, Extra Position Info DDF and Extra Person Info
399                                    DDF.
400    alogue           23-NOV-2000    Always RULE hint for balace dbitems. Bug 1513266.
401    divicker 115.35  30-OCT-2000    trigger enabled check for new_defined_balance
402                                    procedure added.
403    divicker 115.34  30-OCT-2000    Exception handler for reenabling triggers.
404                                    Check on derived codename value and whether triggers
405                                    are disabled or not, keeping original logic if
406                                    insert_database_item, insert_user_entity not called
407                                    via rebuild_ele_input_bal.
408    jarthurt 115.33  28-OCT-2000    Remove enabling and disabling of triggers in
409                                    rebuild_ele_input_bal. These are being transfered
410                                    to hrrbdeib.sql.
411    divicker         04-OCT-2000    Perf. enhancements to rebuild_ele_input_bal
412    alogue           07-AUG-2000    Fix to bug fix 1271588.
413    alogue           28-JUN-2000    Support of BALANCE_DBITEM_TYPE for flexible
414                                    balance dbitem definition text approach.
415                                    Includes Rule Hint.
416    alogue           20-APR-2000    Fix issue in descriptive flex dflex_c1 cursor
417                                    to handle titles that have been passed that
418                                    contain full-stops.  Bug 1271588.
419    alogue           16-MAR-2000    Fix issue in insert_database_item to handle
420                                    NAME_TRANSLATIONS lokkup meanings that
421                                    contain apostrophes.  Bug 1210117.
422    tbattoo          24-FEB-2000    Bug 1207273, if a user entity alredy exists when
423                                    you insert the db item use the id for the
424                                    existing entity and not the currval in the seq
425    alogue           22-FEB-2000    Translated Pay Value Database Item issue.
426                                    Bug 1110849.
427    alogue           14-FEB-2000    Utf8 support.
428    alogue           28-JAN-2000    Performance fix to create_element_type.
429    alogue           10-NOV-1999    Fix issue in descriptive flex dflex_c1 cursor
430                                    to handle titles that have been passed that
431                                    contain apostrophes.  Bug 1061472.
432    jmoyano          03-NOV-1999    generator for Payroll DDF added to procedure
433                                    create_dev_desc_flex_dict.
434    alogue           02-NOV-1999    Fix issue in delete_flexfield_dict to handle
435                                    titles that have been passed that contain
436                                    apostrophes. Bug 1058676.
437    alogue           05-OCT-1999    Fix issue in create_input_value to handle
438                                    scenario where some user entities already exist,
439                                    but others don't. Bug 1018544.
440    alogue           23-SEP-1999    Support application_ids for SSP (804),
441                                    OAD (805), HXT (808), Federal HR (8301).
442    alogue           22-SEP-1999    Change to reflect desc flex titles now being
443                                    stripped of apostrophes prior to being passed
444                                    in.
445    kkawol           14-SEP-1999    Changed create_input_value, now checking date
446                                    UOM is set to 'D' instead of 'D_%'.
447    alogue           04-AUG-1999    Canoncial Number fix for absence dbitems.
448    alogue           01-JUL-1999    Fix to exc_acc and scl dbitem creations so
449                                    that now process several legislations using
450                                    the same passed in flexfield.
451    alogue           09-JUN-1999    Now handles descriptive flexfields titles
452                                    that contain apostrophes ie Add'l Org Unit Details.
453                                    Bug 874129.
454    alogue           24-MAY-1999    Support for Cananda in creation of Org
455                                    dev flex dbis.
456    alogue           27-APR-1999    Change in create_input_value support
457                                    of canonical numbers.
458    alogue           26-APR-1999    Fixes in create_input_value to support
459                                    canonical dates and canonical numbers.
460    alogue           09-APR-1999    Change in new_defined_balance to support
461                                    canonical numbers in balances database items.
462    cborrett         04-DEC-1998    Added generation of context sensitive
463                                    dbitems in procedure CREATE_FLEXFIELD_DICT().
464                                    Replaced hardcoded routes in CREATE_FLEXFIELD_DICT()
465                                    with cursor against new table pay_route_to_descr_flexs.
466    alogue           08-JAN-1999    Change in create_desc_flex to create
467                                    CURRENCY_CODE dbitem for  Org Pay Method
468                                    descriptive flex.
469    arundell         06-JAN-1999    Changes in insert_database_item to support
470                                    MLS.
471    alogue           02-DEC-1998    Removed application_id check on hr_lookups
472                                    within insert_database_item.
473    alogue           05-OCT-1998    Fix insert_user_entity check of whether entity
474                                    exists to also check it is in current bus grp
475                                    or legislation.
476    alogue           09-MAR-1998    Creation of overloading of insert_user_entity
477                                    so 'old' style call is supported ie called
478                                    without p_record_inserted out parameter
479                                    added by 13-JAN-1998 change.
480    mfender          10-FEB-1998    Bug 610203 - removed count(*) from
481                                    insert_database_item.
482    amills   110.11  23-JAN-1998    Bug 523343. Changed insert_database_item procedure.
483                                    Added cursor get_codename which takes the
484                                    parameter item name and splits into constituent
485                                    items where necessary for matching onto hr_lookups,
486                                    so that translation of each part can be effective.
487                                    After retrieving the translatable 'meaning',
488                                    the constituent parts are then concatenated back
489                                    to form a fully translated db item.
490     amyers          13-JAN-1998    Amended procedure insert_user_entitiy to:
491                                    i.  only insert data if it doesn't exist,
492                                    ii. return a value in a new parameter indicating
493                                        whether the insert has happened to determine
494                                        the creation of underlying parameter values
495                                        and database items.
496                                    This change comes from bug 602851, where in an
497                                    R11 upgrade database items and entities were not
498                                    created and formulae would then not compile, so
499                                    in driver hr11gn.drv we need to run procedure
500                                    refresh_grade_spine_rates to ensure this doesn't
501                                    happen.
502                                    New version is 110.10.
503     amills          24-DEC-1997    Added rtrim to same select to remove full stop,
504                                    a temporary workaround for bug 603256 to
505                                    ensure no reserved words or characters are in desc
506                                    flex creation.
507     amills          09-DEC-1997    changed l_title to select from fnd_descriptive_
508                                    flexs_vl rather than take a hardcoded value
509                                    in create_org_pay_flex_dict
510     alogue          28-OCT-1997    legislation_code used in delete from ff_user_entities
511                                    in delete_keyflex_dict. Fix to bug 513364.
512     mreid           24-SEP-1997    Changed table_names for release 11 security.
513     dsaxby          15-SEP-1997    Changed substr to substrb to avoid problems with
514                                    generating NLS database items.
515     alogue          13-AUG-1997    Business_group_id passed to delete_keyflex_dict
516                                    to fix bug 513364.
517     nbristow        25-JUL-1997    Changed all references of fn_descriptive_flexs
518                                    to fnd_descriptive_flexs_vl.
519     mwcallag        26-APR-1995    Entity name passed to delete_keyflex_dict to
520                                    fix bug 278064.
521     rfine           24-NOV-1994    Suppressed index on business_group_id
522     mwcallag        13-OCT-1994    Route PAYROLL_ACTION_FLEXFIELD_ROUTE deleted.
523     rfine           05-OCT-1994    Changed call to renamed package: was us_contr_dbi,
524                                    now pay_us_contr_dbi.
525     mwcallag        28-JUL-1994    Optional commit points added to procedure
526                                    rebuild_ele_input_bal.
527     mwcallag        20-JUL-1994    It has been decided to convert the formula model
528                                    to the payroll model for User Defined Data,
529                                    thereby being consistent for Payroll and Formula.
530                                    This means that for User Defined Data only the
531                                    business group id should be populated on
532                                    ff_user_entities, not legislation code as well.
533                                    (previously both columns were populated).  Refer
534                                    to the Notes above for more information. The
535                                    change dated 15-JUL-1994 is undone.
536     mwcallag        15-JUL-1994    procedure 'new_defined_balance' altered to
537                                    populate leg_code in ff_user_entity if the
538                                    business group id is null. (ie. payroll to
539                                    Formula startup data interface). <- temp. change.
540     mwcallag        13-JUN-1994    G916 Procedure 'rebuild_ele_input_bal' added.
541     mwcallag        07-JUN-1994    G890 Entity name for DF Element Type corrected.
542     mwcallag        06-JUN-1994    G867 The user entity id is no longer appended to
543                                    the user entity name when the entity is created.
544                                    This eases the startup delivery for DB items.
545     mwcallag        25-MAY-1994    G795 The new where clause filler of element type
546                                    id was missing from the input value route
547                                    'INPUT_VALUE_ENTRY_LEVEL'  for multiple
548                                    entries allowed input values.
549     mwcallag        29-APR-1994    Element type id context added for the route:
550                                    INPUT_VALUE_ENTRY_LEVEL to improve performance.
551     mwcallag        28-FEB-1994    Database names changed from '%ASS_%' to '%ASG_%'.
552     mwcallag        20-JAN-1994    Legislation code passed to delete_keyflex_dict,
553                                    procedure delete_compiled_formula added (G516).
554     mwcallag        11-JAN-1994    The title of the Element DF changed from 'Element
555                                    Developer DF' to 'Further Element Information'.
556     mwcallag        09-DEC-1993    G334 For element or input values DB items, if the
557                                    legislation code is null on the base table it
558                                    is derived from per_business_groups.
559     mwcallag        08-DEC-1993    G323 Context name is now used in the entity name
560                                    (together with the title) for all descriptive
561                                    flex DB items.
562     mwcallag        07-DEC-1993    G291 Change to Legal Company DB items.
563     mwcallag        30-NOV-1993    G259 procedure insert_parameter_value corrected to
564                                    properly handle multiple where clause fillers.
565     mwcallag        29-NOV-1993    G221 Improved handling for long database item
566                                    names.
567     mwcallag        23-NOV-1993    G161 Simplified the calls to generate DB items for
568                                    external use.  Element DDF DB item now gets the
569                                    legislation code from per_business_groups if the
570                                    legislation code is null and business_group_id
571                                    is present on the element type table.  (The
572                                    legislation code concatenated with the element
573                                    classification is used as the context code in the
574                                    AOL descriptive flex tables).
575     mwcallag        03-NOV-1993    Assignment Developer Descriptive flex DB items
576                                    added.
577     mwcallag        02-NOV-1993    ********************************
578                                    * DIVERGENCE FROM FROZEN CODE  *
579                                    ********************************
580                                    Input Value DB item creation now tests the
581                                    multiple entries allowed flag, rather than the
582                                    recurring flag.  Developer descriptive flex
583                                    DB items for elements and jobs added.
584                                    Benefit classification DB items added.
585     mwcallag        26-OCT-1993    Sum function in definition text for non-recurring
586                                    input values moved to outer parenthesis to stop
587                                    sql retrival error.
588     mwcallag        28-SEP-1993    pay_name_translations reference replaced with
589                                    hr_lookups in insert_database_item procedure,
590                                    also passed parameter of legislation code removed
591                                    since it is no longer used.
592     abraae          09-SEP-1993    strip blanks from DB Item defn text to fit into
593                                    ff_database_items.definition_text (char(240))
594     mwcallag        08-SEP-1993    Input value definition text modified to include a
595                                    decode on the UOM to avoid problem in formula when
596                                    several DB items of different user definable
597                                    data types are retrieved in 1 formula cursor.
598     mwcallag        01-SEP-1993    Procedure for converting element DB items from the
599                                    context of date earned to date paid added. Enable
600                                    checks added to cursors in SCL and descriptive
601                                    flex routines.
602     mwcallag        23-AUG-1993    More DB items for Descriptive flexfields added,
603                                    plus Organization payment methods, external
604                                    accounts and legal company SCL DB items.
605     mwcallag        03-AUG-1993    Developer Descriptive flexfield and SCL flexfield
606                                    procedures added.
607     mwcallag        27-JUL-1993    Passed parameter name to Key flexfield DB items
608                                    now use the short names of GRP, GRD, POS JOB.
609     mwcallag        20-JUL-1993    Not found flags set to yes, this stops quickpaint
610                                    error on an assignment with minimal information.
611                                    Dummy group function added to recurring input
612                                    values to stop formula error (see input value
613                                    code below for more information).
614     mwcallag        18-JUN-1993    Descriptive and key flex deletion routines now
615                                    delete compilied DB items from ff_fdi_usages_f
616     mwcallag        14-JUN-1993    Application id removed from both
617                                    delete_flexfield_dict and create_flexfield_dict
618     mwcallag        03-JUN-1993    Create descriptive and key flexfield routines
619                                    delete old flexfields before creation attempted.
620     mwcallag        26-MAY-1993    Creator types changed to reflect database change.
621     mwcallag        24-MAY-1993    'rate_type' DB item removed from grade rate
622                                    creation. (Bug 160305 rejected for rel. 10).
623     mwcallag        07-MAY-1993    Spine DB creation added to grade procedure.
624                                    DB creation procedure for key flexfield.
625     mwcallag        30-APR-1993    Grade rates extended, descriptive flexs and
626                                    absence types added.
627     mwcallag        26-APR-1993    Procedures for input values, element types
628                                    and grade rate database items added.
629     Abraae          06-APR-1993    Created.
630 */
631 --
632 -- Translations Data Structures
633 --
634 type r_dbi_prefix is record
635 (language varchar2(30)
636 ,found    boolean
637 ,prefix   varchar2(240)
638 );
639 
640 type t_dbi_prefixes is table of r_dbi_prefix index by binary_integer;
641 --
642 -- Flags for PROCESS_PAY_DYNDBI_CHANGES procedure.
643 --
644 g_dyndbi_changes boolean := false;
645 g_dyndbi_changes_ok boolean;
646 --
647 -- Cursors for descriptive flexs, used by more than one procedure:
648 --
649 -- declare cursor 1 for retrieving the context level of the descriptive flex:
650 --
651 cursor dflex_c1 (p_table_name   varchar2,
652                  p_title        varchar2,
653                  p_global_flag  varchar2,
654                  p_context      varchar2) is
655 SELECT DFC.descriptive_flexfield_name c_flex_name,
656        replace (replace (replace (ltrim(rtrim(upper(DF.title))),
657                                  ' ','_'),'''',''),'.','_') c_title,
658        DFC.created_by c_created_by,
659        DFC.last_update_login c_last_login
660 FROM   fnd_descriptive_flexs_vl             DF,
661        fnd_descr_flex_contexts              DFC
662 WHERE  DF.application_table_name          = p_table_name
663 AND    replace (ltrim (rtrim(DF.title)), '''','') = replace(p_title,'''','')
664 AND    DF.application_id                 IN (800, 801, 804, 805, 808, 8301)
665 AND    DF.descriptive_flexfield_name      = DFC.descriptive_flexfield_name
666 AND    DFC.enabled_flag                   = 'Y'
667 AND    DFC.global_flag                    = p_global_flag
668 AND    DFC.application_id                IN (800, 801, 804, 805, 808, 8301)
669 AND    DFC.descriptive_flex_context_code  = p_context;
670 --
671 -- declare cursor 2 for retrieving the actual column names:
672 --
673 cursor dflex_c2 (p_descr_flex varchar2,
674                  p_context    varchar2) is
675 SELECT DFCU.application_column_name  c_def_text,
676      replace(replace(replace (ltrim(rtrim(upper(DFCU.end_user_column_name))),
677                      ' ','_'),'.',''),'-','_') c_db_name
678 FROM   fnd_descr_flex_column_usages         DFCU
679 WHERE  DFCU.descriptive_flexfield_name    = p_descr_flex
680 AND    DFCU.application_id               IN (800, 801, 804, 805, 808, 8301)
681 AND    DFCU.descriptive_flex_context_code = p_context
682 AND    DFCU.enabled_flag                  = 'Y';
683 --
684 -- Cache parameters for new_defined_balance
685 --
686 cached       boolean  := FALSE;
687 g_low_volume pay_action_parameters.parameter_value%type := 'N';
688 --
689 -- Cache value for security group ID
690 --
691 g_security_group_id number;
692 g_sess_date         date;
693 --
694 -- Multithread support procedure
695 --
696 PROCEDURE insert_mthread_pps (p_stage     number,
697                               p_worker_id number,
698                               p_leg_code  varchar2 default 'ZZ')
699 IS
700  PRAGMA AUTONOMOUS_TRANSACTION;
701 BEGIN
702 
703         insert into PAY_PATCH_STATUS(id,
704                                      patch_number,
705                                      patch_name,
706                                      process_type,
707                                      applied_date)
708         values (
709             pay_patch_status_s.nextval,
710             to_char(p_worker_id),
711             'HRRBDEIB INTERNAL PROC S' || to_char(p_stage),
712             p_leg_code,
713             sysdate);
714         commit;
715 END insert_mthread_pps;
716 --
717 PROCEDURE insert_mthread_pps_err (p_worker_id number,
718                                   p_leg_code  varchar2 default 'ZZ')
719 IS
720  PRAGMA AUTONOMOUS_TRANSACTION;
721 BEGIN
722 
723         insert into PAY_PATCH_STATUS(id,
724                                      patch_number,
725                                      patch_name,
726                                      process_type,
727                                      applied_date)
728         values (
729             pay_patch_status_s.nextval,
730             to_char(p_worker_id),
731             'HRRBDEIB INTERNAL PROC ERR' || to_char(p_worker_id),
732             p_leg_code,
733             sysdate);
734         commit;
735 END insert_mthread_pps_err;
736 --
737 PROCEDURE hrrbdeib_trace_on IS
738 BEGIN
739   if g_debug_cnt > 0 then
740     hr_utility.trace_on(null, 'HRRBDEIB');
741   end if;
742 END;
743 
744 PROCEDURE hrrbdeib_trace_off is
745 BEGIN
746   if g_debug_cnt > 0 then
747     hr_utility.trace_off;
748   end if;
749 END;
750 --
751 -- Function/Procedure declarations.
752 --
753 procedure check_for_dbi_clash
754 (p_user_name      in varchar2
755 ,p_ue_id          in number
756 ,p_leg_code       in varchar2
757 ,p_bg_id          in number
758 ,p_startup_mode   in varchar2
759 ,p_clash          out nocopy boolean
760 );
761 --
762 procedure replace_code_name
763 (p_language_code in            varchar2
764 ,p_item_name     in out nocopy varchar2
765 );
766 --
767 -- Assert a condition in the code.
768 --
769 procedure assert
770 (p_condition  in boolean
771 ,p_location   in varchar2
772 ,p_extra_info in varchar2
773 );
774 --
775 procedure gen_db_tl_dbi_name
776 (p_balance_type_id      in            number
777 ,p_balance_dimension_id in            number
778 ,p_language             in            varchar2
779 ,p_tl_name                 out nocopy varchar2
780 ,p_found                   out nocopy boolean
781 );
782 --
783 procedure gen_et_dbi_prefixes
784 (p_element_type_id in            number
785 ,p_languages       in            dbms_sql.varchar2s
786 ,p_prefixes        in out nocopy t_dbi_prefixes
787 );
788 --
789 procedure gen_eiv_dbi_prefixes
790 (p_input_value_id in number
791 ,p_effective_date in date
792 ,p_languages      in dbms_sql.varchar2s
793 ,p_prefixes       in out nocopy t_dbi_prefixes
794 );
795 --
796 procedure update_tl_dbi_name
797 (p_user_name      in varchar2
798 ,p_user_entity_id in number
799 ,p_leg_code       in varchar2
800 ,p_bg_id          in number
801 ,p_startup_mode   in varchar2
802 ,p_language       in varchar2
803 ,p_tl_user_name   in varchar2
804 );
805 --
806 procedure update_et_tl_dbi_names
807 (p_leg_code       in varchar2
808 ,p_bg_id          in number
809 ,p_startup_mode   in varchar2
810 ,p_user_name      in varchar2
811 ,p_user_entity_id in number
812 ,p_prefixes       in t_dbi_prefixes
813 ,p_suffix         in varchar2
814 ,p_date_p         in varchar2
815 );
816 --
817 function uom_requires_dbis
818 (p_uom in varchar2
819 ) return boolean;
820 --
821 -- New private procedure called by overloaded create_desc_flex()
822 --
823 procedure create_desc_flex_main
824 (
825     p_title             in varchar2,
826     p_table_name        in varchar2,
827     p_route_name        in varchar2,
828     p_entity_name       in varchar2,
829     p_context           in varchar2,
830     p_global_flag       in varchar2,
831     p_param_value       in varchar2,
832     p_leg_code          in varchar2,
833     p_business_group_id in varchar2
834 );
835 --
836 procedure delete_compiled_formula_priv
837 (
838     p_creator_id            in number,
839     p_creator_type          in varchar2,
840     p_user_entity_name      in varchar2,
841     p_leg_code              in varchar2
842 );
843 --
844 procedure ff_compiled_info_del
845 (p_formula_ids in dbms_sql.number_table
846 ,p_start_dates in dbms_sql.date_table
847 );
848 --
849 procedure create_user_entity
850                             (p_db_item_name       in out nocopy varchar2,
851                              p_business_group_id  in     number,
852                              p_legislation_code   in     varchar2,
853                              p_route_id           in     number,
854                              p_notfound_flag      in     varchar2,
855                              p_defined_balance_id in     number,
856                              p_creator_type       in     varchar2,
857                              p_description        in     varchar2,
858                              p_startup_mode       in     varchar2,
859                              p_user_entity_id     in out nocopy number
860                             )
861 is
862    rgeflg varchar2(1);
863 begin
864    IF (g_triggers_altered) THEN
865      -- validate the name is OK. This was originally called as part of
866      -- the FF_USER_ENTITIES_BRI trigger so we add it here.
867      begin
868        -- Check if name legal format eg no spaces, or special characters
869        hr_chkfmt.checkformat (p_db_item_name, 'DB_ITEM_NAME', p_db_item_name,
870                               null,null,'Y',rgeflg,null);
871      exception
872        when hr_utility.hr_error then
873          hr_utility.set_message (802, 'FFHR_6016_ALL_RES_WORDS');
874          hr_utility.set_message_token(802,'VALUE_NAME','FF94_USER_ENTITY');
875          hrrbdeib_trace_on;
876          hr_utility.trace('checkformat create_user_entity');
877          hr_utility.trace('ue name:' || p_db_item_name);
878          hrrbdeib_trace_off;
879          hr_utility.raise_error;
880      end;
881      --
882      --  create user entity
883      select ff_user_entities_s.nextval
884      into p_user_entity_id
885      from sys.dual;
886 
887     BEGIN
888      insert into ff_user_entities
889      (user_entity_id,
890       business_group_id,
891       legislation_code,
892       route_id,
893       notfound_allowed_flag,
894       user_entity_name,
895       creator_id,
896       creator_type,
897       entity_description)
898      select
899       p_user_entity_id,
900       p_business_group_id,
901       p_legislation_code,
902       p_route_id,
903       p_notfound_flag,
904       p_db_item_name,
905       p_defined_balance_id,
906       p_creator_type,
907       p_description
908      from dual
909      where not exists (
910        select null
911        from ff_user_entities a
912        where a.user_entity_name = p_db_item_name
913        and
914        ( p_startup_mode = 'MASTER'
915          or
916          ( p_startup_mode = 'SEED'
917            and
918            ( a.legislation_code = p_legislation_code
919             or
920            (a.legislation_code is null and a.business_group_id is null)
921             or
922             p_legislation_code =
923             (
924               select b.legislation_code
925               from   per_business_groups_perf b
926               where  b.business_group_id = a.business_group_id
927             )
928           )
929         )
930         or
931         ( p_startup_mode = 'NON-SEED'
932           and
933           ( a.business_group_id = p_business_group_id
934             or
935             (a.legislation_code is null and a.business_group_id is null)
936             or
937             (a.business_group_id is null and a.legislation_code = p_legislation_code)
938           )
939         )
940        ));
941       EXCEPTION WHEN OTHERS THEN
942        hrrbdeib_trace_on;
943        hr_utility.trace('hrrbdeib ins user entity: ');
944        hr_utility.trace(p_db_item_name || ' :routeid:');
945        hr_utility.trace(to_char(p_route_id) || ' :legcode:');
946        hr_utility.trace(p_legislation_code || ' :bgid:');
947        hr_utility.trace(to_char(p_business_group_id));
948        hrrbdeib_trace_off;
949        raise;
950       END;
951    ELSE -- g_triggers_altered is FALSE so use existing trigger validation
952 --
953      select ff_user_entities_s.nextval
954        into p_user_entity_id
955        from sys.dual;
956 --
957      insert into ff_user_entities
958      (user_entity_id,
959       business_group_id,
960       legislation_code,
961       route_id,
962       notfound_allowed_flag,
963       user_entity_name,
964       creator_id,
965       creator_type,
966       entity_description)
967      values (
968       p_user_entity_id,
969       p_business_group_id,
970       p_legislation_code,
971       p_route_id,
972       p_notfound_flag,
973       p_db_item_name,
974       p_defined_balance_id,
975       p_creator_type,
976       p_description
977      );
978    END IF; -- g_triggers_altered
979 --
980 --
981 end create_user_entity;
982 --
983 procedure create_dbi
984                     (
985                      p_db_item_name       in varchar2,
986                      p_user_entity_id     in number,
987                      p_datatype           in varchar2,
988                      p_definition         in varchar2,
989                      p_null_allowed       in varchar2,
990                      p_description        in varchar2,
991                      p_startup_mode       in varchar2,
992                      p_legislation_code   in varchar2,
993                      p_business_group_id  in number
994                     )
995 is
996 l_exists varchar2(2);
997 l_clash  boolean;
998 begin
999    --  Insert a Database Item to hold balance value.
1000    check_for_dbi_clash
1001    (p_user_name      => p_db_item_name
1002    ,p_ue_id          => p_user_entity_id
1003    ,p_leg_code       => p_legislation_code
1004    ,p_bg_id          => p_business_group_id
1005    ,p_startup_mode   => p_startup_mode
1006    ,p_clash          => l_clash
1007    );
1008    if not l_clash then
1009      insert into ff_database_items
1010      (user_name
1011      ,user_entity_id
1012      ,data_type
1013      ,definition_text
1014      ,null_allowed_flag
1015      ,description
1016      )
1017      values
1018      (p_db_item_name
1019      ,p_user_entity_id
1020      ,p_datatype
1021      ,p_definition
1022      ,p_null_allowed
1023      ,p_description
1024      );
1025    end if;
1026 exception
1027   when others then
1028     hrrbdeib_trace_on;
1029     hr_utility.trace('hrrbdeib ins dbi: ');
1030     hr_utility.trace(p_db_item_name || ' :ue id:');
1031     hr_utility.trace(to_char(p_user_entity_id) || ' :legcode:');
1032     hr_utility.trace(p_legislation_code || ' :bgid:');
1033     hr_utility.trace(to_char(p_business_group_id));
1034     hrrbdeib_trace_off;
1035     raise;
1036 end;
1037 ---------------------------------------------------------------------------
1038 -- procedure create_alternative_dbis
1039 ---------------------------------------------------------------------------
1040 procedure create_alternative_dbis(p_defined_balance_id    in     number,
1041                                   p_balance_dimension_id  in     number,
1042                                   p_balance_type_id       in     number,
1043                                   p_business_group_id     in     number,
1044                                   p_legislation_code      in     varchar2,
1045                                   p_db_item_name          in     varchar2,
1046                                   p_startup_mode          in     varchar2
1047                                  )
1048 is
1049 cursor get_alt_routes (p_bal_dim in  number)
1050 is
1051 select pdr.route_id,
1052        pdr.route_type,
1053        pdr.run_dimension_id,
1054        pdr.priority
1055 from pay_dimension_routes pdr
1056 where pdr.balance_dimension_id = p_bal_dim
1057 and   not exists (select null
1058                   from   ff_user_entities u
1059                   where  u.creator_id = p_defined_balance_id
1060                   and    u.creator_type = 'RB'
1061                   and    u.route_id = pdr.route_id)
1062 order by pdr.balance_dimension_id, pdr.priority;
1063 --
1064 cursor sel_ffci(p_dbi_item_name in varchar2,
1065                 p_legislation_code in varchar2,
1066                 p_business_group_id in number,
1067                 p_startup_mode in varchar2)
1068 is
1069 select /*+ ORDERED
1070            INDEX(a FF_USER_ENTITIES_N50)
1071            INDEX(fdbi FF_DATABASE_ITEMS_FK1)
1072            INDEX(fdi FF_USER_ENTITIES_N50)
1073            USE_NL(a fdbi fdi) */
1074          formula_id
1075     from
1076           ff_user_entities a,
1077           ff_database_items fdbi,
1078           ff_fdi_usages_f fdi
1079      where  fdi.usage = 'D'
1080      and    fdi.item_name = fdbi.user_name
1081      and    fdbi.user_entity_id = a.user_entity_id
1082      and    a.user_entity_name = p_dbi_item_name
1083      and
1084        ( p_startup_mode = 'MASTER'
1085          or
1086          ( p_startup_mode = 'SEED'
1087            and
1088            ( a.legislation_code = p_legislation_code
1089             or
1090            (a.legislation_code is null and a.business_group_id is null)
1091             or
1092             p_legislation_code =
1093             (
1094               select b.legislation_code
1095               from   per_business_groups_perf b
1096               where  b.business_group_id = a.business_group_id
1097             )
1098           )
1099         )
1100         or
1101         ( p_startup_mode = 'NON-SEED'
1102           and
1103           ( a.business_group_id = p_business_group_id
1104             or
1105             (a.legislation_code is null and a.business_group_id is null)
1106             or
1107             (a.business_group_id is null and a.legislation_code = p_legislation_code)
1108           )
1109         )
1110       );
1111 
1112 l_db_item_name ff_database_items.user_name%type;
1113 usr_ent_id     number;
1114 l_dbitem_def_text ff_database_items.definition_text%type;
1115 --
1116 begin
1117     --
1118     for rrrec in get_alt_routes(p_balance_dimension_id) loop
1119         --
1120         l_db_item_name := p_db_item_name||'_'||to_char(rrrec.priority);
1121         --
1122         -- delete the UE so we ensure that we recreate it
1123         for r_sel_ffci in sel_ffci(l_db_item_name,
1124                                    p_legislation_code,
1125                                    p_business_group_id,
1126                                    p_startup_mode) loop
1127 
1128           delete ff_fdi_usages_f where formula_id = r_sel_ffci.formula_id;
1129           delete ff_compiled_info_f where formula_id = r_sel_ffci.formula_id;
1130 
1131         end loop;
1132 
1133         delete ff_user_entities a
1134         where  a.user_entity_name = l_db_item_name
1135         and
1136        ( p_startup_mode = 'MASTER'
1137          or
1138          ( p_startup_mode = 'SEED'
1139            and
1140            ( a.legislation_code = p_legislation_code
1141             or
1142            (a.legislation_code is null and a.business_group_id is null)
1143             or
1144             p_legislation_code =
1145             (
1146               select b.legislation_code
1147               from   per_business_groups_perf b
1148               where  b.business_group_id = a.business_group_id
1149             )
1150           )
1151         )
1152         or
1153         ( p_startup_mode = 'NON-SEED'
1154           and
1155           ( a.business_group_id = p_business_group_id
1156             or
1157             (a.legislation_code is null and a.business_group_id is null)
1158             or
1159             (a.business_group_id is null and a.legislation_code = p_legislation_code)
1160           )
1161         )
1162        );
1163 
1164         create_user_entity
1165                  (l_db_item_name,
1166                   p_business_group_id,
1167                   p_legislation_code,
1168                   rrrec.route_id,
1169                   'N',
1170                   p_defined_balance_id,
1171                   'RB',
1172                   'To hold database items for the Balance '
1173                      || l_db_item_name || ' (automatically generated)',
1174                   p_startup_mode,
1175                   usr_ent_id
1176                  );
1177 --
1178         --  add Route Parameter values which contains the
1179         --  balance type ID and balance Dimension id to make
1180         --  the route work (we know sequence is 1 and 2)
1181 
1182         insert into ff_route_parameter_values
1183         (route_parameter_id,
1184          user_entity_id,
1185          value)
1186         select RP.route_parameter_id,
1187                usr_ent_id,
1188                to_char(p_balance_type_id)
1189         from   ff_route_parameters RP
1190         where  RP.route_id = rrrec.route_id
1191         and    RP.sequence_no = 1;
1192         if sql%rowcount <> 1 then
1193            hr_utility.set_message(801, 'HR_ERROR');
1194            hrrbdeib_trace_on;
1195            hr_utility.trace('missing seq 1 route param for route : ' || to_char(rrrec.route_id) || ' :user ent id:' || to_char(usr_ent_id));
1196            hrrbdeib_trace_off;
1197            hr_utility.raise_error;
1198         end if;
1199 --
1200     if rrrec.route_type = 'SRB' then
1201     --
1202     -- RR routes will only have route parameters for Balance type_id
1203     --
1204 
1205         insert into ff_route_parameter_values
1206         (route_parameter_id,
1207          user_entity_id,
1208          value)
1209         select RP.route_parameter_id,
1210                usr_ent_id,
1211                to_char(rrrec.run_dimension_id)
1212         from   ff_route_parameters RP
1213         where  RP.route_id = rrrec.route_id
1214         and    RP.sequence_no = 2;
1215         if sql%rowcount <> 1 then
1216            hr_utility.set_message(801, 'HR_ERROR');
1217            hrrbdeib_trace_on;
1218            hr_utility.trace('missing seq 2 route param for route : ' || to_char(rrrec.route_id) || ' :user ent id:' || to_char(usr_ent_id));
1219            hrrbdeib_trace_off;
1220            hr_utility.raise_error;
1221         end if;
1222      end if;
1223      --
1224 
1225      -- For run balances we are not creating database items, just user entities,
1226      -- in order to avoid the incorrect use of dbis in formulas, so call to
1227      -- create_dbi has been removed.
1228      --
1229      --
1230     end loop;
1231     --
1232 end create_alternative_dbis;
1233 --
1234 /*------------------- new_defined_balance  -----------------------------*/
1235 --
1236 /*
1237  *  This routine creates the database item and supporting information
1238  *  for a single defined balance. It is normally called from the
1239  *  trigger on insert of defined balance, or from the refresh routine.
1240  */
1241 procedure new_defined_balance (p_defined_balance_id in number,
1242                                p_balance_dimension_id in number,
1243                                p_balance_type_id in number,
1244                                p_business_group_id in number,
1245                                p_legislation_code in varchar2) is
1246 --
1247 cursor c_language is
1248 select language_code
1249 from   fnd_languages
1250 where  installed_flag in ('I','B');
1251 --
1252 cursor chk_flag_set(p_def_bal number)
1253 is
1254 select count(*)
1255 from   pay_defined_balances
1256 where  defined_balance_id = p_def_bal
1257 and    save_run_balance is null;
1258 --
1259 cursor get_cat_id(p_bal_type number)
1260 is
1261 select balance_category_id
1262 from   pay_balance_types
1263 where  balance_type_id = p_bal_type;
1264 --
1265 cursor get_sess_date
1266 is
1267 select effective_date
1268 from   fnd_sessions
1269 where  session_id = userenv('sessionid');
1270 --
1271    l_route_id ff_routes.route_id%type;
1272    l_db_item_name ff_database_items.user_name%type;
1273    l_dbitem_def_text ff_database_items.definition_text%type;
1274    l_dbi_function pay_balance_dimensions.database_item_function%type;
1275 
1276    startup_mode varchar2(10);
1277    rgeflg varchar2(1);
1278    usr_ent_id number;
1279    route_param_value number;
1280    l_flag_set     number;
1281    l_bal_cat_id   pay_balance_types.balance_category_id%type;
1282    l_run_bal_flag pay_defined_balances.save_run_balance%type;
1283    l_sess_date    date;
1284    l_ora_db_vers  number; -- db version number for LOW_VOLUME
1285 
1286    l_legislation_code varchar2(30);
1287    l_full_mls boolean;
1288    l_found    boolean;
1289    l_tl_name  ff_database_items_tl.translated_user_name%type;
1290    --
1291 begin
1292 --
1293    IF (g_triggers_altered) THEN
1294      -- Get the startup mode
1295      startup_mode := ffstup.get_mode (p_business_group_id,
1296                                       p_legislation_code);
1297    END IF;
1298    --
1299    l_legislation_code := p_legislation_code;
1300    if l_legislation_code is null then
1301      select bg.legislation_code
1302      into   l_legislation_code
1303      from   per_business_groups_perf bg
1304      where  bg.business_group_id = p_business_group_id
1305      ;
1306    end if;
1307    l_full_mls := ff_dbi_utils_pkg.translations_supported(l_legislation_code);
1308 
1309    --
1310    -- First check if the save_run_balance flag has been set on the defined
1311    -- balance. If not update the column if required.
1312    --
1313    -- if this procedure has been called from the trigger pay_defined_bal_ari,
1314    -- then the save run balance flag will have been set if it can be set, so
1315    -- don't do the following check as it will cause a mutating table error.
1316    --
1317    if not g_trigger_dfb_ari then
1318      open  chk_flag_set(p_defined_balance_id);
1319      fetch chk_flag_set into l_flag_set;
1320      close chk_flag_set;
1321      --
1322      if l_flag_set <> 0 then -- flag not set, attempt to set it
1323        open get_cat_id(p_balance_type_id);
1324        fetch get_cat_id into l_bal_cat_id;
1325        close get_cat_id;
1326        --
1327        -- get the session date or default sysdate
1328        --
1329        open  get_sess_date;
1330        fetch get_sess_date into l_sess_date;
1331        if get_sess_date%notfound then
1332          close get_sess_date;
1333          l_sess_date := trunc(sysdate);
1334        end if;
1335        --
1336        l_run_bal_flag := pay_defined_balances_pkg.set_save_run_bals_flag
1337                             (p_balance_category_id  => l_bal_cat_id
1338                             ,p_effective_date       => l_sess_date
1339                             ,p_balance_dimension_id => p_balance_dimension_id);        --
1340        if l_run_bal_flag is not null then
1341        --
1342        -- update the defined balance
1343        --
1344        begin
1345          update pay_defined_balances
1346          set    save_run_balance = l_run_bal_flag
1347          where  defined_balance_id = p_defined_balance_id;
1348        exception
1349          when others then
1350            hrrbdeib_trace_on;
1351            hr_utility.trace('update pay_def_bal.save_run_balance:def_bal_id:' || to_char(p_defined_balance_id) ||
1352                              'to save_run_balance:' || nvl(l_run_bal_flag, 'NULL') || ':');
1353            hrrbdeib_trace_off;
1354            raise;
1355        end;
1356          --
1357        end if; -- flag is null, so dont both to update
1358        --
1359      end if; -- flag is set so dont do anything
1360    end if; -- global is true, so code skipped.
1361    --
1362    --  get details from balance dimension and type
1363    BEGIN
1364    select BALDIM.route_id,
1365           nvl(database_item_function, 'N'),
1366           upper(replace(BALTYPE.balance_name || BALDIM.database_item_suffix,
1367                    ' ','_'))
1368    into   l_route_id,
1369           l_dbi_function,
1370           l_db_item_name
1371    from   pay_balance_dimensions BALDIM,
1372           pay_balance_types BALTYPE
1373    where  BALDIM.balance_dimension_id = p_balance_dimension_id
1374    and    BALTYPE.balance_type_id = p_balance_type_id;
1375    EXCEPTION WHEN OTHERS THEN
1376            hrrbdeib_trace_on;
1377            hr_utility.trace('missing baldim type info : baldim: ' || to_char(p_balance_dimension_id) ||
1378                             ' bal type: ' || to_char(p_balance_type_id));
1379            hrrbdeib_trace_off;
1380    END;
1381    --
1382    create_user_entity
1383                      (l_db_item_name,
1384                       p_business_group_id,
1385                       p_legislation_code,
1386                       l_route_id,
1387                       'N',
1388                       p_defined_balance_id,
1389                       'B',
1390                       'To hold database items for the Balance '
1391                          || l_db_item_name || ' (automatically generated)',
1392                       startup_mode,
1393                       usr_ent_id
1394                      );
1395 --
1396    --  add a Route Parameter value which contains the balance type ID
1397    --  to make the route work (we know sequence is 1)
1398    if (l_dbi_function = 'N') then
1399      route_param_value := p_balance_type_id;
1400    else
1401      route_param_value := p_defined_balance_id;
1402    end if;
1403    insert into ff_route_parameter_values
1404    (route_parameter_id,
1405     user_entity_id,
1406     value)
1407    select RP.route_parameter_id,
1408           usr_ent_id,
1409           to_char(route_param_value)
1410    from   ff_route_parameters RP
1411    where  RP.route_id = l_route_id
1412    and    RP.sequence_no = 1;
1413    if sql%rowcount <> 1 then
1414       hr_utility.set_message(801, 'HR_ERROR');
1415       hrrbdeib_trace_on;
1416       hr_utility.trace('missing seq 1 route param for route : ' || to_char(l_route_id));
1417       hrrbdeib_trace_off;
1418       hr_utility.raise_error;
1419    end if;
1420 --
1421    --
1422    -- Use Rule hint on balances if LOW_VOLUME pay_action_paremeter set
1423    --
1424    -- use caching to avoid repeated finding parameter_value
1425    --
1426    if (cached = FALSE) then
1427       cached := TRUE;
1428       l_ora_db_vers := hr_general2.get_oracle_db_version;
1429       if (nvl(l_ora_db_vers, 0) < 9.0) then
1430          g_low_volume := 'Y';
1431       else
1432          begin
1433             select parameter_value
1434             into g_low_volume
1435             from pay_action_parameters
1436             where parameter_name = 'LOW_VOLUME';
1437          exception
1438             when others then
1439                  g_low_volume := 'N';
1440          end;
1441       end if;
1442    end if;
1443 
1444    if (l_dbi_function = 'N') then
1445       if (g_low_volume = 'Y') then
1446          l_dbitem_def_text := '/*+'||' RULE*/ nvl(sum(fnd_number.canonical_to_number(TARGET.result_value) * FEED.scale),0) ';
1447       else
1448          l_dbitem_def_text := 'nvl(sum(fnd_number.canonical_to_number(TARGET.result_value) * FEED.scale),0) ';
1449       end if;
1450 --
1451    elsif (l_dbi_function = 'Y') then
1452       l_dbitem_def_text := '1';
1453    else
1454       l_dbitem_def_text := l_dbi_function;
1455    end if;
1456 
1457    --  insert a Database Item to hold balance value
1458    create_dbi
1459              (
1460               l_db_item_name,
1461               usr_ent_id,
1462               'N',
1463               l_dbitem_def_text,
1464               'N',
1465               'Current value for balance ' || l_db_item_name || ' (automatically generated)',
1466               startup_mode,
1467               p_legislation_code,
1468               p_business_group_id
1469              );
1470    --
1471    if l_full_mls then
1472      for l in c_language loop
1473        gen_db_tl_dbi_name
1474        (p_balance_type_id      => p_balance_type_id
1475        ,p_balance_dimension_id => p_balance_dimension_id
1476        ,p_language             => l.language_code
1477        ,p_tl_name              => l_tl_name
1478        ,p_found                => l_found
1479        );
1480        --
1481        -- Update the translated database item.
1482        --
1483        if l_found then
1484          update_tl_dbi_name
1485          (p_user_name      => l_db_item_name
1486          ,p_user_entity_id => usr_ent_id
1487          ,p_leg_code       => p_legislation_code
1488          ,p_bg_id          => p_business_group_id
1489          ,p_startup_mode   => startup_mode
1490          ,p_language       => l.language_code
1491          ,p_tl_user_name   => l_tl_name
1492          );
1493        end if;
1494      end loop;
1495    end if;
1496    --
1497 --
1498    create_alternative_dbis(p_defined_balance_id,
1499                            p_balance_dimension_id,
1500                            p_balance_type_id,
1501                            p_business_group_id,
1502                            p_legislation_code,
1503                            l_db_item_name,
1504                            startup_mode
1505                           );
1506 --
1507 end new_defined_balance;
1508 --
1509 /*------------------- refresh_defined_balances  ---------------------------*/
1510 /*
1511  *  This routine creates all database items based on defined balances
1512  *  in the system. The routine assumes that no such database items currently
1513  *  exist.
1514  */
1515 procedure refresh_defined_balances(p_worker_id in number default 0,
1516                                    p_maxworkers in number default 1) is
1517    cursor c1 is select defined_balance_id,
1518                        balance_dimension_id,
1519                        balance_type_id,
1520                        business_group_id,
1521                        legislation_code,
1522                        save_run_balance
1523                 from   pay_defined_balances b
1524                 where  not exists (
1525                   select null from ff_user_entities u
1526                   where  b.defined_balance_id = u.creator_id
1527                   and    u.creator_type = 'B')
1528                 and    mod(defined_balance_id, p_maxworkers) = p_worker_id
1529                 order by b.defined_balance_id;
1530 
1531    cursor c2 is select defined_balance_id,
1532                        balance_dimension_id,
1533                        balance_type_id,
1534                        business_group_id,
1535                        legislation_code,
1536                        save_run_balance
1537                 from   pay_defined_balances b
1538                 where  /* def bal ue simply doesn't exist but has an associated pdr */
1539                 ((
1540                   not exists (
1541                   select null from ff_user_entities u
1542                   where  b.defined_balance_id = u.creator_id
1543                   and    u.creator_type = 'RB')
1544                   and exists
1545                     (select null
1546                      from pay_dimension_routes pdr
1547                      where pdr.balance_dimension_id = b.balance_dimension_id)
1548                 )
1549                 OR /* def bal ue does exists but has a missing ue pdr */
1550                 (
1551                    exists (
1552                    select pdr.balance_dimension_id
1553                    from   pay_dimension_routes pdr
1554                    where  pdr.balance_dimension_id = b.balance_dimension_id
1555                    and    not exists (select null
1556                             from   ff_user_entities ue
1557                             where  ue.creator_id = b.defined_balance_id
1558                             and    ue.route_id = pdr.route_id
1559                             and    ue.creator_type = 'RB'))
1560                 ))
1561                 and    mod(defined_balance_id, p_maxworkers) = p_worker_id
1562                 order by b.defined_balance_id;
1563 
1564    l_db_item_name ff_database_items.user_name%type;
1565    startup_mode varchar2(10);
1566    l_loop_cnt number;
1567 
1568 begin
1569 
1570 hrrbdeib_trace_on;
1571 hr_utility.trace('entering refresh_defined_balances all' ||
1572                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
1573                  to_char(p_maxworkers));
1574 hrrbdeib_trace_off;
1575 
1576 l_loop_cnt := 0;
1577 
1578 -- create missing B and RB data
1579 
1580    for c1rec in c1 loop
1581       hrrbdeib_trace_on;
1582       hr_utility.trace('RDB:B :' || to_char(p_worker_id + 1) || ':' ||
1583                        c1rec.legislation_code || '.' ||
1584                        to_char(c1rec.business_group_id) || '.' ||
1585                        to_char(c1rec.defined_balance_id) || '.' ||
1586                        to_char(c1rec.balance_dimension_id) || '.' ||
1587                        to_char(c1rec.balance_type_id) || '.' ||
1588                        c1rec.save_run_balance);
1589       hrrbdeib_trace_off;
1590 
1591       recreate_defined_balance
1592            (p_defined_balance_id   => c1rec.defined_balance_id,
1593             p_balance_dimension_id => c1rec.balance_dimension_id,
1594             p_balance_type_id      => c1rec.balance_type_id,
1595             p_business_group_id    => c1rec.business_group_id,
1596             p_legislation_code     => c1rec.legislation_code);
1597 
1598    l_loop_cnt := l_loop_cnt + 1;
1599    if l_loop_cnt > 100 then
1600      l_loop_cnt := 0;
1601      commit;
1602    end if;
1603 
1604    end loop;
1605 
1606 -- create missing RB data which can happen if we had some or all B entities
1607 -- before running the c1 loop
1608 -- already created but no associated RB row as in this case the c1 cursor would -- not note it needs to create the missing RB row for an already existing B row
1609 -- however, as we only want to recreate the RB row we will create a new proc
1610 
1611    for c2rec in c2 loop
1612 
1613       hrrbdeib_trace_on;
1614       hr_utility.trace('RDB:RB:' ||  to_char(p_worker_id + 1) || ':' ||
1615                        c2rec.legislation_code || '.' ||
1616                        to_char(c2rec.business_group_id) || '.' ||
1617                        to_char(c2rec.defined_balance_id) || '.' ||
1618                        to_char(c2rec.balance_dimension_id) || '.' ||
1619                        to_char(c2rec.balance_type_id) || '.' ||
1620                        c2rec.save_run_balance);
1621       hrrbdeib_trace_off;
1622 
1623       BEGIN
1624         select upper(replace(BALTYPE.balance_name ||
1625                              BALDIM.database_item_suffix,
1626                       ' ','_'))
1627         into   l_db_item_name
1628         from   pay_balance_dimensions BALDIM,
1629                pay_balance_types BALTYPE
1630         where  BALDIM.balance_dimension_id = c2rec.balance_dimension_id
1631         and    BALTYPE.balance_type_id = c2rec.balance_type_id;
1632       EXCEPTION WHEN OTHERS THEN
1633         hrrbdeib_trace_on;
1634         hr_utility.trace('missing baldim type2 info : baldim: ' ||
1635                           to_char(c2rec.balance_dimension_id) ||
1636                           ' bal type: ' || to_char(c2rec.balance_type_id));
1637         hrrbdeib_trace_off;
1638       END;
1639 
1640       IF (g_triggers_altered) THEN
1641         -- Get the startup mode
1642         startup_mode := ffstup.get_mode (c2rec.business_group_id,
1643                                          c2rec.legislation_code);
1644       END IF;
1645 
1646 --      delete_compiled_formula_priv(c2rec.defined_balance_id , 'RB', '%',
1647 --                                   c2rec.legislation_code);
1648 
1649       delete ff_user_entities
1650       where  creator_id = c2rec.defined_balance_id
1651       and    creator_type = 'RB';
1652 
1653       create_alternative_dbis(c2rec.defined_balance_id,
1654                            c2rec.balance_dimension_id,
1655                            c2rec.balance_type_id,
1656                            c2rec.business_group_id,
1657                            c2rec.legislation_code,
1658                            l_db_item_name,
1659                            startup_mode
1660                           );
1661 
1662    l_loop_cnt := l_loop_cnt + 1;
1663    if l_loop_cnt > 100 then
1664      l_loop_cnt := 0;
1665      commit;
1666    end if;
1667 
1668    end loop;
1669 
1670 hrrbdeib_trace_on;
1671 hr_utility.trace('leaving refresh_defined_balances all' ||
1672                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
1673                  to_char(p_maxworkers));
1674 hrrbdeib_trace_off;
1675 
1676 end refresh_defined_balances;
1677 --
1678 /*------------------- refresh_defined_balances  ---------------------------*/
1679 /*
1680  *  This routine creates all database items based on defined balances
1681  *  in the system. The routine assumes that no such database items currently
1682  *  exist.
1683  */
1684 procedure refresh_defined_balances(p_leg_code in varchar2,
1685                                    p_worker_id in number default 0,
1686                                    p_maxworkers in number default 1) is
1687 
1688    cursor c1 is select defined_balance_id,
1689                        balance_dimension_id,
1690                        balance_type_id,
1691                        business_group_id,
1692                        legislation_code,
1693                        save_run_balance
1694                 from   pay_defined_balances a
1695                 where not exists (
1696                   select null from ff_user_entities u
1697                   where  a.defined_balance_id = u.creator_id
1698                   and    u.creator_type = 'B')
1699                 and  mod(defined_balance_id, p_maxworkers) = p_worker_id
1700                 and    (a.legislation_code = p_leg_code
1701                     or exists (select null
1702                      from   per_business_groups_perf b
1703                      where  a.business_group_id = b.business_group_id
1704                      and    nvl(b.legislation_code, p_leg_code) = p_leg_code))
1705                 order by a.defined_balance_id;
1706 
1707    cursor c2 is select defined_balance_id,
1708                        balance_dimension_id,
1709                        balance_type_id,
1710                        business_group_id,
1711                        legislation_code,
1712                        save_run_balance
1713                 from   pay_defined_balances a
1714                 where  /* def bal ue simply doesn't exist but has an associated pdr */
1715                 ((
1716                   not exists (
1717                   select null from ff_user_entities u
1718                   where  a.defined_balance_id = u.creator_id
1719                   and    u.creator_type = 'RB')
1720                   and exists
1721                     (select null
1722                      from pay_dimension_routes pdr
1723                      where pdr.balance_dimension_id = a.balance_dimension_id)
1724                 )
1725                 OR /* def bal ue does exists but has a missing ue pdr */
1726                 (
1727                    exists (
1728                    select pdr.balance_dimension_id
1729                    from   pay_dimension_routes pdr
1730                    where  pdr.balance_dimension_id = a.balance_dimension_id
1731                    and    not exists (select null
1732                             from   ff_user_entities ue
1733                             where  ue.creator_id = a.defined_balance_id
1734                             and    ue.route_id = pdr.route_id
1735                             and    ue.creator_type = 'RB'))
1736                 ))
1737                 and  mod(defined_balance_id, p_maxworkers) = p_worker_id
1738                 and    (a.legislation_code = p_leg_code
1739                     or exists (select null
1740                      from   per_business_groups_perf b
1741                      where  a.business_group_id = b.business_group_id
1742                      and    nvl(b.legislation_code, p_leg_code) = p_leg_code))
1743                 order by a.defined_balance_id;
1744 
1745    l_db_item_name ff_database_items.user_name%type;
1746    startup_mode varchar2(10);
1747    l_loop_cnt number;
1748 
1749 begin
1750 
1751 hrrbdeib_trace_on;
1752 hr_utility.trace('entering refresh_defined_balances ' || p_leg_code ||
1753                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
1754                  to_char(p_maxworkers));
1755 hrrbdeib_trace_off;
1756 
1757 l_loop_cnt := 0;
1758 
1759 -- create missing B and RB data
1760 
1761    for c1rec in c1 loop
1762 
1763 hrrbdeib_trace_on;
1764       hr_utility.trace('RDB:B :' || to_char(p_worker_id + 1) || ':' ||
1765                        c1rec.legislation_code || '.' ||
1766                        to_char(c1rec.business_group_id) || '.' ||
1767                        to_char(c1rec.defined_balance_id) || '.' ||
1768                        to_char(c1rec.balance_dimension_id) || '.' ||
1769                        to_char(c1rec.balance_type_id) || '.' ||
1770                        c1rec.save_run_balance);
1771 hrrbdeib_trace_off;
1772 
1773       recreate_defined_balance
1774            (p_defined_balance_id   => c1rec.defined_balance_id,
1775             p_balance_dimension_id => c1rec.balance_dimension_id,
1776             p_balance_type_id      => c1rec.balance_type_id,
1777             p_business_group_id    => c1rec.business_group_id,
1778             p_legislation_code     => c1rec.legislation_code);
1779 
1780    l_loop_cnt := l_loop_cnt + 1;
1781    if l_loop_cnt > 100 then
1782      l_loop_cnt := 0;
1783      commit;
1784    end if;
1785 
1786    end loop;
1787 
1788 -- create missing RB data which can happen if we had some or all B entities
1789 -- before running the c1 loop
1790 -- already created but no associated RB row as in this case the c1 cursor would -- not note it needs to create the missing RB row for an already existing B row
1791 -- however, as we only want to recreate the RB row we will create a new proc
1792 
1793    for c2rec in c2 loop
1794 
1795       hrrbdeib_trace_on;
1796       hr_utility.trace('RDB:RB:' || to_char(p_worker_id + 1) || ':' ||
1797                        c2rec.legislation_code || '.' ||
1798                        to_char(c2rec.business_group_id) || '.' ||
1799                        to_char(c2rec.defined_balance_id) || '.' ||
1800                        to_char(c2rec.balance_dimension_id) || '.' ||
1801                        to_char(c2rec.balance_type_id) || '.' ||
1802                        c2rec.save_run_balance);
1803       hrrbdeib_trace_off;
1804 
1805       BEGIN
1806         select upper(replace(BALTYPE.balance_name ||
1807                              BALDIM.database_item_suffix,
1808                       ' ','_'))
1809         into l_db_item_name
1810         from   pay_balance_dimensions BALDIM,
1811                pay_balance_types BALTYPE
1812         where  BALDIM.balance_dimension_id = c2rec.balance_dimension_id
1813         and    BALTYPE.balance_type_id = c2rec.balance_type_id;
1814       EXCEPTION WHEN OTHERS THEN
1815         hrrbdeib_trace_on;
1816         hr_utility.trace('missing baldim type2 info : baldim: ' ||
1817                           to_char(c2rec.balance_dimension_id) ||
1818                           ' bal type: ' || to_char(c2rec.balance_type_id));
1819         hrrbdeib_trace_off;
1820       END;
1821 
1822       IF (g_triggers_altered) THEN
1823         -- Get the startup mode
1824         startup_mode := ffstup.get_mode (c2rec.business_group_id,
1825                                          c2rec.legislation_code);
1826       END IF;
1827 
1828 --      delete_compiled_formula_priv(c2rec.defined_balance_id , 'RB', '%',
1829 --                                   c2rec.legislation_code);
1830 
1831       delete ff_user_entities
1832       where  creator_id = c2rec.defined_balance_id
1833       and    creator_type = 'RB';
1834 
1835       create_alternative_dbis(c2rec.defined_balance_id,
1836                            c2rec.balance_dimension_id,
1837                            c2rec.balance_type_id,
1838                            c2rec.business_group_id,
1839                            c2rec.legislation_code,
1840                            l_db_item_name,
1841                            startup_mode
1842                           );
1843 
1844    l_loop_cnt := l_loop_cnt + 1;
1845    if l_loop_cnt > 100 then
1846      l_loop_cnt := 0;
1847      commit;
1848    end if;
1849 
1850    end loop;
1851 
1852 hrrbdeib_trace_on;
1853 hr_utility.trace('leaving refresh_defined_balances ' || p_leg_code ||
1854                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
1855                  to_char(p_maxworkers));
1856 hrrbdeib_trace_off;
1857 
1858 end refresh_defined_balances;
1859 --
1860 /*------------------- recreate_defined_balance  ---------------------------*/
1861 /*
1862  *  This routine deletes and creates database items based on a given
1863  *  defined balance in the system.
1864  */
1865 procedure recreate_defined_balance(p_defined_balance_id   in number,
1866                                    p_balance_dimension_id in number,
1867                                    p_balance_type_id      in number,
1868                                    p_business_group_id    in number,
1869                                    p_legislation_code     in varchar2)
1870 is
1871 begin
1872 --
1873 --  delete_compiled_formula_priv(p_defined_balance_id, 'B',  '%', p_legislation_code);
1874 --  delete_compiled_formula_priv(p_defined_balance_id, 'RB', '%', p_legislation_code);
1875 
1876   delete from ff_user_entities
1877    where creator_id = p_defined_balance_id
1878      and creator_type = 'B';
1879   --
1880   delete from ff_user_entities
1881    where creator_id = p_defined_balance_id
1882      and creator_type = 'RB';
1883   --
1884   hrdyndbi.new_defined_balance
1885     (p_defined_balance_id   => p_defined_balance_id,
1886      p_balance_dimension_id => p_balance_dimension_id,
1887      p_balance_type_id      => p_balance_type_id,
1888      p_business_group_id    => p_business_group_id,
1889      p_legislation_code     => p_legislation_code);
1890   --
1891 end;
1892 --
1893 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1894 --                                                                        +
1895 --                       insert_parameter_value                           +
1896 --                                                                        +
1897 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1898 /*
1899 NAME
1900     insert_parameter_value - insert the entity value into the route parameter
1901                              table
1902 DESCRIPTION
1903     This routine is called if the routes contains where clause fillers (Ux).
1904     Get the route parameter id from the ff_route_parameters table and insert
1905     the actual entity value into the ff_route_parameter_values table.  For
1906     example, when an  element type is created, the value inserted into the
1907     ff_route_parameter_values table is the element type id.
1908     The parameters passed are:
1909     p_value        - the actual where clause filler value
1910     p_sequence_no  - the number of the where clause filler, eg. 1 for U1.
1911 */
1912 procedure insert_parameter_value
1913 (
1914     p_value         in varchar2,
1915     p_sequence_no   in number
1916 ) is
1917 l_route_parameter_id  number;
1918 l_route_id            number;
1919 l_user_entity_id      number;
1920 l_created_by          ff_user_entities.created_by%type;
1921 l_last_login          ff_user_entities.last_update_login%type;
1922 l_user_entity_name    ff_user_entities.user_entity_name%type;
1923 l_ent_bg_id           ff_user_entities.BUSINESS_GROUP_ID%type;
1924 l_ent_lc              ff_user_entities.LEGISLATION_CODE%type;
1925 l_route_name          ff_routes.route_name%type;
1926 l_route_cd            varchar2(60);
1927 l_route_lud           varchar2(60);
1928 l_route_lub           number;
1929 BEGIN
1930     --
1931     -- get the user entity id to be used:
1932     --
1933     select  ff_user_entities_s.currval
1934     into    l_user_entity_id
1935     from    dual;
1936     --
1937     -- get the relevant information for the user entity we are using
1938     --
1939     BEGIN
1940     select RPARAM.route_parameter_id,
1941            ENTITY.created_by,
1942            ENTITY.last_update_login,
1943            ENTITY.user_entity_name
1944     into   l_route_parameter_id,
1945            l_created_by,
1946            l_last_login,
1947            l_user_entity_name
1948     from   ff_user_entities          ENTITY
1949     ,      ff_route_parameters       RPARAM
1950     where  ENTITY.user_entity_id   = l_user_entity_id
1951     and    RPARAM.route_id         = ENTITY.route_id
1952     and    RPARAM.sequence_no      = p_sequence_no;
1953     EXCEPTION WHEN OTHERS THEN
1954      hrrbdeib_trace_on;
1955      hr_utility.trace(SQLCODE || '-' || SQLERRM);
1956      hr_utility.trace('insert param val');
1957      hr_utility.trace(' seqno: ' || to_char(p_sequence_no));
1958      hr_utility.trace('Checking for user entity ' || to_char(l_user_entity_id)
1959                         || ' details');
1960      BEGIN
1961        select ENTITY.user_entity_name,
1962               ENTITY.route_id,
1963               ENTITY.BUSINESS_GROUP_ID,
1964               ENTITY. LEGISLATION_CODE
1965        into   l_user_entity_name,
1966               l_route_id,
1967               l_ent_bg_id,
1968               l_ent_lc
1969        from   ff_user_entities          ENTITY
1970        where  ENTITY.user_entity_id   = l_user_entity_id;
1971 
1972       hr_utility.trace('entity_name: ' || l_user_entity_name);
1973       hr_utility.trace('entity route id: ' || to_char(l_route_id));
1974       hr_utility.trace('entity BG id: ' || to_char(l_ent_bg_id));
1975       hr_utility.trace('entity LC: ' || l_ent_lc);
1976 
1977        IF l_route_id is not null THEN
1978          select route_name,
1979                 to_char(CREATION_DATE, 'DD-MM-YYYY'),
1980                 to_char(LAST_UPDATE_DATE, 'DD-MM-YYYY'),
1981                 LAST_UPDATED_BY
1982          into   l_route_name,
1983                 l_route_cd,
1984                 l_route_lud,
1985                 l_route_lub
1986          from   ff_routes
1987          where  route_id = l_route_id;
1988 
1989         hr_utility.trace('route_name: ' || l_route_name);
1990         hr_utility.trace('route creation date: ' || l_route_cd);
1991         hr_utility.trace('route LUD: ' || l_route_lud);
1992         hr_utility.trace('route LUB: ' || to_char(l_route_lub));
1993         hrrbdeib_trace_off;
1994 
1995        END IF;
1996       EXCEPTION WHEN OTHERS THEN NULL;
1997      END;
1998 
1999       raise;
2000 
2001     END;
2002     --
2003     -- populate the route parameter value table with the entity value
2004     --
2005     insert into ff_route_parameter_values (
2006             user_entity_id,
2007             route_parameter_id,
2008             value,
2009             last_update_date,
2010             last_updated_by,
2011             last_update_login,
2012             created_by,
2013             creation_date)
2014     --
2015     values (l_user_entity_id,
2016             l_route_parameter_id,
2017             p_value,
2018             sysdate,
2019             l_created_by,
2020             l_last_login,
2021             l_created_by,
2022             sysdate);
2023     --
2024 END insert_parameter_value;
2025 --
2026 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2027 --                                                                        +
2028 --                        insert_database_item                            +
2029 --                                                                        +
2030 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2031 /*
2032 NAME
2033       insert_database_item - load the database item.
2034 --
2035 DESCRIPTION
2036       Internal interface for insert_database_item.
2037 
2038       This is the external insert_database_item but with extra parameters
2039       extra parameters so that only a single base database item is
2040       created.
2041 
2042       If P_FULL_MLS is true then this call just creates a single base
2043       database item whose name is returned in P_BASE_DBI_NAME. If
2044       P_FULL_MLS is false then this call performs the old pseudo-MLS
2045       generation of multiple database items in FF_DATABASE_ITEMS, and
2046       P_BASE_DBI_NAME is ignored.
2047 */
2048 procedure insert_database_item
2049 (
2050     p_entity_name          in  varchar2,
2051     p_item_name            in  varchar2,
2052     p_data_type            in  varchar2,
2053     p_definition_text      in  varchar2,
2054     p_null_allowed_flag    in  varchar2,
2055     p_description          in  varchar2,
2056     p_user_entity_id       in  number,
2057     p_full_mls             in  boolean,
2058     p_base_dbi_name        out nocopy varchar2
2059 ) is
2060 l_item_name           ff_database_items.user_name%type;
2061 l_user_name           ff_database_items.user_name%type;
2062 l_user_entity_id      number;
2063 l_created_by          ff_user_entities.created_by%type;
2064 l_last_login          ff_user_entities.last_update_login%type;
2065 l_db                  number;
2066 l_exists              VARCHAR2(2);
2067 l_clash               boolean;
2068 --
2069 startup_mode varchar2(10);
2070 rgeflg       varchar2(1);
2071 bg_id        number;
2072 leg_code     varchar2(30);
2073 --
2074 cursor c_language is
2075   select language_code
2076   from   fnd_languages
2077   where  installed_flag in ('I','B');
2078 --
2079 cursor c_dbi_exists(c_user_name IN VARCHAR2,
2080   c_user_entity_id IN VARCHAR2) IS
2081   SELECT  'Y'
2082   FROM    ff_database_items
2083   WHERE   user_name = c_user_name
2084   AND     user_entity_id = c_user_entity_id;
2085 --
2086 BEGIN
2087 --
2088   --
2089   -- get the user entity id to be used:
2090   --
2091   if (p_user_entity_id is not NULL) then
2092     l_user_entity_id:=p_user_entity_id;
2093   else
2094     select  ff_user_entities_s.currval
2095     into    l_user_entity_id
2096     from    dual;
2097   end if;
2098 
2099   --
2100   -- get the relevant information for the user entity we are using
2101   --
2102   select created_by,
2103          last_update_login,
2104          business_group_id,
2105          legislation_code
2106   into   l_created_by,
2107          l_last_login,
2108          bg_id,
2109          leg_code
2110   from   ff_user_entities
2111   where  user_entity_id    = l_user_entity_id;
2112   --
2113   IF (g_triggers_altered) THEN
2114     -- Get the startup mode
2115     startup_mode := ffstup.get_mode (bg_id, leg_code);
2116   ELSE
2117     -- get the security group id which won't have been populated yet.
2118     g_security_group_id := fnd_global.lookup_security_group('NAME_TRANSLATIONS', 3);
2119   END IF;
2120 
2121   if not p_full_mls then
2122     --
2123     -- This is the pseudo-MLS process where the base table values are
2124     -- appended with lookup meanings for all languages.
2125     --
2126     for c_lang_rec in c_language loop
2127       --
2128       -- This used to be a cursor for-loop.
2129       --
2130       l_item_name := p_item_name;
2131       replace_code_name
2132       (p_language_code => c_lang_rec.language_code
2133       ,p_item_name     => l_item_name
2134       );
2135 
2136       --
2137       -- If the Database item name is greater than 80, then we have no choice
2138       -- but to truncate the trailing characters. This may lead to the insert
2139       -- failing due to duplicate DB item names.
2140       -- Note the use of substrb.
2141       --
2142       -- For utf8 support we now substr 80 so :
2143       --    (a). for singlebyte environments get same sa previous versions of
2144       --         this package and thus data integrity.
2145       --    (b). for multibyte environments get 80 multibyte characters ... using
2146       --         upto 240 bytes.
2147 
2148 
2149       l_user_name := substr ((p_entity_name || '_' || l_item_name), 1, 80);
2150 
2151       --
2152       -- str2dbiname does all the checks performed here before including
2153       -- checkformat and, if necessary, quoting (see bug 3723715).
2154       --
2155       l_user_name := ff_dbi_utils_pkg.str2dbiname(p_str => l_user_name);
2156 
2157       --
2158       -- load the database name into the database item table
2159       -- As this is now done for each installed language, we should
2160       -- check that the user_name, user_entitiy_id doesn't already
2161       -- exist.
2162       --
2163       OPEN c_dbi_exists(l_user_name, l_user_entity_id);
2164       FETCH c_dbi_exists INTO l_exists;
2165       IF c_dbi_exists%NOTFOUND then
2166         BEGIN
2167           --
2168           -- Make sure that the name does not clash with FF_DATABASE_ITEMS,
2169           -- FF_DATABASE_ITEMS_TL, or FF_CONTEXT rows.
2170           --
2171           check_for_dbi_clash
2172           (p_user_name      => l_user_name
2173           ,p_ue_id          => l_user_entity_id
2174           ,p_leg_code       => leg_code
2175           ,p_bg_id          => bg_id
2176           ,p_startup_mode   => startup_mode
2177           ,p_clash          => l_clash
2178           );
2179           if not l_clash then
2180             insert into ff_database_items
2181             (user_name
2182             ,user_entity_id
2183             ,data_type
2184             ,definition_text
2185             ,null_allowed_flag
2186             ,description
2187             ,last_update_date
2188             ,last_updated_by
2189             ,last_update_login
2190             ,created_by
2191             ,creation_date
2192             )
2193             values
2194             (l_user_name
2195             ,l_user_entity_id
2196             ,p_data_type
2197             ,p_definition_text
2198             ,p_null_allowed_flag
2199             ,p_description
2200             ,sysdate
2201             ,l_created_by
2202             ,l_last_login
2203             ,l_created_by
2204             ,sysdate
2205             );
2206           else
2207             --
2208             -- For the pseudo-MLS process it is possible to get name
2209             -- clashes because translation patches may not have been
2210             -- applied.
2211             --
2212             null;
2213           end if;
2214         EXCEPTION
2215           WHEN OTHERS THEN
2216             hrrbdeib_trace_on;
2217             IF (g_triggers_altered) THEN
2218               hr_utility.trace('ins dbi: g_trigger TRUE');
2219             ELSE
2220               hr_utility.trace('ins dbi: g_trigger FALSE');
2221             END IF;
2222             hr_utility.trace('ins dbi: dbi: ' || l_user_name);
2223             hr_utility.trace('ins dbi: ue: ' || p_entity_name);
2224             hr_utility.trace('ins dbi: item: ' || l_item_name);
2225             hr_utility.trace('ins dbi: ueid: ' || to_char(l_user_entity_id));
2226             hr_utility.trace('ins dbi: lang: ' || c_lang_rec.language_code);
2227             hrrbdeib_trace_off;
2228 
2229             if c_dbi_exists%isopen then
2230               close c_dbi_exists;
2231             end if;
2232             raise;
2233         END;
2234       END IF;
2235       CLOSE c_dbi_exists;
2236       --
2237       -- Repeat the process for the next language
2238       --
2239     end loop;
2240   --
2241   -- For the full MLS process, this code only generates a single base
2242   -- table database item based upon the supplied item name.
2243   --
2244   else
2245     --
2246     -- The translations will be done in other code to be reused elsewhere.
2247     --
2248     l_user_name := substr ((p_entity_name || '_' || p_item_name), 1, 80);
2249 
2250     --
2251     -- str2dbiname does all the checks performed here before including
2252     -- checkformat and, if necessary, quoting (see bug 3723715).
2253     --
2254     l_user_name := ff_dbi_utils_pkg.str2dbiname(p_str => l_user_name);
2255 
2256     OPEN c_dbi_exists(l_user_name, l_user_entity_id);
2257     FETCH c_dbi_exists INTO l_exists;
2258     IF c_dbi_exists%NOTFOUND then
2259       BEGIN
2260         --
2261         -- Make sure that the name does not clash with FF_DATABASE_ITEMS,
2262         -- FF_DATABASE_ITEMS_TL, or FF_CONTEXT rows.
2263         --
2264         check_for_dbi_clash
2265         (p_user_name      => l_user_name
2266         ,p_ue_id          => l_user_entity_id
2267         ,p_leg_code       => leg_code
2268         ,p_bg_id          => bg_id
2269         ,p_startup_mode   => startup_mode
2270         ,p_clash          => l_clash
2271         );
2272         if not l_clash then
2273           insert into ff_database_items
2274           (user_name
2275           ,user_entity_id
2276           ,data_type
2277           ,definition_text
2278           ,null_allowed_flag
2279           ,description
2280           ,last_update_date
2281           ,last_updated_by
2282           ,last_update_login
2283           ,created_by
2284           ,creation_date
2285           )
2286           values
2287           (l_user_name
2288           ,l_user_entity_id
2289           ,p_data_type
2290           ,p_definition_text
2291           ,p_null_allowed_flag
2292           ,p_description
2293           ,sysdate
2294           ,l_created_by
2295           ,l_last_login
2296           ,l_created_by
2297           ,sysdate
2298           );
2299         else
2300           --
2301           -- For the full MLS process, a name clash is a fatal error.
2302           --
2303           hr_utility.set_message (801, 'PAY_33916_DYN_DBI_NAME_CLASH');
2304           hr_utility.set_message_token('1', l_user_name);
2305           hr_utility.raise_error;
2306         end if;
2307       EXCEPTION
2308         WHEN OTHERS THEN
2309           hrrbdeib_trace_on;
2310           IF (g_triggers_altered) THEN
2311             hr_utility.trace('ins dbi: g_trigger TRUE');
2312           ELSE
2313             hr_utility.trace('ins dbi: g_trigger FALSE');
2314           END IF;
2315           hr_utility.trace('ins dbi: dbi: ' || l_user_name);
2316           hr_utility.trace('ins dbi: ue: ' || p_entity_name);
2317           hr_utility.trace('ins dbi: item: ' || l_item_name);
2318           hr_utility.trace('ins dbi: ueid: ' || to_char(l_user_entity_id));
2319           hr_utility.trace('ins dbi: base name' );
2320           hrrbdeib_trace_off;
2321 
2322           if c_dbi_exists%isopen then
2323             close c_dbi_exists;
2324           end if;
2325           raise;
2326       END;
2327     END IF;
2328     CLOSE c_dbi_exists;
2329 
2330     p_base_dbi_name := l_user_name;
2331   end if;
2332 END insert_database_item;
2333 --
2334 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2335 --                                                                        +
2336 --                        insert_database_item                            +
2337 --                                                                        +
2338 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2339 /*
2340 NAME
2341       insert_database_item - load the database item.
2342 --
2343 DESCRIPTION
2344       Insert a new row into the database_items table.  The actual database
2345       name is a concatenation of the supplied entity name and the database
2346       name as:
2347       --
2348                 <ENTITY_NAME>_<ITEM_NAME>
2349       --
2350       The <ITEM_NAME> parameter is checked to see if its name translation is
2351       to be used.  This is now done for each installed language (the c_language
2352       cursor loop), to maintain the current Japanese functionality of using
2353       the name translations lookup to translation JP-specific elements into
2354       Japanese.  This functionality leads to pseudo-translated multilingual
2355       DEH DBIs, and currently does nothing with the translation table.  For
2356       this multilanguage translation to
2357       work, we can not access the data through the single language views,
2358       either HR_LOOKUPS or FND_LOOKUPS, but instead have to access the base table
2359       directly, filtering by the required language.
2360 
2361       The parameters passed are:
2362       p_entity_name         - The first half of the database name
2363       p_item_name           - The second half of the database name
2364       p_data_type           - Data type T = text, N = number, D = date.
2365       p_definition_text     - The text after the 'select' statment and before
2366                               the 'from' that is used to retrieve the data.
2367       p_null_allowed_flag   - Y or N, can the database item be null.
2368       p_description         - The description of the database item
2369 */
2370 procedure insert_database_item
2371 (
2372     p_entity_name          in  varchar2,
2373     p_item_name            in  varchar2,
2374     p_data_type            in  varchar2,
2375     p_definition_text      in  varchar2,
2376     p_null_allowed_flag    in  varchar2,
2377     p_description          in  varchar2,
2378     p_user_entity_id       in  number
2379 ) is
2380 l_base_dbi_name varchar2(2000);
2381 begin
2382   --
2383   -- This call must generate the old-style pseudo-MLS database items
2384   -- so P_FULL_MLS is FALSE.
2385   --
2386   insert_database_item
2387   (
2388     p_entity_name        => p_entity_name,
2389     p_item_name          => p_item_name,
2390     p_data_type          => p_data_type,
2391     p_definition_text    => p_definition_text,
2392     p_null_allowed_flag  => p_null_allowed_flag,
2393     p_description        => p_description,
2394     p_user_entity_id     => p_user_entity_id,
2395     p_full_mls           => false,
2396     p_base_dbi_name      => l_base_dbi_name
2397   );
2398 end insert_database_item;
2399 --
2400 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2401 --                                                                        +
2402 --                          insert_user_entity                            +
2403 --                                                                        +
2404 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2405 /*
2406    NAME
2407       insert_user_entity - load the element type information into user
2408                            entity and route parameter value tables
2409 --
2410    DESCRIPTION
2411       This is the first general purpose routine that should be called by the
2412       main procedures (xxx_dict).  It defines an entity, that the other
2413       procedures ('insert_parameter_value' and 'insert_database_item')
2414       reference.
2415       NB insert_user_entity_main is overloaded by 2 insert_user_entity
2416       procedures: one that is passed the out parameter p_record_inserted
2417       and one that uses its own local p_record_inserted paramter (whose
2418       values is subsequently ignored).
2419       The parameters passed are:
2420       p_route_name        - the route name to be used, this must already be
2421                             seeded in the table ff_routes.
2422       p_user_entity_name  - The name of the user entity.
2423       p_entity_description- The description of the entity.
2424       p_not_found_flag    - Y/ N, Y= the database item may not be found in
2425                             some cases, N= it will ALWAYS return a value.
2426       p_creator_type      - Indicates which type of DB items are to be
2427                             created, eg. E = element type.
2428       p_creator_id        - Further defines who created the DB items, for
2429                             example, element type id.
2430       p_business_group_id - If this is null, the item may be seen by all
2431                             business groups.
2432       p_legislation_code  - The legisaltion code, null = generic.
2433       p_created_by        - Used in the AOL columns of the database.
2434       p_last_login        - Used in the AOL columns of the database.
2435       p_record_inserted   - Boolean indicating whether insertion happened
2436 */
2437 --
2438 --  insert_user_entity called with p_record_inserted
2439 --
2440 procedure insert_user_entity
2441 (
2442     p_route_name           in  varchar2,
2443     p_user_entity_name     in  varchar2,
2444     p_entity_description   in  varchar2,
2445     p_not_found_flag       in  varchar2,
2446     p_creator_type         in  varchar2,
2447     p_creator_id           in  number,
2448     p_business_group_id    in  number,
2449     p_legislation_code     in  varchar2,
2450     p_created_by           in  number,
2451     p_last_login           in  number,
2452     p_record_inserted      out nocopy boolean
2453 ) is
2454 l_user_entity_name    ff_user_entities.user_entity_name%type;
2455 BEGIN
2456    --
2457    -- simply call insert_user_entity_main
2458    --
2459    -- mkandasa substr'd user entity name to 80. Bug fix 2073022.
2460    l_user_entity_name := substr(p_user_entity_name,1,80);
2461 
2462    insert_user_entity_main( p_route_name,
2463                             l_user_entity_name,
2464                             p_entity_description,
2465                             p_not_found_flag,
2466                             p_creator_type,
2467                             p_creator_id,
2468                             p_business_group_id,
2469                             p_legislation_code,
2470                             p_created_by,
2471                             p_last_login,
2472                             p_record_inserted);
2473 END insert_user_entity;
2474 --
2475 --  insert_user_entity called without p_record_inserted
2476 --
2477 procedure insert_user_entity
2478 (
2479     p_route_name           in  varchar2,
2480     p_user_entity_name     in  varchar2,
2481     p_entity_description   in  varchar2,
2482     p_not_found_flag       in  varchar2,
2483     p_creator_type         in  varchar2,
2484     p_creator_id           in  number,
2485     p_business_group_id    in  number,
2486     p_legislation_code     in  varchar2,
2487     p_created_by           in  number,
2488     p_last_login           in  number
2489 ) is
2490 l_record_inserted      boolean;
2491 BEGIN
2492    --
2493    -- call insert_user_entity_main with l_record_inserted
2494    --
2495    insert_user_entity_main( p_route_name,
2496                             p_user_entity_name,
2497                             p_entity_description,
2498                             p_not_found_flag,
2499                             p_creator_type,
2500                             p_creator_id,
2501                             p_business_group_id,
2502                             p_legislation_code,
2503                             p_created_by,
2504                             p_last_login,
2505                             l_record_inserted);
2506 END insert_user_entity;
2507 --
2508 -- main insert user entity procedure
2509 --
2510 procedure insert_user_entity_main
2511 (
2512     p_route_name           in  varchar2,
2513     p_user_entity_name     in  varchar2,
2514     p_entity_description   in  varchar2,
2515     p_not_found_flag       in  varchar2,
2516     p_creator_type         in  varchar2,
2517     p_creator_id           in  number,
2518     p_business_group_id    in  number,
2519     p_legislation_code     in  varchar2,
2520     p_created_by           in  number,
2521     p_last_login           in  number,
2522     p_record_inserted      out nocopy boolean
2523 ) is
2524 l_route_id            number;
2525 l_user_entities_seq   number;
2526 l_dummy_fetch_var     number;
2527 l_user_entity_name    ff_database_items.user_name%type;
2528 startup_mode varchar2(10);
2529 rgeflg varchar2(1);
2530 l_message varchar2(255);
2531 
2532 BEGIN
2533     --
2534     -- get the user entity id from its sequence
2535     --
2536     begin
2537         SELECT ff_user_entities_s.nextval
2538         INTO   l_user_entities_seq
2539         FROM   dual;
2540     end;
2541 --
2542    l_user_entity_name := p_user_entity_name;
2543 --
2544    --
2545    -- Check if name legal format eg no spaces, or special characters
2546    -- If not add quotes : Bug 3723715
2547    --
2548    begin
2549      hr_chkfmt.checkformat (l_user_entity_name, 'DB_ITEM_NAME', l_user_entity_name,
2550                               null,null,'Y',rgeflg,null);
2551    exception
2552      when hr_utility.hr_error then
2553        -- FFHR_6016_ALL_RES_WORDS error condition
2554        -- so add quotes
2555        --Bug 5930272
2556        fnd_message.retrieve(l_message);
2557        l_user_entity_name := '"' || substr(l_user_entity_name, 1, 78) || '"';
2558    end;
2559 --
2560 -- If we are running this via rebuild_ele_input_bal
2561    IF (g_triggers_altered) THEN
2562    -- Get the startup mode
2563      startup_mode := ffstup.get_mode (p_business_group_id,
2564                                       p_legislation_code);
2565    --
2566    -- Check the name is OK
2567    --
2568    -- validate the name is OK. This was originally called as part of
2569    -- the FF_USER_ENTITIES_BRI trigger so we add it here.
2570 
2571      begin
2572        -- Check if name legal format eg no spaces, or special characters
2573        hr_chkfmt.checkformat (l_user_entity_name, 'DB_ITEM_NAME', l_user_entity_name,
2574                               null,null,'Y',rgeflg,null);
2575      exception
2576        when hr_utility.hr_error then
2577          hr_utility.set_message (802, 'FFHR_6016_ALL_RES_WORDS');
2578          hr_utility.set_message_token(802,'VALUE_NAME','FF94_USER_ENTITY');
2579          hrrbdeib_trace_on;
2580          hr_utility.trace('chkfmt DB_ITEM_NAME');
2581          hr_utility.trace('ue: ' || l_user_entity_name);
2582          hr_utility.trace('route_name: ' || p_route_name);
2583          hr_utility.trace('creator_id: ' || to_char(p_creator_id));
2584          hr_utility.trace('creator_type: ' || p_creator_type);
2585          hr_utility.trace('rgeflg: ' || rgeflg);
2586          hrrbdeib_trace_off;
2587          raise;
2588      end;
2589    END IF; -- g_triggers_altered
2590 --
2591 -- Check if entity already exists before inserting it
2592 
2593     select count(*)
2594     into   l_dummy_fetch_var
2595     from   ff_user_entities
2596     where  user_entity_name = l_user_entity_name
2597     and    nvl (legislation_code, ' ') = nvl (p_legislation_code, ' ')
2598     and    nvl (business_group_id, -1) = nvl (p_business_group_id, -1);
2599 
2600     IF l_dummy_fetch_var = 0
2601     THEN
2602     --
2603     -- get the route id
2604     --
2605     BEGIN
2606 
2607     SELECT route_id
2608     INTO   l_route_id
2609     FROM   ff_routes
2610     WHERE  route_name         = p_route_name;
2611 
2612     EXCEPTION WHEN OTHERS THEN
2613          hrrbdeib_trace_on;
2614          hr_utility.trace('insert_user_entity_main : missing route : ' ||
2615                            p_route_name);
2616          hrrbdeib_trace_off;
2617          raise;
2618     END;
2619     --
2620     -- populate the ff_user_entities table :
2621     --
2622     BEGIN
2623 
2624     IF (g_triggers_altered) THEN
2625       insert into ff_user_entities (
2626               user_entity_id,
2627               business_group_id,
2628               legislation_code,
2629               route_id,
2630               notfound_allowed_flag,
2631               user_entity_name,
2632               creator_id,
2633               creator_type,
2634               entity_description,
2635               last_update_date,
2636               last_updated_by,
2637               last_update_login,
2638               created_by,
2639               creation_date)
2640       select  l_user_entities_seq,
2641               p_business_group_id,
2642               p_legislation_code,
2643               l_route_id,
2644               p_not_found_flag,
2645               l_user_entity_name,
2646               p_creator_id,
2647               p_creator_type,
2648               p_entity_description,
2649               sysdate,
2650               p_created_by,
2651               p_last_login,
2652               p_created_by,
2653               sysdate
2654       from dual
2655       where not exists (
2656        select null
2657        from ff_user_entities a
2658        where a.user_entity_name = l_user_entity_name
2659        and
2660        ( startup_mode = 'MASTER'
2661          or
2662          ( startup_mode = 'SEED'
2663            and
2664            ( a.legislation_code = p_legislation_code
2665             or
2666            (a.legislation_code is null and a.business_group_id is null)
2667             or
2668             p_legislation_code =
2669             (
2670               select b.legislation_code
2671               from   per_business_groups_perf b
2672               where  b.business_group_id = a.business_group_id
2673             )
2674           )
2675         )
2676         or
2677         ( startup_mode = 'NON-SEED'
2678           and
2679           ( a.business_group_id = p_business_group_id
2680             or
2681             (a.legislation_code is null and a.business_group_id is null)
2682             or
2683             (a.business_group_id is null and a.legislation_code = p_legislation_code)
2684           )
2685         )
2686         ));
2687       ELSE
2688         insert into ff_user_entities (
2689                 user_entity_id,
2690                 business_group_id,
2691                 legislation_code,
2692                 route_id,
2693                 notfound_allowed_flag,
2694                 user_entity_name,
2695                 creator_id,
2696                 creator_type,
2697                 entity_description,
2698                 last_update_date,
2699                 last_updated_by,
2700                 last_update_login,
2701                 created_by,
2702                 creation_date)
2703         values (l_user_entities_seq,
2704                 p_business_group_id,
2705                 p_legislation_code,
2706                 l_route_id,
2707                 p_not_found_flag,
2708                 l_user_entity_name,
2709                 p_creator_id,
2710                 p_creator_type,
2711                 p_entity_description,
2712                 sysdate,
2713                 p_created_by,
2714                 p_last_login,
2715                 p_created_by,
2716                 sysdate);
2717       END IF;
2718         p_record_inserted := TRUE;
2719    EXCEPTION WHEN OTHERS THEN
2720     hrrbdeib_trace_on;
2721     hr_utility.trace('insert ff_user_entities: ue: ' || l_user_entity_name);
2722     hr_utility.trace('insert ff_user_entities: route_name: ' || p_route_name);
2723     hrrbdeib_trace_off;
2724     raise;
2725    END;
2726 
2727     ELSE
2728         p_record_inserted := FALSE;
2729     END IF;
2730 END insert_user_entity_main;
2731 --
2732 --
2733 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2734 --                                                                        +
2735 --                   delete_compiled_formula                              +
2736 --                                                                        +
2737 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2738 /*
2739 NAME
2740       delete_compiled_formula  - Delete any compiled formula references
2741                                  based on a user entity.
2742 --    this version is for when we can't guarantee that the creator id passed
2743 --    in is not null and as such will use a less efficient index. It also
2744 --    ensures that we don't destabailise outside APIs calling into this proc
2745 --    with a potentially null creator_id
2746 --    For internal calls from this package where we know the creator id is
2747 --    not null we will call into a _priv version of this routine.
2748 
2749 DESCRIPTION
2750       This routine is called before certain database items are deleted to
2751       remove all compiled references to them (eg. Descriptive flexs).  Since
2752       the user creates Descriptive flex database items from a concurrent
2753       program which could be run several times, it is necessary to delete them
2754       before the re-creation.
2755 */
2756 procedure delete_compiled_formula
2757 (
2758     p_creator_id            in number,
2759     p_creator_type          in varchar2,
2760     p_user_entity_name      in varchar2,
2761     p_leg_code              in varchar2
2762 ) is
2763 --
2764 cursor get_formula_ids
2765 is
2766 select /* INDEX(fdi FF_FDI_USAGES_F_N50)*/
2767        distinct fdi.formula_id,
2768        fdi.effective_start_date
2769 from
2770       ff_user_entities ent,
2771       ff_database_items dbi,
2772       ff_fdi_usages_f   fdi
2773 where fdi.item_name  = dbi.user_name
2774 and   fdi.usage = 'D'
2775 and   ent.user_entity_id = dbi.user_entity_id
2776 and   ent.creator_type = p_creator_type
2777 and   ent.user_entity_name like p_user_entity_name
2778 and     (nvl (ent.legislation_code, ' ') = nvl (p_leg_code, ' ')
2779    or exists (select null from per_business_groups_perf b
2780               where  ent.business_group_id = b.business_group_id
2781               and nvl(b.legislation_code, p_leg_code) = p_leg_code))
2782 and   nvl(ent.creator_id, -1) = nvl(nvl(p_creator_id, ent.creator_id), -1);
2783 --
2784 num   number;
2785 begin
2786 
2787 for form in get_formula_ids loop
2788 
2789    select count(*)
2790    into   num
2791    from ff_formulas_f f
2792    where form.formula_id = f.formula_id
2793    and   form.effective_start_date = f.effective_start_date
2794    and     (nvl (f.legislation_code, ' ') = nvl (p_leg_code, nvl (f.legislation_code, ' '))
2795       or exists (select null from per_business_groups_perf b
2796                  where  f.business_group_id = b.business_group_id
2797                  and nvl(b.legislation_code, p_leg_code) = p_leg_code));
2798 
2799    if num > 0 then
2800 
2801       delete from ff_fdi_usages_f fdi
2802       where fdi.formula_id = form.formula_id
2803       and   form.effective_start_date = fdi.effective_start_date;
2804 
2805       delete from ff_compiled_info_f fci
2806       where fci.formula_id = form.formula_id
2807       and   form.effective_start_date = fci.effective_start_date;
2808 
2809    end if;
2810 
2811 end loop;
2812 
2813 END delete_compiled_formula;
2814 --
2815 -- Private version
2816 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2817 --                                                                        +
2818 --                   delete_compiled_formula_priv                         +
2819 --                                                                        +
2820 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2821 /*
2822 NAME
2823       delete_compiled_formula_priv  - Delete any compiled formula references
2824                                       based on a user entity. Performant version
2825 --
2826 DESCRIPTION
2827       This routine is called before certain database items are deleted to
2828       remove all compiled references to them (eg. Descriptive flexs).  Since
2829       the user creates Descriptive flex database items from a concurrent
2830       program which could be run several times, it is necessary to delete them
2831       before the re-creation.
2832       Private version for performance. See note on del_comp_form for more info
2833 */
2834 procedure delete_compiled_formula_priv
2835 (
2836     p_creator_id            in number,
2837     p_creator_type          in varchar2,
2838     p_user_entity_name      in varchar2,
2839     p_leg_code              in varchar2
2840 ) is
2841 --
2842 l_formula_ids dbms_sql.number_table;
2843 l_start_dates dbms_sql.date_table;
2844 begin
2845 
2846 delete ff_fdi_usages_f fdi
2847 where  FDI.usage = 'D'
2848 and exists (select null
2849             from ff_formulas_f f
2850             where fdi.formula_id = f.formula_id
2851             and     (nvl (f.legislation_code, ' ') = nvl (p_leg_code, nvl (f.legislation_code, ' '))
2852                              or exists (select null from per_business_groups_perf b
2853                                         where  f.business_group_id = b.business_group_id
2854                                         and nvl(b.legislation_code, p_leg_code) = p_leg_code)))
2855 and exists (select null from
2856               ff_database_items dbi
2857               where fdi.item_name  = dbi.user_name
2858               and exists (select /*+ INDEX(ent FF_USER_ENTITIES_N51)*/ null from
2859                           ff_user_entities ent
2860                           where   ent.user_entity_id = dbi.user_entity_id
2861                           and     ent.creator_id = p_creator_id
2862                           and     ent.creator_type = p_creator_type
2863                           and     ent.user_entity_name like p_user_entity_name
2864                           and     (nvl (ent.legislation_code, ' ') = nvl (p_leg_code, ' ')
2865                              or exists (select null from per_business_groups_perf b
2866                                         where  ent.business_group_id = b.business_group_id
2867                                         and nvl(b.legislation_code, p_leg_code) = p_leg_code))
2868                           ))
2869 returning fdi.formula_id, fdi.effective_start_date
2870 bulk collect into l_formula_ids, l_start_dates
2871 ;
2872 
2873 ff_compiled_info_del
2874 (p_formula_ids => l_formula_ids
2875 ,p_start_dates => l_start_dates
2876 );
2877 
2878 END delete_compiled_formula_priv;
2879 --
2880 --
2881 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2882 --                                                                        +
2883 --                   ff_compiled_info_del                                 +
2884 --                                                                        +
2885 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2886 /*
2887   NAME
2888     ff_compiled_info_del
2889 
2890   DESCRIPTION
2891     Bulk delete FF_COMPILED_INFO_F using FORMULA_ID and
2892     EFFECTIVE_START_DATE from FF_FDI_USAGES_F.
2893 */
2894 procedure ff_compiled_info_del
2895 (p_formula_ids dbms_sql.number_table
2896 ,p_start_dates dbms_sql.date_table
2897 ) is
2898 l_iterations  number;
2899 l_chunksize   binary_integer := 250;
2900 l_upper_limit binary_integer;
2901 l_lower_limit binary_integer;
2902 begin
2903   --
2904   -- Code will delete l_chunksize rows at most per iteration.
2905   --
2906   l_iterations := trunc(p_formula_ids.count / l_chunksize);
2907   if l_iterations * l_chunksize < p_formula_ids.count then
2908     l_iterations := 1 + l_iterations;
2909   end if;
2910 
2911   l_lower_limit := 1;
2912   l_upper_limit := l_chunksize;
2913   for i in 1 .. l_iterations loop
2914 
2915     if l_upper_limit > p_formula_ids.count then
2916       l_upper_limit := p_formula_ids.count;
2917     end if;
2918 
2919     forall j in l_lower_limit .. l_upper_limit
2920       delete
2921       from   ff_compiled_info_f
2922       where  formula_id = p_formula_ids(j)
2923       and    effective_start_date = p_start_dates(j)
2924       ;
2925 
2926     l_lower_limit := l_upper_limit + 1;
2927     l_upper_limit := l_upper_limit + l_chunksize;
2928   end loop;
2929 end ff_compiled_info_del;
2930 --
2931 --
2932 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2933 --                                                                        +
2934 --                   delete_element_type_dict                             +
2935 --                                                                        +
2936 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2937 /*
2938 NAME
2939       delete_element_type_dict - delete an element type from the data
2940                                  dictionary
2941 --
2942 DESCRIPTION
2943 */
2944 procedure delete_element_type_dict
2945 (
2946     p_element_type_id       in number
2947 ) is
2948 --
2949 BEGIN
2950 
2951 --    delete_compiled_formula_priv(p_element_type_id, 'E', '%', null);
2952 
2953     DELETE FROM ff_user_entities
2954     WHERE  creator_id    = p_element_type_id
2955     AND    creator_type  = 'E';
2956 END delete_element_type_dict;
2957 --
2958 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2959 --                                                                        +
2960 --                     create_element_type                                +
2961 --                                                                        +
2962 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2963 /*
2964    NAME
2965       create_element_type      - create an element type in the data
2966                                  dictionary, with a context of either date
2967                                  earned or date paid.
2968 --
2969    DESCRIPTION
2970       This procedure creates element type database items for a given element
2971       type id, with a context of either date earned or date paid.  Date paid
2972       database items have '_DP' appended to the database name. To create date
2973       earned DB items, set the paramater 'p_date_p' to null.  To create date
2974       paid DB items, set it to '_DP'.
2975       The routes must have already been defined in the
2976       database (in table ff_routes).  The procedure will search for the
2977       routes in this table by using the route name, which is hard coded below.
2978       The procedure processes each route in turn, creating a user entity and
2979       route parameter values, and then inserting each database items for that
2980       particular route.
2981       The database items created use the element type name. This routine
2982       generates the following database items:
2983       --
2984       <NAME>_REPORTING_NAME
2985       <NAME>_PRIMARY_CLASSIFICATION
2986       <NAME>_INPUT_CURRENCY_CODE
2987       <NAME>_OUTPUT_CURRENCY_CODE
2988       <NAME>_PROCESSING_PRIORITY
2989       <NAME>_CLOSED_FOR_ENTRY
2990       <NAME>_CLOSED_FOR_ENTRY_CODE
2991       <NAME>_END_DATE
2992       <NAME>_QUALIFYING_LENGTH_OF_SERVICE
2993       <NAME>_QUALIFYING_UNITS
2994       <NAME>_QUALIFYING_UNITS_CODE
2995       <NAME>_QUALIFYING_AGE
2996       <NAME>_STANDARD_LINK
2997       <NAME>_STANDARD_LINK_CODE
2998       <NAME>_COSTABLE_TYPE
2999       <NAME>_COSTABLE_TYPE_CODE
3000       <NAME>_COUNT
3001 */
3002 procedure create_element_type
3003 (
3004     p_element_type_id       in number,
3005     p_effective_date        in date,
3006     p_date_p                in varchar2
3007 ) is
3008 cursor get_title is
3009    select title from fnd_descriptive_flexs_vl
3010    where descriptive_flexfield_name = 'Element Developer DF'
3011    and   application_id             = 801;
3012 --
3013 cursor c_language is
3014   select language_code
3015   from   fnd_languages
3016   where  installed_flag in ('I','B');
3017 --
3018 l_title               varchar2(80);
3019 l_route1_name varchar2(50):= 'ELEMENT_TYPE_AT_TYPE_LEVEL' || p_date_p;
3020 l_route2_name varchar2(50):= 'ELEMENT_TYPE_AT_ASSIGNMENT_LEVEL' || p_date_p;
3021 l_route3_name varchar2(50):= 'ELEMENT_TYPE_COUNT_OF_ELEMENT_ENTRIES'||p_date_p;
3022 l_created_by          number;
3023 l_last_login          number;
3024 l_dbitem_found        boolean;
3025 l_record_inserted     boolean;
3026 
3027 l_benefit_class_id    number;
3028 l_class_name          pay_element_classifications.classification_name%type;
3029 l_business_group_id   number;
3030 l_element_name        pay_element_types_f.element_name%type;
3031 l_legislation_code    pay_element_types_f.legislation_code%type;
3032 l_leg_code_class      pay_element_types_f.legislation_code%type;
3033 l_full_mls            boolean;
3034 l_base_dbi_name       varchar2(2000);
3035 l_user_entity_id      number;
3036 l_dbi_prefixes        t_dbi_prefixes;
3037 l_languages           dbms_sql.varchar2s;
3038 l_startup_mode        varchar2(100);
3039 l_legislation_code1   pay_element_types_f.legislation_code%type;
3040 --
3041 ------------------------- create_element_type -------------------------
3042 --
3043 BEGIN
3044     --
3045     -- get the element type information
3046     --
3047     begin
3048         select replace (ltrim (rtrim (upper (ETYPE.element_name))), ' ', '_'),
3049                ETYPE.business_group_id,
3050                ltrim(rtrim(ETYPE.legislation_code)),
3051                ETYPE.benefit_classification_id,
3052                upper (CLASS.classification_name),
3053                ETYPE.created_by,
3054                ETYPE.last_update_login
3055         into   l_element_name,
3056                l_business_group_id,
3057                l_legislation_code,
3058                l_benefit_class_id,
3059                l_class_name,
3060                l_created_by,
3061                l_last_login
3062         from   pay_element_types_f             ETYPE
3063         ,      pay_element_classifications     CLASS
3064         where  ETYPE.element_type_id         = p_element_type_id
3065         and    p_effective_date        between ETYPE.effective_start_date
3066                                            and ETYPE.effective_end_date
3067         and    CLASS.classification_id       = ETYPE.classification_id;
3068     end;
3069     --
3070     if (g_triggers_altered) then
3071       -- Get the startup mode
3072       l_startup_mode :=
3073       ffstup.get_mode (l_business_group_id, l_legislation_code);
3074     else
3075       -- Get the security group id which won't have been populated yet.
3076       g_security_group_id :=
3077       fnd_global.lookup_security_group('NAME_TRANSLATIONS', 3);
3078     end if;
3079     --
3080     -- Are the database items to be fully translated ?
3081     --
3082     l_legislation_code1 := l_legislation_code;
3083     if l_legislation_code1 is null and l_business_group_id is not null then
3084       select bg.legislation_code
3085       into   l_legislation_code1
3086       from   per_business_groups_perf bg
3087       where  bg.business_group_id = l_business_group_id
3088       ;
3089     end if;
3090     l_full_mls := ff_dbi_utils_pkg.translations_supported(l_legislation_code1);
3091 
3092     --
3093     -- Set up the data for the full MLS case.
3094     --
3095     if l_full_mls then
3096       open c_language;
3097       fetch c_language bulk collect
3098       into l_languages;
3099       close c_language;
3100 
3101       gen_et_dbi_prefixes
3102       (p_element_type_id => p_element_type_id
3103       ,p_languages       => l_languages
3104       ,p_prefixes        => l_dbi_prefixes
3105       );
3106     end if;
3107     --
3108     -- create the user entity for the first route
3109     --
3110     insert_user_entity (l_route1_name,
3111                         l_element_name || '_E1' || p_date_p,
3112                         'entity for '|| l_route1_name,
3113                         'Y',                         -- not found allowed flag
3114                         'E',
3115                         p_element_type_id,
3116                         l_business_group_id,
3117                         l_legislation_code,
3118                         l_created_by,
3119                         l_last_login,
3120                         l_record_inserted);
3121     --
3122     -- only insert parameter values/database items if an entity was inserted
3123     --
3124     IF l_record_inserted THEN
3125         --
3126         -- Fetch the user_entity_id.
3127         --
3128         select  ff_user_entities_s.currval
3129         into    l_user_entity_id
3130         from    dual;
3131         --
3132         -- insert the element type id for the where clause filler
3133         --
3134         insert_parameter_value (p_element_type_id, 1);
3135         --
3136         -- load up the database items for the first route:
3137         --
3138         insert_database_item (l_element_name,
3139                               'REPORTING_NAME' || p_date_p,
3140                               'T',                           -- data type
3141                               'ETYPE.reporting_name',
3142                               'Y',                           -- null allowed
3143                               'reporting name for element type',
3144                               l_user_entity_id,
3145                               l_full_mls,
3146                               l_base_dbi_name);
3147         if l_full_mls then
3148           update_et_tl_dbi_names
3149           (p_leg_code       => l_legislation_code
3150           ,p_bg_id          => l_business_group_id
3151           ,p_startup_mode   => l_startup_mode
3152           ,p_user_name      => l_base_dbi_name
3153           ,p_user_entity_id => l_user_entity_id
3154           ,p_prefixes       => l_dbi_prefixes
3155           ,p_suffix         => 'REPORTING_NAME'
3156           ,p_date_p         => p_date_p
3157           );
3158         end if;
3159         --
3160         insert_database_item (l_element_name,
3161                               'CLASSIFICATION' || p_date_p,
3162                               'T',                           -- data type
3163                               'ECLASS.classification_name',
3164                               'N',                           -- null allowed
3165                               'primary classification name for element type',
3166                               l_user_entity_id,
3167                               l_full_mls,
3168                               l_base_dbi_name);
3169         if l_full_mls then
3170           update_et_tl_dbi_names
3171           (p_leg_code       => l_legislation_code
3172           ,p_bg_id          => l_business_group_id
3173           ,p_startup_mode   => l_startup_mode
3174           ,p_user_name      => l_base_dbi_name
3175           ,p_user_entity_id => l_user_entity_id
3176           ,p_prefixes       => l_dbi_prefixes
3177           ,p_suffix         => 'CLASSIFICATION'
3178           ,p_date_p         => p_date_p
3179           );
3180         end if;
3181         --
3182         insert_database_item (l_element_name,
3183                               'INPUT_CURRENCY_CODE' || p_date_p,
3184                               'T',                           -- data type
3185                               'ETYPE.input_currency_code',
3186                               'Y',                           -- null allowed
3187                               'input currency code for element type',
3188                               l_user_entity_id,
3189                               l_full_mls,
3190                               l_base_dbi_name);
3191         if l_full_mls then
3192           update_et_tl_dbi_names
3193           (p_leg_code       => l_legislation_code
3194           ,p_bg_id          => l_business_group_id
3195           ,p_startup_mode   => l_startup_mode
3196           ,p_user_name      => l_base_dbi_name
3197           ,p_user_entity_id => l_user_entity_id
3198           ,p_prefixes       => l_dbi_prefixes
3199           ,p_suffix         => 'INPUT_CURRENCY_CODE'
3200           ,p_date_p         => p_date_p
3201           );
3202         end if;
3203         --
3204         insert_database_item (l_element_name,
3205                               'OUTPUT_CURRENCY_CODE' || p_date_p,
3206                               'T',                           -- data type
3207                               'ETYPE.output_currency_code',
3208                               'Y',                           -- null allowed
3209                               'output currency code for element type',
3210                               l_user_entity_id,
3211                               l_full_mls,
3212                               l_base_dbi_name);
3213         if l_full_mls then
3214           update_et_tl_dbi_names
3215           (p_leg_code       => l_legislation_code
3216           ,p_bg_id          => l_business_group_id
3217           ,p_startup_mode   => l_startup_mode
3218           ,p_user_name      => l_base_dbi_name
3219           ,p_user_entity_id => l_user_entity_id
3220           ,p_prefixes       => l_dbi_prefixes
3221           ,p_suffix         => 'OUTPUT_CURRENCY_CODE'
3222           ,p_date_p         => p_date_p
3223           );
3224         end if;
3225         --
3226         insert_database_item (l_element_name,
3227                               'PROCESSING_PRIORITY' || p_date_p,
3228                               'N',                           -- data type
3229                               'ETYPE.processing_priority',
3230                               'N',                           -- null allowed
3231                               'processing priority for element type',
3232                               l_user_entity_id,
3233                               l_full_mls,
3234                               l_base_dbi_name);
3235         if l_full_mls then
3236           update_et_tl_dbi_names
3237           (p_leg_code       => l_legislation_code
3238           ,p_bg_id          => l_business_group_id
3239           ,p_startup_mode   => l_startup_mode
3240           ,p_user_name      => l_base_dbi_name
3241           ,p_user_entity_id => l_user_entity_id
3242           ,p_prefixes       => l_dbi_prefixes
3243           ,p_suffix         => 'PROCESSING_PRIORITY'
3244           ,p_date_p         => p_date_p
3245           );
3246         end if;
3247         --
3248         insert_database_item (l_element_name,
3249                               'CLOSED_FOR_ENTRY' || p_date_p,
3250                               'T',                           -- data type
3251                               'CELOOK.meaning',
3252                               'N',                           -- null allowed
3253            'closed for entry flag meaning from the lookup table for element type',
3254                               l_user_entity_id,
3255                               l_full_mls,
3256                               l_base_dbi_name);
3257         if l_full_mls then
3258           update_et_tl_dbi_names
3259           (p_leg_code       => l_legislation_code
3260           ,p_bg_id          => l_business_group_id
3261           ,p_startup_mode   => l_startup_mode
3262           ,p_user_name      => l_base_dbi_name
3263           ,p_user_entity_id => l_user_entity_id
3264           ,p_prefixes       => l_dbi_prefixes
3265           ,p_suffix         => 'CLOSED_FOR_ENTRY'
3266           ,p_date_p         => p_date_p
3267           );
3268         end if;
3269         --
3270         insert_database_item (l_element_name,
3271                               'CLOSED_FOR_ENTRY_CODE' || p_date_p,
3272                               'T',                           -- data type
3273                               'ETYPE.closed_for_entry_flag',
3274                               'N',                           -- null allowed
3275                               'closed for entry flag - Y or N,  for element type',
3276                               l_user_entity_id,
3277                               l_full_mls,
3278                               l_base_dbi_name);
3279         if l_full_mls then
3280           update_et_tl_dbi_names
3281           (p_leg_code       => l_legislation_code
3282           ,p_bg_id          => l_business_group_id
3283           ,p_startup_mode   => l_startup_mode
3284           ,p_user_name      => l_base_dbi_name
3285           ,p_user_entity_id => l_user_entity_id
3286           ,p_prefixes       => l_dbi_prefixes
3287           ,p_suffix         => 'CLOSED_FOR_ENTRY_CODE'
3288           ,p_date_p         => p_date_p
3289           );
3290         end if;
3291         --
3292         insert_database_item (l_element_name,
3293                               'END_DATE' || p_date_p,
3294                               'D',                           -- data type
3295                               'ETYPE.effective_end_date',
3296                               'N',                           -- null allowed
3297                               'effective end date for element type',
3298                               l_user_entity_id,
3299                               l_full_mls,
3300                               l_base_dbi_name);
3301         if l_full_mls then
3302           update_et_tl_dbi_names
3303           (p_leg_code       => l_legislation_code
3304           ,p_bg_id          => l_business_group_id
3305           ,p_startup_mode   => l_startup_mode
3306           ,p_user_name      => l_base_dbi_name
3307           ,p_user_entity_id => l_user_entity_id
3308           ,p_prefixes       => l_dbi_prefixes
3309           ,p_suffix         => 'END_DATE'
3310           ,p_date_p         => p_date_p
3311           );
3312         end if;
3313         --
3314         -- see if there is a benefit classification for this element, and if
3315         -- so generate a DB item for it.
3316         --
3317         if (l_benefit_class_id is not null) then
3318             insert_database_item (l_element_name,
3319                                   'BEN_CLASS' || p_date_p,
3320                                   'T',                           -- data type
3321                                   'BCLASS.benefit_classification_name',
3322                                   'N',                           -- null allowed
3323                                   'The element''s benefit classification',
3324                                   l_user_entity_id,
3325                                   l_full_mls,
3326                                   l_base_dbi_name);
3327           if l_full_mls then
3328             update_et_tl_dbi_names
3329             (p_leg_code       => l_legislation_code
3330             ,p_bg_id          => l_business_group_id
3331             ,p_startup_mode   => l_startup_mode
3332             ,p_user_name      => l_base_dbi_name
3333             ,p_user_entity_id => l_user_entity_id
3334             ,p_prefixes       => l_dbi_prefixes
3335             ,p_suffix         => 'BEN_CLASS'
3336             ,p_date_p         => p_date_p
3337             );
3338           end if;
3339         end if;
3340     END IF;
3341     --
3342     -- create the user entity for the second route
3343     --
3344     insert_user_entity (l_route2_name,
3345                         l_element_name  || '_E2' || p_date_p,
3346                         'entity for '|| l_route2_name,
3347                         'Y',                         -- not found allowed flag
3348                         'E',
3349                         p_element_type_id,
3350                         l_business_group_id,
3351                         l_legislation_code,
3352                         l_created_by,
3353                         l_last_login,
3354                         l_record_inserted);
3355     --
3356     -- only insert parameter values/database items if an entity was inserted
3357     --
3358     IF l_record_inserted THEN
3359         --
3360         -- Fetch the user_entity_id.
3361         --
3362         select  ff_user_entities_s.currval
3363         into    l_user_entity_id
3364         from    dual;
3365         --
3366         -- insert the element type id for the where clause filler
3367         --
3368         insert_parameter_value (p_element_type_id, 1);
3369         --
3370         -- load up the database items for the second route:
3371         --
3372         insert_database_item
3373                         (l_element_name,
3374                          'LENGTH_OF_SERVICE' || p_date_p,
3375                          'N',                           -- data type
3376     'nvl (ELINK.qualifying_length_of_service, ETYPE.qualifying_length_of_service)',
3377                          'Y',                           -- null allowed
3378                          'qualifying length of service for element type',
3379                           l_user_entity_id,
3380                           l_full_mls,
3381                           l_base_dbi_name);
3382         if l_full_mls then
3383           update_et_tl_dbi_names
3384           (p_leg_code       => l_legislation_code
3385           ,p_bg_id          => l_business_group_id
3386           ,p_startup_mode   => l_startup_mode
3387           ,p_user_name      => l_base_dbi_name
3388           ,p_user_entity_id => l_user_entity_id
3389           ,p_prefixes       => l_dbi_prefixes
3390           ,p_suffix         => 'LENGTH_OF_SERVICE'
3391           ,p_date_p         => p_date_p
3392           );
3393         end if;
3394         --
3395         insert_database_item
3396                         (l_element_name,
3397                          'QUALIFYING_UNITS' || p_date_p,
3398                          'T',                           -- data type
3399                          'nvl(hr_general.decode_lookup(''QUALIFYING_UNITS'',ELINK.QUALIFYING_UNITS),hr_general.decode_lookup(''QUALIFYING_UNITS'',ETYPE.QUALIFYING_UNITS))',
3400                          'Y',                           -- null allowed
3401                          'qualifying units from lookup table for element type',
3402                           l_user_entity_id,
3403                           l_full_mls,
3404                           l_base_dbi_name);
3405         if l_full_mls then
3406           update_et_tl_dbi_names
3407           (p_leg_code       => l_legislation_code
3408           ,p_bg_id          => l_business_group_id
3409           ,p_startup_mode   => l_startup_mode
3410           ,p_user_name      => l_base_dbi_name
3411           ,p_user_entity_id => l_user_entity_id
3412           ,p_prefixes       => l_dbi_prefixes
3413           ,p_suffix         => 'QUALIFYING_UNITS'
3414           ,p_date_p         => p_date_p
3415           );
3416         end if;
3417         --
3418         insert_database_item (l_element_name,
3419                           'QUALIFYING_UNITS_CODE' || p_date_p,
3420                           'T',                           -- data type
3421                           'nvl(ELINK.qualifying_units, ETYPE.qualifying_units)',
3422                           'Y',                           -- null allowed
3423                           'qualifying units from database for element type',
3424                           l_user_entity_id,
3425                           l_full_mls,
3426                           l_base_dbi_name);
3427         if l_full_mls then
3428           update_et_tl_dbi_names
3429           (p_leg_code       => l_legislation_code
3430           ,p_bg_id          => l_business_group_id
3431           ,p_startup_mode   => l_startup_mode
3432           ,p_user_name      => l_base_dbi_name
3433           ,p_user_entity_id => l_user_entity_id
3434           ,p_prefixes       => l_dbi_prefixes
3435           ,p_suffix         => 'QUALIFYING_UNITS_CODE'
3436           ,p_date_p         => p_date_p
3437           );
3438         end if;
3439         --
3440         insert_database_item (l_element_name,
3441                           'QUALIFYING_AGE' || p_date_p,
3442                           'N',                           -- data type
3443                           'nvl (ELINK.qualifying_age, ETYPE.qualifying_age)',
3444                           'Y',                           -- null allowed
3445                           'qualifying age for element type',
3446                           l_user_entity_id,
3447                           l_full_mls,
3448                           l_base_dbi_name);
3449         if l_full_mls then
3450           update_et_tl_dbi_names
3451           (p_leg_code       => l_legislation_code
3452           ,p_bg_id          => l_business_group_id
3453           ,p_startup_mode   => l_startup_mode
3454           ,p_user_name      => l_base_dbi_name
3455           ,p_user_entity_id => l_user_entity_id
3456           ,p_prefixes       => l_dbi_prefixes
3457           ,p_suffix         => 'QUALIFYING_AGE'
3458           ,p_date_p         => p_date_p
3459           );
3460         end if;
3461         --
3462         insert_database_item (l_element_name,
3463                           'STANDARD_LINK' || p_date_p,
3464                           'T',                           -- data type
3465                          'nvl(hr_general.decode_lookup(''YES_NO'',ELINK.STANDARD_LINK_FLAG),hr_general.decode_lookup(''YES_NO'',ETYPE.STANDARD_LINK_FLAG))',
3466                           'N',                           -- null allowed
3467  'standard link meaning from lookup table Yes = standard, No = discretionary',
3468                           l_user_entity_id,
3469                           l_full_mls,
3470                           l_base_dbi_name);
3471         if l_full_mls then
3472           update_et_tl_dbi_names
3473           (p_leg_code       => l_legislation_code
3474           ,p_bg_id          => l_business_group_id
3475           ,p_startup_mode   => l_startup_mode
3476           ,p_user_name      => l_base_dbi_name
3477           ,p_user_entity_id => l_user_entity_id
3478           ,p_prefixes       => l_dbi_prefixes
3479           ,p_suffix         => 'STANDARD_LINK'
3480           ,p_date_p         => p_date_p
3481           );
3482         end if;
3483          --
3484         insert_database_item (l_element_name,
3485                           'STANDARD_LINK_CODE' || p_date_p,
3486                           'T',                           -- data type
3487                     'nvl (ELINK.standard_link_flag, ETYPE.standard_link_flag)',
3488                           'N',                           -- null allowed
3489    'standard link value held on the database Y = standard, N = discretionary',
3490                           l_user_entity_id,
3491                           l_full_mls,
3492                           l_base_dbi_name);
3493         if l_full_mls then
3494           update_et_tl_dbi_names
3495           (p_leg_code       => l_legislation_code
3496           ,p_bg_id          => l_business_group_id
3497           ,p_startup_mode   => l_startup_mode
3498           ,p_user_name      => l_base_dbi_name
3499           ,p_user_entity_id => l_user_entity_id
3500           ,p_prefixes       => l_dbi_prefixes
3501           ,p_suffix         => 'STANDARD_LINK_CODE'
3502           ,p_date_p         => p_date_p
3503           );
3504         end if;
3505         --
3506         insert_database_item (l_element_name,
3507                           'COSTABLE_TYPE' || p_date_p,
3508                           'T',                           -- data type
3509                           'CTLOOK.meaning',
3510                           'N',                           -- null allowed
3511                   'costable type meaning from lookup table for element type',
3512                           l_user_entity_id,
3513                           l_full_mls,
3514                           l_base_dbi_name);
3515         if l_full_mls then
3516           update_et_tl_dbi_names
3517           (p_leg_code       => l_legislation_code
3518           ,p_bg_id          => l_business_group_id
3519           ,p_startup_mode   => l_startup_mode
3520           ,p_user_name      => l_base_dbi_name
3521           ,p_user_entity_id => l_user_entity_id
3522           ,p_prefixes       => l_dbi_prefixes
3523           ,p_suffix         => 'COSTABLE_TYPE'
3524           ,p_date_p         => p_date_p
3525           );
3526         end if;
3527     --
3528         insert_database_item (l_element_name,
3529                           'COSTABLE_TYPE_CODE' || p_date_p,
3530                           'T',                           -- data type
3531                           'ELINK.costable_type',
3532                           'N',                           -- null allowed
3533                   'costable type value held on the database for element type',
3534                           l_user_entity_id,
3535                           l_full_mls,
3536                           l_base_dbi_name);
3537         if l_full_mls then
3538           update_et_tl_dbi_names
3539           (p_leg_code       => l_legislation_code
3540           ,p_bg_id          => l_business_group_id
3541           ,p_startup_mode   => l_startup_mode
3542           ,p_user_name      => l_base_dbi_name
3543           ,p_user_entity_id => l_user_entity_id
3544           ,p_prefixes       => l_dbi_prefixes
3545           ,p_suffix         => 'COSTABLE_TYPE_CODE'
3546           ,p_date_p         => p_date_p
3547           );
3548         end if;
3549     end if;
3550     --
3551     -- create the user entity for the third route
3552     --
3553     insert_user_entity (l_route3_name,
3554                         l_element_name || '_E3' || p_date_p,
3555                         'entity for '|| l_route3_name,
3556                         'Y',                         -- not found allowed flag
3557                         'E',
3558                         p_element_type_id,
3559                         l_business_group_id,
3560                         l_legislation_code,
3561                         l_created_by,
3562                         l_last_login,
3563                         l_record_inserted);
3564     --
3565     -- only insert parameter values/database items if an entity was inserted
3566     --
3567     IF l_record_inserted THEN
3568         --
3569         -- Fetch the user_entity_id.
3570         --
3571         select  ff_user_entities_s.currval
3572         into    l_user_entity_id
3573         from    dual;
3574         --
3575         -- insert the element type id for the where clause filler
3576         --
3577         insert_parameter_value (p_element_type_id, 1);
3578         --
3579         -- load up the database items for the third route:
3580         --
3581         insert_database_item (l_element_name,
3582                           'COUNT' || p_date_p,
3583                           'N',                           -- data type
3584                           'count(0)',
3585                           'Y',                           -- null allowed
3586             'count of element types for given assignment and element type',
3587                           l_user_entity_id,
3588                           l_full_mls,
3589                           l_base_dbi_name);
3590         if l_full_mls then
3591           update_et_tl_dbi_names
3592           (p_leg_code       => l_legislation_code
3593           ,p_bg_id          => l_business_group_id
3594           ,p_startup_mode   => l_startup_mode
3595           ,p_user_name      => l_base_dbi_name
3596           ,p_user_entity_id => l_user_entity_id
3597           ,p_prefixes       => l_dbi_prefixes
3598           ,p_suffix         => 'COUNT'
3599           ,p_date_p         => p_date_p
3600           );
3601         end if;
3602     END IF;
3603 
3604     --
3605     -- Now see if any Element Descriptive flexs are to be created:
3606     -- First get a value for the legislation code:
3607     --
3608     select nvl (ltrim(rtrim(ETYPE.legislation_code)),
3609                 ltrim(rtrim(BUSGP.legislation_code)))
3610     into   l_leg_code_class
3611     from   pay_element_types_f             ETYPE
3612     ,      per_business_groups_perf        BUSGP
3613     where  ETYPE.element_type_id         = p_element_type_id
3614     and    p_effective_date        between ETYPE.effective_start_date
3615                                            and ETYPE.effective_end_date
3616     and    BUSGP.business_group_id (+) = ETYPE.business_group_id;
3617     --
3618     l_class_name := l_leg_code_class ||'_'|| l_class_name;
3619     --
3620     --
3621     open get_title;
3622     fetch get_title into l_title;
3623     close get_title;
3624     --
3625     for c1rec in dflex_c1 ('PAY_ELEMENT_TYPES_F',       -- table name
3626                                 l_title,      -- title of desc. flex
3627                                 'N',                         -- global flag
3628                                 l_class_name) loop  -- context code
3629         l_dbitem_found := FALSE;
3630         --
3631         -- now create the database items
3632         --
3633 
3634         for c2rec in dflex_c2 (c1rec.c_flex_name, l_class_name) loop
3635            --
3636            -- only create a user entity if database items are to be created.
3637            --
3638            if (l_dbitem_found = FALSE) then
3639                l_dbitem_found := TRUE;
3640                --
3641                -- create a user entity.
3642                --
3643                l_created_by := c1rec.c_created_by;
3644                l_last_login := c1rec.c_last_login;
3645                --
3646                insert_user_entity (l_route1_name,
3647                                    l_element_name || '_DF_E3' || p_date_p,
3648                                    'Element DDF entity for '|| l_route1_name,
3649                                    'Y',
3650                                    'E',
3651                                    p_element_type_id,
3652                                    l_business_group_id,
3653                                    l_legislation_code,
3654                                    l_created_by,
3655                                    l_last_login,
3656                                    l_record_inserted);
3657                --
3658                -- insert the element type id for the where clause filler
3659                --
3660                IF l_record_inserted
3661                THEN
3662                   insert_parameter_value (p_element_type_id, 1);
3663                END IF;
3664                --
3665            END IF;
3666            --
3667            IF l_record_inserted
3668            THEN
3669                insert_database_item (l_element_name,
3670                                  c2rec.c_db_name || p_date_p,
3671                                  'T',                           -- data type
3672                                  'ETYPE.' || c2rec.c_def_text,
3673                                  'Y',                           -- null allowed
3674                     'Element Descriptive flex DB item for ' || l_element_name);
3675            END IF;
3676         END LOOP;  -- dflex_c2 loop
3677     END LOOP;  -- dflex_c1 loop
3678 --
3679 END create_element_type;
3680 --
3681 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3682 --                                                                        +
3683 --                   create_element_type_dict                             +
3684 --                                                                        +
3685 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3686 /*
3687    NAME
3688       create_element_type_dict - create an element type in the data
3689                                  dictionary
3690 --
3691    DESCRIPTION
3692       This procedure is the main entry point for creating database items for
3693       a given element type, where the context is date earned.  It calls the
3694       element type creation procedure : create_element_type.
3695 */
3696 procedure create_element_type_dict
3697 (
3698     p_element_type_id       in number,
3699     p_effective_date        in date
3700 ) is
3701 --
3702 begin
3703     create_element_type (p_element_type_id,
3704                          p_effective_date,
3705                          null);
3706 end create_element_type_dict;
3707 --
3708 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3709 --                                                                        +
3710 --                   create_element_type_dp_dict                          +
3711 --                                                                        +
3712 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3713 /*
3714    NAME
3715       create_element_type_dp_dict  - create an element type in the data
3716                                      dictionary of context date paid,
3717 --
3718    DESCRIPTION
3719       This procedure is the main entry point for creating database items for
3720       a given element type, where the context is date paid.  It first
3721       deletes all the old DB items for the given element type id, as these DB
3722       items would have been set up to use the context of date earned. It then
3723       calls the element type creation procedure : create_element_type, with the
3724       parameters to create date paid DB items.  This includes deleting and
3725       re-creating input value database items for the given element type.
3726 */
3727 procedure create_element_type_dp_dict
3728 (
3729     p_element_type_id       in number
3730 ) is
3731 --
3732 -- cursor c1 : select input values to be deleted:
3733 --
3734 cursor c1 is
3735 select   input_value_id
3736 from     pay_input_values_f
3737 where    element_type_id   = p_element_type_id;
3738 --
3739 -- cursor c2 : select input values to be used for database items:
3740 --
3741 cursor c2 is
3742 select   input_value_id,
3743          max(effective_end_date) c_date
3744 from     pay_input_values_f
3745 where    generate_db_items_flag = 'Y'
3746 and      element_type_id        = p_element_type_id
3747 group by input_value_id;
3748 --
3749 l_date         date;
3750 l_element_type  number;
3751 begin
3752     --
3753     -- first delete the old element type DB items which use the context of
3754     -- date earned
3755     --
3756     delete_element_type_dict (p_element_type_id);
3757     --
3758     -- create the new DB items with the context of date paid
3759     --
3760     select  element_type_id,
3761             max(effective_end_date)
3762     into    l_element_type,
3763             l_date
3764     from    pay_element_types_f
3765     where   element_type_id = p_element_type_id
3766     group by element_type_id;
3767     --
3768     create_element_type (p_element_type_id,
3769                          l_date,
3770                          '_DP');
3771     --
3772     -- go through and delete any old input values
3773     --
3774     for c1rec in c1 loop
3775         delete_input_value_dict (c1rec.input_value_id);
3776     end loop;   -- c1 loop
3777     --
3778     -- create the new input values with the context of date paid
3779     --
3780     for c2rec in c2 loop
3781         create_input_value (c2rec.input_value_id,
3782                             c2rec.c_date,
3783                             '_DP');
3784     end loop;   -- c2 loop
3785     --
3786 end create_element_type_dp_dict;
3787 --
3788 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3789 --                                                                        +
3790 --                    delete_input_value_dict                             +
3791 --                                                                        +
3792 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3793 /*
3794 NAME
3795       delete_input_value_dict - delete an input value from the data
3796                                 dictionary
3797 --
3798 DESCRIPTION
3799 */
3800 procedure delete_input_value_dict
3801 (
3802     p_input_value_id       in number
3803 ) is
3804 --
3805 BEGIN
3806 
3807 --    delete_compiled_formula_priv(p_input_value_id, 'I', '%', null);
3808 
3809     DELETE FROM ff_user_entities
3810     WHERE  creator_id    = p_input_value_id
3811     AND    creator_type  = 'I';
3812 END delete_input_value_dict;
3813 --
3814 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3815 --                                                                        +
3816 --                       create_input_value                               +
3817 --                                                                        +
3818 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3819 /*
3820    NAME
3821       create_input_value       - create an element type in the data
3822                                  dictionary, with a context of either date
3823                                  earned or date paid.
3824 --
3825    DESCRIPTION
3826       This procedure creates input value database items for a given input value
3827       id, with a context of either date earned or date paid.  Date paid
3828       database items have '_DP' appended to the database name. To create date
3829       earned DB items, set the paramater 'p_date_p' to null.  To create date
3830       paid DB items, set it to '_DP'.
3831       The routes must have already been defined in the
3832       database (in table ff_routes).  The procedure will search for the
3833       routes in this table by using the route name, which is hard coded below.
3834       The procedure processes each route in turn, creating a user entity and
3835       route parameter values, and then inserting each database items for that
3836       particular route.
3837       The database items created use the input value name. This routine
3838       generates the following database items:
3839       --
3840       <NAME>_UNIT_OF_MEASURE
3841       <NAME>_UNIT_OF_MEASURE_CODE
3842       <NAME>_DEFAULT
3843       <NAME>_MINIMUM
3844       <NAME>_MAXIMUM
3845       --
3846       The following database items are created if multiple entries are NOT
3847       allowed:
3848       --
3849       <NAME>_ENTRY_VALUE
3850       <NAME>_USER_ENTERED_CODE
3851       <NAME>_START_DATE
3852       <NAME>_END_DATE
3853       --
3854       The following database item is created if the multiple entries are
3855       allowed:
3856       --
3857       <NAME>_ENTRY_VALUE             (sum of all non recurring values)
3858 */
3859 procedure create_input_value
3860 (
3861     p_input_value_id       in number,
3862     p_effective_date       in date,
3863     p_date_p               in varchar2
3864 ) is
3865 l_route1_name  varchar2(50) := 'INPUT_VALUE_FROM_INPUT_VALUE_TABLE' ||p_date_p;
3866 l_route2_name  varchar2(50) := 'INPUT_VALUE_USING_PARTIAL_MATCHING' ||p_date_p;
3867 l_entry_route  varchar2(50) := 'INPUT_VALUE_ENTRY_LEVEL' || p_date_p;
3868 l_override_entry_route  varchar2(50) := 'INPUT_VALUE_ENTRY_LEVEL_OVERRIDE' || p_date_p;
3869 l_input_name          pay_input_values_f.name%type;
3870 l_entity_name         ff_user_entities.user_entity_name%type;
3871 l_element_type_id     pay_element_types_f.element_type_id%type;
3872 l_element_name        pay_element_types_f.element_name%type;
3873 l_multiple_entries    pay_element_types_f.multiple_entries_allowed_flag%type;
3874 l_legislation_code    pay_element_types_f.legislation_code%type;
3875 l_leg_code_ben        pay_element_types_f.legislation_code%type;
3876 l_uom                 varchar2(30);  -- unit of measure
3877 l_business_group_id   number;
3878 l_start_string        varchar2(240);
3879 l_end_string          varchar2(240);
3880 l_data_type           varchar2(1);
3881 l_created_by          number;
3882 l_last_login          number;
3883 l_record_inserted     boolean;
3884 l_full_mls            boolean;
3885 l_base_dbi_name       varchar2(2000);
3886 l_user_entity_id      number;
3887 l_legislation_code1   pay_element_types_f.legislation_code%type;
3888 l_startup_mode        varchar2(30);
3889 l_languages           dbms_sql.varchar2s;
3890 l_dbi_prefixes        t_dbi_prefixes;
3891 --
3892 -- debug info
3893 l_iv_eltypeid number;
3894 
3895 --
3896 cursor c_language is
3897   select language_code
3898   from   fnd_languages
3899   where  installed_flag in ('I','B');
3900 
3901 cursor c_list_ivs(p_iv_id in number) is
3902   select name,
3903          element_type_id,
3904          to_char(effective_start_date, 'DD-MM-YYYY') esd,
3905          to_char(effective_end_date, 'DD-MM-YYYY') eed,
3906          legislation_code,
3907          business_group_id
3908   from   pay_input_values_f
3909   where  input_value_id = p_iv_id;
3910 
3911 cursor c_list_elements(p_el_id in number) is
3912   select element_name,
3913          to_char(effective_start_date, 'DD-MM-YYYY') esd,
3914          to_char(effective_end_date, 'DD-MM-YYYY') eed,
3915          legislation_code,
3916          business_group_id
3917   from   pay_element_types_f
3918   where  element_type_id = p_el_id;
3919 
3920 -- This procedure is used to translate hardcoded "Pay Value"
3921 -- for each language installed.
3922 --
3923 PROCEDURE local_insert_database_item (
3924     p_item_name            in  varchar2,
3925     p_data_type            in  varchar2,
3926     p_definition_text      in  varchar2,
3927     p_null_allowed_flag    in  varchar2,
3928     p_description          in  varchar2,
3929     p_user_entity_id       in  number,
3930     p_full_mls             in  boolean,
3931     p_base_dbi_name        out nocopy varchar2)
3932 IS
3933 BEGIN
3934     --
3935     -- NB attention spaces ' ' of l_input_name are not replaced with underscore '_'.
3936     --
3937     --    call to insert_database_item to handle Pay_Value issue : Bug 1110849
3938     --    where if the input value found is Pay Value get dbitem created
3939     --    to contain the translated value for Pay Value by passing the input value
3940     --    name within the second parameter which goes through translation
3941     --    lookup in insert_database_item.
3942     --
3943     if l_input_name = 'PAY VALUE' and not p_full_mls then
3944        insert_database_item (l_element_name,
3945                              l_input_name || '_' || p_item_name || p_date_p,
3946                              p_data_type,
3947                              p_definition_text,
3948                              p_null_allowed_flag,
3949                              p_description,
3950                              p_user_entity_id,
3951                              p_full_mls,
3952                              p_base_dbi_name);
3953     else
3954        insert_database_item (l_entity_name,
3955                              p_item_name || p_date_p,
3956                              p_data_type,
3957                              p_definition_text,
3958                              p_null_allowed_flag,
3959                              p_description,
3960                              p_user_entity_id,
3961                              p_full_mls,
3962                              p_base_dbi_name);
3963     end if;
3964 END local_insert_database_item;
3965 --
3966 -- NOTE:  The variable 'l_entity_name' is used to hold both the element type
3967 -- name concatenated with the input value name.  This exceeds the maximum
3968 -- length of the database item name.  On attempting to create the associated
3969 -- db item, it is possible that the constructed name will exceed this maximum.
3970 -- We rely on this being trapped by the insert statement failing.
3971 --
3972 ------------------------- create_input_value -----------------------------
3973 --
3974 BEGIN
3975     --
3976     -- get the input and element type information
3977     --
3978     BEGIN
3979     select ltrim (rtrim (upper (INPUTV.name))),
3980            INPUTV.uom,
3981            INPUTV.business_group_id,
3982            ltrim(rtrim(INPUTV.legislation_code)),
3983            INPUTV.created_by,
3984            INPUTV.last_update_login,
3985            ET.element_type_id,
3986            replace (ltrim (rtrim (upper (ET.element_name))), ' ', '_'),
3987            ET.multiple_entries_allowed_flag
3988     into   l_input_name,
3989            l_uom,
3990            l_business_group_id,
3991            l_legislation_code,
3992            l_created_by,
3993            l_last_login,
3994            l_element_type_id,
3995            l_element_name,
3996            l_multiple_entries
3997     from   pay_input_values_f              INPUTV
3998     ,      pay_element_types_f             ET
3999     where  INPUTV.input_value_id         = p_input_value_id
4000     and    p_effective_date        between INPUTV.effective_start_date
4001                                        and INPUTV.effective_end_date
4002     and    ET.element_type_id            = INPUTV.element_type_id
4003     and    p_effective_date        between ET.effective_start_date
4004                                        and ET.effective_end_date;
4005     EXCEPTION WHEN OTHERS THEN
4006      BEGIN
4007       hrrbdeib_trace_on;
4008       hr_utility.trace('create_input_value select');
4009       hr_utility.trace('effective_date: ' ||
4010         to_char(p_effective_date, 'DD-MM-YYYY'));
4011       hr_utility.trace('input_value_id : ' || to_char(p_input_value_id));
4012 
4013       FOR iv IN c_list_ivs(p_input_value_id) LOOP
4014         hr_utility.trace('input name: ' || iv.name);
4015         hr_utility.trace('input el_type_id: ' ||
4016           to_char(iv.element_type_id));
4017         hr_utility.trace('input leg_code: ' || iv.legislation_code);
4018         hr_utility.trace('input BG id: ' || to_char(iv.business_group_id));
4019         hr_utility.trace('input ESD: ' || iv.esd);
4020         hr_utility.trace('input EED: ' || iv.eed);
4021       END LOOP;
4022 
4023       select distinct element_type_id
4024       into   l_iv_eltypeid
4025       from   pay_input_values_f
4026       where  input_value_id = p_input_value_id
4027       and    rownum = 1;
4028 
4029       FOR el in c_list_elements(l_iv_eltypeid) LOOP
4030         hr_utility.trace('element name: ' || el.element_name);
4031         hr_utility.trace('element ESD: ' || el.esd);
4032         hr_utility.trace('element EED: ' || el.eed);
4033         hr_utility.trace('element leg_code: ' || el.legislation_code);
4034         hr_utility.trace('element BG id: ' || to_char(el.business_group_id));
4035       END LOOP;
4036       hrrbdeib_trace_off;
4037       raise;
4038       END;
4039     END;
4040     --
4041     if (g_triggers_altered) then
4042       -- Get the startup mode
4043       l_startup_mode :=
4044       ffstup.get_mode (l_business_group_id, l_legislation_code);
4045     else
4046       -- Get the security group id which won't have been populated yet.
4047       g_security_group_id :=
4048       fnd_global.lookup_security_group('NAME_TRANSLATIONS', 3);
4049     end if;
4050     --
4051     -- Are the database items to be fully translated ?
4052     --
4053     l_legislation_code1 := l_legislation_code;
4054     if l_legislation_code1 is null and l_business_group_id is not null then
4055       select bg.legislation_code
4056       into   l_legislation_code1
4057       from   per_business_groups_perf bg
4058       where  bg.business_group_id = l_business_group_id
4059       ;
4060     end if;
4061     l_full_mls := ff_dbi_utils_pkg.translations_supported(l_legislation_code1);
4062 
4063     --
4064     -- Set up the data for the full MLS case.
4065     --
4066     if l_full_mls then
4067       open c_language;
4068       fetch c_language bulk collect
4069       into l_languages;
4070       close c_language;
4071 
4072       gen_eiv_dbi_prefixes
4073       (p_input_value_id => p_input_value_id
4074       ,p_effective_date => p_effective_date
4075       ,p_languages      => l_languages
4076       ,p_prefixes       => l_dbi_prefixes
4077       );
4078     end if;
4079     --
4080     -- assemble the entity name:
4081     -- nb spaces ' ' of l_input_name are not replaced with underscore '_'.
4082     --    now pass l_entity_name to insert_user_entity and
4083     --    use local_insert_database_item instead of direct call to
4084     --    insert_database_item to handle Pay_Value issue : Bug 1110849
4085     --    where if the input value found is Pay value get dbitem created
4086     --    to contain the translated value for Pay Value.
4087     --
4088     -- Bug 2936561. Remove full stops from input value nams prior to
4089     -- ue and dbi creation.
4090     --
4091     l_entity_name := l_element_name || '_' || replace(replace(l_input_name,' ','_'),
4092                                                       '.','');
4093     --
4094     -- create the user entity for the first route
4095     --
4096     insert_user_entity (l_route1_name,
4097                         l_entity_name || '_I1' || p_date_p,
4098                         'entity for '|| l_route1_name,
4099                         'Y',                        -- not found allowed flag
4100                         'I',
4101                         p_input_value_id,
4102                         l_business_group_id,
4103                         l_legislation_code,
4104                         l_created_by,
4105                         l_last_login,
4106                         l_record_inserted);
4107     --
4108     -- only insert parameter values/database items if an entity was inserted
4109     --
4110     IF l_record_inserted THEN
4111         --
4112         -- Fetch the user_entity_id.
4113         --
4114         select  ff_user_entities_s.currval
4115         into    l_user_entity_id
4116         from    dual;
4117         --
4118         -- insert the input value id for the where clause filler
4119         --
4120         insert_parameter_value (p_input_value_id, 1);
4121         --
4122         -- load up the database items for the first route:
4123         --
4124         local_insert_database_item (
4125                           'UNIT_OF_MEASURE',
4126                           'T',                           -- data type
4127                           'UMLOOK.meaning',
4128                           'N',                           -- null allowed
4129                           'unit of measure from lookup table for input value',
4130                           l_user_entity_id,
4131                           l_full_mls,
4132                           l_base_dbi_name);
4133         --
4134         if l_full_mls then
4135           update_et_tl_dbi_names
4136           (p_leg_code       => l_legislation_code
4137           ,p_bg_id          => l_business_group_id
4138           ,p_startup_mode   => l_startup_mode
4139           ,p_user_name      => l_base_dbi_name
4140           ,p_user_entity_id => l_user_entity_id
4141           ,p_prefixes       => l_dbi_prefixes
4142           ,p_suffix         => 'UNIT_OF_MEASURE'
4143           ,p_date_p         => p_date_p
4144           );
4145         end if;
4146         --
4147         local_insert_database_item (
4148                           'UNIT_OF_MEASURE_CODE',
4149                           'T',                           -- data type
4150                           'INPUTV.uom',
4151                           'N',                           -- null allowed
4152                        'unit of measure held on the database for input value',
4153                           l_user_entity_id,
4154                           l_full_mls,
4155                           l_base_dbi_name);
4156         --
4157         if l_full_mls then
4158           update_et_tl_dbi_names
4159           (p_leg_code       => l_legislation_code
4160           ,p_bg_id          => l_business_group_id
4161           ,p_startup_mode   => l_startup_mode
4162           ,p_user_name      => l_base_dbi_name
4163           ,p_user_entity_id => l_user_entity_id
4164           ,p_prefixes       => l_dbi_prefixes
4165           ,p_suffix         => 'UNIT_OF_MEASURE_CODE'
4166           ,p_date_p         => p_date_p
4167           );
4168         end if;
4169     END IF;
4170     --
4171     -- create the user entity for the second route
4172     --
4173     insert_user_entity (l_route2_name,
4174                         l_entity_name || '_I2' || p_date_p,
4175                         'entity for '|| l_route2_name,
4176                         'Y',                        -- not found allowed flag
4177                         'I',
4178                         p_input_value_id,
4179                         l_business_group_id,
4180                         l_legislation_code,
4181                         l_created_by,
4182                         l_last_login,
4183                         l_record_inserted);
4184     --
4185     l_start_string := null;
4186     l_end_string   := null;
4187     --
4188     -- note : If several input values that use the same route are created in
4189     -- a formula, then formula will fetch them all at once in one cursor. A
4190     -- problem arises when the database item has a user definable data type,
4191     -- for example input values.  If several items are used within the same
4192     -- formula and the data types are different, formula will fetch them all
4193     -- in one cursor and get confused about which data types belong to which
4194     -- items.  To avoid this the decode statment is added to the definition
4195     -- text for the DB item.
4196     --
4197     if (l_uom = 'D') then   -- a date, all formula dates to be in cannonical format
4198         l_start_string := 'fnd_date.canonical_to_date(decode(substr(INPUTV.uom,1,1),''D'',';
4199         l_end_string   := ',null))';
4200         l_data_type    := 'D';
4201     elsif (l_uom = 'M') or (l_uom = 'N') or (l_uom = 'I') then
4202         l_start_string := 'fffunc.cn(decode(
4203     decode(INPUTV.uom,''M'',''N'',''N'',''N'',''I'',''N'',null),''N'',';
4204         l_end_string   := ',null))';
4205         l_data_type    := 'N';
4206     elsif (l_uom like 'H_%') then
4207         l_start_string := 'fffunc.cn(decode(
4208     decode(substr(INPUTV.uom,1,2),''H_'',''N'',null),''N'',';
4209         l_end_string   := ',null))';
4210         l_data_type    := 'N';
4211     else
4212         l_data_type    := 'T';
4213     end if;
4214     --
4215     -- only insert parameter values/database items if an entity was inserted
4216     --
4217     IF l_record_inserted THEN
4218         --
4219         -- Fetch the user_entity_id.
4220         --
4221         select  ff_user_entities_s.currval
4222         into    l_user_entity_id
4223         from    dual;
4224         --
4225         -- insert the input value id for the where clause filler
4226         --
4227         insert_parameter_value (p_input_value_id, 1);
4228         --
4229         -- load up the database items for the second route:
4230         --
4231         -- arrange the values to be displayed in the format specified by the UOM
4232         local_insert_database_item (
4233                           'DEFAULT',
4234                           l_data_type,                 -- data type
4235 l_start_string||'nvl(LIV.default_value,INPUTV.default_value)'|| l_end_string,
4236                           'Y',                           -- null allowed
4237                           'default value for input value',
4238                           l_user_entity_id,
4239                           l_full_mls,
4240                           l_base_dbi_name);
4241         --
4242         if l_full_mls then
4243           update_et_tl_dbi_names
4244           (p_leg_code       => l_legislation_code
4245           ,p_bg_id          => l_business_group_id
4246           ,p_startup_mode   => l_startup_mode
4247           ,p_user_name      => l_base_dbi_name
4248           ,p_user_entity_id => l_user_entity_id
4249           ,p_prefixes       => l_dbi_prefixes
4250           ,p_suffix         => 'DEFAULT'
4251           ,p_date_p         => p_date_p
4252           );
4253         end if;
4254         --
4255         local_insert_database_item (
4256                           'MIN',
4257                           l_data_type,                 -- data type
4258  l_start_string || 'nvl(LIV.min_value,INPUTV.min_value)' || l_end_string,
4259                           'Y',                           -- null allowed
4260                           'minimum value for input value',
4261                           l_user_entity_id,
4262                           l_full_mls,
4263                           l_base_dbi_name);
4264         --
4265         if l_full_mls then
4266           update_et_tl_dbi_names
4267           (p_leg_code       => l_legislation_code
4268           ,p_bg_id          => l_business_group_id
4269           ,p_startup_mode   => l_startup_mode
4270           ,p_user_name      => l_base_dbi_name
4271           ,p_user_entity_id => l_user_entity_id
4272           ,p_prefixes       => l_dbi_prefixes
4273           ,p_suffix         => 'MIN'
4274           ,p_date_p         => p_date_p
4275           );
4276         end if;
4277         --
4278         local_insert_database_item (
4279                           'MAX',
4280                           l_data_type,                 -- data type
4281  l_start_string || 'nvl(LIV.max_value,INPUTV.max_value)' || l_end_string,
4282                           'Y',                           -- null allowed
4283                           'maximum value for input value',
4284                           l_user_entity_id,
4285                           l_full_mls,
4286                           l_base_dbi_name);
4287         --
4288         if l_full_mls then
4289           update_et_tl_dbi_names
4290           (p_leg_code       => l_legislation_code
4291           ,p_bg_id          => l_business_group_id
4292           ,p_startup_mode   => l_startup_mode
4293           ,p_user_name      => l_base_dbi_name
4294           ,p_user_entity_id => l_user_entity_id
4295           ,p_prefixes       => l_dbi_prefixes
4296           ,p_suffix         => 'MAX'
4297           ,p_date_p         => p_date_p
4298           );
4299         end if;
4300     END IF;
4301     --
4302     -- now create database items depending whether the element is recurring
4303     -- or non-recurring
4304     --
4305     if (l_multiple_entries = 'N') then    -- multiple entries not allowed
4306         begin
4307             -- note: These non multi entry database items share the same route
4308             -- as the multi entry DB item which has a group function (a 'sum'
4309             -- function) as part of its definition text. Therefore these DB
4310             -- items must also have a dummy group function ('min') as part
4311             -- of their definition text even though they will only return one
4312             -- row.
4313             -- This is to allow for the case when a formula has both
4314             -- types of these DB items, as it will use the same
4315             -- cursor for both sets of DB items.  This would result in an
4316             -- illegal SQL statement, where it was missing a 'group by'
4317             -- clause. Since the 'group by' clause cannot be part of the route,
4318             -- all of the following DB items must contain a dummy group
4319             -- function.  Also, since null is returned for a group function
4320             -- with no rows, the null allowed flag must be set to 'yes'.
4321             --
4322             -- The only other solution to this problem would be to have 2
4323             -- identical routes, one for multi entry allowed, the other for
4324             -- non multi entry allowed.  Since we wanted to minimise the
4325             -- number of routes, this solution was not implemented.
4326             --
4327             --
4328             -- create the user entity for the non multiple entry types
4329             --
4330             insert_user_entity (l_entry_route,
4331                                 l_entity_name || '_I3' || p_date_p,
4332                              'non multiple entry entity for '|| l_entry_route,
4333                                 'Y',                 -- not found allowed flag
4334                                 'I',
4335                                 p_input_value_id,
4336                                 l_business_group_id,
4337                                 l_legislation_code,
4338                                 l_created_by,
4339                                 l_last_login,
4340                                 l_record_inserted);
4341             --
4342             -- only insert parameter values/database items if entity
4343             -- was inserted
4344             --
4345             IF l_record_inserted THEN
4346                 --
4347                 -- Fetch the user_entity_id.
4348                 --
4349                 select  ff_user_entities_s.currval
4350                 into    l_user_entity_id
4351                 from    dual;
4352                 --
4353                 -- insert the input value id for the where clause filler
4354                 --
4355                 insert_parameter_value (p_input_value_id, 1);
4356                 --
4357                 -- insert the element type id for the 2nd where clause filler
4358                 --
4359                 IF p_date_p IS NULL THEN
4360                   insert_parameter_value (l_element_type_id, 2);
4361                 END IF;
4362                 --
4363                 -- load up the database items for the non multiple entry types:
4364                 --
4365                 local_insert_database_item (
4366                                   'ENTRY_VALUE',
4367                                   l_data_type,              -- data type
4368                                   'min (' || l_start_string ||
4369 'decode(INPUTV.hot_default_flag,''Y'',nvl(EEV.screen_entry_value,
4370 nvl(LIV.default_value,INPUTV.default_value)),''N'',EEV.screen_entry_value)'
4371                                   || l_end_string || ')',
4372                                   'Y',                        -- null allowed
4373                                   'the recurring value',
4374                                   l_user_entity_id,
4375                                   l_full_mls,
4376                                   l_base_dbi_name);
4377                 --
4378                 if l_full_mls then
4379                   update_et_tl_dbi_names
4380                   (p_leg_code       => l_legislation_code
4381                   ,p_bg_id          => l_business_group_id
4382                   ,p_startup_mode   => l_startup_mode
4383                   ,p_user_name      => l_base_dbi_name
4384                   ,p_user_entity_id => l_user_entity_id
4385                   ,p_prefixes       => l_dbi_prefixes
4386                   ,p_suffix         => 'ENTRY_VALUE'
4387                   ,p_date_p         => p_date_p
4388                   );
4389                 end if;
4390                 --
4391                 local_insert_database_item (
4392                                   'USER_ENTERED_CODE',
4393                                   'T',                        -- data type
4394                   'min(decode(EEV.screen_entry_value,null,''N'',''Y''))',
4395                                   'Y',                        -- null allowed
4396                     'indicates if a value exists at the element entry level',
4397                           l_user_entity_id,
4398                           l_full_mls,
4399                           l_base_dbi_name);
4400                 --
4401                 if l_full_mls then
4402                   update_et_tl_dbi_names
4403                   (p_leg_code       => l_legislation_code
4404                   ,p_bg_id          => l_business_group_id
4405                   ,p_startup_mode   => l_startup_mode
4406                   ,p_user_name      => l_base_dbi_name
4407                   ,p_user_entity_id => l_user_entity_id
4408                   ,p_prefixes       => l_dbi_prefixes
4409                   ,p_suffix         => 'USER_ENTERED_CODE'
4410                   ,p_date_p         => p_date_p
4411                   );
4412                 end if;
4413                 --
4414                 local_insert_database_item (
4415                                   'START_DATE',
4416                                   'D',                        -- data type
4417                                   'min(EE.effective_start_date)',
4418                                   'Y',                        -- null allowed
4419                                   'start date of element',
4420                                   l_user_entity_id,
4421                                   l_full_mls,
4422                                   l_base_dbi_name);
4423                 --
4424                 if l_full_mls then
4425                   update_et_tl_dbi_names
4426                   (p_leg_code       => l_legislation_code
4427                   ,p_bg_id          => l_business_group_id
4428                   ,p_startup_mode   => l_startup_mode
4429                   ,p_user_name      => l_base_dbi_name
4430                   ,p_user_entity_id => l_user_entity_id
4431                   ,p_prefixes       => l_dbi_prefixes
4432                   ,p_suffix         => 'START_DATE'
4433                   ,p_date_p         => p_date_p
4434                   );
4435                 end if;
4436                 --
4437                 local_insert_database_item (
4438                                   'END_DATE',
4439                                   'D',                        -- data type
4440                                   'min(EE.effective_end_date)',
4441                                   'Y',                        -- null allowed
4442                                   'end date of element',
4443                                   l_user_entity_id,
4444                                   l_full_mls,
4445                                   l_base_dbi_name);
4446                 --
4447                 if l_full_mls then
4448                   update_et_tl_dbi_names
4449                   (p_leg_code       => l_legislation_code
4450                   ,p_bg_id          => l_business_group_id
4451                   ,p_startup_mode   => l_startup_mode
4452                   ,p_user_name      => l_base_dbi_name
4453                   ,p_user_entity_id => l_user_entity_id
4454                   ,p_prefixes       => l_dbi_prefixes
4455                   ,p_suffix         => 'END_DATE'
4456                   ,p_date_p         => p_date_p
4457                   );
4458                 end if;
4459             END IF;
4460             --
4461             -- Override Entry dbitems
4462             --
4463             insert_user_entity (l_override_entry_route,
4464                                 l_entity_name || '_I4' || p_date_p,
4465                              'non multiple entry entity for '|| l_override_entry_route,
4466                                 'Y',                 -- not found allowed flag
4467                                 'I',
4468                                 p_input_value_id,
4469                                 l_business_group_id,
4470                                 l_legislation_code,
4471                                 l_created_by,
4472                                 l_last_login,
4473                                 l_record_inserted);
4474             --
4475             -- only insert parameter values/database items if entity
4476             -- was inserted
4477             --
4478             IF l_record_inserted THEN
4479                 --
4480                 -- Fetch the user_entity_id.
4481                 --
4482                 select  ff_user_entities_s.currval
4483                 into    l_user_entity_id
4484                 from    dual;
4485                 --
4486                 -- insert the input value id for the where clause filler
4487                 --
4488                 insert_parameter_value (p_input_value_id, 1);
4489                 --
4490                 -- insert the element type id for the 2nd where clause filler
4491                 --
4492                 IF p_date_p IS NULL THEN
4493                   insert_parameter_value (l_element_type_id, 2);
4494                 END IF;
4495                 --
4496                 -- load up the database items for the non multiple entry types:
4497                 --
4498                 local_insert_database_item (
4499                                   'OVERRIDE_ENTRY_VALUE',
4500                                   l_data_type,              -- data type
4501                                   'min (' || l_start_string ||
4502 'decode(INPUTV.hot_default_flag,''Y'',nvl(EEV.screen_entry_value,
4503 nvl(LIV.default_value,INPUTV.default_value)),''N'',EEV.screen_entry_value)'
4504                                   || l_end_string || ')',
4505                                   'Y',                        -- null allowed
4506                                   'the recurring value',
4507                                   l_user_entity_id,
4508                                   l_full_mls,
4509                                   l_base_dbi_name);
4510                 --
4511                 if l_full_mls then
4512                   update_et_tl_dbi_names
4513                   (p_leg_code       => l_legislation_code
4514                   ,p_bg_id          => l_business_group_id
4515                   ,p_startup_mode   => l_startup_mode
4516                   ,p_user_name      => l_base_dbi_name
4517                   ,p_user_entity_id => l_user_entity_id
4518                   ,p_prefixes       => l_dbi_prefixes
4519                   ,p_suffix         => 'OVERRIDE_ENTRY_VALUE'
4520                   ,p_date_p         => p_date_p
4521                   );
4522                 end if;
4523                 --
4524                 local_insert_database_item (
4525                                   'OVERRIDE_USER_ENTERED_CODE',
4526                                   'T',                        -- data type
4527                   'min(decode(EEV.screen_entry_value,null,''N'',''Y''))',
4528                                   'Y',                        -- null allowed
4529                     'indicates if a value exists at the element entry level',
4530                                   l_user_entity_id,
4531                                   l_full_mls,
4532                                   l_base_dbi_name);
4533                 --
4534                 if l_full_mls then
4535                   update_et_tl_dbi_names
4536                   (p_leg_code       => l_legislation_code
4537                   ,p_bg_id          => l_business_group_id
4538                   ,p_startup_mode   => l_startup_mode
4539                   ,p_user_name      => l_base_dbi_name
4540                   ,p_user_entity_id => l_user_entity_id
4541                   ,p_prefixes       => l_dbi_prefixes
4542                   ,p_suffix         => 'OVERRIDE_USER_ENTERED_CODE'
4543                   ,p_date_p         => p_date_p
4544                   );
4545                 end if;
4546                 --
4547                 local_insert_database_item (
4548                                   'OVERRIDE_START_DATE',
4549                                   'D',                        -- data type
4550                                   'min(EE.effective_start_date)',
4551                                   'Y',                        -- null allowed
4552                                   'start date of element',
4553                                   l_user_entity_id,
4554                                   l_full_mls,
4555                                   l_base_dbi_name);
4556                 --
4557                 if l_full_mls then
4558                   update_et_tl_dbi_names
4559                   (p_leg_code       => l_legislation_code
4560                   ,p_bg_id          => l_business_group_id
4561                   ,p_startup_mode   => l_startup_mode
4562                   ,p_user_name      => l_base_dbi_name
4563                   ,p_user_entity_id => l_user_entity_id
4564                   ,p_prefixes       => l_dbi_prefixes
4565                   ,p_suffix         => 'OVERRIDE_START_DATE'
4566                   ,p_date_p         => p_date_p
4567                   );
4568                 end if;
4569                 --
4570                 local_insert_database_item (
4571                                   'OVERRIDE_END_DATE',
4572                                   'D',                        -- data type
4573                                   'min(EE.effective_end_date)',
4574                                   'Y',                        -- null allowed
4575                                   'end date of element',
4576                                   l_user_entity_id,
4577                                   l_full_mls,
4578                                   l_base_dbi_name);
4579                 --
4580                 if l_full_mls then
4581                   update_et_tl_dbi_names
4582                   (p_leg_code       => l_legislation_code
4583                   ,p_bg_id          => l_business_group_id
4584                   ,p_startup_mode   => l_startup_mode
4585                   ,p_user_name      => l_base_dbi_name
4586                   ,p_user_entity_id => l_user_entity_id
4587                   ,p_prefixes       => l_dbi_prefixes
4588                   ,p_suffix         => 'OVERRIDE_END_DATE'
4589                   ,p_date_p         => p_date_p
4590                   );
4591                 end if;
4592             END IF;
4593         end;
4594     else                                    -- multiple entries allowed
4595         --
4596         -- for multiple entries allowed, UOM must be hours, money or number,
4597         -- as it is summed in the definition text
4598         --
4599         if uom_requires_dbis(p_uom => l_uom) then
4600         begin
4601             --
4602             -- create the user entity for the multiple entries element
4603             --
4604             insert_user_entity (l_entry_route,
4605                                 l_entity_name || '_I3' || p_date_p,
4606                                 'multiple entry entity for '|| l_entry_route,
4607                                 'Y',
4608                                 'I',
4609                                 p_input_value_id,
4610                                 l_business_group_id,
4611                                 l_legislation_code,
4612                                 l_created_by,
4613                                 l_last_login,
4614                                 l_record_inserted);
4615             --
4616             -- only insert parameter values/database items if entity
4617             -- was inserted
4618             --
4619             IF l_record_inserted THEN
4620                 --
4621                 -- Fetch the user_entity_id.
4622                 --
4623                 select  ff_user_entities_s.currval
4624                 into    l_user_entity_id
4625                 from    dual;
4626                 --
4627                 -- insert the input value id for the where clause filler
4628                 --
4629                 insert_parameter_value (p_input_value_id, 1);
4630                 --
4631                 -- insert the element type id for the 2nd where clause filler
4632                 --
4633                 IF p_date_p IS NULL THEN
4634                   insert_parameter_value (l_element_type_id, 2);
4635                 END IF;
4636                 --
4637                 -- load up the database items for the multiple entry items:
4638                 --
4639                 local_insert_database_item (
4640                                   'ENTRY_VALUE',
4641                                  l_data_type,             -- data type
4642  'sum(' || l_start_string || 'decode(INPUTV.hot_default_flag,
4643 ''Y'',nvl(EEV.screen_entry_value,
4644 nvl(LIV.default_value,INPUTV.default_value)),
4645 ''N'',EEV.screen_entry_value)' || l_end_string || ')',
4646                                   'Y',                        -- null allowed
4647                                  'the summed multiple entry element values',
4648                                   l_user_entity_id,
4649                                   l_full_mls,
4650                                   l_base_dbi_name);
4651                 --
4652                 if l_full_mls then
4653                   update_et_tl_dbi_names
4654                   (p_leg_code       => l_legislation_code
4655                   ,p_bg_id          => l_business_group_id
4656                   ,p_startup_mode   => l_startup_mode
4657                   ,p_user_name      => l_base_dbi_name
4658                   ,p_user_entity_id => l_user_entity_id
4659                   ,p_prefixes       => l_dbi_prefixes
4660                   ,p_suffix         => 'ENTRY_VALUE'
4661                   ,p_date_p         => p_date_p
4662                   );
4663                 end if;
4664             END IF;
4665            --
4666             -- Override Entry dbitems
4667             --
4668             insert_user_entity (l_override_entry_route,
4669                                 l_entity_name || '_I4' || p_date_p,
4670                                 'multiple entry entity for '|| l_override_entry_route,
4671                                 'Y',
4672                                 'I',
4673                                 p_input_value_id,
4674                                 l_business_group_id,
4675                                 l_legislation_code,
4676                                 l_created_by,
4677                                 l_last_login,
4678                                 l_record_inserted);
4679             --
4680             -- only insert parameter values/database items if entity
4681             -- was inserted
4682             --
4683             IF l_record_inserted THEN
4684                 --
4685                 -- Fetch the user_entity_id.
4686                 --
4687                 select  ff_user_entities_s.currval
4688                 into    l_user_entity_id
4689                 from    dual;
4690                 --
4691                 -- insert the input value id for the where clause filler
4692                 --
4693                 insert_parameter_value (p_input_value_id, 1);
4694                 --
4695                 -- insert the element type id for the 2nd where clause filler
4696                 --
4697                 IF p_date_p IS NULL THEN
4698                   insert_parameter_value (l_element_type_id, 2);
4699                 END IF;
4700                 --
4701                 -- load up the database items for the multiple entry items:
4702                 --
4703                 local_insert_database_item (
4704                                   'OVERRIDE_ENTRY_VALUE',
4705                                  l_data_type,             -- data type
4706  'sum(' || l_start_string || 'decode(INPUTV.hot_default_flag,
4707 ''Y'',nvl(EEV.screen_entry_value,
4708 nvl(LIV.default_value,INPUTV.default_value)),
4709 ''N'',EEV.screen_entry_value)' || l_end_string || ')',
4710                                   'Y',                        -- null allowed
4711                                  'the summed multiple entry element values',
4712                                   l_user_entity_id,
4713                                   l_full_mls,
4714                                   l_base_dbi_name);
4715                 --
4716                 if l_full_mls then
4717                   update_et_tl_dbi_names
4718                   (p_leg_code       => l_legislation_code
4719                   ,p_bg_id          => l_business_group_id
4720                   ,p_startup_mode   => l_startup_mode
4721                   ,p_user_name      => l_base_dbi_name
4722                   ,p_user_entity_id => l_user_entity_id
4723                   ,p_prefixes       => l_dbi_prefixes
4724                   ,p_suffix         => 'OVERRIDE_ENTRY_VALUE'
4725                   ,p_date_p         => p_date_p
4726                   );
4727                 end if;
4728             END IF;
4729         end;
4730         end if;
4731     end if;
4732     --
4733     -- create the benefit input values if legislation = US.
4734     --
4735 
4736     select nvl (ltrim(rtrim(INPUTV.legislation_code)),
4737                 ltrim(rtrim(BUSGP.legislation_code)))
4738     into   l_leg_code_ben
4739     from   pay_input_values_f              INPUTV
4740     ,      per_business_groups_perf        BUSGP
4741     where  INPUTV.input_value_id         = p_input_value_id
4742     and    p_effective_date        between INPUTV.effective_start_date
4743                                        and INPUTV.effective_end_date
4744     and    BUSGP.business_group_id (+) = INPUTV.business_group_id;
4745 
4746     --
4747     if (l_leg_code_ben = 'US') then
4748         pay_us_contr_dbi.create_contr_items (p_input_value_id,
4749                                          p_effective_date,
4750                                          l_start_string,
4751                                          l_end_string,
4752                                          l_data_type);
4753     end if;
4754 END create_input_value;
4755 --
4756 --
4757 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4758 --                                                                        +
4759 --                       create_input_value_dict                          +
4760 --                                                                        +
4761 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4762 /*
4763    NAME
4764       create_input_value_dict - create an input value in the data
4765                                  dictionary
4766 --
4767    DESCRIPTION
4768       This procedure is the main entry point for creating database items for
4769       a given input value, where the context is date earned. It calls the
4770       input value creation procedure : create_input_value.
4771 */
4772 procedure create_input_value_dict
4773 (
4774     p_input_value_id       in number,
4775     p_effective_date       in date
4776 ) is
4777 begin
4778     create_input_value (p_input_value_id,
4779                         p_effective_date,
4780                         null);
4781 end create_input_value_dict;
4782 --
4783 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4784 --                                                                        +
4785 --                       refresh_element_types                            +
4786 --                                                                        +
4787 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4788 /*
4789 NAME
4790     refresh_element_types -   create all DB items for element type and input
4791                               values
4792 --
4793 DESCRIPTION
4794     This routine creates all database items based on element types
4795     in the system. The routine assumes that no such database items currently
4796     exist.
4797 */
4798 procedure refresh_element_types(p_worker_id in number default 0,
4799                                 p_maxworkers in number default 1) is
4800    cursor c1 is select   element_type_id,
4801                          max(effective_end_date)
4802                 from     pay_element_types_f e
4803                 where    not exists (
4804                  select null
4805                  from ff_user_entities u
4806                  where u.creator_id = e.element_type_id
4807                  and u.creator_type = 'E')
4808                  and mod(element_type_id, p_maxworkers) = p_worker_id
4809                 group by element_type_id
4810                 order by element_type_id;
4811    --
4812    cursor c2 is select   input_value_id,
4813                          max(effective_end_date)
4814                 from     pay_input_values_f i
4815                 where    generate_db_items_flag = 'Y'
4816                 and      not exists (
4817                  select null
4818                  from ff_user_entities u
4819                  where u.creator_id = i.input_value_id
4820                  and u.creator_type = 'I')
4821                  and mod(input_value_id, p_maxworkers) = p_worker_id
4822                 group by input_value_id
4823                 order by input_value_id;
4824 
4825 l_input_value_id  number;
4826 l_element_type_id number;
4827 l_date            date;
4828 l_loop_cnt number;
4829 
4830 begin
4831    --
4832    -- create element types
4833    --
4834 hrrbdeib_trace_on;
4835 hr_utility.trace('entering refresh_el types elements all' ||
4836                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
4837                  to_char(p_maxworkers));
4838 hrrbdeib_trace_off;
4839 
4840 l_loop_cnt := 0;
4841 
4842    open c1;
4843    loop
4844        fetch c1 into l_element_type_id,
4845                      l_date;
4846        EXIT when c1%notfound;
4847        hrrbdeib_trace_on;
4848        hr_utility.trace('RELE:'|| to_char(p_worker_id + 1) || ':' ||
4849                         to_char(l_element_type_id) || '.' ||
4850                         to_char(l_date,'DD-MM-YYYY'));
4851        hrrbdeib_trace_off;
4852        create_element_type_dict (l_element_type_id, l_date);
4853 
4854        l_loop_cnt := l_loop_cnt + 1;
4855        if l_loop_cnt > 100 then
4856          l_loop_cnt := 0;
4857          commit;
4858        end if;
4859 
4860    end loop;
4861    close c1;
4862    --
4863    -- create input values
4864    --
4865 hrrbdeib_trace_on;
4866 hr_utility.trace('leaving refresh_el types elements all' ||
4867                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
4868                  to_char(p_maxworkers));
4869 
4870 hr_utility.trace('entering refresh_el types ivs all' ||
4871                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
4872                  to_char(p_maxworkers));
4873 hrrbdeib_trace_off;
4874 
4875 l_loop_cnt := 0;
4876 
4877    open c2;
4878    loop
4879        fetch c2 into l_input_value_id,
4880                      l_date;
4881        EXIT when c2%notfound;
4882        hrrbdeib_trace_on;
4883        hr_utility.trace('RELI:'|| to_char(p_worker_id + 1) || ':' ||
4884                         to_char(l_input_value_id) || '.' ||
4885                         to_char(l_date,'DD-MM-YYYY'));
4886        hrrbdeib_trace_off;
4887        create_input_value_dict (l_input_value_id, l_date);
4888 
4889        l_loop_cnt := l_loop_cnt + 1;
4890        if l_loop_cnt > 100 then
4891          l_loop_cnt := 0;
4892          commit;
4893        end if;
4894 
4895    end loop;
4896    close c2;
4897 
4898 hrrbdeib_trace_on;
4899 hr_utility.trace('leaving refresh_el types ivs all' ||
4900                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
4901                  to_char(p_maxworkers));
4902 hrrbdeib_trace_off;
4903 
4904 end refresh_element_types;
4905 --
4906 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4907 --                                                                        +
4908 --                       refresh_element_types                            +
4909 --                                                                        +
4910 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4911 /*
4912 NAME
4913     refresh_element_types -   create all DB items for element type and input
4914                               values
4915 --
4916 DESCRIPTION
4917     This routine creates all database items based on element types
4918     in the system. The routine assumes that no such database items currently
4919     exist.
4920 */
4921 procedure refresh_element_types(p_leg_code in varchar2,
4922                                 p_worker_id in number default 0,
4923                                 p_maxworkers in number default 1) is
4924    cursor c1 is select   element_type_id,
4925                          max(effective_end_date)
4926                 from     pay_element_types_f a
4927                 where    not exists (
4928                  select null
4929                  from ff_user_entities u
4930                  where u.creator_id = a.element_type_id
4931                  and u.creator_type = 'E')
4932                  and mod(element_type_id, p_maxworkers) = p_worker_id
4933                 and      (a.legislation_code = p_leg_code
4934                           or exists (select null
4935                                  from   per_business_groups_perf b
4936                                  where  a.business_group_id = b.business_group_id
4937                                  and    nvl(b.legislation_code, p_leg_code) = p_leg_code))
4938                 group by element_type_id
4939                 order by element_type_id;
4940    --
4941    cursor c2 is select   input_value_id,
4942                          max(effective_end_date)
4943                 from     pay_input_values_f a
4944                 where    generate_db_items_flag = 'Y'
4945                 and      not exists (
4946                  select null
4947                  from ff_user_entities u
4948                  where u.creator_id = a.input_value_id
4949                  and u.creator_type = 'I')
4950                  and      mod(input_value_id, p_maxworkers) = p_worker_id
4951                 and      (a.legislation_code = p_leg_code
4952                           or exists (select null
4953                                  from   per_business_groups_perf b
4954                                  where  a.business_group_id = b.business_group_id
4955                                  and    nvl(b.legislation_code, p_leg_code) = p_leg_code))
4956                 group by input_value_id
4957                 order by input_value_id;
4958 
4959 l_input_value_id  number;
4960 l_element_type_id number;
4961 l_date            date;
4962 l_loop_cnt number;
4963 
4964 begin
4965    --
4966    -- create element types
4967    --
4968 hrrbdeib_trace_on;
4969 hr_utility.trace('entering refresh_el types elements ' || p_leg_code ||
4970                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
4971                  to_char(p_maxworkers));
4972 hrrbdeib_trace_off;
4973 
4974 l_loop_cnt := 0;
4975 
4976    open c1;
4977    loop
4978        fetch c1 into l_element_type_id,
4979                      l_date;
4980        EXIT when c1%notfound;
4981        hrrbdeib_trace_on;
4982        hr_utility.trace('RELE:'|| to_char(p_worker_id + 1) || ':' ||
4983                         to_char(l_element_type_id) || '.' ||
4984                         to_char(l_date,'DD-MM-YYYY'));
4985        hrrbdeib_trace_off;
4986        create_element_type_dict (l_element_type_id, l_date);
4987 
4988        l_loop_cnt := l_loop_cnt + 1;
4989        if l_loop_cnt > 100 then
4990          l_loop_cnt := 0;
4991          commit;
4992        end if;
4993 
4994    end loop;
4995    close c1;
4996    --
4997 hrrbdeib_trace_on;
4998 hr_utility.trace('leaving refresh_el types elements ' || p_leg_code ||
4999                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5000                  to_char(p_maxworkers));
5001 
5002    -- create input values
5003    --
5004 hr_utility.trace('entering refresh_el types ivs ' || p_leg_code ||
5005                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5006                  to_char(p_maxworkers));
5007 hrrbdeib_trace_off;
5008 
5009 l_loop_cnt := 0;
5010 
5011    open c2;
5012    loop
5013        fetch c2 into l_input_value_id,
5014                      l_date;
5015        EXIT when c2%notfound;
5016        hrrbdeib_trace_on;
5017        hr_utility.trace('RELI:'|| to_char(p_worker_id + 1) || ':' ||
5018                         to_char(l_input_value_id) || '.' ||
5019                         to_char(l_date,'DD-MM-YYYY'));
5020        hrrbdeib_trace_off;
5021        create_input_value_dict (l_input_value_id, l_date);
5022 
5023        l_loop_cnt := l_loop_cnt + 1;
5024        if l_loop_cnt > 100 then
5025          l_loop_cnt := 0;
5026          commit;
5027        end if;
5028 
5029    end loop;
5030    close c2;
5031 
5032 hrrbdeib_trace_on;
5033 hr_utility.trace('leaving refresh_el types ivs ' || p_leg_code ||
5034                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5035                  to_char(p_maxworkers));
5036 hrrbdeib_trace_off;
5037 
5038 end refresh_element_types;
5039 --
5040 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5041 --                                                                        +
5042 --                        delete_element_types                            +
5043 --                                                                        +
5044 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5045 /*
5046 NAME
5047     delete_element_types -   delete all DB itms for element type and input
5048                              values
5049 --
5050 DESCRIPTION
5051    This routine deletes all database items based on element types
5052    in the system. The routine assumes that no such database items currently
5053    exist.
5054 */
5055 procedure delete_element_types(p_worker_id in number default 0,
5056                                p_maxworkers in number default 1) is
5057 begin
5058    --
5059    delete ff_user_entities u
5060    where  u.creator_type = 'I'
5061    and exists (
5062      select null
5063      from   pay_input_values_f a
5064      where  u.creator_id  = a.input_value_id);
5065 
5066    delete ff_user_entities u
5067    where  u.creator_type = 'E'
5068    and exists (
5069      select null
5070      from   pay_element_types_f x
5071      where  u.creator_id  = x.element_type_id);
5072 end;
5073 --
5074 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5075 --                                                                        +
5076 --                        delete_element_types                            +
5077 --                                                                        +
5078 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5079 /*
5080 NAME
5081     delete_element_types -   delete all DB itms for element type and input
5082                              values
5083 --
5084 DESCRIPTION
5085    This routine deletes all database items based on element types
5086    in the system. The routine assumes that no such database items currently
5087    exist.
5088 */
5089 procedure delete_element_types(p_leg_code in varchar2,
5090                                p_worker_id in number default 0,
5091                                p_maxworkers in number default 1) is
5092 begin
5093    --
5094    -- delete the input values
5095    --
5096    delete ff_user_entities u
5097    where  u.creator_type = 'I'
5098    and exists (
5099      select null
5100      from   pay_input_values_f a
5101      where  u.creator_id  = a.input_value_id
5102      and    (a.legislation_code = p_leg_code
5103           or exists
5104               (select null
5105                from   per_business_groups_perf b
5106                where  a.business_group_id = b.business_group_id
5107                and    nvl(b.legislation_code, p_leg_code) = p_leg_code)));
5108 
5109    delete ff_user_entities u
5110    where  u.creator_type = 'E'
5111    and exists (
5112      select null
5113      from   pay_element_types_f x
5114      where  u.creator_id  = x.element_type_id
5115      and    (x.legislation_code = p_leg_code
5116           or exists
5117               (select null
5118                from   per_business_groups_perf y
5119                where  x.business_group_id = y.business_group_id
5120                and    nvl(y.legislation_code, p_leg_code) = p_leg_code)));
5121 
5122 end delete_element_types;
5123 --
5124 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5125 --                                                                        +
5126 --                      rebuild_ele_input_bal                             +
5127 --                                                                        +
5128 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5129 --
5130 /*
5131 NAME
5132     rebuild_ele_input_bal -  Delete and then re-create Db items for elements,
5133                              input values and balances.
5134 --
5135 DESCRIPTION
5136    This routine deletes all database items for element, input values and
5137    balances in the database.  It then re-creates them.
5138    This routine would typically be called after a startup delivery.
5139    If the parameter 'p_commit' is set to 'Y' then the routine will commit
5140    after the procedure calls to delete/re-create the DB items.  This helps
5141    the installation process when there is many DB items, or if the rollback
5142    segment space is limited.
5143 */
5144 procedure rebuild_ele_input_bal
5145 (
5146     p_commit in varchar2 default 'N',
5147     p_worker_id in number default 0,
5148     p_maxworkers in number default 1
5149 )
5150 is
5151 
5152    workers_complete number;
5153    worker_err       number;
5154 
5155 begin
5156    --
5157    g_debug_cnt := 0;
5158 
5159    select count(*)
5160    into g_debug_cnt
5161    from pay_patch_status
5162    where patch_name = 'HRGLOBAL_DEBUG2';
5163 
5164    hrrbdeib_trace_on;
5165    hr_utility.trace('entering rebuild_ele_input_bal all' ||
5166                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5167                  to_char(p_maxworkers));
5168    hrrbdeib_trace_off;
5169 
5170    -- First set global to say we are disabling triggers.
5171    -- Loop thru each worker
5172   if p_worker_id = 0 then
5173    enable_ffue_cascade_trig;
5174    enable_refbal_trig;
5175 
5176    -- Running Core so delete all compiled info and usages
5177    hrrbdeib_trace_on;
5178    hr_utility.trace('entering truncate_fcomp_info');
5179    hrrbdeib_trace_off;
5180 
5181 --   truncate_fcomp_info;
5182 
5183    hrrbdeib_trace_on;
5184    hr_utility.trace('leaving truncate_fcomp_info');
5185    hrrbdeib_trace_off;
5186 
5187   else
5188    dbms_lock.sleep(5);
5189   end if;
5190 
5191    g_triggers_altered := TRUE;
5192    --
5193    if (p_commit = 'Y') then
5194      commit;
5195    end if;
5196    --
5197    -- Delete ALL balance DB items:
5198    --
5199    -- disable delete triggers for these entities for performance.
5200   if p_worker_id = 0 then
5201    disable_ffue_cascade_trig;
5202   else
5203    dbms_lock.sleep(5);
5204   end if;
5205 
5206    --
5207    if (p_commit = 'Y') then
5208      commit;
5209    end if;
5210    --
5211    -- INSERT A COMPLETION STEP AND
5212    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5213    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5214    -- FOR EXAMPLE
5215    insert_mthread_pps(1, p_worker_id, 'ZZ');
5216    --
5217    if (p_commit = 'Y') then
5218      commit;
5219    end if;
5220    --
5221    loop
5222 
5223      select count(*)
5224      into   worker_err
5225      from   pay_patch_status
5226      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5227 
5228      if worker_err > 0 then
5229        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5230      end if;
5231 
5232      select count(*)
5233      into   workers_complete
5234      from   pay_patch_status
5235      where  patch_name = 'HRRBDEIB INTERNAL PROC S1'
5236      and    process_type = 'ZZ';
5237 
5238      exit when workers_complete = p_maxworkers;
5239 
5240      dbms_lock.sleep(5);
5241 
5242    end loop;
5243 
5244    if (p_commit = 'Y') then
5245      commit;
5246    end if;
5247 
5248    -- re-enable delete triggers
5249   if p_worker_id = 0 then
5250    enable_ffue_cascade_trig;
5251    disable_refbal_trig;
5252   else
5253    dbms_lock.sleep(5);
5254   end if;
5255 
5256    --
5257    hrdyndbi.refresh_defined_balances(p_worker_id,
5258                                      p_maxworkers);
5259 
5260    --
5261    -- INSERT A COMPLETION STEP AND
5262    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5263    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5264    -- FOR EXAMPLE
5265    insert_mthread_pps(2, p_worker_id, 'ZZ');
5266 
5267    if (p_commit = 'Y') then
5268      commit;
5269    end if;
5270 
5271 
5272    loop
5273 
5274      select count(*)
5275      into   worker_err
5276      from   pay_patch_status
5277      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5278 
5279      if worker_err > 0 then
5280        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5281      end if;
5282 
5283      select count(*)
5284      into   workers_complete
5285      from   pay_patch_status
5286      where  patch_name = 'HRRBDEIB INTERNAL PROC S2'
5287      and    process_type = 'ZZ';
5288 
5289      exit when workers_complete = p_maxworkers;
5290 
5291      dbms_lock.sleep(5);
5292 
5293    end loop;
5294    --
5295    if (p_commit = 'Y') then
5296      commit;
5297    end if;
5298    --
5299    -- re-enable insert triggers
5300   if p_worker_id = 0 then
5301    enable_refbal_trig;
5302    disable_ffue_cascade_trig;
5303   else
5304    dbms_lock.sleep(5);
5305   end if;
5306 
5307    --
5308    --
5309    -- INSERT A COMPLETION STEP AND
5310    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5311    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5312    -- FOR EXAMPLE
5313    insert_mthread_pps(3, p_worker_id, 'ZZ');
5314 
5315    if (p_commit = 'Y') then
5316      commit;
5317    end if;
5318 
5319 
5320    loop
5321 
5322      select count(*)
5323      into   worker_err
5324      from   pay_patch_status
5325      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5326 
5327      if worker_err > 0 then
5328        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5329      end if;
5330 
5331      select count(*)
5332      into   workers_complete
5333      from   pay_patch_status
5334      where  patch_name = 'HRRBDEIB INTERNAL PROC S3'
5335      and    process_type = 'ZZ';
5336 
5337      exit when workers_complete = p_maxworkers;
5338 
5339      dbms_lock.sleep(5);
5340 
5341    end loop;
5342 
5343    if (p_commit = 'Y') then
5344      commit;
5345    end if;
5346    --
5347    -- re-enable delete triggers
5348   if p_worker_id = 0 then
5349    enable_ffue_cascade_trig;
5350   else
5351    dbms_lock.sleep(5);
5352   end if;
5353 
5354    --
5355    -- Create all input and element DB items:
5356    --
5357    -- Get the security ID for the codename cursor
5358    g_security_group_id := fnd_global.lookup_security_group('NAME_TRANSLATIONS', 3);
5359    --
5360    --
5361    -- disable insert triggers for these entities for performance.
5362   if p_worker_id = 0 then
5363    disable_refbal_trig;
5364   else
5365    dbms_lock.sleep(5);
5366   end if;
5367 
5368    --
5369    hrdyndbi.refresh_element_types(p_worker_id,
5370                                   p_maxworkers);
5371    -- INSERT A COMPLETION STEP AND
5372    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5373    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5374    -- FOR EXAMPLE
5375    insert_mthread_pps(4, p_worker_id, 'ZZ');
5376 
5377    if (p_commit = 'Y') then
5378      commit;
5379    end if;
5380 
5381 
5382    loop
5383 
5384      select count(*)
5385      into   worker_err
5386      from   pay_patch_status
5387      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5388 
5389      if worker_err > 0 then
5390        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5391      end if;
5392 
5393      select count(*)
5394      into   workers_complete
5395      from   pay_patch_status
5396      where  patch_name = 'HRRBDEIB INTERNAL PROC S4'
5397      and    process_type = 'ZZ';
5398 
5399      exit when workers_complete = p_maxworkers;
5400 
5401      dbms_lock.sleep(5);
5402 
5403    end loop;
5404    --
5405    -- Important. In order not to hang when we have selected more than
5406    -- 1 non Core legislation for install, we must of course delete the
5407    -- tracking pay_patch_status rows so that the next leg loop of hrrbdeib
5408    -- starts afresh. We  take care of this now by not trashing history and
5409    -- tag a legislation code to the pps rows
5410    --
5411    if (p_commit = 'Y') then
5412      commit;
5413    end if;
5414    --
5415    -- re-enable insert triggers
5416   if p_worker_id = 0 then
5417    enable_refbal_trig;
5418   else
5419    dbms_lock.sleep(5);
5420   end if;
5421 
5422    --
5423    -- reset global
5424    g_triggers_altered := FALSE;
5425    --
5426    hrrbdeib_trace_on;
5427    hr_utility.trace('leaving rebuild_ele_input_bal all' ||
5428                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5429                  to_char(p_maxworkers));
5430    hrrbdeib_trace_off;
5431    --
5432 exception
5433    when others then
5434      -- re-enable any disabled triggers
5435      hrrbdeib_trace_on;
5436      hr_utility.trace('exception raised in rebuild_ele_input_bal all' ||
5437                    ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5438                    to_char(p_maxworkers));
5439      hrrbdeib_trace_off;
5440      insert_mthread_pps_err(p_worker_id, 'ZZ');
5441      enable_ffue_cascade_trig;
5442      enable_refbal_trig;
5443      raise; -- reraise the exception
5444 --
5445 end rebuild_ele_input_bal;
5446 --
5447 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5448 --                                                                        +
5449 --                      rebuild_ele_input_bal                             +
5450 --                                                                        +
5451 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5452 --
5453 /*
5454 NAME
5455     rebuild_ele_input_bal -  Delete and then re-create Db items for elements,
5456                              input values and balances.
5457 --
5458 DESCRIPTION
5459    This routine deletes all database items for element, input values and
5460    balances in the database.  It then re-creates them.
5461    This routine would typically be called after a startup delivery.
5462    If the parameter 'p_commit' is set to 'Y' then the routine will commit
5463    after the procedure calls to delete/re-create the DB items.  This helps
5464    the installation process when there is many DB items, or if the rollback
5465    segment space is limited.
5466 */
5467 procedure rebuild_ele_input_bal
5468 (
5469     p_commit in varchar2 default 'N',
5470     p_leg_code in varchar2,
5471     p_worker_id in number default 0,
5472     p_maxworkers in number default 1
5473 )
5474 is
5475 
5476    workers_complete number;
5477    worker_err       number;
5478    l_formula_ids dbms_sql.number_table;
5479    l_start_dates dbms_sql.date_table;
5480    l_rowids      dbms_sql.varchar2s;
5481    form_name varchar2(80);
5482 
5483 --
5484 -- Cursor to fetch FDIU row information for rows affected by the EIB
5485 -- database item recreation.
5486 --
5487 cursor csr_affected_fdiu_rows
5488 (p_leg_code in varchar2
5489 ) is
5490 select fdi.rowid
5491 ,      fdi.formula_id
5492 ,      fdi.effective_start_date
5493 from   ff_fdi_usages_f fdi
5494 where exists
5495   (select null
5496    from   ff_database_items dbi
5497    where  fdi.item_name = dbi.user_name
5498    and exists
5499      (select null
5500       from   ff_user_entities ent
5501       where  ent.user_entity_id = dbi.user_entity_id
5502       and    ent.creator_type in ('B','RB','E','I')
5503       -- MERGE B RB E I main cursors
5504       --
5505       -- B
5506       and (
5507         not exists (
5508           select null
5509           from   pay_defined_balances b
5510           where  b.defined_balance_id = ent.creator_id
5511           and    ent.creator_type = 'B'
5512         )
5513         OR
5514         -- RB
5515         (not exists (
5516           select null
5517           from   pay_defined_balances b
5518           where  b.defined_balance_id = ent.creator_id
5519           and    ent.creator_type = 'RB'
5520           and exists
5521                     (select null
5522                      from pay_dimension_routes pdr
5523                      where pdr.balance_dimension_id = b.balance_dimension_id)
5524           )
5525           OR
5526           (exists (
5527             select pdr.balance_dimension_id
5528             from   pay_dimension_routes pdr,
5529                    pay_defined_balances b
5530             where  pdr.balance_dimension_id = b.balance_dimension_id
5531             and    not exists (select null
5532                                from   ff_user_entities ue
5533                                where  ue.creator_id = b.defined_balance_id
5534                                and    ue.route_id = pdr.route_id
5535                                and    ue.creator_type = 'RB'))
5536           )
5537          ) -- end RB
5538          OR
5539          -- E
5540          (not exists (
5541           select null
5542           from   pay_element_types_f et
5543           where ent.creator_id = et.element_type_id
5544           and   ent.creator_type = 'E'))
5545          OR
5546          -- I
5547          (not exists (
5548           select null
5549           from   pay_input_values_f i
5550           where  ent.creator_id = i.input_value_id
5551           and    i.generate_db_items_flag = 'Y'
5552           and    ent.creator_type = 'I'))
5553         ) -- end B RB E I
5554       and
5555         (nvl (ent.legislation_code, ' ') = nvl (p_leg_code, ' ')
5556          or exists
5557            (select null
5558             from   per_business_groups_perf b
5559             where  ent.business_group_id = b.business_group_id
5560             and nvl(b.legislation_code, p_leg_code) = p_leg_code
5561            )
5562         )
5563      )
5564   )
5565 ;
5566 begin
5567    --
5568    g_debug_cnt := 0;
5569 
5570    select count(*)
5571    into g_debug_cnt
5572    from pay_patch_status
5573    where patch_name = 'HRGLOBAL_DEBUG2';
5574 
5575    hrrbdeib_trace_on;
5576    hr_utility.trace('entering rebuild_ele_input_bal ' || p_leg_code ||
5577                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5578                  to_char(p_maxworkers));
5579    hrrbdeib_trace_off;
5580    --
5581    -- First set global to say we are disabling triggers.
5582   if p_worker_id = 0 then
5583    enable_ffue_cascade_trig;
5584    enable_refbal_trig;
5585 
5586    g_triggers_altered := TRUE;
5587    --
5588    -- delete legislative formulae usages and compiled info
5589    --
5590    hrrbdeib_trace_on;
5591    hr_utility.trace('entering delete fcomp info: LC: ' || p_leg_code);
5592    hrrbdeib_trace_off;
5593 
5594 /*
5595    open csr_affected_fdiu_rows(p_leg_code => p_leg_code);
5596 
5597    loop
5598      --
5599      -- Delete in chunks to avoid potential memory issues with bulk
5600      -- collecting many thousands of rows.
5601      --
5602      fetch csr_affected_fdiu_rows bulk collect
5603      into  l_rowids
5604      ,     l_formula_ids
5605      ,     l_start_dates
5606      limit 500;
5607 
5608      exit when csr_affected_fdiu_rows%notfound;
5609 
5610      forall i in 1 .. l_rowids.count
5611        delete
5612        from   ff_fdi_usages_f fdi
5613        where  fdi.rowid = l_rowids(i)
5614        ;
5615 
5616      forall i in 1 .. l_rowids.count
5617        delete
5618        from   ff_compiled_info_f fci
5619        where  fci.formula_id = l_formula_ids(i)
5620        and    fci.effective_start_date = l_start_dates(i)
5621        ;
5622 
5623    end loop;
5624 
5625    close csr_affected_fdiu_rows;
5626 */
5627 
5628    hrrbdeib_trace_on;
5629    hr_utility.trace('leaving delete fcomp info: LC: ' || p_leg_code);
5630    hrrbdeib_trace_off;
5631 
5632    end if;
5633    --
5634    if (p_commit = 'Y') then
5635      commit;
5636    end if;
5637    --
5638    -- INSERT A COMPLETION STEP AND
5639    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5640    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5641    -- FOR EXAMPLE
5642    insert_mthread_pps(1, p_worker_id, p_leg_code);
5643 
5644    if (p_commit = 'Y') then
5645      commit;
5646    end if;
5647 
5648 
5649    loop
5650 
5651      select count(*)
5652      into   worker_err
5653      from   pay_patch_status
5654      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5655 
5656      if worker_err > 0 then
5657        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5658      end if;
5659 
5660      select count(*)
5661      into   workers_complete
5662      from   pay_patch_status
5663      where  patch_name = 'HRRBDEIB INTERNAL PROC S1'
5664      and    process_type = p_leg_code;
5665 
5666      exit when workers_complete = p_maxworkers;
5667 
5668      dbms_lock.sleep(5);
5669 
5670    end loop;
5671    --
5672    -- Create ALL DB items for defined balances in the account:
5673    --
5674    -- disable insert triggers for these entities for performance.
5675   if p_worker_id = 0 then
5676    disable_refbal_trig;
5677   else
5678    dbms_lock.sleep(5);
5679   end if;
5680 
5681    --
5682    hrdyndbi.refresh_defined_balances(p_leg_code,
5683                                      p_worker_id,
5684                                      p_maxworkers);
5685    --
5686    -- INSERT A COMPLETION STEP AND
5687    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5688    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5689    -- FOR EXAMPLE
5690    insert_mthread_pps(2, p_worker_id, p_leg_code);
5691    --
5692    if (p_commit = 'Y') then
5693      commit;
5694    end if;
5695 
5696 
5697    loop
5698 
5699      select count(*)
5700      into   worker_err
5701      from   pay_patch_status
5702      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5703 
5704      if worker_err > 0 then
5705        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5706      end if;
5707 
5708      select count(*)
5709      into   workers_complete
5710      from   pay_patch_status
5711      where  patch_name = 'HRRBDEIB INTERNAL PROC S2'
5712      and    process_type = p_leg_code;
5713 
5714      exit when workers_complete = p_maxworkers;
5715 
5716      dbms_lock.sleep(5);
5717 
5718    end loop;
5719 
5720    if (p_commit = 'Y') then
5721      commit;
5722    end if;
5723    --
5724    -- re-enable insert triggers
5725   if p_worker_id = 0 then
5726    enable_refbal_trig;
5727    disable_ffue_cascade_trig;
5728   else
5729    dbms_lock.sleep(5);
5730   end if;
5731 
5732    --
5733    --
5734    -- INSERT A COMPLETION STEP AND
5735    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5736    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5737    -- FOR EXAMPLE
5738    insert_mthread_pps(3, p_worker_id, p_leg_code);
5739 
5740    if (p_commit = 'Y') then
5741      commit;
5742    end if;
5743 
5744 
5745    loop
5746 
5747      select count(*)
5748      into   worker_err
5749      from   pay_patch_status
5750      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5751 
5752      if worker_err > 0 then
5753        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5754      end if;
5755 
5756      select count(*)
5757      into   workers_complete
5758      from   pay_patch_status
5759      where  patch_name = 'HRRBDEIB INTERNAL PROC S3'
5760      and    process_type = p_leg_code;
5761 
5762      exit when workers_complete = p_maxworkers;
5763 
5764      dbms_lock.sleep(5);
5765 
5766    end loop;
5767 
5768    if (p_commit = 'Y') then
5769      commit;
5770    end if;
5771    --
5772    -- re-enable delete triggers
5773   if p_worker_id = 0 then
5774    enable_ffue_cascade_trig;
5775   else
5776    dbms_lock.sleep(5);
5777   end if;
5778 
5779    --
5780    -- Create all input and element DB items:
5781    --
5782    -- Get the security ID for the codename cursor
5783    g_security_group_id := fnd_global.lookup_security_group('NAME_TRANSLATIONS',
5784 3);
5785    --
5786    --
5787    -- disable insert triggers for these entities for performance.
5788   if p_worker_id = 0 then
5789    disable_refbal_trig;
5790   else
5791    dbms_lock.sleep(5);
5792   end if;
5793 
5794    --
5795    hrdyndbi.refresh_element_types(p_leg_code,
5796                                   p_worker_id,
5797                                   p_maxworkers);
5798    --
5799    --
5800    -- INSERT A COMPLETION STEP AND
5801    -- LOOP HERE UNTIL ALL WORKERS HAVE COMPLETED INITIAL SET UP
5802    -- SO THAT WORKER 2 WONT BE DELETING WHILST WORKER 1 IS CREATING
5803    -- FOR EXAMPLE
5804    insert_mthread_pps(4, p_worker_id, p_leg_code);
5805 
5806    if (p_commit = 'Y') then
5807      commit;
5808    end if;
5809 
5810 
5811    loop
5812 
5813      select count(*)
5814      into   worker_err
5815      from   pay_patch_status
5816      where  patch_name like 'HRRBDEIB INTERNAL PROC ERR%';
5817 
5818      if worker_err > 0 then
5819        raise_application_error(-20106, 'A hrrbdeib worker has failed, terminating all workers.');
5820      end if;
5821 
5822      select count(*)
5823      into   workers_complete
5824      from   pay_patch_status
5825      where  patch_name = 'HRRBDEIB INTERNAL PROC S4'
5826      and    process_type = p_leg_code;
5827 
5828      exit when workers_complete = p_maxworkers;
5829 
5830      dbms_lock.sleep(5);
5831 
5832    end loop;
5833    --
5834    -- Important. In order not to hang when we have selected more than
5835    -- 1 non Core legislation for install, we must of course delete the
5836    -- tracking pay_patch_status rows so that the next leg loop of hrrbdeib
5837    -- starts afresh. We  take care of this now by not trashing history and
5838    -- tag a legislation code to the pps rows
5839    --
5840    if (p_commit = 'Y') then
5841      commit;
5842    end if;
5843    --
5844    -- re-enable insert triggers
5845   if p_worker_id = 0 then
5846    enable_refbal_trig;
5847   else
5848    dbms_lock.sleep(5);
5849   end if;
5850 
5851    --
5852    -- reset global
5853    g_triggers_altered := FALSE;
5854    --
5855    hrrbdeib_trace_on;
5856    hr_utility.trace('leaving rebuild_ele_input_bal ' || p_leg_code ||
5857                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5858                  to_char(p_maxworkers));
5859    hrrbdeib_trace_off;
5860    --
5861 exception
5862    when others then
5863      hrrbdeib_trace_on;
5864      hr_utility.trace('exception in rebuild_ele_input_bal ' || p_leg_code ||
5865                  ' worker: ' || to_char(p_worker_id + 1) || '/' ||
5866                  to_char(p_maxworkers));
5867      hrrbdeib_trace_off;
5868      --
5869      if csr_affected_fdiu_rows%isopen then
5870        close  csr_affected_fdiu_rows;
5871      end if;
5872      --
5873      insert_mthread_pps_err(p_worker_id, p_leg_code);
5874      -- re-enable any disabled triggers
5875      enable_ffue_cascade_trig;
5876      enable_refbal_trig;
5877      raise; -- reraise the exception
5878 --
5879 end rebuild_ele_input_bal;
5880 --
5881 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5882 --                                                                        +
5883 --                     delete_grade_spine_dict                            +
5884 --                                                                        +
5885 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5886 /*
5887 NAME
5888       delete_grade_spine_dict - delete the grade rate items from the data
5889                                 dictionary
5890 --
5891 DESCRIPTION
5892 */
5893 procedure delete_grade_spine_dict
5894 (
5895     p_rate_id       in number
5896 ) is
5897 --
5898 BEGIN
5899     DELETE FROM ff_user_entities
5900     WHERE  creator_id    = p_rate_id
5901     AND    creator_type  = 'G';
5902 end delete_grade_spine_dict;
5903 --
5904 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5905 --                                                                        +
5906 --                      create_grade_spine_dict                           +
5907 --                                                                        +
5908 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5909 --
5910 /*
5911    NAME
5912       create_grade_spine_dict - create grade/ spine rate database items
5913 --
5914    DESCRIPTION
5915       This procedure is the main entry point for creating database items for
5916       either grades or spines. The routes must have already been defined in the
5917       database (in table ff_routes).  The procedure will search for the
5918       routes in this table by using the route name, which is hard coded below.
5919       The procedure processes each route in turn, creating a user entity and
5920       route parameter values, and then inserting each database items for that
5921       particular route.
5922       The database items created use the rate name. This routine
5923       generates the following database items for grades:
5924       --
5925       GRADE_<NAME>_VALUE
5926       GRADE_<NAME>_MINIMUM
5927       GRADE_<NAME>_MAXIMUM
5928       --
5929       For spines the following database item is generated:
5930       --
5931       SPINE_<NAME>_VALUE
5932 */
5933 procedure create_grade_spine_dict
5934 (
5935     p_rate_id       in number
5936 ) is
5937 l_grade_route_name    varchar2(50) := 'GRADE_RATE_ROUTE';
5938 l_spine_route_name    varchar2(50) := 'SPINE_RATE_ROUTE';
5939 l_rate_type           pay_rates.rate_type%type;
5940 l_name                pay_rates.name%type;
5941 l_business_group_id   number;
5942 l_created_by          number;
5943 l_last_login          number;
5944 l_record_inserted     boolean;
5945 --
5946 ------------------------- create_grade_spine_dict -------------------------
5947 --
5948 BEGIN
5949     --
5950     -- find out if its a grade or spine that needs to be created:
5951     --
5952     select rate_type,
5953            replace (ltrim (rtrim (upper (name))), ' ', '_'),
5954            business_group_id,
5955            created_by,
5956            last_update_login
5957     into   l_rate_type,
5958            l_name,
5959            l_business_group_id,
5960            l_created_by,
5961            l_last_login
5962     from   pay_rates
5963     where  rate_id = p_rate_id;
5964     --
5965     if (l_rate_type = 'G') then          -- grade
5966         --
5967         -- create the user entity for the grade rate route
5968         --
5969         insert_user_entity (l_grade_route_name,
5970                             'GRADE_' || l_name,
5971                             'entity for '|| l_grade_route_name,
5972                             'Y',                -- not found allowed flag
5973                             'G',
5974                             p_rate_id,
5975                             l_business_group_id,
5976                             null,               -- null legislation code
5977                             l_created_by,
5978                             l_last_login,
5979                             l_record_inserted);
5980         --
5981         -- only insert parameter values/database items if entity was inserted
5982         --
5983         IF l_record_inserted THEN
5984             --
5985             -- insert the rate id for the where clause filler
5986             --
5987             insert_parameter_value (p_rate_id, 1);
5988             --
5989             l_name := 'GRADE_' || l_name;
5990             --
5991             -- load up the database items for the grade rate route:
5992             --
5993             insert_database_item (l_name,
5994                               'VALUE',
5995                               'T',                       -- data type
5996                               'GRULE.value',
5997                               'Y',                       -- null allowed
5998                               'value for grade rates');
5999             --
6000             insert_database_item (l_name,
6001                               'MINIMUM',
6002                               'T',                       -- data type
6003                               'GRULE.minimum',
6004                               'Y',                       -- null allowed
6005                               'minimum value for grade rates');
6006             --
6007             insert_database_item (l_name,
6008                               'MAXIMUM',
6009                               'T',                       -- data type
6010                               'GRULE.maximum',
6011                               'Y',                       -- null allowed
6012                               'maximum value for grade rates');
6013         END IF;
6014     else                                  -- a spine rate
6015         --
6016         -- create the user entity for the spine rate route
6017         --
6018         insert_user_entity (l_spine_route_name,
6019                             'SPINE_' || l_name,
6020                             'entity for '|| l_spine_route_name,
6021                             'Y',                -- not found allowed flag
6022                             'G',
6023                             p_rate_id,
6024                             l_business_group_id,
6025                             null,               -- null legislation code
6026                             l_created_by,
6027                             l_last_login,
6028                             l_record_inserted);
6029         --
6030         -- only insert parameter values/database items if entity was inserted
6031         --
6032         IF l_record_inserted THEN
6033             --
6034             -- insert the rate id for the where clause filler
6035             --
6036             insert_parameter_value (p_rate_id, 1);
6037             --
6038             l_name := 'SPINE_' || l_name;
6039             --
6040             -- load up the database items for the grade rate route:
6041             --
6042             insert_database_item (l_name,
6043                               'VALUE',
6044                               'T',                       -- data type
6045                               'target.value',
6046                               'Y',                       -- null allowed
6047                               'value for spine rates');
6048         END IF;
6049     end if;
6050 end create_grade_spine_dict;
6051 --
6052 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6053 --                                                                        +
6054 --                     refresh_grade_spine_rates                          +
6055 --                                                                        +
6056 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6057 /*
6058 NAME
6059     refresh_grade_spine_rates  - create DB items for grade and spine rates
6060 --
6061 DESCRIPTION
6062     This routine creates all database items based on grade and spine rates
6063     in the system. The routine assumes that no such database items currently
6064     exist.
6065 */
6066 procedure refresh_grade_spine_rates is
6067    cursor c1 is select rate_id
6068                 from   pay_rates r
6069                 where not exists (select null from ff_user_entities u
6070                    where u.creator_id = r.rate_id
6071                    and   u.creator_type = 'G');
6072 begin
6073    for c1rec in c1 loop
6074        hrrbdeib_trace_on;
6075        hr_utility.trace ('creating database item grade/ spine rate id: '||
6076                                           to_char (c1rec.rate_id));
6077        hrrbdeib_trace_off;
6078        create_grade_spine_dict (c1rec.rate_id);
6079    end loop;
6080 end refresh_grade_spine_rates;
6081 --
6082 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6083 --                                                                        +
6084 --                        delete_grade_spine_rates                        +
6085 --                                                                        +
6086 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6087 /*
6088 NAME
6089     delete_grade_spine_rates  - delete DB items for grade and spine rates
6090 --
6091 DESCRIPTION
6092     This routine deletes all database items based on grade or spine rates
6093     in the system. The routine assumes that no such database items currently
6094     exist.
6095 */
6096 procedure delete_grade_spine_rates is
6097    cursor c1 is select rate_id
6098                 from   pay_rates;
6099 begin
6100    --
6101    -- delete the grade/ spine rates
6102    --
6103    for c1rec in c1 loop
6104        hrrbdeib_trace_on;
6105        hr_utility.trace ('deleting database item grade/ spine rate id: '||
6106                                           to_char (c1rec.rate_id));
6107        hrrbdeib_trace_off;
6108        delete_grade_spine_dict (c1rec.rate_id);
6109    end loop;
6110 end delete_grade_spine_rates;
6111 --
6112 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6113 --                                                                        +
6114 --                     delete_flexfield_dict                              +
6115 --                                                                        +
6116 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6117 /*
6118 NAME
6119       delete_flexfield_dict - delete a descriptive flexfield in the
6120                               data dictionary
6121 --
6122 DESCRIPTION
6123       This procedure is the main entry point for deleting descriptive
6124       flexfield database items.  To delete all the descriptive flexfield
6125       database items for a given legislation code, pass the title parameter
6126       as '%'. To delete an individual  descriptive flexfield pass the title
6127       of the flexfield.
6128 NOTES
6129       Since the legislation code for a descriptive flexfield could be null
6130       a nvl function is required as part of the SQL statement.
6131 */
6132 procedure delete_flexfield_dict
6133 (
6134     p_title       in varchar2,
6135     p_context     in varchar2,
6136     p_leg_code    in varchar2
6137 ) is
6138 l_entity_name     ff_user_entities.user_entity_name%type;
6139 BEGIN
6140     if (p_title   = '%') and
6141        (p_context = '%') then  -- delete all descriptive flexfield DB items
6142         --
6143         -- first delete any complied formula references
6144         --
6145         delete_compiled_formula (null,
6146                                  'DF',
6147                                  '%',
6148                                  p_leg_code);
6149         --
6150         -- now delete the actual database items
6151         --
6152         delete from ff_user_entities
6153         where  creator_type                 = 'DF'
6154         and    nvl (legislation_code, ' ')  = nvl (p_leg_code, ' ');
6155         --
6156     else                    -- delete selected DB items
6157         --
6158         -- assemble the entity name:
6159         --
6160         l_entity_name := replace (replace (ltrim(rtrim(upper(p_title))),' ','_'),'''','')
6161                          ||'_'|| replace (ltrim(rtrim(upper(p_context))),' ','_');
6162         l_entity_name := l_entity_name || '_DF%';
6163         --
6164         -- first delete any complied formula references
6165         --
6166         delete_compiled_formula (null,
6167                                  'DF',
6168                                  l_entity_name,
6169                                  p_leg_code);
6170         --
6171         -- now delete the actual database items
6172         --
6173         delete from ff_user_entities
6174         where  creator_type             = 'DF'
6175         and    user_entity_name      like l_entity_name
6176         and    nvl (legislation_code, ' ')  = nvl (p_leg_code, ' ');
6177     end if;
6178 end delete_flexfield_dict;
6179 --
6180 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6181 --                                                                        +
6182 --                         create_desc_flex                               +
6183 --                                                                        +
6184 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6185 /*
6186    NAME
6187       create_desc_flex - General routine to create Descriptive flexs.  Called
6188                          from the main Descriptive flexfield DB item generation
6189                          procedures.
6190 --
6191    DESCRIPTION
6192       This procedure creates Descriptive flexfield DB items, and is responsible
6193       for creating the user entities for a particular flexfield.  For the
6194       given flexfield there could be several contexts that apply to several
6195       flexfield segment names.  Hence two cursor loops are used to generate
6196       the database items, the outer one to select the context
6197       and the inner one to select the column names.
6198 */
6199 --
6200 -- This create_desc_flex() does not accept business_group_id for context
6201 -- sensitive db_item generation.
6202 --
6203 procedure create_desc_flex
6204 (
6205     p_title       in varchar2,
6206     p_table_name  in varchar2,
6207     p_route_name  in varchar2,
6208     p_entity_name in varchar2,
6209     p_context     in varchar2,
6210     p_global_flag in varchar2,
6211     p_param_value in varchar2,
6212     p_leg_code    in varchar2
6213 ) is
6214 BEGIN
6215    create_desc_flex_main( p_title,
6216                           p_table_name,
6217                           p_route_name,
6218                           p_entity_name,
6219                           p_context,
6220                           p_global_flag,
6221                           p_param_value,
6222                           p_leg_code,
6223                           p_business_group_id => NULL );
6224 END create_desc_flex;
6225 --
6226 -- This create_desc_flex() accepts business_group_id for context
6227 -- sensitive db_item generation.
6228 --
6229 procedure create_desc_flex
6230 (
6231     p_title             in varchar2,
6232     p_table_name        in varchar2,
6233     p_route_name        in varchar2,
6234     p_entity_name       in varchar2,
6235     p_context           in varchar2,
6236     p_global_flag       in varchar2,
6237     p_param_value       in varchar2,
6238     p_leg_code          in varchar2,
6239     p_business_group_id in varchar2
6240 ) is
6241 BEGIN
6242    create_desc_flex_main( p_title,
6243                           p_table_name,
6244                           p_route_name,
6245                           p_entity_name,
6246                           p_context,
6247                           p_global_flag,
6248                           p_param_value,
6249                           p_leg_code,
6250                           p_business_group_id );
6251 END create_desc_flex;
6252 --
6253 -- Main create_desc_flex() procedure
6254 --
6255 procedure create_desc_flex_main
6256 (
6257     p_title             in varchar2,
6258     p_table_name        in varchar2,
6259     p_route_name        in varchar2,
6260     p_entity_name       in varchar2,
6261     p_context           in varchar2,
6262     p_global_flag       in varchar2,
6263     p_param_value       in varchar2,
6264     p_leg_code          in varchar2,
6265     p_business_group_id in varchar2
6266 ) is
6267 l_param_value         ff_route_parameter_values.value%type;
6268 l_dbitem_found        boolean;
6269 l_entity_name         ff_user_entities.user_entity_name%type;
6270 l_created_by          number;
6271 l_last_login          number;
6272 l_record_inserted     boolean;
6273 l_user_entity_id      number;
6274 --
6275 --
6276 begin
6277    for c1rec in dflex_c1 (p_table_name,
6278                           p_title,
6279                           p_global_flag,
6280                           p_context) loop
6281 
6282        l_dbitem_found := FALSE;
6283        --
6284        -- now create the database items
6285        --
6286        for c2rec in dflex_c2 (c1rec.c_flex_name,
6287                               p_context) loop
6288            --
6289            -- only create a user entity if database items are to be created.
6290            --
6291            if (l_dbitem_found = FALSE) then
6292                l_dbitem_found := TRUE;
6293                --
6294                -- delete any old descriptive flex DB items of the same name:
6295                --
6296                delete_flexfield_dict (p_title,
6297                                       p_context,
6298                                       p_leg_code);
6299                --
6300                -- create a user entity, first construct the entity name:
6301                -- (note: the c1 cursor perform the upper functions, etc. for
6302                -- the title name).
6303                --
6304                l_entity_name := c1rec.c_title || '_' ||
6305                               replace (ltrim(rtrim(upper(p_context))),' ','_');
6306                --
6307                l_created_by := c1rec.c_created_by;
6308                l_last_login := c1rec.c_last_login;
6309                --
6310                insert_user_entity (p_route_name,
6311                                    l_entity_name || '_DF',
6312                                    'entity for '|| p_route_name,
6313                                    'Y',
6314                                    'DF',
6315                                    null,        -- null creator id
6316                                    p_business_group_id,
6317                                    p_leg_code,
6318                                    l_created_by,
6319                                    l_last_login,
6320                                    l_record_inserted);
6321                --
6322                -- only insert parameter values/database items if entity
6323                -- was inserted
6324                --
6325                IF l_record_inserted THEN
6326                   --
6327                   -- if we are creating certain Developer DF DB items then we
6328                   -- need to insert the type context into the route parameter
6329                   -- value table.
6330                   --
6331                   if (p_route_name = 'DEVELOPER_ORG_DESC_FLEX_ROUTE') OR
6332                      (p_route_name = 'LEGAL_CO_DESC_FLEX_ROUTE')      OR
6333                      (p_route_name = 'DEVELOPER_ASS_DESC_FLEX_ROUTE') OR
6334                      (p_route_name = 'DEVELOPER_LOC_DESC_FLEX_ROUTE') OR
6335                      (p_route_name = 'DEVELOPER_POS_DESC_FLEX_ROUTE') OR
6336                      (p_route_name = 'DEVELOPER_PER_DESC_FLEX_ROUTE') then
6337                       --
6338                       -- note: fast formula requires the quotes for a text
6339                       -- string to be in the parameter value table, as opposed
6340                       -- to in the route.
6341                          --
6342                       l_param_value := '''' ||
6343                         replace (ltrim(rtrim(p_param_value)),' ','_') || '''';
6344                       insert_parameter_value (l_param_value, 1);
6345                       --
6346                   elsif (p_route_name = 'ENTRY_DESC_FLEX_ROUTE') then
6347                       -- Different insert for the Entry DDF as the
6348                       -- space replacement is not required
6349                       l_param_value := '''' ||
6350                                           ltrim(rtrim(p_param_value)) || '''';
6351                       insert_parameter_value (l_param_value, 1);
6352 
6353                   elsif (p_route_name = 'ORG_PAY_METHOD_DESC_FLEX_ROUTE') then
6354                       insert_parameter_value (p_param_value, 1);
6355                       --
6356                       --  We create the CURRENCY_CODE database item here
6357                       --  as the above delete_flexfield_dict will have
6358                       --  removed it if it had been delivered earlier.
6359                       --
6360                       insert_database_item (p_entity_name,
6361                                             'CURRENCY_CODE',
6362                                             'T',                -- data type
6363                                             'target.currency_code',
6364                                             'N',                -- null allowed
6365                                             'database item for : ' ||
6366                                                        p_entity_name);
6367 
6368 		  elsif (p_route_name is not null
6369                          and p_param_value is not null) then
6370                       --
6371                       -- create a parameter value if a route uses a parameter.
6372                       --
6373                       insert_parameter_value (p_param_value, 1);
6374                       --
6375 		  end if;
6376                ELSE
6377                 select user_entity_id
6378                 into l_user_entity_id
6379                 from ff_user_entities
6380                 where  user_entity_name=l_entity_name || '_DF'
6381                 and nvl(legislation_code,'X')=nvl(p_leg_code,'X')
6382                 and nvl(business_group_id,-1)=nvl(p_business_group_id,-1);
6383                END IF;
6384            end if;
6385            --
6386            insert_database_item (p_entity_name,
6387                                  c2rec.c_db_name,
6388                                  'T',                           -- data type
6389                                  'target.' || c2rec.c_def_text,
6390                                  'Y',                           -- null allowed
6391                                  'database item for : ' || p_entity_name,
6392                                  l_user_entity_id);
6393        end loop;  -- dflex_c2 loop
6394    end loop;  -- dflex_c1 loop
6395 end create_desc_flex_main;
6396 --
6397 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6398 --                                                                        +
6399 --                       get_legislation_code                             +
6400 --                                                                        +
6401 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6402 --
6403 -- This private function is used to get the legislation code for the Developer
6404 -- Descriptive flex context as specified in the Information type tables.
6405 -- This function returns 'M' if the flex context allows multiple occurrences.
6406 --
6407 function get_legislation_code
6408   (p_flexfield_name in varchar2
6409   ,p_context        in varchar2)
6410   return varchar2 is
6411 --
6412 l_legislation_code    hr_org_information_types.legislation_code%type;
6413 l_navigation_method   hr_org_information_types.navigation_method%type;
6414 l_multi_occur_flag    per_assignment_info_types.multiple_occurences_flag%type;
6415 --
6416 begin
6417     --
6418     --
6419     if (p_flexfield_name in  ('Person Developer DF',
6420                               'Payroll Developer DF',
6421                               'Element Entry Developer DF',
6422                               'Job Developer DF')) then
6423         --
6424         l_legislation_code := p_context;
6425         --
6426     elsif (p_flexfield_name = 'Org Developer DF') then -- Organization DF
6427         --
6428         -- get the legislation code
6429         --
6430         select legislation_code,
6431                navigation_method
6432         into   l_legislation_code,
6433                l_navigation_method
6434         from   hr_org_information_types
6435         where  org_information_type = p_context;
6436         --
6437         -- The database item generated can only return one row. So if the
6438         -- navigation method is not 'GS' then raise an error.
6439         --
6440         if (l_navigation_method <> 'GS') then
6441             --
6442             return 'M';
6443             --
6444         end if;
6445         --
6446     elsif (p_flexfield_name = 'Assignment Developer DF') then
6447         --
6448         -- get the legislation code
6449         --
6450         select legislation_code,
6451                multiple_occurences_flag
6452         into   l_legislation_code,
6453                l_multi_occur_flag
6454         from   per_assignment_info_types
6455         where  information_type           = p_context;
6456         --
6457         -- The database item generated can only return one row. So if the
6458         -- multiple occurrences flag is not 'N' then raise an error.
6459         --
6460         if (l_multi_occur_flag <> 'N') then
6461             --
6462             return 'M';
6463             --
6464         end if;
6465         --
6466     elsif (p_flexfield_name = 'Extra Location Info DDF') then
6467         --
6468         -- get the legislation code:
6469         --
6470         select legislation_code,
6471                multiple_occurences_flag
6472         into   l_legislation_code,
6473                l_multi_occur_flag
6474         from   hr_location_info_types
6475         where  information_type           = p_context;
6476         --
6477         -- The database item generated can only return one row. So if the
6478         -- multiple occurrences flag is not 'N' then raise an error.
6479         --
6480         if (l_multi_occur_flag <> 'N') then
6481             --
6482             return 'M';
6483             --
6484         end if;
6485         --
6486     elsif (p_flexfield_name = 'Extra Position Info DDF') then
6487         --
6488         -- get the legislation code:
6489         --
6490         select legislation_code,
6491                multiple_occurences_flag
6492         into   l_legislation_code,
6493                l_multi_occur_flag
6494         from   per_position_info_types
6495         where  information_type           = p_context;
6496         --
6497         -- The database item generated can only return one row. So if the
6498         -- multiple occurrences flag is not 'N' then raise an error.
6499         --
6500         if (l_multi_occur_flag <> 'N') then
6501             --
6502             return 'M';
6503             --
6504         end if;
6505         --
6506     elsif (p_flexfield_name = 'Extra Person Info DDF') then
6507         --
6508         -- get the legislation code:
6509         --
6510         select legislation_code,
6511                multiple_occurences_flag
6512         into   l_legislation_code,
6513                l_multi_occur_flag
6514         from   per_people_info_types
6515         where  information_type           = p_context;
6516         --
6517         -- The database item generated can only return one row. So if the
6518         -- multiple occurrences flag is not 'N' then raise an error.
6519         --
6520         if (l_multi_occur_flag <> 'N') then
6521             --
6522             return 'M';
6523             --
6524         end if;
6525         --
6526     end if;
6527     --
6528     --
6529     return l_legislation_code;
6530     --
6531 end get_legislation_code;
6532 --
6533 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6534 --                                                                        +
6535 --                       create_flexfield_dict                            +
6536 --                                                                        +
6537 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6538 /*
6539    NAME
6540       create_flexfield_dict - create descriptive flexfield database items
6541 --
6542    DESCRIPTION
6543       This procedure is the main entry point for creating descriptive
6544       flexfield database items.  The title of the descriptive flex is passed to
6545       this routine as a parameter.  To create all the descriptive flexfield
6546       database items for a particular application pass the title parameter
6547       as '%'
6548       --
6549       The database items created use the name as defined in the column
6550       'end_user_column_name' from the foundation table
6551       'fnd_descr_flex_column_usages'.  For a given descriptive flexfield there
6552       could be several database items.
6553       --
6554    NOTES
6555       Since there is no desciptive flex id to identify an individual row in
6556       the ff_user_entities table, the title of the descriptive flex is used
6557       instead, holding it in the user_entity_name column.
6558       --
6559       It is intended that this flexfield creation procedure be run from the
6560       Standard Report Submission (SRS) form.
6561 */
6562 procedure create_flexfield_dict
6563 (
6564     p_title       in varchar2
6565 ) is
6566 -- declare a cursor to determine the routes to a descriptive flexfields'
6567 -- tables and an entity name for each of these tables.
6568 --
6569 cursor routes_c is
6570     select df.application_table_name,
6571            rtd.route_name,
6572            rtd.user_key
6573     from   fnd_descriptive_flexs_vl    df,
6574            pay_route_to_descr_flexs   rtd
6575     where  df.application_id = rtd.application_id
6576     and    df.descriptive_flexfield_name = rtd.descriptive_flexfield_name
6577     and    replace (ltrim (rtrim(df.title)), '''','') = p_title;
6578 --
6579 -- declare a cursor to determine all the business_group_id's that any
6580 -- context descriptive flexfield elements are sensitive to.
6581 --
6582 cursor bgrp_c (p_table_name varchar2) is
6583     select dfc.descriptive_flex_context_code bus_grp_id
6584     from   fnd_descr_flex_contexts  dfc,
6585            fnd_descriptive_flexs_vl df
6586     where  dfc.application_id = df.application_id
6587     and    dfc.descriptive_flexfield_name = df.descriptive_flexfield_name
6588     and    df.application_table_name = p_table_name
6589     and    replace (ltrim (rtrim(df.title)), '''','') = p_title
6590     and    df.default_context_field_name = 'BUSINESS_GROUP_ID'
6591     and    dfc.enabled_flag = 'Y'
6592     and    dfc.global_flag = 'N';
6593 --
6594 BEGIN
6595     for routes_crec in routes_c loop
6596 
6597         create_desc_flex (p_title,
6598                           routes_crec.application_table_name,
6599                           routes_crec.route_name,
6600                           routes_crec.user_key,
6601                           'Global Data Elements', -- context
6602                           'Y',                    -- global flag
6603                           null,                   -- no route parameters
6604                           null);                  -- legislation code
6605         --
6606         -- Now create business_group_id context dbitems
6607         --
6608         for bgrp_crec in bgrp_c(routes_crec.application_table_name) loop
6609             create_desc_flex (p_title,
6610                               routes_crec.application_table_name,
6611                               routes_crec.route_name,
6612                               routes_crec.user_key,
6613                               bgrp_crec.bus_grp_id,   -- context
6614                               'N',                    -- global flag
6615                               null,                   -- no route params
6616                               null,                   -- legislation code
6617                               bgrp_crec.bus_grp_id);  -- business group id
6618         end loop; -- bgrp_c loop
6619 
6620     end loop; -- routes_crec
6621 end create_flexfield_dict;
6622 --
6623 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6624 --                                                                        +
6625 --                   create_dev_desc_flex_dict                            +
6626 --                                                                        +
6627 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6628 /*
6629    NAME
6630       create_dev_desc_flex_dict - create developer descriptive flexfield
6631                                   database items
6632 --
6633    DESCRIPTION
6634       This procedure is the main entry point for creating developer descriptive
6635       flexfield database items.  The parameters passed in are the
6636       title of the descriptive flex and the context.
6637       --
6638       The database items created use the name as defined in the column
6639       'end_user_column_name' from the foundation table
6640       'fnd_descr_flex_column_usages'.  For a given descriptive flexfield there
6641       could be several database items.
6642       --
6643       This same procedure is called by different reports:
6644       --
6645       Create Organization Developer Descriptive Flexfield
6646       Create Person Developer Descriptive Flexfield
6647       Create Job Developer Descriptive Flexfield
6648       --
6649       The differences that affect this procedure are outlined below:
6650       --
6651       For the Organization DF report, the passed in context is a valid
6652       organization information type.  In order to create a unique name the
6653       database item is named:
6654       --
6655       <CONTEXT>_ORG_<SEGMENT_NAME>
6656       --
6657       where <CONTEXT> is the passed in value, upper cased and spaces removed.
6658       --
6659       For the Person DF and the Job Developer Descriptive Flexfield
6660       report, the passed in context is the legislation code.
6661       In order to create a unique name the database item for the Person
6662       developer DF is:
6663       --
6664       PEOPLE_<LEGISLATION_CODE>_<SEGMENT_NAME>
6665       --
6666       and for the Job developer DF, it is name:
6667       --
6668       JOB_<LEGISLATION_CODE>_<SEGMENT_NAME>
6669       --
6670       where <LEGISLATION_CODE> is the passed in value of 'p_context'.
6671       --
6672       Code added to create dbitems for Extra Location Info DDF,
6673       Extra Position Info DDF and Extra Person Info DDF.  The
6674       context passed for these 3 flexfields is the appropriate
6675       information type.
6676    NOTES
6677       Since there is no desciptive flex id to identify an individual row in
6678       the ff_user_entities table, the title of the descriptive flex is used
6679       instead, holding it in the user_entity_name column.
6680       --
6681       It is intended that this flexfield creation procedure be run from the
6682       Standard Report Submission (SRS) form.
6683 */
6684 procedure create_dev_desc_flex_dict
6685 (
6686     p_title       in varchar2,
6687     p_context     in varchar2
6688 ) is
6689 l_flexfield_name      fnd_descriptive_flexs_vl.descriptive_flexfield_name%type;
6690 l_legislation_code    hr_org_information_types.legislation_code%type;
6691 l_context             hr_org_information_types.org_information_type%type;
6692 l_navigation_method   hr_org_information_types.navigation_method%type;
6693 l_multi_occur_flag    per_assignment_info_types.multiple_occurences_flag%type;
6694 --
6695 -- declare a cursor to determine the routes to a descriptive flexfield's
6696 -- tables and an entity name for each of these tables.
6697 --
6698 cursor c_routes is
6699     select df.application_table_name,
6700            rtd.route_name,
6701            rtd.user_key
6702     from   fnd_descriptive_flexs_vl df,
6703            pay_route_to_descr_flexs rtd
6704     where  df.application_id = rtd.application_id
6705     and    df.descriptive_flexfield_name = rtd.descriptive_flexfield_name
6706     and    replace (ltrim (rtrim(df.title)), '''','') = p_title
6707     and    rtd.descriptive_flex_context_code = p_context;
6708 --
6709 -- declare a cursor to check whether the route uses a parameter
6710 --
6711 cursor c_chk_route_parameter (p_route_name varchar2) is
6712     select data_type
6713     from   ff_route_parameters rpm, ff_routes rt
6714     where  rt.route_name = p_route_name
6715     and    rpm.route_id  = rt.route_id;
6716 
6717 l_routes            c_routes%rowtype;
6718 l_routes_count      number := 0;
6719 l_parameter_type    varchar2(1);
6720 l_entity_name       varchar2(80);
6721 l_parameter_value   ff_route_parameter_values.value%type;
6722 --
6723 ---------------------- create_dev_desc_flex_dict  -------------------------
6724 --
6725 BEGIN
6726   --
6727   select descriptive_flexfield_name
6728   into   l_flexfield_name
6729   from   fnd_descriptive_flexs_vl
6730   where  title           = p_title
6731   and    application_id  between 800 and 801;
6732   --
6733   l_legislation_code := get_legislation_code(l_flexfield_name, p_context);
6734   --
6735   -- Create the DB items only if the context allows single occurrence
6736   --
6737   if nvl(l_legislation_code,'N') <> 'M' then
6738   --
6739   -- Bug 2637573 - Code added to check if any Developer DF contexts are
6740   -- seeded. If yes, then the DB items are created using the routes in
6741   -- table pay_route_to_descr_flexs.
6742   --
6743     open c_routes;
6744     loop
6745       --
6746       fetch c_routes into l_routes;
6747       l_routes_count := c_routes%rowcount;
6748       --
6749       exit when c_routes%notfound;
6750       --
6751       open c_chk_route_parameter(l_routes.route_name);
6752       fetch c_chk_route_parameter into l_parameter_type;
6753       --
6754       if c_chk_route_parameter%found then
6755         if (l_parameter_type = 'T') then
6756           l_parameter_value := '''' || p_context || '''';
6757         else
6758           l_parameter_value := p_context;
6759         end if;
6760       end if;
6761       --
6762       close c_chk_route_parameter;
6763       --
6764       l_entity_name := replace (ltrim(rtrim(upper(l_flexfield_name))),' ','_')
6765                        ||'_'||l_routes.user_key;
6766       --
6767       create_desc_flex (p_title,
6768                         l_routes.application_table_name,
6769                         l_routes.route_name,
6770                         l_entity_name,
6771                         p_context,                      -- context
6772                         'N',                            -- global flag
6773                         l_parameter_value,              -- route parameter
6774                         l_legislation_code);            -- legislation_code
6775       --
6776     end Loop;
6777     close c_routes;
6778     --
6779   end if;
6780   --
6781   -- If no Developer DF contexts are seeded then DB items areccreated using the
6782   -- regular method.
6783   --
6784   If l_routes_count = 0 then
6785     --
6786     -- find out which report called this routine, either the Organization
6787     -- DF, the person developer DF or the job developer DF.
6788     --
6789     if (l_flexfield_name = 'Person Developer DF') then
6790         create_desc_flex (p_title,
6791                           'PER_ALL_PEOPLE_F',
6792                           'PEOPLE_FLEXFIELD_ROUTE',
6793                           'PEOPLE_' || p_context,
6794                           p_context,                 -- the context name
6795                           'N',                       -- global flag
6796                           null,                      -- no route parameters
6797                           p_context);                -- legislation code
6798         --
6799     elsif (l_flexfield_name = 'Org Developer DF') then -- Organization DF
6800         --
6801         -- get the legislation code
6802         --
6803         select legislation_code,
6804                navigation_method
6805         into   l_legislation_code,
6806                l_navigation_method
6807         from   hr_org_information_types
6808         where  org_information_type = p_context;
6809         --
6810         -- this check to see if the navigation_method is 'GS' is also
6811         -- performed in the concurrent program.  It has been added here as
6812         -- well, in case this procedure is called directly, and to ensure that
6813         -- the database item generated can only return one row.
6814         --
6815         if (l_navigation_method = 'GS') then
6816             l_context := replace (ltrim (rtrim (upper (p_context))), ' ', '_');
6817             --
6818             create_desc_flex (p_title,
6819                               'HR_ORGANIZATION_INFORMATION',
6820                               'DEVELOPER_ORG_DESC_FLEX_ROUTE',
6821                               l_context || '_ORG',
6822                               p_context,            -- the context name
6823                               'N',                  -- global flag
6824                               p_context,            -- used for route parameter
6825                               l_legislation_code);  -- legislation code
6826             --
6827             -- see if any Legal Company Descriptive Flexs are to be created:
6828             --
6829             if ((l_legislation_code is null)
6830                 or (l_legislation_code ='US')
6831                 or (l_legislation_code ='CA')) then
6832                 create_desc_flex (p_title,
6833                                   'HR_ORGANIZATION_INFORMATION',
6834                                   'LEGAL_CO_DESC_FLEX_ROUTE',
6835                                   'LC_' || l_context || '_ORG',
6836                                    p_context,            -- the context name
6837                                   'N',                   -- global flag
6838                                   p_context,        -- used for route parameter
6839                                   l_legislation_code);  -- legislation code
6840             end if;
6841 	    --
6842         end if;
6843         --
6844     elsif (l_flexfield_name = 'Assignment Developer DF') then
6845         --
6846         -- get the legislation code:
6847         --
6848         select legislation_code,
6849                multiple_occurences_flag
6850         into   l_legislation_code,
6851                l_multi_occur_flag
6852         from   per_assignment_info_types
6853         where  information_type           = p_context;
6854         --
6855         -- this check to see if the multiple_occurences_flag is 'N' is also
6856         -- performed in the concurrent program.  It has been added here as
6857         -- well in case this procedure is called directly, and to ensure that
6858         -- the database item generated can only return one row.
6859         --
6860         if (l_multi_occur_flag = 'N') then
6861             l_context := replace (ltrim (rtrim (upper (p_context))), ' ', '_');
6862             --
6863             create_desc_flex (p_title,
6864                               'PER_ASSIGNMENT_EXTRA_INFO',
6865                               'DEVELOPER_ASS_DESC_FLEX_ROUTE',
6866                               l_context || '_ASG',
6867                               p_context,            -- the context name
6868                               'N',                  -- global flag
6869                               p_context,            -- used for route parameter
6870                               l_legislation_code);  -- legislation code
6871         end if;
6872 --
6873     elsif (l_flexfield_name = 'Payroll Developer DF') then -- Payroll DDF
6874         create_desc_flex (p_title,
6875                           'PAY_ALL_PAYROLLS_F',
6876                           'PAYROLL_FLEXFIELD_ROUTE',
6877                           'PAY_' || p_context,
6878                           p_context,                 -- the context name
6879                           'N',                       -- global flag
6880                           null,                      -- no route parameters
6881                           p_context);                -- legislation code
6882 --
6883     elsif (l_flexfield_name = 'Extra Location Info DDF') then
6884         --
6885         -- get the legislation code:
6886         --
6887         select legislation_code,
6888                multiple_occurences_flag
6889         into   l_legislation_code,
6890                l_multi_occur_flag
6891         from   hr_location_info_types
6892         where  information_type           = p_context;
6893         --
6894         -- this check to see if the multiple_occurences_flag is 'N' is also
6895         -- performed in the concurrent program.  It has been added here as
6896         -- well in case this procedure is called directly, and to ensure that
6897         -- the database item generated can only return one row.
6898         --
6899         if (l_multi_occur_flag = 'N') then
6900             l_context := replace (ltrim (rtrim (upper (p_context))), ' ', '_');
6901             --
6902             create_desc_flex (p_title,
6903                               'HR_LOCATION_EXTRA_INFO',
6904                               'DEVELOPER_LOC_DESC_FLEX_ROUTE',
6905                               l_context || '_LOC',
6906                               p_context,            -- the context name
6907                               'N',                  -- global flag
6908                               p_context,            -- used for route parameter
6909                               l_legislation_code);  -- legislation code
6910 	end if;
6911 --
6912     elsif (l_flexfield_name = 'Extra Position Info DDF') then
6913         --
6914         -- get the legislation code:
6915         --
6916         select legislation_code,
6917                multiple_occurences_flag
6918         into   l_legislation_code,
6919                l_multi_occur_flag
6920         from   per_position_info_types
6921         where  information_type           = p_context;
6922         --
6923         -- this check to see if the multiple_occurences_flag is 'N' is also
6924         -- performed in the concurrent program.  It has been added here as
6925         -- well in case this procedure is called directly, and to ensure that
6926         -- the database item generated can only return one row.
6927         --
6928         if (l_multi_occur_flag = 'N') then
6929             l_context := replace (ltrim (rtrim (upper (p_context))), ' ', '_');
6930             --
6931             create_desc_flex (p_title,
6932                               'PER_POSITION_EXTRA_INFO',
6933                               'DEVELOPER_POS_DESC_FLEX_ROUTE',
6934                               l_context || '_POS',
6935                               p_context,            -- the context name
6936                               'N',                  -- global flag
6937                               p_context,            -- used for route parameter
6938                               l_legislation_code);  -- legislation code
6939 	end if;
6940 --
6941     elsif (l_flexfield_name = 'Extra Person Info DDF') then
6942         --
6943         -- get the legislation code:
6944         --
6945         select legislation_code,
6946                multiple_occurences_flag
6947         into   l_legislation_code,
6948                l_multi_occur_flag
6949         from   per_people_info_types
6950         where  information_type           = p_context;
6951         --
6952         -- this check to see if the multiple_occurences_flag is 'N' is also
6953         -- performed in the concurrent program.  It has been added here as
6954         -- well in case this procedure is called directly, and to ensure that
6955         -- the database item generated can only return one row.
6956         --
6957         if (l_multi_occur_flag = 'N') then
6958             l_context := replace (ltrim (rtrim (upper (p_context))), ' ', '_');
6959             --
6960             create_desc_flex (p_title,
6961                               'PER_PEOPLE_EXTRA_INFO',
6962                               'DEVELOPER_PER_DESC_FLEX_ROUTE',
6963                               l_context || '_PER',
6964                               p_context,            -- the context name
6965                               'N',                  -- global flag
6966                               p_context,            -- used for route parameter
6967                               l_legislation_code);  -- legislation code
6968 	end if;
6969 --
6970     elsif (l_flexfield_name = 'Element Entry Developer DF') then
6971         create_desc_flex (p_title,
6972                           'PAY_ELEMENT_ENTRIES_F',
6973                           'ENTRY_DESC_FLEX_ROUTE',
6974                           'ENTRY_'|| replace(ltrim(rtrim(p_context)),' ','_'),
6975                           p_context,              -- the context name
6976                           'N',                    -- global flag
6977                           p_context,              -- used for route parameter
6978                           substrb(p_context,1,2));   -- legislation code
6979     else                       -- a job developer DF
6980         --
6981         -- A Job developer descriptive flex.  The 'p_context' parameter is a
6982         -- legislation code, which is used as the context code in the
6983         -- descriptive flex tables, and as part of the DB item name.
6984         --
6985         create_desc_flex (p_title,
6986                           'PER_JOBS',
6987                           'JOBS_DESC_FLEX_ROUTE',
6988                           'JOBS_' || p_context,
6989                           p_context,
6990                           'N',                        -- global flag
6991                           null,                       -- no route parameters
6992                           p_context);                 -- legislation code
6993     end if;
6994   --
6995   end if;
6996   --
6997 end create_dev_desc_flex_dict;
6998 --
6999 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7000 --                                                                        +
7001 --                   create_org_pay_flex_dict                             +
7002 --                                                                        +
7003 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7004 /*
7005    NAME
7006       create_org_pay_flex_dict - Create Organization Payment descriptive
7007                                  flexfield database items
7008 --
7009    DESCRIPTION
7010       This procedure is the main entry point for creating Organization
7011       Payment descriptive flexfield database items.  The parameters passed
7012       in are the payment type id.
7013       --
7014       The database items created use the name as defined in the column
7015       'end_user_column_name' from the foundation table
7016       'fnd_descr_flex_column_usages'.  For a given descriptive flexfield there
7017       could be several database items.
7018    NOTES
7019       Since there is no desciptive flex id to identify an individual row in
7020       the ff_user_entities table, the title of the descriptive flex is used
7021       instead, holding it in the user_entity_name column.
7022 
7023       Added rtrim to title select below, due to Reserved word problem, ie
7024       the title, in creating descriptive flex cannot contain full stops,
7025       eg 'Further Payment Info.' - this is a temporary measure.
7026 */
7027 procedure create_org_pay_flex_dict
7028 (
7029     p_payment_id  in number
7030 ) is
7031 cursor get_title is
7032    select rtrim(title,'.') from fnd_descriptive_flexs_vl
7033    where descriptive_flexfield_name = 'Paymeth Developer DF';
7034 --
7035 l_context        pay_payment_types.payment_type_name%type;
7036 l_context_upper  pay_payment_types.payment_type_name%type;
7037 l_title          varchar2(80);
7038 --
7039 ---------------------- create_org_pay_flex_dict  -------------------------
7040 --
7041 BEGIN
7042     --
7043     -- get the context
7044     --
7045     select payment_type_name
7046     into   l_context
7047     from   pay_payment_types
7048     where  payment_type_id   = p_payment_id;
7049     --
7050     open get_title;
7051     fetch get_title into l_title;
7052     close get_title;
7053     --
7054     l_context_upper := replace (ltrim (rtrim (upper (l_context))), ' ', '_');
7055     create_desc_flex (l_title,
7056                       'PAY_ORG_PAYMENT_METHODS_F',
7057                       'ORG_PAY_METHOD_DESC_FLEX_ROUTE',
7058                       l_context_upper,            -- used for entity name
7059                       l_context,                  -- the context name
7060                       'N',                        -- global flag
7061                       p_payment_id,               -- the route parameter
7062                       null);                      -- legislation code
7063 end create_org_pay_flex_dict;
7064 --
7065 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7066 --                                                                        +
7067 --                       create_absence_dict                              +
7068 --                                                                        +
7069 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7070 /*
7071    NAME
7072       create_absence_dict - create an absence database item in the dictionary
7073 --
7074    DESCRIPTION
7075       This procedure is the main entry point for creating absence type
7076       database items.  The routes must have already been defined in the
7077       database (in table ff_routes).  The procedure will search for the
7078       routes in this table by using the route name, which is hard coded below.
7079       The database items use the absence type name.  The following
7080       database item is created:
7081       --
7082       <NAME>_CUM_BALANCE        -- sum of entry values for that absence type
7083 */
7084 procedure create_absence_dict
7085 (
7086     p_absence_type_id   in number
7087 ) is
7088 l_route_name          varchar2(50) := 'ABSENCE_SUM_OF_ELEMENT_ENTRY_VALUES';
7089 l_absence_name        per_absence_attendance_types.name%type;
7090 l_business_group_id   number;
7091 l_created_by          number;
7092 l_last_login          number;
7093 l_record_inserted     boolean;
7094 --
7095 ------------------------- create_absence_dict -------------------------
7096 --
7097 BEGIN
7098     --
7099     -- get the absence type information
7100     --
7101     select replace (ltrim (rtrim (upper (name))), ' ', '_'),
7102            business_group_id,
7103            created_by,
7104            last_update_login
7105     into   l_absence_name,
7106            l_business_group_id,
7107            l_created_by,
7108            l_last_login
7109     from   per_absence_attendance_types
7110     where  absence_attendance_type_id    = p_absence_type_id;
7111     --
7112     -- create the user entity for the route
7113     --
7114     insert_user_entity (l_route_name,
7115                         l_absence_name,
7116                         'entity for '|| l_route_name,
7117                         'Y',                         -- not found allowed flag
7118                         'A',
7119                         p_absence_type_id,
7120                         l_business_group_id,
7121                         null,                        -- null legislation code
7122                         l_created_by,
7123                         l_last_login,
7124                         l_record_inserted);
7125     --
7126     -- only insert parameter values/database items if entity was inserted
7127     --
7128     IF l_record_inserted THEN
7129         --
7130         -- insert the absence type id for the where clause filler
7131         --
7132         insert_parameter_value (p_absence_type_id, 1);
7133         --
7134         -- load up the database item for the route:
7135         --
7136         insert_database_item (l_absence_name,
7137                           'CUM_BALANCE',
7138                           'N',                           -- data type
7139                           'sum (fnd_number.canonical_to_number(target.screen_entry_value))',
7140                           'Y',                           -- null allowed
7141               'cumulative balance of an absence type for a given assignment');
7142     END IF;
7143 end create_absence_dict;
7144 --
7145 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7146 --                                                                        +
7147 --                        delete_absence_dict                             +
7148 --                                                                        +
7149 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7150 /*
7151 NAME
7152       delete_absence_dict - delete the absence DB items from the data
7153                             dictionary
7154 --
7155 DESCRIPTION
7156 */
7157 procedure delete_absence_dict
7158 (
7159     p_absence_type_id  in number
7160 ) is
7161 --
7162 BEGIN
7163     DELETE FROM ff_user_entities
7164     WHERE  creator_id    = p_absence_type_id
7165     AND    creator_type  = 'A';
7166 end delete_absence_dict;
7167 --
7168 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7169 --                                                                        +
7170 --                        refresh_absence_types                           *
7171 --                                                                        +
7172 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7173 /*
7174 NAME
7175     refresh_absence_types  - create DB items for all absence types
7176 --
7177 DESCRIPTION
7178     This routine creates all database items based on absence types
7179     in the system. The routine assumes that no such database items currently
7180     exist.
7181 */
7182 procedure refresh_absence_types is
7183    cursor c1 is select absence_attendance_type_id type_id
7184                 from   per_absence_attendance_types;
7185 begin
7186    for c1rec in c1 loop
7187        hrrbdeib_trace_on;
7188        hr_utility.trace ('creating database item absence type id: '||
7189                                           to_char (c1rec.type_id));
7190        hrrbdeib_trace_off;
7191        create_absence_dict (c1rec.type_id);
7192    end loop;
7193 end refresh_absence_types;
7194 --
7195 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7196 --                                                                        +
7197 --                        delete_absence_types                            +
7198 --                                                                        +
7199 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7200 /*
7201 NAME
7202     delete_absence_types  - delete DB items for absence types
7203 --
7204 DESCRIPTION
7205     This routine deletes all database items based on absence types
7206     in the system. The routine assumes that no such database items currently
7207     exist.
7208 */
7209 procedure delete_absence_types is
7210    cursor c1 is select absence_attendance_type_id type_id
7211                 from   per_absence_attendance_types;
7212 begin
7213    --
7214    -- delete the absence types
7215    --
7216    for c1rec in c1 loop
7217        hrrbdeib_trace_on;
7218        hr_utility.trace ('deleting database item absence type id: '||
7219                                           to_char (c1rec.type_id));
7220        hrrbdeib_trace_off;
7221        delete_absence_dict (c1rec.type_id);
7222    end loop;
7223 end delete_absence_types;
7224 --
7225 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7226 --                                                                        +
7227 --                     delete_keyflex_dict                                +
7228 --                                                                        +
7229 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7230 /*
7231    NAME
7232       delete_keyflex_dict - delete a key flexfield in the data dictionary
7233 --
7234    DESCRIPTION
7235       This procedure is the main entry point for deleting key
7236       flexfield database items.  The parameters passed in are the id flex num
7237       and the name of the key flexfield.
7238 --
7239    NOTES
7240 */
7241 procedure delete_keyflex_dict
7242 (
7243     p_creator_id    in number,
7244     p_entity_name   in varchar2,
7245     p_leg_code      in varchar2,
7246     p_business_group_id in number
7247 ) is
7248 l_entity_name     ff_user_entities.user_entity_name%type;
7249 BEGIN
7250     l_entity_name := p_entity_name || '%';
7251     --
7252     -- delete any complied formula references
7253     --
7254    delete_compiled_formula (p_creator_id,
7255                             'KF',
7256                             l_entity_name,
7257                             p_leg_code);
7258     --
7259     -- now delete the actual database items
7260     --
7261     delete from ff_user_entities
7262     where creator_type        = 'KF'
7263     and   creator_id          = p_creator_id
7264     and   user_entity_name like l_entity_name
7265     and  ( nvl (legislation_code, ' ') = nvl (p_leg_code, ' ')        -- 6955080
7266         OR nvl (business_group_id, -1) = nvl (p_business_group_id, -1));
7267 end delete_keyflex_dict;
7268 --
7269 --
7270 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7271 --                                                                        +
7272 --                         create_key_flex                                +
7273 --                                                                        +
7274 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7275 /*
7276    NAME
7277       create_key_flex - General procedure for creating Key flexfield DB items
7278 --
7279    DESCRIPTION
7280       This procedure is responsible for creating the database items for a
7281       particular key flexfield.
7282 --
7283    NOTES
7284       The parameter 'p_table_name' is the name of the table as referred to in
7285       the table alias of the route.
7286 */
7287 procedure create_key_flex
7288 (
7289     p_applic_id       in number,
7290     p_business_group  in number,
7291     p_id_flex_num     in number,
7292     p_id_flex_code    in varchar2,
7293     p_entity_name     in varchar2,
7294     p_leg_code        in varchar2,
7295     p_route_name      in varchar2,
7296     p_table_name      in varchar2
7297 ) is
7298 --
7299 -- declare cursor for retrieving the actual column names:
7300 --
7301 cursor c1 is
7302 SELECT  application_column_name c_def_text,
7303         replace (ltrim(rtrim(upper(segment_name))),' ','_') c_db_name
7304 FROM    fnd_id_flex_segments
7305 WHERE   application_id                = p_applic_id
7306 AND     id_flex_num                   = p_id_flex_num
7307 AND     id_flex_code                  = p_id_flex_code;
7308 --
7309 l_dbitem_found        boolean;
7310 l_record_inserted     boolean;
7311 l_user_entity_id      number;
7312 l_created_by          number := 0;
7313 l_last_login          number := 0;
7314 --
7315 ------------------------- create_key_flex -------------------------
7316 --
7317 begin
7318    l_dbitem_found := FALSE;
7319    --
7320    for c1rec in c1 loop
7321        if (l_dbitem_found = FALSE) then
7322            l_dbitem_found := TRUE;
7323            --
7324            -- create a user entity only if database items exist.
7325            --
7326            insert_user_entity (p_route_name,
7327                                p_entity_name || '_KEY_FLEX_ENTITY',
7328                                'route for key flexfield : '|| p_route_name,
7329                                'Y',
7330                                'KF',
7331                                p_id_flex_num,
7332                                p_business_group,
7333                                p_leg_code,
7334                                l_created_by,
7335                                l_last_login,
7336                         l_record_inserted);
7337        end if;
7338        insert_database_item (p_entity_name,
7339                              c1rec.c_db_name,
7340                              'T',                           -- data type
7341                              p_table_name || '.' || c1rec.c_def_text,
7342                              'Y',                           -- null allowed
7343                              'database item for : ' || p_entity_name);
7344    end loop;  -- c1 loop
7345 end create_key_flex;
7346 --
7347 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7348 --                                                                        +
7349 --                       create_keyflex_dict                              +
7350 --                                                                        +
7351 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7352 /*
7353    NAME
7354       create_keyflex_dict - create a key flexfield in the data dictionary
7355 --
7356    DESCRIPTION
7357       This procedure is the main entry point for creating key
7358       flexfield database items.  The routes must have already been defined
7359       in the database (in table ff_routes).  The procedure will search for the
7360       routes in this table by using the route name, which is hard coded below.
7361       The parameters passed in are the business group id and the name of the
7362       key flexfield.  To create all the key flexfield database items for a
7363       particular business group pass the name parameter as '%'. To create an
7364       individual key flexfield the following key flexfields are supported:
7365       --
7366       JOB         for 'p_keyflex_name' pass in : 'JOB'
7367       POSITION    for 'p_keyflex_name' pass in : 'POS'
7368       GRADE       for 'p_keyflex_name' pass in : 'GRD'
7369       GROUP       for 'p_keyflex_name' pass in : 'GRP'
7370       --
7371       The database items use the segment name column from the foundation
7372       table 'fnd_id_flex_segments'.  For a given key flexfield there
7373       could be several database items.
7374       The following database items are created:
7375       --
7376       GRADE_KF_<NAME>
7377       JOB_KF_<NAME>
7378       POS_KF_<NAME>
7379       GROUP_KF_<NAME>
7380       --
7381       It is intended that this flexfield creation procedure be run from the
7382       Standard Report Submission (SRS) form.
7383 */
7384 procedure create_keyflex_dict
7385 (
7386     p_business_group_id  in number,
7387     p_keyflex_name       in varchar2
7388 ) is
7389 l_legislation_code    varchar2(30);
7390 l_grade_flex_num      number;
7391 l_group_flex_num      number;
7392 l_job_flex_num        number;
7393 l_position_flex_num   number;
7394 l_competence_flex_num number;
7395 l_route_name          varchar2(50)  := 'KEY_FLEXFIELD_ROUTE';
7396 --
7397 ------------------------- create_keyflex_dict -------------------------
7398 --
7399 BEGIN
7400     --
7401     -- select the id flex numbers for each of the key flexfields
7402     --
7403     select  grade_structure,
7404             people_group_structure,
7405             job_structure,
7406             position_structure,
7407             competence_structure,
7408             legislation_code
7409     into    l_grade_flex_num,
7410             l_group_flex_num,
7411             l_job_flex_num,
7412             l_position_flex_num,
7413             l_competence_flex_num,
7414             l_legislation_code
7415     from    per_business_groups_perf
7416     where   business_group_id     = p_business_group_id;
7417     --
7418     -- create each of the flexfields
7419     --
7420     if ('GRD' like p_keyflex_name) then     -- create grade keyflex
7421         --
7422         -- first delete key flexfields that were previously created
7423         --
7424         delete_keyflex_dict (l_grade_flex_num,
7425                              'GRADE_KF',
7426                              l_legislation_code,
7427                              p_business_group_id);
7428         --
7429         create_key_flex (800,
7430                          p_business_group_id,
7431                          l_grade_flex_num,
7432                          'GRD',
7433                          'GRADE_KF',
7434                          null,
7435                          l_route_name,
7436                          'GRADEF');           -- target table name
7437     end if;
7438     --
7439     if ('JOB' like p_keyflex_name) then       -- create job keyflex
7440         --
7441         -- first delete key flexfields that were previously created
7442         --
7443         delete_keyflex_dict (l_job_flex_num,
7444                              'JOB_KF',
7445                              l_legislation_code,
7446                              p_business_group_id);
7447         --
7448         create_key_flex (800,
7449                          p_business_group_id,
7450                          l_job_flex_num,
7451                          'JOB',
7452                          'JOB_KF',
7453                          null,
7454                          l_route_name,
7455                          'JOBDEF');           -- target table name
7456     end if;
7457     --
7458     if ('POS' like p_keyflex_name) then  -- create position keyflex
7459         --
7460         -- first delete key flexfields that were previously created
7461         --
7462         delete_keyflex_dict (l_position_flex_num,
7463                              'POS_KF',
7464                              l_legislation_code,
7465                              p_business_group_id);
7466         --
7467         create_key_flex (800,
7468                          p_business_group_id,
7469                          l_position_flex_num,
7470                          'POS',
7471                          'POS_KF',
7472                          null,
7473                          l_route_name,
7474                          'POSDEF');           -- target table name
7475     end if;
7476     --
7477     if ('GRP' like p_keyflex_name) then     -- create group keyflex
7478         --
7479         -- first delete key flexfields that were previously created
7480         --
7481         delete_keyflex_dict (l_group_flex_num,
7482                              'GROUP_KF',
7483                              l_legislation_code,
7484                              p_business_group_id);
7485         --
7486         create_key_flex (801,
7487                          p_business_group_id,
7488                          l_group_flex_num,
7489                          'GRP',
7490                          'GROUP_KF',
7491                          null,
7492                          l_route_name,
7493                          'PGROUP');           -- target table name
7494     end if;
7495     --
7496     if ('CMP' like p_keyflex_name) then     -- create group keyflex
7497         --
7498         -- first delete key flexfields that were previously created
7499         --
7500         delete_keyflex_dict (l_competence_flex_num,
7501                              'COMP_KF',
7502                              l_legislation_code,
7503                              p_business_group_id);
7504         --
7505         create_key_flex (800,
7506                          p_business_group_id,
7507                          l_competence_flex_num,
7508                          'CMP',
7509                          'COMP_KF',
7510                          null,
7511                          l_route_name,
7512                          'COMP');           -- target table name
7513     end if;
7514 end create_keyflex_dict;
7515 --
7516 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7517 --                                                                        +
7518 --                    create_ext_acc_keyflex_dict                         +
7519 --                                                                        +
7520 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7521 /*
7522    NAME
7523       create_ext_acc_keyflex_dict - create a key flexfield for an External
7524                                     Account in the data dictionary
7525 --
7526    DESCRIPTION
7527       This procedure is the main entry point for creating External Account Key
7528       flexfield database items.  The routes must have already been defined
7529       in the database (in table ff_routes).  The procedure will search for the
7530       routes in this table by using the route name, which is hard coded below.
7531       The parameter passed in is the id_flex_num of the keyflex.
7532       --
7533       The database items use the segment name column from the foundation
7534       table 'fnd_id_flex_segments'.  For a given key flexfield there
7535       could be several database items.
7536       --
7537       The routine has been enhanced to loop around to create dbitems
7538       for each of the legislations which use the flex_num passed in.
7539 */
7540 procedure create_ext_acc_keyflex_dict
7541 (
7542     p_id_flex_num  in number
7543 ) is
7544 --
7545 -- declare cursor 1 for retrieving each legislation using this flex num
7546 --
7547 cursor c1 is
7548 select legislation_code
7549 from   pay_legislation_rules
7550 where  rule_type = 'E'
7551 and    rule_mode = to_char (p_id_flex_num);
7552 --
7553 l_legislation_code    pay_legislation_rules.legislation_code%type;
7554 l_route_name          varchar2(50)  := 'EXT_ACCOUNT_ORG_KEYFLEX_ROUTE';
7555 --
7556 ----------------------- create_ext_acc_keyflex_dict -------------------------
7557 --
7558 BEGIN
7559     --
7560     -- get each legislation code
7561     --
7562     --
7563     for c1rec in c1 loop
7564        --
7565        l_legislation_code := c1rec.legislation_code;
7566        --
7567        -- delete key flexfields that were previously created
7568        --
7569        delete_keyflex_dict (p_id_flex_num,
7570                             'ORG_' || l_legislation_code,
7571                             l_legislation_code,
7572                             null);
7573        --
7574        -- create the Organization External Account Keyflex
7575        --
7576        create_key_flex (801,
7577                         null,                       -- business group id
7578                         p_id_flex_num,
7579                         'BANK',
7580                         'ORG_' || l_legislation_code,
7581                         l_legislation_code,
7582                         l_route_name,
7583                         'target');                  -- target table name
7584        --
7585        -- delete key flexfields that were previously created
7586        --
7587        delete_keyflex_dict (p_id_flex_num,
7588                             'PER_' || l_legislation_code,
7589                             l_legislation_code,
7590                             null);
7591        --
7592        -- create the Personal External Account Keyflex
7593        --
7594        l_route_name := 'EXT_ACCOUNT_PER_KEYFLEX_ROUTE';
7595        --
7596        create_key_flex (801,
7597                         null,                       -- business group id
7598                         p_id_flex_num,
7599                         'BANK',
7600                         'PER_' || l_legislation_code,
7601                         l_legislation_code,
7602                         l_route_name,
7603                         'target');                  -- target table name
7604        --
7605     end loop; -- c1 loop
7606 end create_ext_acc_keyflex_dict;
7607 --
7608 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7609 --                                                                        +
7610 --                   create_scl_flex_dict                                 +
7611 --                                                                        +
7612 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7613 /*
7614    NAME
7615       create_scl_flex_dict - create Soft Coded Legislation Keyflex DB items
7616 --
7617    DESCRIPTION
7618       This procedure is the main entry point for creating Soft Coded
7619       Legislation Keyflex database items.  The parameter passed is is the
7620       id flex number.
7621       --
7622       The database items created use the name as defined in the column
7623       'segment_name' from the foundation table 'fnd_id_flex_segments'.
7624       There are 3 levels of SCL keyflex:
7625       --
7626       ASSIGNMENT
7627       PAYROLL
7628       ORGANIZATION
7629       --
7630       The routine loops through and generates DB items for each level.
7631       For a given SCL flexfield there could be several database items.
7632       --
7633       The routine has been enhanced to loop around to create dbitems
7634       for each of the legislations which use the flex_num passed in.
7635    NOTES
7636       It is intended that this  creation procedure be run from the
7637       Standard Report Submission (SRS) form.
7638 */
7639 procedure create_scl_flex_dict
7640 (
7641     p_id_flex_num in number
7642 ) is
7643 --
7644 -- declare cursor 0 for retrieving each legislation using this flex num
7645 --
7646 cursor c0 is
7647 select legislation_code
7648 from   pay_legislation_rules
7649 where  rule_type = 'S'
7650 and    rule_mode = to_char (p_id_flex_num);
7651 l_created_by          number;
7652 l_last_login          number;
7653 l_legislation_code    pay_legislation_rules.legislation_code%type;
7654 --
7655 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7656 --                         create_scl_flex                                +
7657 --+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7658 /*
7659    NAME
7660       create_scl_flex - called from procedure create_scl_flex_dict
7661 --
7662    DESCRIPTION
7663       This procedure is called from create_scl_flex_dict, and is responsible
7664       for creating the user entity and database items for a particular SCL
7665       flexfield.
7666 */
7667 procedure create_scl_flex
7668 (
7669     p_id_flex_num     in number,
7670     p_leg_code        in varchar2,
7671     p_route_name      in varchar2,
7672     p_entity_name     in varchar2,
7673     p_attribute_type  in varchar2
7674 ) is
7675 --
7676 -- declare cursor 1 for retrieving the segment names and target columns
7677 --
7678 cursor c1 is
7679 select SEG.application_column_name     c_def_text,
7680        replace (ltrim(rtrim(upper(SEG.segment_name))),' ','_') c_db_name,
7681        SEG.created_by                  c_created_by,
7682        SEG.last_update_login           c_last_login
7683 from   fnd_id_flex_segments            SEG
7684 ,      fnd_segment_attribute_values    VALUE
7685 where  SEG.application_id            = 800
7686 and    SEG.id_flex_code              = 'SCL'
7687 and    SEG.id_flex_num               = p_id_flex_num
7688 and    SEG.enabled_flag              = 'Y'
7689 and    VALUE.application_column_name = SEG.application_column_name
7690 and    VALUE.id_flex_code            = 'SCL'
7691 and    VALUE.id_flex_num             = p_id_flex_num
7692 and    VALUE.segment_attribute_type  = p_attribute_type
7693 and    VALUE.attribute_value         = 'Y';
7694 --
7695 l_user_entity_id   number;
7696 l_db_item_exist    boolean;
7697 l_record_inserted     boolean;
7698 begin
7699     l_db_item_exist := false;
7700     for c1rec in c1 loop
7701         if (l_db_item_exist = false) then  -- first time through loop
7702             --
7703             -- create a user entity
7704             --
7705             l_created_by := c1rec.c_created_by;
7706             l_last_login := c1rec.c_last_login;
7707             --
7708             hrrbdeib_trace_on;
7709             hr_utility.trace ('creating SCL flex entity for '|| p_entity_name);
7710             hrrbdeib_trace_off;
7711             insert_user_entity (p_route_name,
7712                                 p_entity_name,
7713                                 'route for SCL level : '|| p_attribute_type,
7714                                 'Y',
7715                                 'KF',
7716                                 p_id_flex_num,
7717                                 null,               -- null business group id
7718                                 p_leg_code,
7719                                 l_created_by,
7720                                 l_last_login,
7721                                 l_record_inserted);
7722             --
7723             -- only insert parameter values/database items if entity
7724             -- was inserted
7725             --
7726             IF l_record_inserted THEN
7727                 --
7728                 -- insert the id flex num for the where clause filler
7729                 --
7730                 insert_parameter_value (p_id_flex_num, 1);
7731                 l_db_item_exist := true;
7732             END IF;
7733         end if;
7734         --
7735         -- now create the database item
7736         --
7737         insert_database_item (p_entity_name,
7738                               c1rec.c_db_name,
7739                               'T',                           -- data type
7740                               'target.' || c1rec.c_def_text,
7741                               'Y',                           -- null allowed
7742                               'database item for : ' || p_entity_name);
7743     end loop;  -- c1 loop
7744 end create_scl_flex;
7745 --
7746 ---------------------- create_scl_flex_dict  -------------------------
7747 --
7748 BEGIN
7749     --
7750     -- get each legislation code
7751     --
7752     --
7753     for c0rec in c0 loop
7754         --
7755         l_legislation_code := c0rec.legislation_code;
7756         --
7757         -- delete any old SCL keyflex DB items that were created with the same id
7758         --
7759         delete_keyflex_dict (p_id_flex_num,
7760                              'SCL',
7761                              l_legislation_code,
7762                              null);
7763 
7764         --
7765         -- delete user entities (and dbitems) owned by a user entity
7766         -- for an old value of the S leg rule
7767         --
7768         delete from ff_user_entities
7769         where creator_type        = 'KF'
7770         and   creator_id          <> p_id_flex_num
7771         and   user_entity_name like 'SCL%'
7772         and   nvl (legislation_code, ' ') = nvl (l_legislation_code, ' ')
7773         and   business_group_id is null;
7774 
7775         --
7776         -- generate DB items for the 3 levels of SCL:
7777         --
7778         create_scl_flex (p_id_flex_num,
7779                          l_legislation_code,
7780                          'SCL_ASS_FLEX_ROUTE',
7781                          'SCL_ASG_' || l_legislation_code,
7782                          'ASSIGNMENT');
7783         --
7784         create_scl_flex (p_id_flex_num,
7785                          l_legislation_code,
7786                          'SCL_PAY_FLEX_ROUTE',
7787                          'SCL_PAY_' || l_legislation_code,
7788                          'PAYROLL');
7789         --
7790         create_scl_flex (p_id_flex_num,
7791                          l_legislation_code,
7792                          'SCL_ORG_FLEX_ROUTE',
7793                          'SCL_ORG_' || l_legislation_code,
7794                          'ORGANIZATION');
7795         --
7796     end loop; -- c0 loop
7797 end create_scl_flex_dict;
7798 --
7799 procedure truncate_fcomp_info is
7800   statem varchar2(256);
7801   sql_cur number;
7802   ignore number;
7803   l_status    varchar2(50);
7804   l_industry  varchar2(50);
7805   l_per_owner varchar2(30);
7806   l_ret_per   boolean;
7807 begin
7808 
7809   -- Get FF table owner
7810   l_ret_per  := FND_INSTALLATION.GET_APP_INFO ('PER', l_status,
7811                                                l_industry, l_per_owner);
7812 
7813   statem := 'truncate table ' ||  l_per_owner || '.' || 'ff_fdi_usages_f';
7814   sql_cur := dbms_sql.open_cursor;
7815   dbms_sql.parse(sql_cur,
7816                  statem,
7817                  dbms_sql.v7);
7818   ignore := dbms_sql.execute(sql_cur);
7819   dbms_sql.close_cursor(sql_cur);
7820   statem := 'truncate table ' ||  l_per_owner || '.' || 'ff_compiled_info_f';
7821   sql_cur := dbms_sql.open_cursor;
7822   dbms_sql.parse(sql_cur,
7823                  statem,
7824                  dbms_sql.v7);
7825   ignore := dbms_sql.execute(sql_cur);
7826   dbms_sql.close_cursor(sql_cur);
7827 end truncate_fcomp_info;
7828 --
7829 
7830 procedure disable_ffue_cascade_trig is
7831   statem varchar2(256);
7832   sql_cur number;
7833   ignore number;
7834 begin
7835   statem := 'alter trigger ff_database_items_brd disable';
7836   sql_cur := dbms_sql.open_cursor;
7837   dbms_sql.parse(sql_cur,
7838                  statem,
7839                  dbms_sql.v7);
7840   ignore := dbms_sql.execute(sql_cur);
7841   dbms_sql.close_cursor(sql_cur);
7842   statem := 'alter trigger ff_rpv_brud disable';
7843   sql_cur := dbms_sql.open_cursor;
7844   dbms_sql.parse(sql_cur,
7845                  statem,
7846                  dbms_sql.v7);
7847   ignore := dbms_sql.execute(sql_cur);
7848   dbms_sql.close_cursor(sql_cur);
7849 end disable_ffue_cascade_trig;
7850 --
7851 procedure enable_ffue_cascade_trig is
7852   statem varchar2(256);
7853   sql_cur number;
7854   ignore number;
7855 begin
7856   statem := 'alter trigger ff_database_items_brd enable';
7857   sql_cur := dbms_sql.open_cursor;
7858   dbms_sql.parse(sql_cur,
7859                  statem,
7860                  dbms_sql.v7);
7861   ignore := dbms_sql.execute(sql_cur);
7862   dbms_sql.close_cursor(sql_cur);
7863   statem := 'alter trigger ff_rpv_brud enable';
7864   sql_cur := dbms_sql.open_cursor;
7865   dbms_sql.parse(sql_cur,
7866                  statem,
7867                  dbms_sql.v7);
7868   ignore := dbms_sql.execute(sql_cur);
7869   dbms_sql.close_cursor(sql_cur);
7870 end enable_ffue_cascade_trig;
7871 --
7872 procedure disable_refbal_trig is
7873   statem varchar2(256);
7874   sql_cur number;
7875   ignore number;
7876 begin
7877   statem := 'alter trigger ff_user_entities_bri disable';
7878   sql_cur := dbms_sql.open_cursor;
7879   dbms_sql.parse(sql_cur,
7880                  statem,
7881                  dbms_sql.v7);
7882   ignore := dbms_sql.execute(sql_cur);
7883   dbms_sql.close_cursor(sql_cur);
7884   statem := 'alter trigger ff_database_items_bri disable';
7885   sql_cur := dbms_sql.open_cursor;
7886   dbms_sql.parse(sql_cur,
7887                  statem,
7888                  dbms_sql.v7);
7889   ignore := dbms_sql.execute(sql_cur);
7890   dbms_sql.close_cursor(sql_cur);
7891   statem := 'alter trigger ff_rpv_bri disable';
7892   sql_cur := dbms_sql.open_cursor;
7893   dbms_sql.parse(sql_cur,
7894                  statem,
7895                  dbms_sql.v7);
7896   ignore := dbms_sql.execute(sql_cur);
7897   dbms_sql.close_cursor(sql_cur);
7898 end disable_refbal_trig;
7899 --
7900 procedure enable_refbal_trig is
7901   statem varchar2(256);
7902   sql_cur number;
7903   ignore number;
7904 begin
7905   statem := 'alter trigger ff_user_entities_bri enable';
7906   sql_cur := dbms_sql.open_cursor;
7907   dbms_sql.parse(sql_cur,
7908                  statem,
7909                  dbms_sql.v7);
7910   ignore := dbms_sql.execute(sql_cur);
7911   dbms_sql.close_cursor(sql_cur);
7912   statem := 'alter trigger ff_database_items_bri enable';
7913   sql_cur := dbms_sql.open_cursor;
7914   dbms_sql.parse(sql_cur,
7915                  statem,
7916                  dbms_sql.v7);
7917   ignore := dbms_sql.execute(sql_cur);
7918   dbms_sql.close_cursor(sql_cur);
7919   statem := 'alter trigger ff_rpv_bri enable';
7920   sql_cur := dbms_sql.open_cursor;
7921   dbms_sql.parse(sql_cur,
7922                  statem,
7923                  dbms_sql.v7);
7924   ignore := dbms_sql.execute(sql_cur);
7925   dbms_sql.close_cursor(sql_cur);
7926 end enable_refbal_trig;
7927 --
7928 -- The following procedure recreates ALL dbis and UEs for all
7929 -- existing elements input values and balances. It is not intended to
7930 -- be used outside of Oracle development
7931 --
7932 procedure reib_all is
7933 begin
7934    --
7935    -- First set global to say we are disabling triggers.
7936    g_triggers_altered := TRUE;
7937    --
7938    delete pay_patch_status
7939    where  patch_name like 'HRRBDEIB%';
7940    --
7941    commit;
7942    --
7943    disable_ffue_cascade_trig;
7944    --
7945    delete from ff_user_entities
7946    where  creator_type in ('B', 'RB');
7947    --
7948    enable_ffue_cascade_trig;
7949    disable_refbal_trig;
7950    --
7951    hrdyndbi.refresh_defined_balances(0, 1);
7952    --
7953    commit;
7954    --
7955    enable_refbal_trig;
7956    disable_ffue_cascade_trig;
7957    --
7958    hrdyndbi.delete_element_types(0,1);
7959    --
7960    enable_ffue_cascade_trig;
7961    disable_refbal_trig;
7962    --
7963    hrdyndbi.refresh_element_types(0, 1);
7964    --
7965    delete pay_patch_status
7966    where  patch_name like 'HRRBDEIB%';
7967    --
7968    enable_refbal_trig;
7969    --
7970    g_triggers_altered := FALSE;
7971    --
7972    exception when others then
7973      enable_ffue_cascade_trig;
7974      enable_refbal_trig;
7975      raise; -- reraise the exception
7976 end reib_all;
7977 --
7978 -- check_for_dbi_clash
7979 --
7980 -- This keeps the database item clash checking code in one place.
7981 -- This is for additions to FF_DATABASE_ITEMS.
7982 -- It also checks G_TRIGGERS_ALTERED.
7983 -- The code does not bother with FF_GLOBALS_F as that's the
7984 -- same as checking against database items.
7985 --
7986 procedure check_for_dbi_clash
7987 (p_user_name      in varchar2
7988 ,p_ue_id          in number
7989 ,p_leg_code       in varchar2
7990 ,p_bg_id          in number
7991 ,p_startup_mode   in varchar2
7992 ,p_clash          out nocopy boolean
7993 ) is
7994 l_exists varchar2(1);
7995 begin
7996   p_clash := true;
7997 
7998   --
7999   -- For NOT G_TRIGGERS_ALTERED, the code will defer the checking to
8000   -- to database item trigger code.
8001   --
8002   if not g_triggers_altered then
8003     p_clash := false;
8004     return;
8005   end if;
8006 
8007   select null
8008   into   l_exists
8009   from   dual
8010   where exists
8011   (
8012      select /*+ INDEX(a FF_DATABASE_ITEMS_PK)
8013                 INDEX(b FF_USER_ENTITIES_PK) */ null
8014      from   ff_database_items a,
8015             ff_user_entities b
8016      where  a.user_name = p_user_name
8017      and    a.user_entity_id = b.user_entity_id
8018      and
8019         (
8020            p_startup_mode = 'MASTER'
8021            or
8022            (
8023               p_startup_mode = 'SEED'
8024               and
8025               (
8026                  b.legislation_code = p_leg_code
8027                  or
8028                  (
8029                     b.legislation_code is null and b.business_group_id is null
8030                  )
8031                  or
8032                  p_leg_code =
8033                  (
8034                     select c.legislation_code
8035                     from   per_business_groups_perf c
8036                     where  c.business_group_id = b.business_group_id
8037                  )
8038               )
8039            )
8040            or
8041            (
8042               p_startup_mode = 'NON-SEED'
8043               and
8044               (
8045                  b.business_group_id = p_bg_id
8046                  or
8047                  (
8048                     b.legislation_code is null and b.business_group_id is null
8049                  )
8050                  or
8051                  (
8052                     b.business_group_id is null and b.legislation_code = p_leg_code
8053                  )
8054               )
8055            )
8056         )
8057   )
8058   or    exists
8059   (
8060      select /*+ ORDERED INDEX(a FF_DATABASE_ITEMS_TL_N2)
8061                 INDEX(b FF_USER_ENTITIES_PK) */ null
8062      from   ff_database_items_tl a,
8063             ff_user_entities b
8064      where  a.translated_user_name = p_user_name
8065      and    (a.user_name <> p_user_name or a.user_entity_id <> p_ue_id)
8066      and    a.user_entity_id = b.user_entity_id
8067      and
8068         (
8069            p_startup_mode = 'MASTER'
8070            or
8071            (
8072               p_startup_mode = 'SEED'
8073               and
8074               (
8075                  b.legislation_code = p_leg_code
8076                  or
8077                  (
8078                     b.legislation_code is null and b.business_group_id is null
8079                  )
8080                  or
8081                  p_leg_code =
8082                  (
8083                     select c.legislation_code
8084                     from   per_business_groups_perf c
8085                     where  c.business_group_id = b.business_group_id
8086                  )
8087               )
8088            )
8089            or
8090            (
8091               p_startup_mode = 'NON-SEED'
8092               and
8093               (
8094                  b.business_group_id = p_bg_id
8095                  or
8096                  (
8097                     b.legislation_code is null and b.business_group_id is null
8098                  )
8099                  or
8100                  (
8101                     b.business_group_id is null and b.legislation_code = p_leg_code
8102                  )
8103               )
8104            )
8105         )
8106   )
8107   or    exists
8108   (
8109      select null
8110      from   ff_contexts
8111      where  context_name = p_user_name
8112   );
8113 
8114   hrrbdeib_trace_on;
8115   hr_utility.trace('DBI name clash in (' || p_leg_code || ',' || p_bg_id ||
8116                    ') for ' ||  p_user_name);
8117   hrrbdeib_trace_off;
8118 
8119 exception
8120   when no_data_found then
8121     p_clash := false;
8122 end check_for_dbi_clash;
8123 --
8124 -- replace_code_name
8125 --
8126 -- This takes the NAME_TRANSLATIONS lookup search-and-replace code from
8127 -- insert_database_item so that it can be used in many places.
8128 --
8129 procedure replace_code_name
8130 (p_language_code in            varchar2
8131 ,p_item_name     in out nocopy varchar2
8132 ) is
8133 --
8134 -- Get codename cursor now accesses FND table directly, since we
8135 -- need all language values, not just the ones for the current
8136 -- language.
8137 --
8138 -- As bugfix 1210117 we replace apostrophes with underscores.
8139 --
8140 cursor get_codename (c_lookup_code       in varchar2,
8141                      c_language          in varchar2) is
8142   select    lookup_code,
8143             replace(replace(replace(replace(replace(ltrim(rtrim(upper(meaning))),' ','_'),'''','_'),'(',''),')',''),'.','') meaning2
8144   from      fnd_lookup_values
8145   where     instr(c_lookup_code,lookup_code) > 0
8146   and       lookup_type         = 'NAME_TRANSLATIONS'
8147   and       language = c_language
8148   and       view_application_id = 3
8149   and       security_group_id = g_security_group_id
8150   order by  length(lookup_code) desc;
8151 --
8152 l_item_name ff_database_items.user_name%type;
8153 begin
8154   --
8155   -- 523343. if the item name consists of more than one lookup_code,
8156   -- split into its constituent parts and translate separately, then
8157   -- concat back together to form the entirely translated item name.
8158   --
8159   l_item_name := p_item_name;
8160   for c1_rec in get_codename(p_item_name, p_language_code) loop
8161      l_item_name := replace(l_item_name,c1_rec.lookup_code,
8162                             lower(c1_rec.meaning2));
8163   end loop;
8164   p_item_name := upper(l_item_name);
8165 end replace_code_name;
8166 --
8167 -- =================================== --
8168 -- DBI Base name generation procedures --
8169 -- =================================== --
8170 
8171 -- Defined Balance
8172 procedure gen_db_base_dbi_name
8173 (p_defined_balance_id in number
8174 ,p_leg_code              out nocopy varchar2
8175 ,p_bg_id                 out nocopy number
8176 ,p_base_name             out nocopy varchar2
8177 ,p_balance_type_id       out nocopy number
8178 ,p_balance_dimension_id  out nocopy number
8179 ) is
8180 cursor csr_balance_dbi_name
8181 (p_defined_balance_id in number
8182 ) is
8183 select b.balance_name || d.database_item_suffix
8184 ,      db.legislation_code
8185 ,      db.business_group_id
8186 ,      db.balance_type_id
8187 ,      db.balance_dimension_id
8188 from   pay_defined_balances db
8189 ,      pay_balance_types b
8190 ,      pay_balance_dimensions d
8191 where  db.defined_balance_id = p_defined_balance_id
8192 and    b.balance_type_id = db.balance_type_id
8193 and    d.balance_dimension_id = db.balance_dimension_id
8194 ;
8195 --
8196 l_found boolean;
8197 l_base_name ff_database_items.user_name%type;
8198 l_leg_code  pay_defined_balances.legislation_code%type;
8199 l_bg_id     pay_defined_balances.business_group_id%type;
8200 l_bal_id    pay_defined_balances.balance_type_id%type;
8201 l_baldim_id pay_defined_balances.balance_dimension_id%type;
8202 begin
8203   open csr_balance_dbi_name
8204        (p_defined_balance_id => p_defined_balance_id
8205        );
8206   fetch csr_balance_dbi_name
8207   into  l_base_name
8208   ,     l_leg_code
8209   ,     l_bg_id
8210   ,     l_bal_id
8211   ,     l_baldim_id
8212   ;
8213   l_found := csr_balance_dbi_name%found;
8214   close csr_balance_dbi_name;
8215 
8216   assert(l_found, 'gen_db_base_dbi_name:1', p_defined_balance_id);
8217 
8218   -- Set output values.
8219   p_leg_code := l_leg_code;
8220   p_bg_id := l_bg_id;
8221   p_balance_type_id := l_bal_id;
8222   p_balance_dimension_id := l_baldim_id;
8223 
8224   --
8225   -- Convert to a valid database item name.
8226   --
8227   p_base_name := ff_dbi_utils_pkg.str2dbiname(substr(l_base_name, 1, 80));
8228 end gen_db_base_dbi_name;
8229 
8230 --
8231 -- gen_et_base_dbi_name
8232 --
8233 -- p_prefix is the element name and is taken from the database
8234 -- if null, otherwise it is reused.
8235 --
8236 procedure gen_et_base_dbi_name
8237 (p_element_type_id in            number
8238 ,p_leg_code        in out nocopy varchar2
8239 ,p_bg_id           in out nocopy number
8240 ,p_prefix          in out nocopy varchar2
8241 ,p_suffix          in            varchar2
8242 ,p_date_p          in            varchar2
8243 ,p_base_name          out nocopy varchar2
8244 ) is
8245 cursor csr_prefix
8246 (p_element_type_id in number
8247 ) is
8248 select et.element_name
8249 ,      et.legislation_code
8250 ,      et.business_group_id
8251 from   pay_element_types_f et
8252 where  et.element_type_id = p_element_type_id
8253 ;
8254 --
8255 l_prefix    varchar2(240);
8256 l_ele_name  pay_element_types_f.element_name%type;
8257 l_found     boolean;
8258 l_leg_code  pay_element_types_f.legislation_code%type;
8259 l_bg_id     pay_element_types_f.business_group_id%type;
8260 begin
8261   --
8262   -- Fetch the element name if necessary.
8263   --
8264   if p_prefix is null then
8265     open csr_prefix
8266          (p_element_type_id => p_element_type_id
8267          );
8268     fetch csr_prefix
8269     into  l_ele_name
8270     ,     l_leg_code
8271     ,     l_bg_id
8272     ;
8273     l_found := csr_prefix%found;
8274     close csr_prefix;
8275 
8276     assert(l_found, 'gen_et_base_dbi_name:1', p_element_type_id);
8277 
8278     p_prefix := l_ele_name;
8279     p_leg_code := l_leg_code;
8280     p_bg_id := l_bg_id;
8281   end if;
8282 
8283   --
8284   -- Convert to a valid database item name.
8285   --
8286   p_base_name :=
8287   ff_dbi_utils_pkg.str2dbiname(substr(p_prefix || '_' || p_suffix || p_date_p, 1, 80));
8288 end gen_et_base_dbi_name;
8289 
8290 --
8291 -- gen_eiv_base_dbi_name
8292 --
8293 -- p_prefix is the element name and input value name, and is taken from
8294 -- the database if null, otherwise it is reused. There is special
8295 -- processing for PAY VALUE so that the lookup meaning from the
8296 -- NAME_TRANSLATIONS lookup is substituted in.
8297 --
8298 procedure gen_eiv_base_dbi_name
8299 (p_input_value_id in            number
8300 ,p_leg_code       in out nocopy varchar2
8301 ,p_bg_id          in out nocopy number
8302 ,p_prefix         in out nocopy varchar2
8303 ,p_suffix         in            varchar2
8304 ,p_date_p         in            varchar2
8305 ,p_base_name         out nocopy varchar2
8306 ) is
8307 cursor csr_prefix
8308 (p_input_value_id in number
8309 ) is
8310 select et.element_name || '_' || iv.name
8311 ,      et.legislation_code
8312 ,      et.business_group_id
8313 from   pay_element_types_f et
8314 ,      pay_input_values_f iv
8315 where  iv.input_value_id = p_input_value_id
8316 and    et.element_type_id = iv.element_type_id
8317 ;
8318 --
8319 l_prefix   ff_database_items.user_name%type;
8320 l_leg_code pay_input_values_f.legislation_code%type;
8321 l_bg_id    pay_input_values_f.business_group_id%type;
8322 l_found    boolean;
8323 begin
8324   --
8325   -- Fetch the prefix if necessary.
8326   --
8327   if p_prefix is null then
8328     open csr_prefix
8329          (p_input_value_id => p_input_value_id
8330          );
8331     fetch csr_prefix
8332     into  l_prefix
8333     ,     l_leg_code
8334     ,     l_bg_id
8335     ;
8336     l_found := csr_prefix%found;
8337     close csr_prefix;
8338 
8339     assert(l_found, 'gen_eiv_base_dbi_name:1', p_input_value_id);
8340 
8341     p_prefix := l_prefix;
8342     p_leg_code := l_leg_code;
8343     p_bg_id := l_bg_id;
8344   end if;
8345 
8346   --
8347   -- Convert to a valid database item name.
8348   --
8349   p_base_name :=
8350   ff_dbi_utils_pkg.str2dbiname(substr(p_prefix || '_' || p_suffix || p_date_p, 1, 80));
8351 end gen_eiv_base_dbi_name;
8352 
8353 -- ========================================= --
8354 -- DBI translated name generation procedures --
8355 -- ========================================= --
8356 
8357 -- =============== --
8358 -- Defined Balance --
8359 -- =============== --
8360 procedure gen_db_tl_dbi_name
8361 (p_balance_type_id      in            number
8362 ,p_balance_dimension_id in            number
8363 ,p_language             in            varchar2
8364 ,p_tl_name                 out nocopy varchar2
8365 ,p_found                   out nocopy boolean
8366 ) is
8367 cursor csr_balance_name
8368 (p_balance_type_id in number
8369 ,p_language        in varchar2
8370 ) is
8371 select b.balance_name
8372 from   pay_balance_types_tl b
8373 where  b.balance_type_id = p_balance_type_id
8374 and    b.language = p_language
8375 ;
8376 cursor csr_dbi_suffix
8377 (p_balance_dimension_id in number
8378 ,p_language             in varchar2
8379 ) is
8380 select bd.database_item_suffix
8381 from   pay_balance_dimensions_tl bd
8382 where  bd.balance_dimension_id = p_balance_dimension_id
8383 and    bd.language = p_language
8384 ;
8385 --
8386 l_balance_name pay_balance_types_tl.balance_name%type;
8387 l_dbi_suffix   pay_balance_dimensions_tl.database_item_suffix%type;
8388 l_debug        boolean := hr_utility.debug_enabled;
8389 l_found        boolean;
8390 begin
8391   open csr_balance_name
8392        (p_balance_type_id => p_balance_type_id
8393        ,p_language        => p_language
8394        );
8395   fetch csr_balance_name
8396   into  l_balance_name
8397   ;
8398   l_found := csr_balance_name%found;
8399   close csr_balance_name;
8400 
8401   if l_found then
8402     open csr_dbi_suffix
8403        (p_balance_dimension_id => p_balance_dimension_id
8404        ,p_language             => p_language
8405        );
8406     fetch csr_dbi_suffix
8407     into  l_dbi_suffix
8408     ;
8409     l_found := csr_dbi_suffix%found;
8410     close csr_dbi_suffix;
8411   end if;
8412 
8413   if l_found then
8414     --
8415     -- Check name, converting if necessary. STR2DBINAME will be called
8416     -- later in the processing.
8417     --
8418     p_tl_name := l_balance_name || l_dbi_suffix;
8419   elsif l_debug then
8420     hr_utility.trace('Could not generate _TL DBI for defined balance (' ||
8421                      p_balance_type_id || ',' || p_balance_dimension_id ||
8422                      ')');
8423   end if;
8424 
8425   p_found := l_found;
8426 end gen_db_tl_dbi_name;
8427 
8428 -- =================== --
8429 -- Element Type Prefix --
8430 -- =================== --
8431 procedure gen_et_tl_dbi_prefix
8432 (p_element_type_id in            number
8433 ,p_language        in            varchar2
8434 ,p_prefix          in out nocopy varchar2
8435 ,p_found              out nocopy boolean
8436 ) is
8437 cursor csr_prefix
8438 (p_element_type_id in number
8439 ,p_language        in varchar2
8440 ) is
8441 select ettl.element_name
8442 from   pay_element_types_f_tl ettl
8443 where  ettl.element_type_id = p_element_type_id
8444 and    ettl.language = p_language
8445 ;
8446 --
8447 l_found  boolean := true;
8448 l_debug  boolean := hr_utility.debug_enabled;
8449 begin
8450   open csr_prefix
8451        (p_element_type_id => p_element_type_id
8452        ,p_language        => p_language
8453        );
8454   fetch csr_prefix
8455   into  p_prefix;
8456   l_found := csr_prefix%found;
8457   close csr_prefix;
8458 
8459   if not l_found then
8460     if l_debug then
8461       hr_utility.trace('Could not generate _TL DBI for element type ' ||
8462                        p_element_type_id);
8463     end if;
8464   end if;
8465 
8466   p_found := l_found;
8467 end gen_et_tl_dbi_prefix;
8468 
8469 -- ========================== --
8470 -- Element Input Value Prefix --
8471 -- ========================== --
8472 procedure gen_eiv_tl_dbi_prefix
8473 (p_input_value_id in            number
8474 ,p_effective_date in            date
8475 ,p_language       in            varchar2
8476 ,p_prefix         in out nocopy varchar2
8477 ,p_found             out nocopy boolean
8478 ) is
8479 cursor csr_base_name
8480 (p_input_value_id in number
8481 ) is
8482 select iv.name
8483 from   pay_input_values_f iv
8484 where  iv.input_value_id = p_input_value_id
8485 and    p_effective_date between
8486        iv.effective_start_date and iv.effective_end_date
8487 ;
8488 --
8489 cursor csr_prefix
8490 (p_input_value_id in number
8491 ,p_language       in varchar2
8492 ) is
8493 select ivtl.name
8494 ,      ettl.element_name
8495 from   pay_input_values_f iv
8496 ,      pay_element_types_f_tl ettl
8497 ,      pay_input_values_f_tl ivtl
8498 where  iv.input_value_id = p_input_value_id
8499 and    p_effective_date between
8500        iv.effective_start_date and iv.effective_end_date
8501 and    ettl.element_type_id = iv.element_type_id
8502 and    ettl.language = p_language
8503 and    ivtl.input_value_id = iv.input_value_id
8504 and    ivtl.language = p_language
8505 ;
8506 --
8507 l_pay_value pay_input_values_f.name%type := null;
8508 l_ipv_name  pay_input_values_f_tl.name%type;
8509 l_ele_name  pay_element_types_f_tl.element_name%type;
8510 l_found     boolean := true;
8511 l_debug     boolean := hr_utility.debug_enabled;
8512 begin
8513   --
8514   -- Check if the input is PAY VALUE.
8515   --
8516   open csr_base_name
8517        (p_input_value_id => p_input_value_id
8518        );
8519   fetch csr_base_name
8520   into  l_pay_value
8521   ;
8522   l_found := csr_base_name%found;
8523   close csr_base_name;
8524 
8525   --
8526   -- Whatever happens the base name must exist.
8527   --
8528   assert(l_found, 'gen_eiv_tl_dbi_name:1', p_input_value_id);
8529 
8530   if upper(l_pay_value) = 'PAY VALUE' then
8531     l_pay_value := 'PAY VALUE';
8532     replace_code_name
8533     (p_language_code => p_language
8534     ,p_item_name     => l_pay_value
8535     );
8536   else
8537     l_pay_value := null;
8538   end if;
8539 
8540   open csr_prefix
8541        (p_input_value_id => p_input_value_id
8542        ,p_language       => p_language
8543        );
8544   fetch csr_prefix
8545   into  l_ipv_name
8546   ,     l_ele_name
8547   ;
8548   l_found := csr_prefix%found;
8549   close csr_prefix;
8550 
8551   if l_found then
8552     p_prefix := l_ele_name || '_' || nvl(l_pay_value, l_ipv_name);
8553   else
8554     if l_debug then
8555       hr_utility.trace('Could not generate _TL DBI for element input value ' ||
8556                        p_input_value_id);
8557     end if;
8558   end if;
8559 
8560   p_found := l_found;
8561 end gen_eiv_tl_dbi_prefix;
8562 
8563 procedure gen_et_dbi_prefixes
8564 (p_element_type_id in number
8565 ,p_languages       in            dbms_sql.varchar2s
8566 ,p_prefixes        in out nocopy t_dbi_prefixes
8567 ) is
8568 l_prefix r_dbi_prefix;
8569 begin
8570   if p_prefixes.count = 0 then
8571     for i in 1 .. p_languages.count loop
8572       gen_et_tl_dbi_prefix
8573       (p_element_type_id => p_element_type_id
8574       ,p_language        => p_languages(i)
8575       ,p_prefix          => l_prefix.prefix
8576       ,p_found           => l_prefix.found
8577       );
8578       p_prefixes(i) := l_prefix;
8579       p_prefixes(i).language := p_languages(i);
8580     end loop;
8581   end if;
8582 end gen_et_dbi_prefixes;
8583 
8584 procedure gen_eiv_dbi_prefixes
8585 (p_input_value_id in number
8586 ,p_effective_date in            date
8587 ,p_languages      in            dbms_sql.varchar2s
8588 ,p_prefixes       in out nocopy t_dbi_prefixes
8589 ) is
8590 l_prefix r_dbi_prefix;
8591 begin
8592   if p_prefixes.count = 0 then
8593     for i in 1 .. p_languages.count loop
8594       gen_eiv_tl_dbi_prefix
8595       (p_input_value_id => p_input_value_id
8596       ,p_effective_date => p_effective_date
8597       ,p_language       => p_languages(i)
8598       ,p_prefix         => l_prefix.prefix
8599       ,p_found          => l_prefix.found
8600       );
8601       p_prefixes(i) := l_prefix;
8602       p_prefixes(i).language := p_languages(i);
8603     end loop;
8604   end if;
8605 end gen_eiv_dbi_prefixes;
8606 
8607 -- =================================== --
8608 -- Element Type / Input Value DBI Name --
8609 -- =================================== --
8610 procedure gen_et_tl_dbi_name
8611 (p_prefix   in            varchar2
8612 ,p_suffix   in            varchar2
8613 ,p_date_p   in            varchar2
8614 ,p_language in            varchar2
8615 ,p_tl_name     out nocopy varchar2
8616 ) is
8617 l_suffix varchar2(240);
8618 begin
8619   -- Translate the suffix.
8620   l_suffix := p_suffix || p_date_p;
8621   replace_code_name
8622   (p_language_code => p_language
8623   ,p_item_name     => l_suffix
8624   );
8625 
8626   --
8627   -- Convert to a valid database item name. STR2DBINAME will be
8628   -- called later in the processing.
8629   --
8630   p_tl_name := p_prefix || '_' || l_suffix;
8631 end gen_et_tl_dbi_name;
8632 
8633 -- ====================================== --
8634 -- Utility procedures for translated DBIs --
8635 -- ====================================== --
8636 
8637 --
8638 -- dbi2ueid
8639 --
8640 -- Takes a database item name and entity information to retrieve the
8641 -- corresponding user_entity_id.
8642 --
8643 function dbi2ueid
8644 (p_creator_id   in number
8645 ,p_creator_type in varchar2
8646 ,p_user_name    in varchar2
8647 ) return number is
8648 cursor csr_user_entity_id
8649 (p_creator_id   in number
8650 ,p_creator_type in varchar2
8651 ,p_user_name    in varchar2
8652 ) is
8653 select u.user_entity_id
8654 from   ff_database_items d
8655 ,      ff_user_entities u
8656 where  d.user_name = p_user_name
8657 and    u.user_entity_id = d.user_entity_id
8658 and    u.creator_id = p_creator_id
8659 and    u.creator_type = p_creator_type
8660 ;
8661 --
8662 l_found boolean;
8663 l_ueid      number;
8664 begin
8665   open csr_user_entity_id
8666        (p_creator_id   => p_creator_id
8667        ,p_creator_type => p_creator_type
8668        ,p_user_name    => p_user_name
8669        );
8670   fetch csr_user_entity_id
8671   into  l_ueid
8672   ;
8673   l_found := csr_user_entity_id%found;
8674   close csr_user_entity_id;
8675 
8676   assert(l_found, 'dbi2ueid:1',
8677          p_user_name || ':' || p_creator_type || ':' || p_creator_id);
8678 
8679   return l_ueid;
8680 end dbi2ueid;
8681 
8682 --
8683 -- check_for_tl_dbi_clash
8684 --
8685 -- This keeps the database item clash checking code in one place.
8686 -- This is for additions to FF_DATABASE_ITEMS_TL.
8687 -- It also checks G_TRIGGERS_ALTERED.
8688 -- The code does not bother with FF_GLOBALS_F as that's the
8689 -- same as checking against database items.
8690 --
8691 procedure check_for_tl_dbi_clash
8692 (p_user_name      in varchar2
8693 ,p_user_entity_id in number
8694 ,p_tl_user_name   in varchar2
8695 ,p_leg_code       in varchar2
8696 ,p_bg_id          in number
8697 ,p_startup_mode   in varchar2
8698 ,p_clash          out nocopy boolean
8699 ) is
8700 l_exists varchar2(1);
8701 begin
8702   p_clash := true;
8703 
8704   --
8705   -- For NOT G_TRIGGERS_ALTERED, the code will defer the checking to
8706   -- to database item trigger code.
8707   --
8708   if not g_triggers_altered then
8709     p_clash := false;
8710     return;
8711   end if;
8712 
8713   select null
8714   into   l_exists
8715   from   dual
8716   where exists
8717   (
8718      select /*+ INDEX(a FF_DATABASE_ITEMS_PK)
8719                 INDEX(b FF_USER_ENTITIES_PK) */ null
8720      from   ff_database_items a,
8721             ff_user_entities b
8722      where  a.user_name = p_tl_user_name
8723      and    (p_user_name <> p_tl_user_name or a.user_entity_id <> p_user_entity_id)
8724      and    a.user_entity_id = b.user_entity_id
8725      and
8726      (
8727            p_startup_mode = 'MASTER'
8728            or
8729            (
8730               p_startup_mode = 'SEED'
8731               and
8732               (
8733                  b.legislation_code = p_leg_code
8734                  or
8735                  (
8736                     b.legislation_code is null and b.business_group_id is null
8737                  )
8738                  or
8739                  p_leg_code =
8740                  (
8741                     select c.legislation_code
8742                     from   per_business_groups_perf c
8743                     where  c.business_group_id = b.business_group_id
8744                  )
8745               )
8746            )
8747            or
8748            (
8749               p_startup_mode = 'NON-SEED'
8750               and
8751               (
8752                  b.business_group_id = p_bg_id
8753                  or
8754                  (
8755                     b.legislation_code is null and b.business_group_id is null
8756                  )
8757                  or
8758                  (
8759                     b.business_group_id is null and b.legislation_code = p_leg_code
8760                  )
8761               )
8762            )
8763      )
8764   )
8765   or    exists
8766   (
8767      select /*+ ORDERED INDEX(a FF_DATABASE_ITEMS_TL_N2)
8768                 INDEX(b FF_USER_ENTITIES_PK) */ null
8769      from   ff_database_items_tl a,
8770             ff_user_entities b
8771      where  a.translated_user_name = p_tl_user_name
8772      and    (a.user_name <> p_user_name or a.user_entity_id <> p_user_entity_id)
8773      and    a.user_entity_id = b.user_entity_id
8774      and
8775      (
8776            p_startup_mode = 'MASTER'
8777            or
8778            (
8779               p_startup_mode = 'SEED'
8780               and
8781               (
8782                  b.legislation_code = p_leg_code
8783                  or
8784                  (
8785                     b.legislation_code is null and b.business_group_id is null
8786                  )
8787                  or
8788                  p_leg_code =
8789                  (
8790                     select c.legislation_code
8791                     from   per_business_groups_perf c
8792                     where  c.business_group_id = b.business_group_id
8793                  )
8794               )
8795            )
8796            or
8797            (
8798               p_startup_mode = 'NON-SEED'
8799               and
8800               (
8801                  b.business_group_id = p_bg_id
8802                  or
8803                  (
8804                     b.legislation_code is null and b.business_group_id is null
8805                  )
8806                  or
8807                  (
8808                     b.business_group_id is null and b.legislation_code = p_leg_code
8809                  )
8810               )
8811            )
8812      )
8813   )
8814   or    exists
8815   (
8816      select null
8817      from   ff_contexts
8818      where  context_name = p_tl_user_name
8819   );
8820 
8821   hrrbdeib_trace_on;
8822   hr_utility.trace('TL DBI name clash in (' || p_leg_code || ',' || p_bg_id ||
8823                    ') for ' ||  p_user_name);
8824   hrrbdeib_trace_off;
8825 
8826 exception
8827   when no_data_found then
8828     p_clash := false;
8829 end check_for_tl_dbi_clash;
8830 
8831 -- Assert a condition in the code.
8832 procedure assert
8833 (p_condition  in boolean
8834 ,p_location   in varchar2
8835 ,p_extra_info in varchar2
8836 ) is
8837 l_debug_cnt number;
8838 begin
8839   if not p_condition then
8840     hr_utility.set_message(801, 'FFPLU01_ASSERTION_FAILED');
8841     hr_utility.set_message_token('1', p_location || ':[' || p_extra_info || ']');
8842     hr_utility.raise_error;
8843   end if;
8844 end assert;
8845 
8846 -- Check for DATE_PAID database items.
8847 function has_date_paid_dbis
8848 (p_creator_type in varchar2
8849 ,p_creator_id   in number
8850 ) return boolean is
8851 l_count number;
8852 begin
8853   select count(*)
8854   into   l_count
8855   from   ff_user_entities ue
8856   where  ue.creator_id = p_creator_id
8857   and    ue.creator_type = p_creator_type
8858   and    ue.user_entity_name like '%_DP'
8859   ;
8860 
8861   return l_count > 0;
8862 end has_date_paid_dbis;
8863 
8864 -- Check for non-DATE_PAID database items.
8865 function has_non_date_paid_dbis
8866 (p_creator_type in varchar2
8867 ,p_creator_id   in number
8868 ) return boolean is
8869 l_count number;
8870 begin
8871   select count(*)
8872   into   l_count
8873   from   ff_user_entities ue
8874   where  ue.creator_id = p_creator_id
8875   and    ue.creator_type = p_creator_type
8876   and    ue.user_entity_name not like '%_DP'
8877   ;
8878 
8879   return l_count > 0;
8880 end has_non_date_paid_dbis;
8881 
8882 --
8883 -- Update the _TL database item name.
8884 --
8885 procedure update_tl_dbi_name
8886 (p_user_name      in varchar2
8887 ,p_user_entity_id in number
8888 ,p_leg_code       in varchar2
8889 ,p_bg_id          in number
8890 ,p_startup_mode   in varchar2
8891 ,p_language       in varchar2
8892 ,p_tl_user_name   in varchar2
8893 ) is
8894 l_clash        boolean;
8895 l_tl_user_name ff_database_items_tl.translated_user_name%type;
8896 l_got_error    boolean;
8897 begin
8898   --
8899   -- G_TRIGGERS_ALTERED is true for the bulk generation of balance,
8900   -- element, and input value names in HRDYNDBI. The validation assumes
8901   -- that FF_FDI_USAGES_F rows have been deleted.
8902   --
8903   if g_triggers_altered then
8904     --
8905     -- Format the translated name.
8906     --
8907     l_tl_user_name :=
8908     ff_dbi_utils_pkg.str2dbiname(p_str => p_tl_user_name);
8909 
8910     check_for_tl_dbi_clash
8911     (p_user_name      => p_user_name
8912     ,p_user_entity_id => p_user_entity_id
8913     ,p_tl_user_name   => l_tl_user_name
8914     ,p_leg_code       => p_leg_code
8915     ,p_bg_id          => p_bg_id
8916     ,p_startup_mode   => p_startup_mode
8917     ,p_clash          => l_clash
8918     );
8919 
8920     if not l_clash then
8921       update ff_database_items_tl dbitl
8922       set    dbitl.translated_user_name = l_tl_user_name
8923       ,      dbitl.source_lang = p_language
8924       where  dbitl.language = p_language
8925       and    dbitl.user_name = p_user_name
8926       and    dbitl.user_entity_id = p_user_entity_id
8927       ;
8928 
8929       --
8930       -- Put in an assertion to check for missing database items.
8931       -- However, the US deduction form creates the element type
8932       -- before updating the benefit_classification_id causing this
8933       -- assertion to fail, because the database items are created
8934       -- before the benefit_classification_id is made NOT NULL.
8935       --
8936       if not p_user_name like '%BEN_CLASS' then
8937         assert(SQL%rowcount > 0, 'update_tl_dbi_name:1',
8938                p_user_name || ':' || p_user_entity_id);
8939       end if;
8940     else
8941       --
8942       -- For the MLS process, a name clash is a fatal error.
8943       --
8944       hr_utility.set_message (801, 'PAY_33916_DYN_DBI_NAME_CLASH');
8945       hr_utility.set_message_token('1', l_tl_user_name);
8946       hr_utility.raise_error;
8947     end if;
8948   elsif g_dyndbi_changes then
8949      l_tl_user_name := p_tl_user_name;
8950      ff_database_items_pkg.update_seeded_tl_rows
8951      (x_user_name            => p_user_name
8952      ,x_user_entity_id       => p_user_entity_id
8953      ,x_language             => p_language
8954      ,x_translated_user_name => l_tl_user_name
8955      ,x_description          => null
8956      ,x_got_error            => l_got_error
8957      );
8958 
8959      if l_got_error then
8960        g_dyndbi_changes_ok := false;
8961      end if;
8962 
8963   --
8964   -- One-off update for a single element type, input value, or balance.
8965   -- In the FF_DATABASE_ITEMS case, the FF_DATABASE_ITEMS trigger would
8966   -- handle this validation. Unfortunately, an update trigger cannot
8967   -- perform this because of ORA-04091 errors.
8968   --
8969   else
8970     --
8971     -- Note: UPDATE_TL_ROW calls STR2DBINAME so passing p_tl_user_name
8972     -- unmodified to UPDATE_TL_ROW.
8973     --
8974     ff_database_items_pkg.update_tl_row
8975     (x_user_name            => p_user_name
8976     ,x_user_entity_id       => p_user_entity_id
8977     ,x_language             => p_language
8978     ,x_source_lang          => p_language
8979     ,x_translated_user_name => p_tl_user_name
8980     ,x_description          => null
8981     );
8982   end if;
8983 end update_tl_dbi_name;
8984 
8985 -- =================================================== --
8986 -- Element Type/Input Value DBI name update procedure --
8987 -- =================================================== --
8988 procedure update_et_tl_dbi_names
8989 (p_leg_code       in varchar2
8990 ,p_bg_id          in number
8991 ,p_startup_mode   in varchar2
8992 ,p_user_name      in varchar2
8993 ,p_user_entity_id in number
8994 ,p_prefixes       in t_dbi_prefixes
8995 ,p_suffix         in varchar2
8996 ,p_date_p         in varchar2
8997 ) is
8998 --
8999 l_tl_name ff_database_items_tl.translated_user_name%type;
9000 begin
9001   for i in 1 .. p_prefixes.count loop
9002     if p_prefixes(i).found then
9003       --
9004       -- Generate the translated DBI name.
9005       --
9006       gen_et_tl_dbi_name
9007       (p_prefix          => p_prefixes(i).prefix
9008       ,p_suffix          => p_suffix
9009       ,p_date_p          => p_date_p
9010       ,p_language        => p_prefixes(i).language
9011       ,p_tl_name         => l_tl_name
9012       );
9013 
9014       --
9015       -- Update the translated database item.
9016       --
9017       update_tl_dbi_name
9018       (p_user_name      => p_user_name
9019       ,p_user_entity_id => p_user_entity_id
9020       ,p_leg_code       => p_leg_code
9021       ,p_bg_id          => p_bg_id
9022       ,p_startup_mode   => p_startup_mode
9023       ,p_language       => p_prefixes(i).language
9024       ,p_tl_user_name   => l_tl_name
9025       );
9026     end if;
9027   end loop;
9028 end update_et_tl_dbi_names;
9029 
9030 -- ========================================= --
9031 -- Update all the dbis for a defined balance --
9032 -- ========================================= --
9033 procedure update_defined_balance
9034 (p_defined_balance_id in number
9035 ,p_languages          in dbms_sql.varchar2s
9036 ) is
9037 l_leg_code     varchar2(30);
9038 l_bg_id        number;
9039 l_bal_id       pay_defined_balances.balance_type_id%type;
9040 l_baldim_id    pay_defined_balances.balance_dimension_id%type;
9041 l_base_name    ff_database_items.user_name%type;
9042 l_ueid         number;
9043 l_tl_name      ff_database_items_tl.translated_user_name%type;
9044 l_found        boolean;
9045 l_startup_mode varchar2(30);
9046 begin
9047   --
9048   -- Generate the base database item information.
9049   --
9050   gen_db_base_dbi_name
9051   (p_defined_balance_id   => p_defined_balance_id
9052   ,p_leg_code             => l_leg_code
9053   ,p_bg_id                => l_bg_id
9054   ,p_base_name            => l_base_name
9055   ,p_balance_type_id      => l_bal_id
9056   ,p_balance_dimension_id => l_baldim_id
9057   );
9058   l_ueid :=
9059   dbi2ueid
9060   (p_creator_id   => p_defined_balance_id
9061   ,p_creator_type => 'B'
9062   ,p_user_name    => l_base_name
9063   );
9064 
9065   --
9066   -- Get the startup mode.
9067   --
9068   if g_triggers_altered then
9069     l_startup_mode := ffstup.get_mode(l_bg_id, l_leg_code);
9070   end if;
9071 
9072   --
9073   -- Generate the translated name and create the database item
9074   -- for each language
9075   --
9076   for i in 1 .. p_languages.count loop
9077     gen_db_tl_dbi_name
9078     (p_balance_type_id      => l_bal_id
9079     ,p_balance_dimension_id => l_baldim_id
9080     ,p_language             => p_languages(i)
9081     ,p_tl_name              => l_tl_name
9082     ,p_found                => l_found
9083     );
9084 
9085     --
9086     -- Update the translated database item.
9087     --
9088     if l_found then
9089       update_tl_dbi_name
9090       (p_user_name      => l_base_name
9091       ,p_user_entity_id => l_ueid
9092       ,p_leg_code       => l_leg_code
9093       ,p_bg_id          => l_bg_id
9094       ,p_startup_mode   => l_startup_mode
9095       ,p_language       => p_languages(i)
9096       ,p_tl_user_name   => l_tl_name
9097       );
9098     end if;
9099   end loop;
9100 end update_defined_balance;
9101 
9102 -- =============================== --
9103 -- Update dbis for an element type --
9104 -- =============================== --
9105 
9106 --
9107 -- Interface 1: does not reference PAY_ELEMENT_TYPES_F_TL - the core
9108 -- interface.
9109 --
9110 procedure update_element_type
9111 (p_element_type_id in number
9112 ,p_effective_date  in date
9113 ,p_languages       in dbms_sql.varchar2s
9114 ,p_dbi_prefixes    in t_dbi_prefixes
9115 ) is
9116 l_date_p        varchar2(16);
9117 l_do_date_p     boolean;
9118 l_do_non_date_p boolean;
9119 l_leg_code      varchar2(30);
9120 l_bg_id         number;
9121 l_ueid          number;
9122 l_prefix        varchar2(240);
9123 l_found         boolean;
9124 l_startup_mode  varchar2(30);
9125 l_ben_class_id  number;
9126 
9127 --
9128 -- Cursor to fetch element type information.
9129 --
9130 cursor csr_element_type_info
9131 (p_element_type_id in number
9132 ,p_effective_date  in date
9133 ) is
9134 select et.benefit_classification_id
9135 ,      et.legislation_code
9136 ,      et.business_group_id
9137 from   pay_element_types_f et
9138 where  et.element_type_id = p_element_type_id
9139 and    p_effective_date between
9140        et.effective_start_date and et.effective_end_date
9141 ;
9142 --
9143 procedure update_dbis
9144 (p_element_type_id in number
9145 ,p_leg_code        in out nocopy varchar2
9146 ,p_bg_id           in out nocopy number
9147 ,p_prefix          in out nocopy varchar2
9148 ,p_dbi_prefixes    in t_dbi_prefixes
9149 ,p_date_p          in varchar2
9150 ,p_startup_mode    in varchar2
9151 ,p_languages       in dbms_sql.varchar2s
9152 ,p_user_entity_id  in out nocopy number
9153 ,p_suffix          in varchar2
9154 ) is
9155 l_base_name ff_database_items.user_name%type;
9156 begin
9157   gen_et_base_dbi_name
9158   (p_element_type_id => p_element_type_id
9159   ,p_leg_code        => p_leg_code
9160   ,p_bg_id           => p_bg_id
9161   ,p_prefix          => p_prefix
9162   ,p_suffix          => p_suffix
9163   ,p_date_p          => p_date_p
9164   ,p_base_name       => l_base_name
9165   );
9166 
9167   if p_user_entity_id is null then
9168     p_user_entity_id :=
9169     dbi2ueid
9170     (p_creator_id   => p_element_type_id
9171     ,p_creator_type => 'E'
9172     ,p_user_name    => l_base_name
9173     );
9174   end if;
9175 
9176   update_et_tl_dbi_names
9177   (p_leg_code       => p_leg_code
9178   ,p_bg_id          => p_bg_id
9179   ,p_startup_mode   => p_startup_mode
9180   ,p_user_name      => l_base_name
9181   ,p_user_entity_id => p_user_entity_id
9182   ,p_prefixes       => p_dbi_prefixes
9183   ,p_suffix         => p_suffix
9184   ,p_date_p         => p_date_p
9185   );
9186 end update_dbis;
9187 
9188 begin
9189   -- ==================================================== --
9190   -- Are there DATE_PAID / non-DATE_PAID database items ? --
9191   -- ==================================================== --
9192   l_do_date_p :=
9193   has_date_paid_dbis
9194   (p_creator_type => 'E'
9195   ,p_creator_id   => p_element_type_id
9196   );
9197 
9198   l_do_non_date_p :=
9199   has_non_date_paid_dbis
9200   (p_creator_type => 'E'
9201   ,p_creator_id   => p_element_type_id
9202   );
9203 
9204   -- ============================= --
9205   -- Get element type information. --
9206   -- ============================= --
9207   open csr_element_type_info
9208        (p_element_type_id => p_element_type_id
9209        ,p_effective_date  => p_effective_date
9210        );
9211   fetch csr_element_type_info
9212   into  l_ben_class_id
9213   ,     l_leg_code
9214   ,     l_bg_id
9215   ;
9216   l_found := csr_element_type_info%found;
9217   close csr_element_type_info;
9218 
9219   assert(l_found, 'update_element_type:1', p_element_type_id);
9220 
9221   --
9222   -- Get the startup mode. This only needs to be done at this
9223   -- stage as l_bg_id and l_leg_code should not change.
9224   --
9225   if g_triggers_altered then
9226     l_startup_mode := ffstup.get_mode(l_bg_id, l_leg_code);
9227   end if;
9228 
9229   -- Force fetch of element type information.
9230   l_prefix := null;
9231 
9232   -- ============================== --
9233   -- Database item processing code. --
9234   -- ============================== --
9235   loop
9236 
9237     --
9238     -- Loop control based upon processing DATE PAID and non-DATE PAID
9239     -- database items.
9240     --
9241     if l_do_non_date_p then
9242       l_date_p := null;
9243       l_do_non_date_p := false;
9244     elsif l_do_date_p then
9245       l_date_p := '_DP';
9246       l_do_date_p := false;
9247     else
9248       exit;
9249     end if;
9250 
9251     -- ========================================= --
9252     -- Process the dbis for the _E1 user entity. --
9253     -- ========================================= --
9254 
9255     --
9256     -- This must be done for the first dbi in each user entity.
9257     --
9258     l_ueid := null;
9259 
9260     -- REPORTING_NAME --
9261     update_dbis
9262     (p_element_type_id => p_element_type_id
9263     ,p_leg_code        => l_leg_code
9264     ,p_bg_id           => l_bg_id
9265     ,p_prefix          => l_prefix
9266     ,p_dbi_prefixes    => p_dbi_prefixes
9267     ,p_date_p          => l_date_p
9268     ,p_startup_mode    => l_startup_mode
9269     ,p_languages       => p_languages
9270     ,p_user_entity_id  => l_ueid
9271     ,p_suffix          => 'REPORTING_NAME'
9272     );
9273 
9274     -- CLASSIFICATION --
9275     update_dbis
9276     (p_element_type_id => p_element_type_id
9277     ,p_leg_code        => l_leg_code
9278     ,p_bg_id           => l_bg_id
9279     ,p_prefix          => l_prefix
9280     ,p_dbi_prefixes    => p_dbi_prefixes
9281     ,p_date_p          => l_date_p
9282     ,p_startup_mode    => l_startup_mode
9283     ,p_languages       => p_languages
9284     ,p_user_entity_id  => l_ueid
9285     ,p_suffix          => 'CLASSIFICATION'
9286     );
9287 
9288     -- INPUT_CURRENCY_CODE --
9289     update_dbis
9290     (p_element_type_id => p_element_type_id
9291     ,p_leg_code        => l_leg_code
9292     ,p_bg_id           => l_bg_id
9293     ,p_prefix          => l_prefix
9294     ,p_dbi_prefixes    => p_dbi_prefixes
9295     ,p_date_p          => l_date_p
9296     ,p_startup_mode    => l_startup_mode
9297     ,p_languages       => p_languages
9298     ,p_user_entity_id  => l_ueid
9299     ,p_suffix          => 'INPUT_CURRENCY_CODE'
9300     );
9301 
9302     -- OUTPUT_CURRENCY_CODE --
9303     update_dbis
9304     (p_element_type_id => p_element_type_id
9305     ,p_leg_code        => l_leg_code
9306     ,p_bg_id           => l_bg_id
9307     ,p_prefix          => l_prefix
9308     ,p_dbi_prefixes    => p_dbi_prefixes
9309     ,p_date_p          => l_date_p
9310     ,p_startup_mode    => l_startup_mode
9311     ,p_languages       => p_languages
9312     ,p_user_entity_id  => l_ueid
9313     ,p_suffix          => 'OUTPUT_CURRENCY_CODE'
9314     );
9315 
9316     -- PROCESSING_PRIORITY --
9317     update_dbis
9318     (p_element_type_id => p_element_type_id
9319     ,p_leg_code        => l_leg_code
9320     ,p_bg_id           => l_bg_id
9321     ,p_prefix          => l_prefix
9322     ,p_dbi_prefixes    => p_dbi_prefixes
9323     ,p_date_p          => l_date_p
9324     ,p_startup_mode    => l_startup_mode
9325     ,p_languages       => p_languages
9326     ,p_user_entity_id  => l_ueid
9327     ,p_suffix          => 'PROCESSING_PRIORITY'
9328     );
9329 
9330     -- CLOSED_FOR_ENTRY --
9331     update_dbis
9332     (p_element_type_id => p_element_type_id
9333     ,p_leg_code        => l_leg_code
9334     ,p_bg_id           => l_bg_id
9335     ,p_prefix          => l_prefix
9336     ,p_dbi_prefixes    => p_dbi_prefixes
9337     ,p_date_p          => l_date_p
9338     ,p_startup_mode    => l_startup_mode
9339     ,p_languages       => p_languages
9340     ,p_user_entity_id  => l_ueid
9341     ,p_suffix          => 'CLOSED_FOR_ENTRY'
9342     );
9343 
9344     -- CLOSED_FOR_ENTRY_CODE --
9345     update_dbis
9346     (p_element_type_id => p_element_type_id
9347     ,p_leg_code        => l_leg_code
9348     ,p_bg_id           => l_bg_id
9349     ,p_prefix          => l_prefix
9350     ,p_dbi_prefixes    => p_dbi_prefixes
9351     ,p_date_p          => l_date_p
9352     ,p_startup_mode    => l_startup_mode
9353     ,p_languages       => p_languages
9354     ,p_user_entity_id  => l_ueid
9355     ,p_suffix          => 'CLOSED_FOR_ENTRY_CODE'
9356     );
9357 
9358     -- END_DATE --
9359     update_dbis
9360     (p_element_type_id => p_element_type_id
9361     ,p_leg_code        => l_leg_code
9362     ,p_bg_id           => l_bg_id
9363     ,p_prefix          => l_prefix
9364     ,p_dbi_prefixes    => p_dbi_prefixes
9365     ,p_date_p          => l_date_p
9366     ,p_startup_mode    => l_startup_mode
9367     ,p_languages       => p_languages
9368     ,p_user_entity_id  => l_ueid
9369     ,p_suffix          => 'END_DATE'
9370     );
9371 
9372     --
9373     -- BEN_CLASS
9374     --
9375     -- Database item is only generated when the BENEFIT_CLASSIFICATION_ID
9376     -- is NOT NULL.
9377     --
9378     if l_ben_class_id is not null then
9379       update_dbis
9380       (p_element_type_id => p_element_type_id
9381       ,p_leg_code        => l_leg_code
9382       ,p_bg_id           => l_bg_id
9383       ,p_prefix          => l_prefix
9384       ,p_dbi_prefixes    => p_dbi_prefixes
9385       ,p_date_p          => l_date_p
9386       ,p_startup_mode    => l_startup_mode
9387       ,p_languages       => p_languages
9388       ,p_user_entity_id  => l_ueid
9389       ,p_suffix          => 'BEN_CLASS'
9390       );
9391     end if;
9392 
9393     -- ========================================= --
9394     -- Process the dbis for the _E2 user entity. --
9395     -- ========================================= --
9396 
9397     --
9398     -- This must be done for the first dbi in each user entity.
9399     --
9400     l_ueid := null;
9401 
9402     -- LENGTH_OF_SERVICE --
9403     update_dbis
9404     (p_element_type_id => p_element_type_id
9405     ,p_leg_code        => l_leg_code
9406     ,p_bg_id           => l_bg_id
9407     ,p_prefix          => l_prefix
9408     ,p_dbi_prefixes    => p_dbi_prefixes
9409     ,p_date_p          => l_date_p
9410     ,p_startup_mode    => l_startup_mode
9411     ,p_languages       => p_languages
9412     ,p_user_entity_id  => l_ueid
9413     ,p_suffix          => 'LENGTH_OF_SERVICE'
9414     );
9415 
9416     -- QUALIFYING_UNITS --
9417     update_dbis
9418     (p_element_type_id => p_element_type_id
9419     ,p_leg_code        => l_leg_code
9420     ,p_bg_id           => l_bg_id
9421     ,p_prefix          => l_prefix
9422     ,p_dbi_prefixes    => p_dbi_prefixes
9423     ,p_date_p          => l_date_p
9424     ,p_startup_mode    => l_startup_mode
9425     ,p_languages       => p_languages
9426     ,p_user_entity_id  => l_ueid
9427     ,p_suffix          => 'QUALIFYING_UNITS'
9428     );
9429 
9430     -- QUALIFYING_UNITS_CODE --
9431     update_dbis
9432     (p_element_type_id => p_element_type_id
9433     ,p_leg_code        => l_leg_code
9434     ,p_bg_id           => l_bg_id
9435     ,p_prefix          => l_prefix
9436     ,p_dbi_prefixes    => p_dbi_prefixes
9437     ,p_date_p          => l_date_p
9438     ,p_startup_mode    => l_startup_mode
9439     ,p_languages       => p_languages
9440     ,p_user_entity_id  => l_ueid
9441     ,p_suffix          => 'QUALIFYING_UNITS_CODE'
9442     );
9443 
9444     -- QUALIFYING_AGE --
9445     update_dbis
9446     (p_element_type_id => p_element_type_id
9447     ,p_leg_code        => l_leg_code
9448     ,p_bg_id           => l_bg_id
9449     ,p_prefix          => l_prefix
9450     ,p_dbi_prefixes    => p_dbi_prefixes
9451     ,p_date_p          => l_date_p
9452     ,p_startup_mode    => l_startup_mode
9453     ,p_languages       => p_languages
9454     ,p_user_entity_id  => l_ueid
9455     ,p_suffix          => 'QUALIFYING_AGE'
9456     );
9457 
9458     -- STANDARD_LINK --
9459     update_dbis
9460     (p_element_type_id => p_element_type_id
9461     ,p_leg_code        => l_leg_code
9462     ,p_bg_id           => l_bg_id
9463     ,p_prefix          => l_prefix
9464     ,p_dbi_prefixes    => p_dbi_prefixes
9465     ,p_date_p          => l_date_p
9466     ,p_startup_mode    => l_startup_mode
9467     ,p_languages       => p_languages
9468     ,p_user_entity_id  => l_ueid
9469     ,p_suffix          => 'STANDARD_LINK'
9470     );
9471 
9472     -- STANDARD_LINK_CODE --
9473     update_dbis
9474     (p_element_type_id => p_element_type_id
9475     ,p_leg_code        => l_leg_code
9476     ,p_bg_id           => l_bg_id
9477     ,p_prefix          => l_prefix
9478     ,p_dbi_prefixes    => p_dbi_prefixes
9479     ,p_date_p          => l_date_p
9480     ,p_startup_mode    => l_startup_mode
9481     ,p_languages       => p_languages
9482     ,p_user_entity_id  => l_ueid
9483     ,p_suffix          => 'STANDARD_LINK_CODE'
9484     );
9485 
9486     -- COSTABLE_TYPE --
9487     update_dbis
9488     (p_element_type_id => p_element_type_id
9489     ,p_leg_code        => l_leg_code
9490     ,p_bg_id           => l_bg_id
9491     ,p_prefix          => l_prefix
9492     ,p_dbi_prefixes    => p_dbi_prefixes
9493     ,p_date_p          => l_date_p
9494     ,p_startup_mode    => l_startup_mode
9495     ,p_languages       => p_languages
9496     ,p_user_entity_id  => l_ueid
9497     ,p_suffix          => 'COSTABLE_TYPE'
9498     );
9499 
9500     -- COSTABLE_TYPE_CODE --
9501     update_dbis
9502     (p_element_type_id => p_element_type_id
9503     ,p_leg_code        => l_leg_code
9504     ,p_bg_id           => l_bg_id
9505     ,p_prefix          => l_prefix
9506     ,p_dbi_prefixes    => p_dbi_prefixes
9507     ,p_date_p          => l_date_p
9508     ,p_startup_mode    => l_startup_mode
9509     ,p_languages       => p_languages
9510     ,p_user_entity_id  => l_ueid
9511     ,p_suffix          => 'COSTABLE_TYPE_CODE'
9512     );
9513 
9514     -- ========================================= --
9515     -- Process the dbis for the _E3 user entity. --
9516     -- ========================================= --
9517 
9518     --
9519     -- This must be done for the first dbi in each user entity.
9520     --
9521     l_ueid := null;
9522 
9523     -- COUNT --
9524     update_dbis
9525     (p_element_type_id => p_element_type_id
9526     ,p_leg_code        => l_leg_code
9527     ,p_bg_id           => l_bg_id
9528     ,p_prefix          => l_prefix
9529     ,p_dbi_prefixes    => p_dbi_prefixes
9530     ,p_date_p          => l_date_p
9531     ,p_startup_mode    => l_startup_mode
9532     ,p_languages       => p_languages
9533     ,p_user_entity_id  => l_ueid
9534     ,p_suffix          => 'COUNT'
9535     );
9536   end loop;
9537 
9538 end update_element_type;
9539 
9540 --
9541 -- Interface 2: references PAY_ELEMENT_TYPES_F_TL.
9542 --
9543 procedure update_element_type
9544 (p_element_type_id in number
9545 ,p_effective_date  in date
9546 ,p_languages       in dbms_sql.varchar2s
9547 ) is
9548 l_prefixes     t_dbi_prefixes;
9549 begin
9550   -- ========================== --
9551   -- Generate the _TL prefixes. --
9552   -- ========================== --
9553   gen_et_dbi_prefixes
9554   (p_element_type_id => p_element_type_id
9555   ,p_languages       => p_languages
9556   ,p_prefixes        => l_prefixes
9557   );
9558 
9559   -- ========================================== --
9560   -- Call the overloaded version with prefixes. --
9561   -- ========================================== --
9562   update_element_type
9563   (p_element_type_id => p_element_type_id
9564   ,p_effective_date  => p_effective_date
9565   ,p_languages       => p_languages
9566   ,p_dbi_prefixes    => l_prefixes
9567   );
9568 end update_element_type;
9569 
9570 -- ====================================== --
9571 -- Update all the dbis for an input value --
9572 -- ====================================== --
9573 
9574 --
9575 -- Interface 1: does not reference PAY_INPUT_VALUES_F_TL - the core
9576 -- interface.
9577 --
9578 procedure update_input_value
9579 (p_input_value_id in number
9580 ,p_effective_date in date
9581 ,p_languages      in dbms_sql.varchar2s
9582 ,p_dbi_prefixes   in t_dbi_prefixes
9583 ) is
9584 --
9585 -- Cursor to get input value information.
9586 --
9587 cursor csr_input_value_info
9588 (p_input_value_id in number
9589 ,p_effective_date in date
9590 ) is
9591 select et.multiple_entries_allowed_flag
9592 ,      iv.legislation_code
9593 ,      iv.business_group_id
9594 ,      iv.uom
9595 ,      iv.generate_db_items_flag
9596 from   pay_input_values_f iv
9597 ,      pay_element_types_f et
9598 where  iv.input_value_id = p_input_value_id
9599 and    p_effective_date between
9600        iv.effective_start_date and iv.effective_end_date
9601 and    et.element_type_id = iv.element_type_id
9602 and    p_effective_date between
9603        et.effective_start_date and et.effective_end_date
9604 ;
9605 --
9606 l_multi_entries pay_element_types_f.multiple_entries_allowed_flag%type;
9607 l_uom           pay_input_values_f.uom%type;
9608 l_generate_dbis pay_input_values_f.generate_db_items_flag%type;
9609 l_do_date_p     boolean;
9610 l_do_non_date_p boolean;
9611 l_date_p        varchar2(16);
9612 l_leg_code      varchar2(30);
9613 l_bg_id         number;
9614 l_ueid          number;
9615 l_prefix        varchar2(240);
9616 l_found         boolean;
9617 l_startup_mode  varchar2(30);
9618 --
9619 procedure update_dbis
9620 (p_input_value_id in number
9621 ,p_leg_code       in out nocopy varchar2
9622 ,p_bg_id          in out nocopy number
9623 ,p_prefix         in out nocopy varchar2
9624 ,p_dbi_prefixes   in t_dbi_prefixes
9625 ,p_date_p         in varchar2
9626 ,p_startup_mode   in varchar2
9627 ,p_languages      in dbms_sql.varchar2s
9628 ,p_user_entity_id in out nocopy number
9629 ,p_suffix         in varchar2
9630 ) is
9631 l_base_name ff_database_items.user_name%type;
9632 begin
9633   gen_eiv_base_dbi_name
9634   (p_input_value_id => p_input_value_id
9635   ,p_leg_code       => p_leg_code
9636   ,p_bg_id          => p_bg_id
9637   ,p_prefix         => p_prefix
9638   ,p_suffix         => p_suffix
9639   ,p_date_p         => p_date_p
9640   ,p_base_name      => l_base_name
9641   );
9642 
9643   if p_user_entity_id is null then
9644     p_user_entity_id :=
9645     dbi2ueid
9646     (p_creator_id   => p_input_value_id
9647     ,p_creator_type => 'I'
9648     ,p_user_name    => l_base_name
9649     );
9650   end if;
9651 
9652   update_et_tl_dbi_names
9653   (p_leg_code       => p_leg_code
9654   ,p_bg_id          => p_bg_id
9655   ,p_startup_mode   => p_startup_mode
9656   ,p_user_name      => l_base_name
9657   ,p_user_entity_id => p_user_entity_id
9658   ,p_prefixes       => p_dbi_prefixes
9659   ,p_suffix         => p_suffix
9660   ,p_date_p         => p_date_p
9661   );
9662 
9663 end update_dbis;
9664 
9665 begin
9666 
9667   -- ============================== --
9668   -- Fetch input value information. --
9669   -- ============================== --
9670   open csr_input_value_info
9671        (p_input_value_id => p_input_value_id
9672        ,p_effective_date => p_effective_date
9673        );
9674   fetch csr_input_value_info
9675   into  l_multi_entries
9676   ,     l_leg_code
9677   ,     l_bg_id
9678   ,     l_uom
9679   ,     l_generate_dbis
9680   ;
9681   l_found := csr_input_value_info%found;
9682   close csr_input_value_info;
9683 
9684   assert(l_found, 'update_input_value:1', p_input_value_id);
9685 
9686   if l_generate_dbis <> 'Y' then
9687     --
9688     -- No need to do anything.
9689     --
9690     return;
9691   end if;
9692 
9693   --
9694   -- Get the startup mode. This only needs to be done at this
9695   -- stage as l_bg_id and l_leg_code should not change.
9696   --
9697   if g_triggers_altered then
9698     l_startup_mode := ffstup.get_mode(l_bg_id, l_leg_code);
9699   end if;
9700 
9701   -- Force fetch of element type information.
9702   l_prefix := null;
9703 
9704   -- ==================================================== --
9705   -- Are there DATE_PAID / non-DATE_PAID database items ? --
9706   -- ==================================================== --
9707   l_do_date_p :=
9708   has_date_paid_dbis
9709   (p_creator_type => 'I'
9710   ,p_creator_id   => p_input_value_id
9711   );
9712 
9713   l_do_non_date_p :=
9714   has_non_date_paid_dbis
9715   (p_creator_type => 'I'
9716   ,p_creator_id   => p_input_value_id
9717   );
9718 
9719   -- ============================== --
9720   -- Database item processing code. --
9721   -- ============================== --
9722   loop
9723 
9724     --
9725     -- Loop control based upon processing DATE PAID and non-DATE PAID
9726     -- database items.
9727     --
9728     if l_do_non_date_p then
9729       l_date_p := null;
9730       l_do_non_date_p := false;
9731     elsif l_do_date_p then
9732       l_date_p := '_DP';
9733       l_do_date_p := false;
9734     else
9735       exit;
9736     end if;
9737 
9738     -- ========================================= --
9739     -- Process the dbis for the _I1 user entity. --
9740     -- ========================================= --
9741 
9742     --
9743     -- This must be done for the first dbi in each user entity.
9744     --
9745     l_ueid := null;
9746 
9747     -- UNIT_OF_MEASURE --
9748     update_dbis
9749     (p_input_value_id => p_input_value_id
9750     ,p_leg_code       => l_leg_code
9751     ,p_bg_id          => l_bg_id
9752     ,p_prefix         => l_prefix
9753     ,p_dbi_prefixes   => p_dbi_prefixes
9754     ,p_date_p         => l_date_p
9755     ,p_startup_mode   => l_startup_mode
9756     ,p_languages      => p_languages
9757     ,p_user_entity_id => l_ueid
9758     ,p_suffix         => 'UNIT_OF_MEASURE'
9759     );
9760 
9761     -- UNIT_OF_MEASURE_CODE --
9762     update_dbis
9763     (p_input_value_id => p_input_value_id
9764     ,p_leg_code       => l_leg_code
9765     ,p_bg_id          => l_bg_id
9766     ,p_prefix         => l_prefix
9767     ,p_dbi_prefixes   => p_dbi_prefixes
9768     ,p_date_p         => l_date_p
9769     ,p_startup_mode   => l_startup_mode
9770     ,p_languages      => p_languages
9771     ,p_user_entity_id => l_ueid
9772     ,p_suffix         => 'UNIT_OF_MEASURE_CODE'
9773     );
9774 
9775     -- ========================================= --
9776     -- Process the dbis for the _I2 user entity. --
9777     -- ========================================= --
9778 
9779     --
9780     -- This must be done for the first dbi in each user entity.
9781     --
9782     l_ueid := null;
9783 
9784     -- DEFAULT --
9785     update_dbis
9786     (p_input_value_id => p_input_value_id
9787     ,p_leg_code       => l_leg_code
9788     ,p_bg_id          => l_bg_id
9789     ,p_prefix         => l_prefix
9790     ,p_dbi_prefixes   => p_dbi_prefixes
9791     ,p_date_p         => l_date_p
9792     ,p_startup_mode   => l_startup_mode
9793     ,p_languages      => p_languages
9794     ,p_user_entity_id => l_ueid
9795     ,p_suffix         => 'DEFAULT'
9796     );
9797 
9798     -- MIN --
9799     update_dbis
9800     (p_input_value_id => p_input_value_id
9801     ,p_leg_code       => l_leg_code
9802     ,p_bg_id          => l_bg_id
9803     ,p_prefix         => l_prefix
9804     ,p_dbi_prefixes   => p_dbi_prefixes
9805     ,p_date_p         => l_date_p
9806     ,p_startup_mode   => l_startup_mode
9807     ,p_languages      => p_languages
9808     ,p_user_entity_id => l_ueid
9809     ,p_suffix         => 'MIN'
9810     );
9811 
9812     -- MAX --
9813     update_dbis
9814     (p_input_value_id => p_input_value_id
9815     ,p_leg_code       => l_leg_code
9816     ,p_bg_id          => l_bg_id
9817     ,p_prefix         => l_prefix
9818     ,p_dbi_prefixes   => p_dbi_prefixes
9819     ,p_date_p         => l_date_p
9820     ,p_startup_mode   => l_startup_mode
9821     ,p_languages      => p_languages
9822     ,p_user_entity_id => l_ueid
9823     ,p_suffix         => 'MAX'
9824     );
9825 
9826     -- ================================= --
9827     -- Multiple Entries are not allowed. --
9828     -- ================================= --
9829     if l_multi_entries = 'N' then
9830       -- ========================================= --
9831       -- Process the dbis for the _I3 user entity. --
9832       -- ========================================= --
9833 
9834       --
9835       -- This must be done for the first dbi in each user entity.
9836       --
9837       l_ueid := null;
9838 
9839       -- ENTRY_VALUE --
9840       update_dbis
9841       (p_input_value_id => p_input_value_id
9842       ,p_leg_code       => l_leg_code
9843       ,p_bg_id          => l_bg_id
9844       ,p_prefix         => l_prefix
9845       ,p_dbi_prefixes   => p_dbi_prefixes
9846       ,p_date_p         => l_date_p
9847       ,p_startup_mode   => l_startup_mode
9848       ,p_languages      => p_languages
9849       ,p_user_entity_id => l_ueid
9850       ,p_suffix         => 'ENTRY_VALUE'
9851       );
9852 
9853       -- USER_ENTERED_CODE --
9854       update_dbis
9855       (p_input_value_id => p_input_value_id
9856       ,p_leg_code       => l_leg_code
9857       ,p_bg_id          => l_bg_id
9858       ,p_prefix         => l_prefix
9859       ,p_dbi_prefixes   => p_dbi_prefixes
9860       ,p_date_p         => l_date_p
9861       ,p_startup_mode   => l_startup_mode
9862       ,p_languages      => p_languages
9863       ,p_user_entity_id => l_ueid
9864       ,p_suffix         => 'USER_ENTERED_CODE'
9865       );
9866 
9867       -- START_DATE --
9868       update_dbis
9869       (p_input_value_id => p_input_value_id
9870       ,p_leg_code       => l_leg_code
9871       ,p_bg_id          => l_bg_id
9872       ,p_prefix         => l_prefix
9873       ,p_dbi_prefixes   => p_dbi_prefixes
9874       ,p_date_p         => l_date_p
9875       ,p_startup_mode   => l_startup_mode
9876       ,p_languages      => p_languages
9877       ,p_user_entity_id => l_ueid
9878       ,p_suffix         => 'START_DATE'
9879       );
9880 
9881       -- END_DATE --
9882       update_dbis
9883       (p_input_value_id => p_input_value_id
9884       ,p_leg_code       => l_leg_code
9885       ,p_bg_id          => l_bg_id
9886       ,p_prefix         => l_prefix
9887       ,p_dbi_prefixes   => p_dbi_prefixes
9888       ,p_date_p         => l_date_p
9889       ,p_startup_mode   => l_startup_mode
9890       ,p_languages      => p_languages
9891       ,p_user_entity_id => l_ueid
9892       ,p_suffix         => 'END_DATE'
9893       );
9894 
9895       -- ========================================= --
9896       -- Process the dbis for the _I4 user entity. --
9897       -- ========================================= --
9898 
9899       --
9900       -- This must be done for the first dbi in each user entity.
9901       --
9902       l_ueid := null;
9903 
9904       -- OVERRIDE_ENTRY_VALUE --
9905       update_dbis
9906       (p_input_value_id => p_input_value_id
9907       ,p_leg_code       => l_leg_code
9908       ,p_bg_id          => l_bg_id
9909       ,p_prefix         => l_prefix
9910       ,p_dbi_prefixes   => p_dbi_prefixes
9911       ,p_date_p         => l_date_p
9912       ,p_startup_mode   => l_startup_mode
9913       ,p_languages      => p_languages
9914       ,p_user_entity_id => l_ueid
9915       ,p_suffix         => 'OVERRIDE_ENTRY_VALUE'
9916       );
9917 
9918       -- OVERRIDE_USER_ENTERED_CODE --
9919       update_dbis
9920       (p_input_value_id => p_input_value_id
9921       ,p_leg_code       => l_leg_code
9922       ,p_bg_id          => l_bg_id
9923       ,p_prefix         => l_prefix
9924       ,p_dbi_prefixes   => p_dbi_prefixes
9925       ,p_date_p         => l_date_p
9926       ,p_startup_mode   => l_startup_mode
9927       ,p_languages      => p_languages
9928       ,p_user_entity_id => l_ueid
9929       ,p_suffix         => 'OVERRIDE_USER_ENTERED_CODE'
9930       );
9931 
9932       -- OVERRIDE_START_DATE --
9933       update_dbis
9934       (p_input_value_id => p_input_value_id
9935       ,p_leg_code       => l_leg_code
9936       ,p_bg_id          => l_bg_id
9937       ,p_prefix         => l_prefix
9938       ,p_dbi_prefixes   => p_dbi_prefixes
9939       ,p_date_p         => l_date_p
9940       ,p_startup_mode   => l_startup_mode
9941       ,p_languages      => p_languages
9942       ,p_user_entity_id => l_ueid
9943       ,p_suffix         => 'OVERRIDE_START_DATE'
9944       );
9945 
9946       -- OVERRIDE_END_DATE --
9947       update_dbis
9948       (p_input_value_id => p_input_value_id
9949       ,p_leg_code       => l_leg_code
9950       ,p_bg_id          => l_bg_id
9951       ,p_prefix         => l_prefix
9952       ,p_dbi_prefixes   => p_dbi_prefixes
9953       ,p_date_p         => l_date_p
9954       ,p_startup_mode   => l_startup_mode
9955       ,p_languages      => p_languages
9956       ,p_user_entity_id => l_ueid
9957       ,p_suffix         => 'OVERRIDE_END_DATE'
9958       );
9959 
9960     -- ============================= --
9961     -- Multiple Entries are allowed. --
9962     -- ============================= --
9963     else
9964       if uom_requires_dbis(p_uom => l_uom) then
9965         -- ========================================= --
9966         -- Process the dbis for the _I3 user entity. --
9967         -- ========================================= --
9968 
9969         --
9970         -- This must be done for the first dbi in each user entity.
9971         --
9972         l_ueid := null;
9973 
9974         -- ENTRY_VALUE --
9975         update_dbis
9976         (p_input_value_id => p_input_value_id
9977         ,p_leg_code       => l_leg_code
9978         ,p_bg_id          => l_bg_id
9979         ,p_prefix         => l_prefix
9980         ,p_dbi_prefixes   => p_dbi_prefixes
9981         ,p_date_p         => l_date_p
9982         ,p_startup_mode   => l_startup_mode
9983         ,p_languages      => p_languages
9984         ,p_user_entity_id => l_ueid
9985         ,p_suffix         => 'ENTRY_VALUE'
9986         );
9987 
9988         -- ========================================= --
9989         -- Process the dbis for the _I4 user entity. --
9990         -- ========================================= --
9991 
9992         --
9993         -- This must be done for the first dbi in each user entity.
9994         --
9995         l_ueid := null;
9996 
9997         -- OVERRIDE_ENTRY_VALUE --
9998         update_dbis
9999         (p_input_value_id => p_input_value_id
10000         ,p_leg_code       => l_leg_code
10001         ,p_bg_id          => l_bg_id
10002         ,p_prefix         => l_prefix
10003         ,p_dbi_prefixes   => p_dbi_prefixes
10004         ,p_date_p         => l_date_p
10005         ,p_startup_mode   => l_startup_mode
10006         ,p_languages      => p_languages
10007         ,p_user_entity_id => l_ueid
10008         ,p_suffix         => 'OVERRIDE_ENTRY_VALUE'
10009         );
10010 
10011       end if;
10012     end if;
10013   end loop;
10014 
10015 end update_input_value;
10016 
10017 --
10018 -- Interface 2: references PAY_INPUT_VALUES_F_TL.
10019 --
10020 procedure update_input_value
10021 (p_input_value_id in number
10022 ,p_effective_date in date
10023 ,p_languages      in dbms_sql.varchar2s
10024 ) is
10025 l_prefixes t_dbi_prefixes;
10026 begin
10027   -- ========================== --
10028   -- Generate the _TL prefixes. --
10029   -- ========================== --
10030   gen_eiv_dbi_prefixes
10031   (p_input_value_id => p_input_value_id
10032   ,p_effective_date => p_effective_date
10033   ,p_languages      => p_languages
10034   ,p_prefixes       => l_prefixes
10035   );
10036 
10037   -- ========================================== --
10038   -- Call the overloaded version with prefixes. --
10039   -- ========================================== --
10040   update_input_value
10041   (p_input_value_id => p_input_value_id
10042   ,p_effective_date => p_effective_date
10043   ,p_languages      => p_languages
10044   ,p_dbi_prefixes   => l_prefixes
10045   );
10046 end update_input_value;
10047 
10048 --
10049 -- Is it necessary to generate database items for the UOM if multiple
10050 -- entries are allowed ?
10051 --
10052 -- Code extracted as it is used in more than one place.
10053 --
10054 function uom_requires_dbis
10055 (p_uom in varchar2
10056 ) return boolean is
10057 begin
10058   return p_uom like 'H_%' -- Hours
10059       or p_uom = 'I'      -- Integer
10060       or p_uom = 'M'      -- Money
10061       or p_uom = 'N'      -- Number
10062       ;
10063 end uom_requires_dbis;
10064 
10065 --
10066 -- Run legislation-specific translation procedure.
10067 --
10068 -- P_ERRORS collects errors in this procedure.
10069 --
10070 procedure process_leg_translations
10071 (p_errors in out nocopy dbms_sql.varchar2_table
10072 ) is
10073 l_dummy        varchar2(1);
10074 l_package_name varchar2(1000);
10075 l_debug        boolean := hr_utility.debug_enabled;
10076 --
10077 -- Cursor to fetch information on legislations that support translations.
10078 --
10079 cursor csr_fetch_legs is
10080 select plr.legislation_code
10081 from   pay_legislation_rules plr
10082 where  rule_type = 'FF_TRANSLATE_DATABASE_ITEMS'
10083 and    rule_mode = 'Y'
10084 ;
10085 --
10086 -- Cursor to check validity of a package.
10087 --
10088 cursor csr_package_exists(p_package_name in varchar2) is
10089 select null
10090 from   user_objects uo
10091 where  uo.object_name = p_package_name
10092 and    uo.object_type = 'PACKAGE BODY'
10093 and    uo.status ='VALID'
10094 ;
10095 begin
10096   if l_debug then
10097     hr_utility.set_location('PROCESS_LEG_TRANSLATIONS', 5);
10098   end if;
10099 
10100   --
10101   -- Loop through the available legislations.
10102   --
10103   for crec in csr_fetch_legs loop
10104 
10105     if l_debug then
10106       hr_utility.set_location('PROCESS_LEG_TRANSLATIONS:' || crec.legislation_code, 15);
10107     end if;
10108     --
10109     -- Build the package name, PAY_<LEG_CODE>_DBI_PKG, and only execute <PKG>.TRANSLATE
10110     -- if it exists.
10111     --
10112     begin
10113       l_package_name := upper('PAY_' || crec.legislation_code || '_DBI_PKG');
10114       open csr_package_exists(p_package_name => l_package_name);
10115       fetch csr_package_exists
10116       into  l_dummy
10117       ;
10118       if csr_package_exists%found then
10119         if l_debug then
10120           hr_utility.set_location('PROCESS_LEG_TRANSLATIONS:' || l_package_name || '.TRANSLATE', 25);
10121         end if;
10122 
10123         execute immediate
10124         'begin  '|| l_package_name || '.TRANSLATE; end;';
10125       end if;
10126 
10127       close csr_package_exists;
10128     exception
10129       when others then
10130         if csr_package_exists%isopen then
10131           close csr_package_exists;
10132         end if;
10133 
10134         if l_debug then
10135           hr_utility.set_location('PROCESS_LEG_TRANSLATIONS:' || sqlerrm, 30);
10136         end if;
10137 
10138         p_errors(p_errors.count + 1) := sqlerrm;
10139     end;
10140 
10141   end loop;
10142 
10143   if l_debug then
10144     hr_utility.set_location('PROCESS_LEG_TRANSLATIONS', 35);
10145   end if;
10146 
10147 exception
10148   when others then
10149 
10150     if l_debug then
10151       hr_utility.set_location('PROCESS_LEG_TRANSLATIONS', 45);
10152     end if;
10153 
10154     p_errors(p_errors.count + 1) := sqlerrm;
10155 end process_leg_translations;
10156 
10157 -- ================================ --
10158 -- Process PAY_DYNDBI_CHANGES rows. --
10159 -- ================================ --
10160 
10161 --
10162 -- Procedure to fetch changes for a particular entity type.
10163 --
10164 procedure fetch_dyndbi_changes
10165 (p_type      in            varchar2
10166 ,p_ids          out nocopy dbms_sql.number_table
10167 ,p_languages    out nocopy dbms_sql.varchar2s
10168 ) is
10169 cursor csr_dyndbi_changes
10170 (p_type in varchar2
10171 ) is
10172 select pdc.id
10173 ,      pdc.language
10174 from   pay_dyndbi_changes pdc
10175 where  pdc.type = p_type
10176 order  by 1, 2
10177 ;
10178 begin
10179   open csr_dyndbi_changes(p_type => p_type);
10180   fetch csr_dyndbi_changes bulk collect
10181   into  p_ids
10182   ,     p_languages
10183   ;
10184   close csr_dyndbi_changes;
10185 end fetch_dyndbi_changes;
10186 
10187 --
10188 -- From the lists returned from FETCH_DYNDBI_CHANGES, return the
10189 -- _id to process, the list of languages, and the next index
10190 -- to start from.
10191 --
10192 procedure next_dyndbi_change
10193 (p_ids       in            dbms_sql.number_table
10194 ,p_languages in            dbms_sql.varchar2s
10195 ,p_start     in out nocopy binary_integer
10196 ,p_id           out nocopy number
10197 ,p_id_langs     out nocopy dbms_sql.varchar2s
10198 ) is
10199 i    binary_integer;
10200 j    binary_integer;
10201 l_id number;
10202 begin
10203   --
10204   -- Perform initialisations.
10205   --
10206   l_id := p_ids(p_start);
10207   p_id := l_id;
10208 
10209   i := p_start;
10210   j := 1;
10211 
10212   while p_ids.exists(i) and p_ids(i) = l_id loop
10213     p_id_langs(j) := p_languages(i);
10214     j := j + 1;
10215     i := i + 1;
10216   end loop;
10217 
10218   --
10219   -- Set the next start point.
10220   --
10221   p_start := i;
10222 end next_dyndbi_change;
10223 
10224 procedure process_pay_dyndbi_changes
10225 (errbuf                out nocopy varchar2
10226 ,retcode               out nocopy number
10227 ,p_element_types    in     varchar2
10228 ,p_input_values     in     varchar2
10229 ,p_defined_balances in     varchar2
10230 ,p_localization     in     varchar2
10231 ) is
10232 l_proc      varchar2(2000) := 'PROCESS_PAY_DYNDBI_CHANGES:';
10233 l_ids       dbms_sql.number_table;
10234 l_languages dbms_sql.varchar2s;
10235 l_id        number;
10236 l_id_langs  dbms_sql.varchar2s;
10237 i           binary_integer;
10238 l_eff_date  date;
10239 l_found     boolean;
10240 l_cnt       binary_integer;
10241 l_dummy     varchar2(1);
10242 l_rowids    dbms_sql.varchar2s;
10243 l_messages  dbms_sql.varchar2_table;
10244 l_errors    dbms_sql.varchar2_table;
10245 l_debug     boolean := hr_utility.debug_enabled;
10246 l_newline   varchar2(10) := '
10247 ';
10248 l_separator varchar2(100);
10249 --
10250 cursor csr_ele_eff_date
10251 (p_element_type_id in number
10252 ) is
10253 select et.effective_end_date
10254 from   pay_element_types_f et
10255 where  et.element_type_id = p_element_type_id
10256 order  by 1 desc
10257 ;
10258 --
10259 cursor csr_ipv_eff_date
10260 (p_input_value_id in number
10261 ) is
10262 select iv.effective_end_date
10263 from   pay_input_values_f iv
10264 where  iv.input_value_id = p_input_value_id
10265 order  by 1 desc
10266 ;
10267 --
10268 cursor csr_def_balance
10269 (p_defined_balance_id in number
10270 ) is
10271 select to_char(null)
10272 from   pay_defined_balances db
10273 where  db.defined_balance_id = p_defined_balance_id
10274 ;
10275 --
10276 procedure init_cnt(p_cnt in out nocopy binary_integer) is
10277 begin
10278   p_cnt := 1;
10279 end init_cnt;
10280 --
10281 procedure incr_cnt(p_cnt in out nocopy binary_integer) is
10282 begin
10283   if mod(p_cnt, 50) = 0 then
10284     commit;
10285     init_cnt(p_cnt => p_cnt);
10286   else
10287     p_cnt := p_cnt + 1;
10288   end if;
10289 end incr_cnt;
10290 
10291 begin
10292   -- Assume success.
10293   retcode := 0;
10294   errbuf := null;
10295 
10296   g_dyndbi_changes := true;
10297   g_security_group_id :=
10298   fnd_global.lookup_security_group('NAME_TRANSLATIONS', 3);
10299 
10300   if l_debug then
10301     hr_utility.set_location('process_pay_dyndbi_changes', 0);
10302   end if;
10303 
10304   --
10305   -- Set log file message separator.
10306   --
10307   l_separator := l_newline || '--------------------------------' || l_newline;
10308 
10309   -- ============== --
10310   -- Element Types. --
10311   -- ============== --
10312   if upper(p_element_types) = 'Y' then
10313 
10314     if l_debug then
10315       hr_utility.set_location('process_pay_dyndbi_changes', 10);
10316     end if;
10317 
10318     --
10319     -- Initialise everything.
10320     --
10321     l_ids.delete;
10322     l_languages.delete;
10323     i := 1;
10324 
10325     --
10326     -- Fetch the PAY_DYNDBI_CHANGES rows.
10327     --
10328     fetch_dyndbi_changes
10329     (p_type      => pay_dyndbi_changes_pkg.c_element_type
10330     ,p_ids       => l_ids
10331     ,p_languages => l_languages
10332     );
10333 
10334     if l_debug then
10335       hr_utility.set_location('process_pay_dyndbi_changes', 20);
10336     end if;
10337 
10338     --
10339     -- Do the updates.
10340     --
10341     init_cnt(p_cnt => l_cnt);
10342 
10343     while l_ids.exists(i) loop
10344 
10345       if l_debug then
10346         hr_utility.set_location('process_pay_dyndbi_changes', 30);
10347       end if;
10348 
10349       l_id_langs.delete;
10350       next_dyndbi_change
10351       (p_ids       => l_ids
10352       ,p_languages => l_languages
10353       ,p_start     => i
10354       ,p_id        => l_id
10355       ,p_id_langs  => l_id_langs
10356       );
10357 
10358       --
10359       -- Fetch the effective date.
10360       --
10361       open csr_ele_eff_date(p_element_type_id => l_id);
10362       fetch csr_ele_eff_date
10363       into  l_eff_date
10364       ;
10365       l_found := csr_ele_eff_date%found;
10366       close csr_ele_eff_date;
10367 
10368       if l_debug then
10369         hr_utility.set_location('process_pay_dyndbi_changes', 40);
10370       end if;
10371 
10372       g_dyndbi_changes_ok := true;
10373       if l_found then
10374 
10375         if l_debug then
10376           hr_utility.set_location('process_pay_dyndbi_changes', 50);
10377         end if;
10378 
10379         begin
10380           update_element_type
10381           (p_element_type_id => l_id
10382           ,p_effective_date  => l_eff_date
10383           ,p_languages       => l_id_langs
10384           );
10385         exception
10386           when others then
10387             g_dyndbi_changes_ok := false;
10388             fnd_file.put(fnd_file.log, l_separator);
10389             fnd_file.put(fnd_file.log, sqlerrm);
10390             errbuf := sqlerrm;
10391             retcode := 2;
10392         end;
10393 
10394         if l_debug then
10395           hr_utility.set_location('process_pay_dyndbi_changes', 60);
10396         end if;
10397       else
10398         hr_utility.trace(l_proc||'no such element '||l_id);
10399       end if;
10400 
10401       if l_debug then
10402         hr_utility.set_location('process_pay_dyndbi_changes', 70);
10403       end if;
10404 
10405       --
10406       -- Delete the PAY_DYNDBI_CHANGES rows.
10407       --
10408       if g_dyndbi_changes_ok then
10409         pay_dyndbi_changes_pkg.delete_rows
10410         (p_id   => l_id
10411         ,p_type => pay_dyndbi_changes_pkg.c_element_type
10412         );
10413       end if;
10414 
10415       if l_debug then
10416         hr_utility.set_location('process_pay_dyndbi_changes', 80);
10417       end if;
10418 
10419       incr_cnt(p_cnt => l_cnt);
10420     end loop;
10421 
10422     --
10423     -- COMMIT the last lot of changes.
10424     --
10425     commit;
10426   end if;
10427 
10428   if l_debug then
10429     hr_utility.set_location('process_pay_dyndbi_changes', 90);
10430   end if;
10431 
10432   -- ============= --
10433   -- Input Values. --
10434   -- ============= --
10435   if upper(p_input_values) = 'Y' then
10436 
10437     if l_debug then
10438       hr_utility.set_location('process_pay_dyndbi_changes', 100);
10439     end if;
10440 
10441     --
10442     -- Initialise everything.
10443     --
10444     l_ids.delete;
10445     l_languages.delete;
10446     i := 1;
10447 
10448     --
10449     -- Fetch the PAY_DYNDBI_CHANGES rows.
10450     --
10451     fetch_dyndbi_changes
10452     (p_type      => pay_dyndbi_changes_pkg.c_input_value
10453     ,p_ids       => l_ids
10454     ,p_languages => l_languages
10455     );
10456 
10457     if l_debug then
10458       hr_utility.set_location('process_pay_dyndbi_changes', 110);
10459     end if;
10460 
10461     --
10462     -- Do the updates.
10463     --
10464     init_cnt(p_cnt => l_cnt);
10465 
10466     while l_ids.exists(i) loop
10467 
10468       if l_debug then
10469         hr_utility.set_location('process_pay_dyndbi_changes', 120);
10470       end if;
10471 
10472       l_id_langs.delete;
10473       next_dyndbi_change
10474       (p_ids       => l_ids
10475       ,p_languages => l_languages
10476       ,p_start     => i
10477       ,p_id        => l_id
10478       ,p_id_langs  => l_id_langs
10479       );
10480 
10481       --
10482       -- Fetch the effective date.
10483       --
10484       open csr_ipv_eff_date(p_input_value_id => l_id);
10485       fetch csr_ipv_eff_date
10486       into  l_eff_date
10487       ;
10488       l_found := csr_ipv_eff_date%found;
10489       close csr_ipv_eff_date;
10490 
10491       if l_debug then
10492         hr_utility.set_location('process_pay_dyndbi_changes', 130);
10493       end if;
10494 
10495       g_dyndbi_changes_ok := true;
10496       if l_found then
10497         begin
10498           update_input_value
10499           (p_input_value_id => l_id
10500           ,p_effective_date => l_eff_date
10501           ,p_languages      => l_id_langs
10502           );
10503         exception
10504           when others then
10505             g_dyndbi_changes_ok := false;
10506             fnd_file.put(fnd_file.log, l_separator);
10507             fnd_file.put(fnd_file.log, sqlerrm);
10508             errbuf := sqlerrm;
10509             retcode := 2;
10510         end;
10511       else
10512         hr_utility.trace(l_proc||'no such input value '||l_id);
10513       end if;
10514 
10515       if l_debug then
10516         hr_utility.set_location('process_pay_dyndbi_changes', 140);
10517       end if;
10518 
10519       --
10520       -- Delete the PAY_DYNDBI_CHANGES rows.
10521       --
10522       if g_dyndbi_changes_ok then
10523         pay_dyndbi_changes_pkg.delete_rows
10524         (p_id   => l_id
10525         ,p_type => pay_dyndbi_changes_pkg.c_input_value
10526         );
10527       end if;
10528 
10529       if l_debug then
10530         hr_utility.set_location('process_pay_dyndbi_changes', 150);
10531       end if;
10532 
10533       incr_cnt(p_cnt => l_cnt);
10534     end loop;
10535 
10536     --
10537     -- COMMIT the last lot of changes.
10538     --
10539     commit;
10540   end if;
10541 
10542   if l_debug then
10543     hr_utility.set_location('process_pay_dyndbi_changes', 160);
10544   end if;
10545 
10546   -- ================= --
10547   -- Defined Balances. --
10548   -- ================= --
10549   if upper(p_defined_balances) = 'Y' then
10550 
10551     if l_debug then
10552       hr_utility.set_location('process_pay_dyndbi_changes', 170);
10553     end if;
10554 
10555     --
10556     -- Initialise everything.
10557     --
10558     l_ids.delete;
10559     l_languages.delete;
10560     i := 1;
10561 
10562     --
10563     -- Fetch the PAY_DYNDBI_CHANGES rows.
10564     --
10565     fetch_dyndbi_changes
10566     (p_type      => pay_dyndbi_changes_pkg.c_defined_balance
10567     ,p_ids       => l_ids
10568     ,p_languages => l_languages
10569     );
10570 
10571     if l_debug then
10572       hr_utility.set_location('process_pay_dyndbi_changes', 180);
10573     end if;
10574 
10575     --
10576     -- Do the updates.
10577     --
10578     init_cnt(p_cnt => l_cnt);
10579 
10580     while l_ids.exists(i) loop
10581 
10582       if l_debug then
10583         hr_utility.set_location('process_pay_dyndbi_changes', 190);
10584       end if;
10585 
10586       l_id_langs.delete;
10587       next_dyndbi_change
10588       (p_ids       => l_ids
10589       ,p_languages => l_languages
10590       ,p_start     => i
10591       ,p_id        => l_id
10592       ,p_id_langs  => l_id_langs
10593       );
10594 
10595       open csr_def_balance(p_defined_balance_id => l_id);
10596       fetch csr_def_balance
10597       into  l_dummy
10598       ;
10599       l_found := csr_def_balance%found;
10600       close csr_def_balance;
10601 
10602       if l_debug then
10603         hr_utility.set_location('process_pay_dyndbi_changes', 200);
10604       end if;
10605 
10606       g_dyndbi_changes_ok := true;
10607       if l_found then
10608 
10609         if l_debug then
10610           hr_utility.set_location('process_pay_dyndbi_changes', 210);
10611         end if;
10612 
10613         begin
10614           update_defined_balance
10615           (p_defined_balance_id => l_id
10616           ,p_languages          => l_id_langs
10617           );
10618         exception
10619           when others then
10620             g_dyndbi_changes_ok := false;
10621             fnd_file.put(fnd_file.log, l_separator);
10622             fnd_file.put(fnd_file.log, sqlerrm);
10623             errbuf := sqlerrm;
10624             retcode := 2;
10625         end;
10626       else
10627         hr_utility.trace(l_proc||'no defined balance '||l_id);
10628       end if;
10629 
10630       --
10631       -- Delete the PAY_DYNDBI_CHANGES rows.
10632       --
10633       if g_dyndbi_changes_ok then
10634         pay_dyndbi_changes_pkg.delete_rows
10635         (p_id   => l_id
10636         ,p_type => pay_dyndbi_changes_pkg.c_defined_balance
10637         );
10638       end if;
10639 
10640       if l_debug then
10641         hr_utility.set_location('process_pay_dyndbi_changes', 220);
10642       end if;
10643 
10644       incr_cnt(p_cnt => l_cnt);
10645     end loop;
10646 
10647     --
10648     -- COMMIT the last lot of changes.
10649     --
10650     commit;
10651   end if;
10652 
10653   if l_debug then
10654     hr_utility.set_location('process_pay_dyndbi_changes', 230);
10655   end if;
10656 
10657   --
10658   -- Do the legislation-specfic changes.
10659   --
10660   if upper(p_localization) = 'Y' then
10661 
10662     if l_debug then
10663       hr_utility.set_location('process_pay_dyndbi_changes', 235);
10664     end if;
10665 
10666     process_leg_translations(p_errors => l_errors);
10667     for i in 1 .. l_errors.count loop
10668       fnd_file.put(fnd_file.log, l_separator);
10669       fnd_file.put(fnd_file.log, l_errors(i));
10670     end loop;
10671   end if;
10672 
10673   --
10674   -- Fetch any error log messages for this process.
10675   --
10676   pay_dbitl_update_errors_pkg.fetch_all_rows
10677   (p_rowids   => l_rowids
10678   ,p_messages => l_messages
10679   );
10680 
10681   if l_debug then
10682     hr_utility.set_location('process_pay_dyndbi_changes', 240);
10683   end if;
10684 
10685   --
10686   -- Set error status if there are any error messages.
10687   --
10688   if l_messages.count <> 0 then
10689     errbuf := l_messages(1);
10690     retcode := 2;
10691   elsif l_errors.count <> 0 then
10692     errbuf := l_errors(1);
10693     retcode := 2;
10694   end if;
10695 
10696   --
10697   -- Write messages to the log.
10698   --
10699   for i in 1 .. l_messages.count loop
10700     fnd_file.put(fnd_file.log, l_separator);
10701     fnd_message.set_encoded(l_messages(i));
10702     fnd_file.put(fnd_file.log, fnd_message.get);
10703   end loop;
10704 
10705   --
10706   -- Delete the messages.
10707   --
10708   pay_dbitl_update_errors_pkg.delete_rows
10709   (p_rowids => l_rowids
10710   );
10711 
10712   g_dyndbi_changes := false;
10713 
10714   if l_debug then
10715     hr_utility.set_location('process_pay_dyndbi_changes', 250);
10716   end if;
10717 
10718 exception
10719   when others then
10720     g_dyndbi_changes := false;
10721     errbuf := sqlerrm;
10722     retcode := 2;
10723 
10724     if l_debug then
10725       hr_utility.set_location('process_pay_dyndbi_changes', 300);
10726     end if;
10727 end process_pay_dyndbi_changes;
10728 
10729 end hrdyndbi;