DBA Data[Home] [Help]

PACKAGE BODY: APPS.HXC_GENERIC_RETRIEVAL_PKG

Source


1 PACKAGE BODY hxc_generic_retrieval_pkg AS
2 /* $Header: hxcgnret.pkb 120.22.12010000.2 2008/08/05 12:02:39 ubhat ship $ */
3 
4    -- global package data type and variables
5    TYPE r_parameters IS RECORD (
6       p_process             hxc_retrieval_processes.NAME%TYPE,
7       p_transaction_code    hxc_transactions.transaction_code%TYPE,
8       p_start_date          DATE,
9       p_end_date            DATE,
10       p_incremental         VARCHAR2 (1),
11       p_rerun_flag          VARCHAR2 (1),
12       p_where_clause        VARCHAR2 (3000),
13       p_scope               VARCHAR2 (10),
14       p_clusive             VARCHAR2 (2),
15       p_unique_params       VARCHAR2 (2000),
16       transfer_batch_size   NUMBER,
17       retrieval_options     VARCHAR2 (10),
18       since_date            DATE,
19       l_using_dates         BOOLEAN
20    );
21 
22    g_params                        r_parameters;
23    glb_debug                       BOOLEAN                 := FALSE;
24    g_debug                         BOOLEAN         := hr_utility.debug_enabled;
25                            -- Used for conditionally enabling hr_utility calls
26 -- variables for storing the old bld blk information
27    t_old_time_seq                  DBMS_SQL.number_table;
28    t_old_day_seq                   DBMS_SQL.number_table;
29    t_old_detail_seq                DBMS_SQL.number_table;
30    t_old_time_bb_id                DBMS_SQL.number_table;
31    t_old_day_bb_id                 DBMS_SQL.number_table;
32    t_old_detail_bb_id              DBMS_SQL.number_table;
33    t_old_time_ovn                  DBMS_SQL.number_table;
34    t_old_day_ovn                   DBMS_SQL.number_table;
35    t_old_detail_ovn                DBMS_SQL.number_table;
36 -- dynamic SQL arrays
37    t_timecard_bb_id                DBMS_SQL.number_table;
38    t_timecard_ovn                  DBMS_SQL.number_table;
39    t_timecard_max_ovn              DBMS_SQL.number_table;
40    t_timecard_start_time           DBMS_SQL.date_table;
41    t_timecard_stop_time            DBMS_SQL.date_table;
42    t_timecard_comment_text         DBMS_SQL.varchar2_table;
43    t_timecard_deleted              DBMS_SQL.varchar2_table;
44    t_day_bb_id                     DBMS_SQL.number_table;
45    t_day_ovn                       DBMS_SQL.number_table;
46    t_day_start_time                DBMS_SQL.date_table;
47    t_day_stop_time                 DBMS_SQL.date_table;
48    t_day_max_ovn                   DBMS_SQL.number_table;
49    t_detail_bb_id                  DBMS_SQL.number_table;
50    t_detail_parent_id              DBMS_SQL.number_table;
51    t_detail_resource_type          DBMS_SQL.varchar2_table;
52    t_detail_resource_id            DBMS_SQL.number_table;
53    t_detail_comment_text           DBMS_SQL.varchar2_table;
54    t_detail_start_time             DBMS_SQL.date_table;
55    t_detail_stop_time              DBMS_SQL.date_table;
56    t_detail_measure                DBMS_SQL.number_table;
57    t_detail_scope                  DBMS_SQL.varchar2_table;
58    t_detail_type                   DBMS_SQL.varchar2_table;
59    t_detail_ta_id                  DBMS_SQL.number_table;
60    t_detail_bld_blk_info_type_id   DBMS_SQL.number_table;
61    t_detail_attribute1             DBMS_SQL.varchar2_table;
62    t_detail_attribute2             DBMS_SQL.varchar2_table;
63    t_detail_attribute3             DBMS_SQL.varchar2_table;
64    t_detail_attribute4             DBMS_SQL.varchar2_table;
65    t_detail_attribute5             DBMS_SQL.varchar2_table;
66    t_detail_attribute6             DBMS_SQL.varchar2_table;
67    t_detail_attribute7             DBMS_SQL.varchar2_table;
68    t_detail_attribute8             DBMS_SQL.varchar2_table;
69    t_detail_attribute9             DBMS_SQL.varchar2_table;
70    t_detail_attribute10            DBMS_SQL.varchar2_table;
71    t_detail_attribute11            DBMS_SQL.varchar2_table;
72    t_detail_attribute12            DBMS_SQL.varchar2_table;
73    t_detail_attribute13            DBMS_SQL.varchar2_table;
74    t_detail_attribute14            DBMS_SQL.varchar2_table;
75    t_detail_attribute15            DBMS_SQL.varchar2_table;
76    t_detail_attribute16            DBMS_SQL.varchar2_table;
77    t_detail_attribute17            DBMS_SQL.varchar2_table;
78    t_detail_attribute18            DBMS_SQL.varchar2_table;
79    t_detail_attribute19            DBMS_SQL.varchar2_table;
80    t_detail_attribute20            DBMS_SQL.varchar2_table;
81    t_detail_attribute21            DBMS_SQL.varchar2_table;
82    t_detail_attribute22            DBMS_SQL.varchar2_table;
83    t_detail_attribute23            DBMS_SQL.varchar2_table;
84    t_detail_attribute24            DBMS_SQL.varchar2_table;
85    t_detail_attribute25            DBMS_SQL.varchar2_table;
86    t_detail_attribute26            DBMS_SQL.varchar2_table;
87    t_detail_attribute27            DBMS_SQL.varchar2_table;
88    t_detail_attribute28            DBMS_SQL.varchar2_table;
89    t_detail_attribute29            DBMS_SQL.varchar2_table;
90    t_detail_attribute30            DBMS_SQL.varchar2_table;
91    t_detail_attribute_category     DBMS_SQL.varchar2_table;
92    t_detail_ovn                    DBMS_SQL.number_table;
93    t_detail_max_ovn                DBMS_SQL.number_table;
94    t_detail_deleted                DBMS_SQL.varchar2_table;
95    t_detail_uom                    DBMS_SQL.varchar2_table;
96    t_detail_date_from              DBMS_SQL.date_table;
97    t_detail_date_to                DBMS_SQL.date_table;
98    t_detail_approval_status        DBMS_SQL.varchar2_table;
99    t_detail_approval_style_id      DBMS_SQL.number_table;
100 
101 -- time attribute types
102    TYPE tab_ta_fk_bb_id IS TABLE OF hxc_time_building_blocks.time_building_block_id%TYPE
103       INDEX BY BINARY_INTEGER;
104 
105    TYPE tab_ta_field_name IS TABLE OF hxc_mapping_components.field_name%TYPE
106       INDEX BY BINARY_INTEGER;
107 
108    TYPE tab_ta_attribute IS TABLE OF hxc_time_attributes.attribute1%TYPE
109       INDEX BY BINARY_INTEGER;
110 
111 -- global package variable in order to reference table.LAST in the procedure populate_attribute
112    t_attribute_fk_bb_id            tab_ta_fk_bb_id;
113    l_pkg_range_start               NUMBER;
114    l_pkg_range_stop                NUMBER;
115    l_pkg_retrieval_range_id        NUMBER (15);
116    l_alter_session                 VARCHAR2 (50);
117    e_no_ranges                     EXCEPTION;
118 
119 -- package cursor
120    CURSOR csr_get_tx_id
121    IS
122       SELECT hxc_transactions_s.NEXTVAL
123         FROM SYS.DUAL;
124 
125    CURSOR csr_get_tx_detail_id (p_max BINARY_INTEGER)
126    IS
127       SELECT /*+ INDEX_FFS(TXD HXC_TRANSACTION_DETAILS_PK) */
128              hxc_transaction_details_s.NEXTVAL
129         FROM hxc_transaction_details txd
130        WHERE ROWNUM <= p_max;
131 
132    g_conc_request_id               NUMBER (15);
133 
134    PROCEDURE insert_query (p_query LONG
135 /*PROFILER(457): LONG (advise: migrate to LOB) is Oracle 7.0 (deprecated in 8.1.5) */
136                                        , p_type VARCHAR2)
137    IS
138       PRAGMA AUTONOMOUS_TRANSACTION;
139    BEGIN
140       DELETE FROM hxc_debug_text
141             WHERE process = 'RETRIEVAL' AND TYPE = p_type;
142 
143       INSERT INTO hxc_debug_text
144                   (process, TYPE, text
145                   )
146            VALUES ('RETRIEVAL', p_type, p_query
147                   );
148 
149       COMMIT;
150    END insert_query;
151 
152    FUNCTION initialise_g_resource (p_resource_id NUMBER)
153       RETURN NUMBER
154    IS
155    BEGIN
156 -- just in case deterministic is not working use EXISTS
157       IF (NOT hxc_generic_retrieval_utils.g_resources.EXISTS (p_resource_id)
158          )
159       THEN
160          hxc_generic_retrieval_utils.g_resources (p_resource_id).resource_id :=
161                                                                 p_resource_id;
162          -- NOTE: these setting are not the wrong way round
163          -- need a date for when the first LEAST/GREATEST comparison is done, so we always get the
164          -- TC start/stop time
165          hxc_generic_retrieval_utils.g_resources (p_resource_id).start_time :=
166                                                        hr_general.end_of_time;
167          hxc_generic_retrieval_utils.g_resources (p_resource_id).stop_time :=
168                                                      hr_general.start_of_time;
169       END IF;
170 
171       RETURN 1;
172    END initialise_g_resource;
173 
174    FUNCTION replace_timecard_string (p_where VARCHAR2)
175       RETURN VARCHAR2
176    IS
177       l_where   VARCHAR2 (2000);
178    BEGIN
179       IF (g_params.p_process = 'Maintenance Retrieval Process')
180       THEN
181          l_where := REPLACE (p_where, 'TIMECARD_BLOCK', 'tbb_latest');
182          l_where := REPLACE (l_where, 'DAY_BLOCK', 'tbb_latest');
183          l_where := REPLACE (l_where, 'DETAIL_BLOCK', 'tbb_latest');
184       ELSE
185          l_where := REPLACE (p_where, 'TIMECARD_BLOCK', 'tbb');
186          l_where := REPLACE (l_where, 'DAY_BLOCK', 'tbb');
187          l_where := REPLACE (l_where, 'DETAIL_BLOCK', 'tbb');
188       END IF;
189 
190       RETURN l_where;
191    END replace_timecard_string;
192 
193 -- private procedure
194 --    parse_it
195 --
196 -- description
197 --    Used to parse the application specific WHERE clause
198 --    passed to the generic retrieval
199 --
200 -- parameters
201 --   p_where_clause  -  the application specific WHERE clause
202    PROCEDURE parse_it (
203       p_where_clause_blk   IN OUT NOCOPY   VARCHAR2,
204       p_where_clause_att   IN OUT NOCOPY   VARCHAR2
205    )
206    IS
207       l_text   VARCHAR2 (2000);
208       l_proc   VARCHAR2 (72);
209 
210       PROCEDURE translate_it (
211          p_text       IN OUT NOCOPY   VARCHAR2,
212          p_text_blk   IN OUT NOCOPY   VARCHAR2,
213          p_text_att   IN OUT NOCOPY   VARCHAR2
214       )
215       IS
216 --
217          l_proc                          VARCHAR2 (72);
218          l_start_position                NUMBER (4);
219          l_end_position                  NUMBER (4);
220          l_new_start_position            NUMBER (4);
221          l_absolute_start_position       NUMBER (4);
222          l_absolute_end_position         NUMBER (4);
223          l_blk_absolute_start_position   NUMBER (4);
224          l_blk_absolute_end_position     NUMBER (4);
225          l_att_absolute_start_position   NUMBER (4);
226          l_att_absolute_end_position     NUMBER (4);
227          l_placeholder                   VARCHAR2 (100);
228          l_predicate                     VARCHAR2 (2000);
229          l_attribute                     VARCHAR2 (15);
230          l_table_dot_column              VARCHAR2 (2000);
231          l_blk_table_dot_column          VARCHAR2 (2000);
232          l_att_table_dot_column          VARCHAR2 (2000);
233          l_info_type_id                  hxc_bld_blk_info_types.bld_blk_info_type_id%TYPE;
234          l_detail_exists                 VARCHAR2 (400)
235             := '
236  EXISTS ( select 1 from hxc_time_attribute_usages usage,
237                         hxc_time_attributes att
238           where usage.time_building_Block_id  = detail_block.time_building_block_id AND
239                 usage.time_building_block_ovn = detail_block.object_version_number
240           and
241                 att.time_attribute_id = usage.time_attribute_id and
242                 att.';
243          l_exists                        VARCHAR2 (400)
244             := '
245  EXISTS ( select 1 from hxc_time_attribute_usages usage,
246                         hxc_time_attributes att
247           where usage.time_building_Block_id  = timecard_block.time_building_block_id AND
248                 usage.time_building_block_ovn = timecard_block.object_version_number
249           and
250                 att.time_attribute_id = usage.time_attribute_id and
251                 att.';
252       BEGIN                                                    -- translate_it
253          IF g_debug
254          THEN
255             l_proc := g_package || 'translate_it';
256             hr_utility.set_location ('Entering ' || l_proc, 10);
257          END IF;
258 
259 -- placeholder is delimited by [ ], find the delimited string
260          l_start_position := INSTR (p_text, '[', 1, 1) + 1;
261          l_end_position :=
262                  ((INSTR (p_text, ']', 1, 1) - INSTR (p_text, '[', 1, 1)) - 1
263                  );
264          l_placeholder := SUBSTR (p_text, l_start_position, l_end_position);
265 
266          IF g_debug
267          THEN
268             hr_utility.set_location ('Processing ' || l_proc, 20);
269          END IF;
270 
271 -- predicate is delimited by {}, find the predicate
272          l_start_position := INSTR (p_text, '{', 1, 1) + 1;
273          l_end_position :=
274                  ((INSTR (p_text, '}', 1, 1) - INSTR (p_text, '{', 1, 1)) - 1
275                  );
276          l_predicate := SUBSTR (p_text, l_start_position, l_end_position);
277 
278          IF g_debug
279          THEN
280             hr_utility.set_location ('Processing ' || l_proc, 30);
281          END IF;
282 
283 -- now that we have the string ensure it is not a reserved keyword.
284 -- if it is then we can leave it be, otherwise we need to map this
285 -- against the field mappings
286          IF (UPPER (l_placeholder) IN
287                 ('TIMECARD_BLOCK.COMMENT_TEXT',
288                  'TIMECARD_BLOCK.RESOURCE_TYPE',
289                  'TIMECARD_BLOCK.RESOURCE_ID',
290                  'DAY_BLOCK.COMMENT_TEXT',
291                  'DAY_BLOCK.RESOURCE_TYPE',
292                  'DAY_BLOCK.RESOURCE_ID',
293                  'DETAIL_BLOCK.COMMENT_TEXT',
294                  'DETAIL_BLOCK.RESOURCE_TYPE',
295                  'DETAIL_BLOCK.RESOURCE_ID'
296                 )
297             )
298          THEN
299             l_table_dot_column := l_placeholder || ' ' || l_predicate;
300             l_blk_table_dot_column := l_placeholder || ' ' || l_predicate;
301          ELSE
302             -- find which attribute it is associated with by looping through the mappings table
303             FOR map_cnt IN
304                g_field_mappings_table.FIRST .. g_field_mappings_table.LAST
305             LOOP
306                IF g_debug
307                THEN
311                -- check to see if placeholder matches field name
308                   hr_utility.set_location ('Processing ' || l_proc, 40);
309                END IF;
310 
312                IF (g_field_mappings_table (map_cnt).field_name =
313                                                          UPPER (l_placeholder)
314                   )
315                THEN
316                   l_attribute := g_field_mappings_table (map_cnt).ATTRIBUTE;
317                   l_info_type_id :=
318                         g_field_mappings_table (map_cnt).bld_blk_info_type_id;
319                   EXIT;
320                END IF;
321             END LOOP;
322 
323             IF g_debug
324             THEN
325                hr_utility.set_location ('Processing ' || l_proc, 50);
326             END IF;
327 
328             IF (g_params.p_process = 'Projects Retrieval Process')
329             THEN
330                l_table_dot_column :=
331                      l_exists
332                   || l_attribute
333                   || ' '
334                   || l_predicate
335                   || ' and att.bld_blk_info_type_id = '
336                   || l_info_type_id
337                   || ' ) ';
338                l_att_table_dot_column :=
339                      l_exists
340                   || l_attribute
341                   || ' '
342                   || l_predicate
343                   || ' and att.bld_blk_info_type_id = '
344                   || l_info_type_id
345                   || ' ) ';
346             ELSE
347                l_table_dot_column :=
348                      l_detail_exists
349                   || l_attribute
350                   || ' '
351                   || l_predicate
352                   || ' and att.bld_blk_info_type_id = '
353                   || l_info_type_id
354                   || ' ) ';
355                l_att_table_dot_column :=
356                      l_detail_exists
357                   || l_attribute
358                   || ' '
359                   || l_predicate
360                   || ' and att.bld_blk_info_type_id = '
361                   || l_info_type_id
362                   || ' ) ';
363             END IF;
364          END IF;                                       -- UPPER( l_placeholder
365 
366          IF g_debug
367          THEN
368             hr_utility.set_location ('Processing ' || l_proc, 60);
369          END IF;
370 
371 -- now replace the placeholder with the table dot column expression and remove the predicate all together
372          l_absolute_start_position := INSTR (p_text, '[', 1, 1);
373          l_absolute_end_position := INSTR (p_text, '}', 1, 1) + 1;
374          p_text :=
375                REPLACE (SUBSTR (p_text, 1, l_absolute_start_position), '[')
376             || ' '
377             || l_table_dot_column
378             || ' '
379             || SUBSTR (p_text, l_absolute_end_position);
380          l_blk_absolute_start_position := INSTR (p_text_blk, '[', 1, 1);
381          l_blk_absolute_end_position := INSTR (p_text_blk, '}', 1, 1) + 1;
382          l_att_absolute_start_position := INSTR (p_text_att, '[', 1, 1);
383          l_att_absolute_end_position := INSTR (p_text_att, '}', 1, 1) + 1;
384 
385 -- This next seciton of code is to support EAM which can pass a mixture of both ATTribute and
386 -- BLK level where clause.
387          IF (    l_blk_absolute_start_position >= 5
388              AND l_blk_table_dot_column IS NULL
389             )
390          THEN
391             l_new_start_position :=
392                INSTR (p_text_blk,
393                       'AND',
394                       (l_blk_absolute_start_position - 4),
395                       1
396                      );
397 
398             IF (l_new_start_position <> 0)
399             THEN
400                l_blk_absolute_start_position := l_new_start_position - 1;
401             END IF;
402          ELSIF (    l_blk_absolute_start_position = 5
403                 AND l_blk_table_dot_column IS NOT NULL
404                )
405          THEN
406             l_blk_absolute_start_position := 0;
407          END IF;
408 
409          IF (    l_att_absolute_start_position >= 5
410              AND l_att_table_dot_column IS NULL
411             )
412          THEN
413             l_new_start_position :=
414                INSTR (p_text_att,
415                       'AND',
416                       (l_att_absolute_start_position - 4),
417                       1
418                      );
419 
420             IF (l_new_start_position <> 0)
421             THEN
422                l_att_absolute_start_position := l_new_start_position - 1;
423             END IF;
424          ELSIF (    l_att_absolute_start_position = 5
425                 AND l_att_table_dot_column IS NOT NULL
426                )
427          THEN
428             l_att_absolute_start_position := 0;
429          END IF;
430 
431          p_text_blk :=
432             LTRIM (RTRIM (   REPLACE (SUBSTR (p_text_blk,
433                                               1,
434                                               l_blk_absolute_start_position
435                                              ),
436                                       '['
437                                      )
438                           || ' '
442                          )
439                           || l_blk_table_dot_column
440                           || ' '
441                           || SUBSTR (p_text_blk, l_blk_absolute_end_position)
443                   );
444          p_text_att :=
445             LTRIM (RTRIM (   REPLACE (SUBSTR (p_text_att,
446                                               1,
447                                               l_att_absolute_start_position
448                                              ),
449                                       '['
450                                      )
451                           || ' '
452                           || l_att_table_dot_column
453                           || ' '
454                           || SUBSTR (p_text_att, l_att_absolute_end_position)
455                          )
456                   );
457       END translate_it;
458    BEGIN                                                           -- parse it
459       IF g_debug
460       THEN
461          l_proc := g_package || 'parse_it';
462          hr_utility.set_location ('Entering ' || l_proc, 10);
463       END IF;
464 
465       l_text := p_where_clause_blk;
466 
467 -- first check that there is something to decode
468       IF INSTR (l_text, '[', 1, 1) <> 0
469       THEN
470          WHILE INSTR (l_text, '[', 1, 1) <> 0
471          LOOP
472             translate_it (p_text          => l_text,
473                           p_text_blk      => p_where_clause_blk,
474                           p_text_att      => p_where_clause_att
475                          );
476 
477             IF g_debug
478             THEN
479                hr_utility.TRACE ('where blk is ' || p_where_clause_blk);
480                hr_utility.TRACE ('where att is ' || p_where_clause_att);
481             END IF;
482          END LOOP;
483       END IF;
484 
485       IF g_debug
486       THEN
487          hr_utility.set_location ('Leaving ' || l_proc, 20);
488       END IF;
489 
490 -- using length since the ASCII new line is left when the WHERE has carriage returns
491       IF (LENGTH (LTRIM (RTRIM (p_where_clause_att))) > 5)
492       THEN
493          p_where_clause_att := ' AND ' || p_where_clause_att || ' ';
494       END IF;
495 
496       IF (LENGTH (LTRIM (RTRIM (p_where_clause_blk))) > 5)
497       THEN
498          p_where_clause_blk := ' AND ' || p_where_clause_blk || ' ';
499       END IF;
500    END parse_it;
501 
502    PROCEDURE maintain_ranges (
503       p_process_id                     NUMBER,
504       p_range_start    IN OUT NOCOPY   NUMBER,
505       p_range_stop     IN OUT NOCOPY   NUMBER,
506       p_where_clause                   VARCHAR2
507    )
508    IS
509       PRAGMA AUTONOMOUS_TRANSACTION;
510       l_proc                    VARCHAR2 (72);
511 
512       CURSOR csr_get_next_range
513       IS
514          SELECT        rr.retrieval_range_id, rr.range_start, rr.range_stop
515                   FROM hxc_retrieval_ranges rr
516                  WHERE rr.retrieval_process_id = p_process_id
517                    AND rr.transaction_id = 0
518                    AND (   rr.where_clause = g_params.p_where_clause
519                         OR rr.where_clause IS NULL
520                        )
521               ORDER BY rr.seq
522          FOR UPDATE OF transaction_id NOWAIT;
523 
524       r_range                   csr_get_next_range%ROWTYPE;
525       l_dummy                   VARCHAR2 (1);
526       l_cnt                     PLS_INTEGER                               := 0;
527       l_not_maintained_ranges   BOOLEAN                                := TRUE;
528       l_first_resource_id       hxc_time_building_blocks.resource_id%TYPE;
529       l_last_resource_id        hxc_time_building_blocks.resource_id%TYPE;
530       l_dynamic_sql             VARCHAR2 (32000);
531       l_range_start             NUMBER;
532       l_range_stop              NUMBER;
533 
534       TYPE tab_rr_id IS TABLE OF hxc_retrieval_ranges.retrieval_range_id%TYPE
535          INDEX BY BINARY_INTEGER;
536 
537       TYPE tab_retrieval_process_id IS TABLE OF hxc_retrieval_ranges.retrieval_process_id%TYPE
538          INDEX BY BINARY_INTEGER;
539 
540       TYPE tab_range_start IS TABLE OF hxc_retrieval_ranges.range_start%TYPE
541          INDEX BY BINARY_INTEGER;
542 
543       TYPE tab_range_stop IS TABLE OF hxc_retrieval_ranges.range_stop%TYPE
544          INDEX BY BINARY_INTEGER;
545 
546       TYPE tab_seq IS TABLE OF hxc_retrieval_ranges.seq%TYPE
547          INDEX BY BINARY_INTEGER;
548 
549       TYPE tab_where_clause IS TABLE OF hxc_retrieval_ranges.where_clause%TYPE
550          INDEX BY BINARY_INTEGER;
551 
552       TYPE r_resource_id IS RECORD (
553          resource_id   NUMBER (15)
554       );
555 
556       TYPE tab_resource_id IS TABLE OF r_resource_id
557          INDEX BY BINARY_INTEGER;
558 
559       t_rr_id                   tab_rr_id;
560       t_retrieval_process_id    tab_retrieval_process_id;
561       t_range_start             tab_range_start;
562       t_range_stop              tab_range_stop;
563       t_seq                     tab_seq;
564       t_where_clause            tab_where_clause;
565       t_resource_id_bulk        tab_resource_id;
566       t_resource_id             DBMS_SQL.number_table;
567       t_retrieval_range_id      DBMS_SQL.number_table;
571       l_since_date              DATE;
568       l_resource_list           DBMS_SQL.number_table;
569       l_rows_fetched            INTEGER;
570       l_csr                     INTEGER;
572       x                         PLS_INTEGER                               := 0;
573       l_chunk_size              NUMBER;
574       l_rr_id                   NUMBER (15);
575       l_ind                     PLS_INTEGER;
576 
577 -- private procedure
578 --   generate_resource_sql
579 --
580 -- description
581 --   returns the dynamic SQL used to generate the resource list
582 --
583       PROCEDURE generate_resource_sql (
584          p_dynamic_sql         IN OUT NOCOPY   VARCHAR2,
585          p_first_resource_id   IN OUT NOCOPY   NUMBER,
586          p_last_resource_id    IN OUT NOCOPY   NUMBER,
587          p_where_clause                        VARCHAR2
588       )
589       IS
590          l_proc                VARCHAR2 (72);
591 
592          CURSOR csr_get_range (p_range VARCHAR2)
593          IS
594             SELECT TYPE
595               FROM hxc_debug_text
596              WHERE process = p_range;
597 
598          l_first_resource_id   hxc_time_building_blocks.resource_id%TYPE
599                                                                         := -1;
600          l_last_resource_id    hxc_time_building_blocks.resource_id%TYPE
601                                                                         := -1;
602          l_where_blk           VARCHAR2 (2000);
603          l_where_att           VARCHAR2 (2000);
604          l_dynamic_sql         VARCHAR2 (32000);
605          l_range_caveat        BOOLEAN                               := FALSE;
606 	 l_root                VARCHAR2 (1500)
607             := '
608 	SELECT DISTINCT tbb.resource_id
609 	FROM   hxc_latest_details tbb
610 	WHERE  tbb.last_update_date > :p_since_date ';
611 
612          l_root_day            VARCHAR2 (1500)
613 	            := '
614 	SELECT DISTINCT tbb.resource_id
615 	FROM   hxc_latest_details tbb
616 	WHERE  tbb.last_update_date > :p_since_date ';
617 
618          l_order_by            VARCHAR2 (100)                := ' ORDER BY 1';
619       BEGIN
620          IF g_debug
621          THEN
622             l_proc := g_package || 'generate_resource_sql';
623             hr_utility.TRACE ('in generate resource sql');
624          END IF;
625 
626 -- preserve caveat for skipping resources
627          OPEN csr_get_range ('LOWER');
628 
629          FETCH csr_get_range
630           INTO l_first_resource_id;
631 
632          IF (csr_get_range%FOUND)
633          THEN
634             CLOSE csr_get_range;
635 
636             OPEN csr_get_range ('UPPER');
637 
638             FETCH csr_get_range
639              INTO l_last_resource_id;
640 
641             IF (csr_get_range%FOUND)
642             THEN
643                CLOSE csr_get_range;
644 
645                l_range_caveat := TRUE;
646 
647                IF g_debug
648                THEN
649                   hr_utility.TRACE ('Using range caveat');
650                END IF;
651             END IF;
652          ELSE
653             CLOSE csr_get_range;
654          END IF;
655 
656          IF (    (INSTR (UPPER (p_where_clause), 'TIMECARD_ATT') = 0)
657              AND (INSTR (UPPER (p_where_clause), 'DAY_ATT') = 0)
658              AND (INSTR (UPPER (p_where_clause), 'DETAIL_ATT') = 0)
659              AND (INSTR (UPPER (p_where_clause), 'RESOURCE_ID') <> 0)
660             )
661          THEN
662             l_where_blk := LTRIM (RTRIM (p_where_clause));
663             l_where_att := LTRIM (RTRIM (p_where_clause));
664             parse_it (p_where_clause_blk      => l_where_blk,
665                       p_where_clause_att      => l_where_att
666                      );
667 
668             IF g_debug
669             THEN
670                hr_utility.TRACE ('after parse ');
671                hr_utility.TRACE (SUBSTR (l_where_blk, 1, 250));
672             END IF;
673 
674             l_where_blk := replace_timecard_string (l_where_blk);
675 
676             IF g_debug
677             THEN
678                hr_utility.TRACE ('after replace ');
679                hr_utility.TRACE (SUBSTR (l_where_blk, 1, 250));
680             END IF;
681 
682             IF (g_params.l_using_dates)
683             THEN
684                IF g_debug
685                THEN
686                   hr_utility.TRACE ('Using Dates');
687                END IF;
688 
689                IF (l_range_caveat)
690                THEN
691                   l_dynamic_sql :=
692                         l_root_day
693                      || ' '
694                      || l_where_blk
695                      || ' and tbb.resource_id between '
696                      || l_first_resource_id
697                      || ' AND '
698                      || l_last_resource_id
699                      || l_order_by;
700                ELSE
701                   l_dynamic_sql :=
702                                l_root_day || ' ' || l_where_blk || l_order_by;
703                END IF;
704             ELSE
705                IF g_debug
706                THEN
707                   hr_utility.TRACE ('Not using dates');
708                END IF;
709 
713                         l_root
710                IF (l_range_caveat)
711                THEN
712                   l_dynamic_sql :=
714                      || ' '
715                      || l_where_blk
716                      || ' and tbb.resource_id between '
717                      || l_first_resource_id
718                      || ' AND '
719                      || l_last_resource_id
720                      || l_order_by;
721                ELSE
722                   l_dynamic_sql := l_root || ' ' || l_where_blk || l_order_by;
723                END IF;
724             END IF;
725          ELSE
726             IF (g_params.l_using_dates)
727             THEN
728                IF g_debug
729                THEN
730                   hr_utility.TRACE ('Using Dates');
731                END IF;
732 
733                IF (l_range_caveat)
734                THEN
735                   l_dynamic_sql :=
736                         l_root_day
737                      || ' '
738                      || ' and tbb.resource_id between '
739                      || l_first_resource_id
740                      || ' AND '
741                      || l_last_resource_id
742                      || l_order_by;
743                ELSE
744                   l_dynamic_sql := l_root_day || ' ' || l_order_by;
745                END IF;
746             ELSE
747                IF g_debug
748                THEN
749                   hr_utility.TRACE ('Not using dates');
750                END IF;
751 
752                IF (l_range_caveat)
753                THEN
754                   l_dynamic_sql :=
755                         l_root
756                      || ' '
757                      || ' and tbb.resource_id between '
758                      || l_first_resource_id
759                      || ' AND '
760                      || l_last_resource_id
761                      || l_order_by;
762                ELSE
763                   l_dynamic_sql := l_root || ' ' || l_order_by;
764                END IF;
765             END IF;
766          END IF;
767 
768          IF g_debug
769          THEN
770             hr_utility.TRACE ('dynamic sql is ');
771             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 1, 250));
772             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 251, 250));
773             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 501, 250));
774             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 751, 250));
775             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 1001, 250));
776             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 1251, 250));
777             hr_utility.TRACE (   'FIRST RESOURCE IS : '
778                               || TO_CHAR (l_first_resource_id)
779                              );
780             hr_utility.TRACE (   'LAST RESOURCE IS  : '
781                               || TO_CHAR (l_last_resource_id)
782                              );
783          END IF;
784 
785          p_first_resource_id := l_first_resource_id;
786          p_last_resource_id := l_last_resource_id;
787          p_dynamic_sql := l_dynamic_sql;
788          insert_query (l_dynamic_sql, 'RANGE');
789       END generate_resource_sql;
790 
791       PROCEDURE insert_rr_resources (
792          p_resource_list   IN              DBMS_SQL.number_table,
793          p_rr_id           IN OUT NOCOPY   NUMBER
794       )
795       IS
796          CURSOR csr_get_rr_id
797          IS
798             SELECT hxc_retrieval_ranges_s.NEXTVAL
799               FROM DUAL;
800 
801          l_rr_id   NUMBER (15);
802          l_proc    VARCHAR2 (72);
803       BEGIN
804          IF g_debug
805          THEN
806             l_proc := g_package || '.insert_rr_resources';
807             hr_utility.set_location ('Entering ' || l_proc, 10);
808          END IF;
809 
810          OPEN csr_get_rr_id;
811 
812          FETCH csr_get_rr_id
813           INTO l_rr_id;
814 
815          CLOSE csr_get_rr_id;
816 
817          p_rr_id := l_rr_id;
818          FORALL rrx IN p_resource_list.FIRST .. p_resource_list.LAST
819             INSERT INTO hxc_retrieval_range_resources
820                         (retrieval_range_id, resource_id
821                         )
822                  VALUES (l_rr_id, p_resource_list (rrx)
823                         );
824 
825          IF g_debug
826          THEN
827             hr_utility.set_location ('Leaving ' || l_proc, 10);
828          END IF;
829       END insert_rr_resources;
830 
831       FUNCTION chk_empty
832          RETURN BOOLEAN
833       IS
834          CURSOR csr_chk_rr
835          IS
836             SELECT 'x'
837               FROM hxc_retrieval_ranges rr
838              WHERE rr.retrieval_process_id = p_process_id
839                AND (   rr.where_clause IS NULL
840                     OR rr.where_clause = g_params.p_where_clause
841                    )
842                AND rr.transaction_id = 0;
843 
844          CURSOR csr_chk_tx
845          IS
846             SELECT 'x'
847               FROM hxc_transactions tx
848              WHERE tx.status = 'IN PROGRESS'
849                AND tx.TYPE = 'RETRIEVAL'
850                AND tx.transaction_process_id = p_process_id
854                              AND (   rr.where_clause IS NULL
851                AND EXISTS (SELECT 'y'
852                              FROM hxc_retrieval_ranges rr
853                             WHERE rr.transaction_id = tx.transaction_id
855                                       OR rr.where_clause = g_params.p_where_clause)
856                             );
857 
858          l_dummy   VARCHAR2 (1);
859       BEGIN
860          OPEN csr_chk_tx;
861 
862          FETCH csr_chk_tx
863           INTO l_dummy;
864 
865          IF csr_chk_tx%NOTFOUND
866          THEN
867             OPEN csr_chk_rr;
868 
869             FETCH csr_chk_rr
870              INTO l_dummy;
871 
872             IF csr_chk_rr%NOTFOUND
873             THEN
874                CLOSE csr_chk_tx;
875 
876                CLOSE csr_chk_rr;
877 
878                RETURN TRUE;
879             END IF;
880          END IF;
881 
882          CLOSE csr_chk_tx;
883 
884          RETURN FALSE;
885       END chk_empty;
886    BEGIN
887       g_debug := hr_utility.debug_enabled;
888 
889       IF g_debug
890       THEN
891          l_proc := g_package || 'maintain_ranges';
892          hr_utility.set_location ('Processing ' || l_proc, 10);
893       END IF;
894 
895 -- if the table is empty for the retrieval process
896 -- then insert the rows
897 
898       -- NOTE: put this is an anonymous PL/SQL block to handle
899 --       the ORA-00054: resource busy and acquire with NOWAIT specified
900 --       exception. If this occurs then we want to requery the table
901 --       until no exception
902       IF g_debug
903       THEN
904          hr_utility.TRACE ('Entering maintain_ranges');
905       END IF;
906 
907       WHILE l_not_maintained_ranges
908       LOOP
909          IF g_debug
910          THEN
911             hr_utility.set_location ('Processing ' || l_proc, 20);
912          END IF;
913 
914          BEGIN
915             IF g_debug
916             THEN
917                hr_utility.TRACE ('Locking table');
918             END IF;
919 
920             IF NOT hxc_generic_retrieval_pkg.g_in_loop
921             THEN
922                -- LOCK the table
923                LOCK TABLE hxc_retrieval_ranges
924                   IN EXCLUSIVE MODE NOWAIT;
925 
926                IF g_debug
927                THEN
928                   hr_utility.TRACE ('Before chk empty');
929                END IF;
930 
931                IF (chk_empty)
932                THEN
933                   generate_resource_sql
934                                  (p_dynamic_sql            => l_dynamic_sql,
935                                   p_first_resource_id      => l_first_resource_id,
936                                   p_last_resource_id       => l_last_resource_id,
937                                   p_where_clause           => p_where_clause
938                                  );
939                   l_chunk_size := g_params.transfer_batch_size;
940 
941                   IF g_debug
942                   THEN
943                      hr_utility.TRACE (   'Chunk Size Profile Value is '
944                                        || TO_CHAR (l_chunk_size)
945                                       );
946                   END IF;
947 
948 			fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
949 				|| ' > Chunk Size Profile Value is '
950 				|| TO_CHAR (l_chunk_size));
951 
952                   IF ((l_chunk_size = 0) OR (l_chunk_size IS NULL))
953                   THEN
954                      l_chunk_size := 100;
955                   END IF;
956 
957                   IF g_debug
958                   THEN
959                      hr_utility.TRACE ('Inserting rows');
960                   END IF;
961 
962                   -- insert rows
963                   IF g_debug
964                   THEN
965                      hr_utility.TRACE ('using dynamic SQL for resource list');
966                   END IF;
967 
968                   -- use dynamic SQL BULK FETCH to generate resource list
969                   l_rows_fetched := l_chunk_size;
970                   l_csr := DBMS_SQL.open_cursor;
971                   DBMS_SQL.parse (l_csr, l_dynamic_sql, DBMS_SQL.native);
972                   -- bind variables needed by all queries
973                   DBMS_SQL.bind_variable (l_csr,
974                                           ':p_since_date',
975                                           g_params.since_date
976                                          );
977                   -- define arrays for each item in the select list
978                   DBMS_SQL.define_array (c                => l_csr,
979                                          POSITION         => 1,
980                                          n_tab            => t_resource_id,
981                                          cnt              => l_chunk_size,
982                                          lower_bound      => 1
983                                         );
984                   l_dummy := DBMS_SQL.EXECUTE (l_csr);
985 
986                   -- loop to ensure we fetch all the rows
987                   WHILE (l_rows_fetched = l_chunk_size)
988                   LOOP
989                      IF g_debug
990                      THEN
994                      l_rows_fetched := DBMS_SQL.fetch_rows (l_csr);
991                         hr_utility.TRACE ('in loop');
992                      END IF;
993 
995 
996                      IF g_debug
997                      THEN
998                         hr_utility.TRACE (   'rows fetched is '
999                                           || TO_CHAR (l_rows_fetched)
1000                                          );
1001                      END IF;
1002 
1003                      IF (l_rows_fetched = 0 AND t_range_start.COUNT = 0)
1004                      THEN
1005                         IF g_debug
1006                         THEN
1007                            hr_utility.TRACE ('No ranges !!!');
1008                         END IF;
1009 
1010                         DBMS_SQL.close_cursor (l_csr);
1011                         RAISE e_no_ranges;
1012                      ELSIF (l_rows_fetched > 0)
1013                      THEN
1014                         DBMS_SQL.column_value (c             => l_csr,
1015                                                POSITION      => 1,
1016                                                n_tab         => t_resource_id
1017                                               );
1018                         -- populate retrieval range resources
1019                         l_range_start := t_resource_id (t_resource_id.FIRST);
1020                         l_range_stop := t_resource_id (t_resource_id.LAST);
1021                         insert_rr_resources (p_resource_list      => t_resource_id,
1022                                              p_rr_id              => l_rr_id
1023                                             );
1024                         x := x + 1;
1025 
1026                         IF g_debug
1027                         THEN
1028                            hr_utility.TRACE (   'range_start is '
1029                                              || TO_CHAR (l_range_start)
1030                                             );
1031                            hr_utility.TRACE (   'range_stop  is '
1032                                              || TO_CHAR (l_range_stop)
1033                                             );
1034                         END IF;
1035 
1036                         t_rr_id (x) := l_rr_id;
1037                         t_retrieval_process_id (x) := p_process_id;
1038                         t_range_start (x) := l_range_start;
1039                         t_range_stop (x) := l_range_stop;
1040                         t_seq (x) := x;
1041                         t_where_clause (x) := g_params.p_where_clause;
1042 
1043                         IF g_debug
1044                         THEN
1045                            hr_utility.TRACE (   'loop conditions is '
1046                                              || TO_CHAR (l_rows_fetched)
1047                                              || ':'
1048                                              || TO_CHAR (l_chunk_size)
1049                                             );
1050                         END IF;
1051 
1052                         t_resource_id.DELETE;
1053                      END IF;                               -- l_rows_fetch = 0
1054                   END LOOP;                      -- dynamic fetch of resources
1055 
1056                   IF g_debug
1057                   THEN
1058                      hr_utility.TRACE ('Leaving loop');
1059                   END IF;
1060 
1061                   DBMS_SQL.close_cursor (l_csr);
1062                   -- now insert retrieval ranges
1063                   FORALL rrx IN 1 .. x
1064                      INSERT INTO hxc_retrieval_ranges
1065                                  (retrieval_range_id,
1066                                   retrieval_process_id,
1067                                   range_start, range_stop,
1068                                   seq, transaction_id, where_clause,
1069                                   unique_params, conc_request_id
1070                                  )
1071                           VALUES (t_rr_id (rrx),
1072                                   t_retrieval_process_id (rrx),
1073                                   t_range_start (rrx), t_range_stop (rrx),
1074                                   t_seq (rrx), 0, t_where_clause (rrx),
1075                                   g_params.p_unique_params, g_conc_request_id
1076                                  );
1077 
1078                   IF g_debug
1079                   THEN
1080                      hr_utility.TRACE ('After bulk insert');
1081                   END IF;
1082 
1083                   l_not_maintained_ranges := FALSE;
1084                END IF;                                            -- chk_empty
1085 
1086                IF g_debug
1087                THEN
1088                   hr_utility.set_location ('Processing ' || l_proc, 30);
1089                END IF;
1090             END IF;                 -- NOT hxc_generic_retrieval_pkg.G_IN_LOOP
1091 
1092             IF g_debug
1093             THEN
1094                hr_utility.set_location ('Processing ' || l_proc, 40);
1095                hr_utility.TRACE ('About to get range value');
1096             END IF;
1097 
1098             -- if the table is not empty then select the next row, lock it
1099             -- set the range values and update the row
1100             OPEN csr_get_next_range;
1101 
1102             FETCH csr_get_next_range
1103              INTO r_range;
1104 
1108                THEN
1105             IF (csr_get_next_range%FOUND)
1106             THEN
1107                IF g_debug
1109                   hr_utility.TRACE ('FOUND range value');
1110                END IF;
1111 
1112                -- maintain range
1113                UPDATE hxc_retrieval_ranges rr
1114                   SET rr.transaction_id =
1115                                     hxc_generic_retrieval_pkg.g_transaction_id,
1116                       rr.conc_request_id = g_conc_request_id
1117                 WHERE rr.retrieval_range_id = r_range.retrieval_range_id;
1118 
1119                hxc_generic_retrieval_pkg.g_in_loop := TRUE;
1120                p_range_start := r_range.range_start;
1121                p_range_stop := r_range.range_stop;
1122                l_pkg_retrieval_range_id := r_range.retrieval_range_id;
1123             ELSE
1124                IF g_debug
1125                THEN
1126                   hr_utility.TRACE ('NOT FOUND range value');
1127                END IF;
1128 
1129                -- no more ranges
1130 
1131                -- set the G_IN_LOOP, G_LAST_CHUNK and dummy ranges
1132                hxc_generic_retrieval_pkg.g_in_loop := TRUE;
1133                hxc_generic_retrieval_pkg.g_last_chunk := TRUE;
1134                p_range_start := r_range.range_start;
1135                p_range_stop := r_range.range_stop;
1136                l_pkg_retrieval_range_id := -1;
1137             END IF;
1138 
1139             IF g_debug
1140             THEN
1141                hr_utility.set_location ('Processing ' || l_proc, 50);
1142             END IF;
1143 
1144             CLOSE csr_get_next_range;
1145 
1146             l_not_maintained_ranges := FALSE;
1147             COMMIT;
1148          EXCEPTION
1149             WHEN OTHERS
1150             THEN
1151                IF g_debug
1152                THEN
1153                   hr_utility.TRACE ('sqlerrm is ' || SQLERRM);
1154                   hr_utility.TRACE ('sqlcode is ' || SQLCODE);
1155                END IF;
1156 
1157                IF (SQLCODE = '-54')
1158                THEN
1159                   IF g_debug
1160                   THEN
1161                      hr_utility.TRACE ('TABLE LOCKED!!!!');
1162                   END IF;
1163 
1164                   l_cnt := l_cnt + 1;
1165                   -- wait for 30 seconds before attempting to lock again
1166                   DBMS_LOCK.sleep (30);
1167                ELSE
1168                   RAISE;
1169                END IF;
1170          END;                 -- anonymous PL/SQL block to trap lock exception
1171 
1172          IF g_debug
1173          THEN
1174             hr_utility.set_location ('Processing ' || l_proc, 60);
1175          END IF;
1176 
1177          IF (l_cnt > 60)
1178          THEN
1179             -- after 60 attempts (30 minutes)
1180             fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
1181             fnd_message.set_token ('PROCEDURE', l_proc);
1182             fnd_message.set_token ('STEP', 'cannot maintain ranges');
1183             fnd_message.raise_error;
1184          END IF;
1185 
1186          IF g_debug
1187          THEN
1188             hr_utility.set_location ('Processing ' || l_proc, 70);
1189          END IF;
1190       END LOOP;
1191    END maintain_ranges;
1192 
1193 --   maintain_chunks
1194 --
1195 -- description
1196 --   sets the chunk size based on the profile option
1197 --   sets the ranges for each iteration
1198 --   intialises the following global variables
1199 --
1200 --      G_LAST_CHUNK
1201 --      G_IN_LOOP
1202 --      G_OVERALL_SUCCESS
1203 --
1204 --   NOTE: for now only Projects Retrieval Process uses chunks
1205 --
1206 --
1207 --
1208 -- Parameters
1209 --   None
1210    PROCEDURE maintain_chunks (p_where_clause VARCHAR2)
1211    IS
1212       l_proc   VARCHAR2 (72);
1213    BEGIN
1214       IF g_debug
1215       THEN
1216          l_proc := g_package || 'maintain_chunks';
1217          hr_utility.set_location ('Entering ' || l_proc, 10);
1218       END IF;
1219 
1220       IF (g_params.p_process IN
1221              ('Projects Retrieval Process',
1222               'BEE Retrieval Process',
1223               'Apply Schedule Rules',
1224               'Purchasing Retrieval Process'
1225              )
1226          )
1227       THEN
1228          IF g_debug
1229          THEN
1230             hr_utility.set_location ('Entering ' || l_proc, 20);
1231          END IF;
1232 
1233          maintain_ranges (p_process_id        => g_retrieval_process_id,
1234                           p_range_start       => l_pkg_range_start,
1235                           p_range_stop        => l_pkg_range_stop,
1236                           p_where_clause      => p_where_clause
1237                          );
1238 
1239          IF g_debug
1240          THEN
1241             hr_utility.set_location ('Entering ' || l_proc, 50);
1242          END IF;
1243       ELSE
1244          IF g_debug
1245          THEN
1246             hr_utility.set_location ('Entering ' || l_proc, 80);
1247          END IF;
1248 
1249          -- not the Project Retrieval Process
1250          -- set range to be full range
1251          l_pkg_range_start := 0;
1255       IF g_debug
1252          l_pkg_range_stop := 999999999999999999;
1253       END IF;       -- IF ( g_params.p_process = 'Projects Retrieval Process')
1254 
1256       THEN
1257          hr_utility.TRACE ('');
1258          hr_utility.TRACE ('******* GLOBALS AFTER MAINTAIN CHUNKS ********');
1259       END IF;
1260 
1261       IF (g_in_loop)
1262       THEN
1263          IF g_debug
1264          THEN
1265             hr_utility.TRACE ('G_IN_LOOP is TRUE');
1266          END IF;
1267       ELSE
1268          IF g_debug
1269          THEN
1270             hr_utility.TRACE ('G_IN_LOOP is FALSE');
1271          END IF;
1272       END IF;
1273 
1274       IF (g_last_chunk)
1275       THEN
1276          IF g_debug
1277          THEN
1278             hr_utility.TRACE ('G_LAST_CHUNK is TRUE');
1279          END IF;
1280       ELSE
1281          IF g_debug
1282          THEN
1283             hr_utility.TRACE ('G_LAST_CHUNK is FALSE');
1284          END IF;
1285       END IF;
1286 
1287       IF g_debug
1288       THEN
1289          hr_utility.TRACE ('l_range_start is ' || TO_CHAR (l_pkg_range_start));
1290          hr_utility.TRACE ('l_range_stop is ' || TO_CHAR (l_pkg_range_stop));
1291          hr_utility.TRACE (   'l retrieval range id is '
1292                            || TO_CHAR (l_pkg_retrieval_range_id)
1293                           );
1294       END IF;
1295    END maintain_chunks;
1296 
1297    PROCEDURE populate_ret_range_blks
1298    IS
1299       CURSOR csr_get_ret_range_blks
1300       IS
1301          SELECT TO_CHAR (time_building_block_id) tbb_id,
1302                 TO_CHAR (object_version_number) tbb_ovn
1303            FROM hxc_retrieval_range_blks;
1304 
1305       l_ret_range_rec         csr_get_ret_range_blks%ROWTYPE;
1306       l_select_from           VARCHAR2 (250)
1307          := '
1308 SELECT /*+ ordered */
1309        tbb_latest.time_building_block_id,
1310        tbb_latest.object_version_number insert_latest
1311 FROM    hxc_retrieval_ranges rr
1312 ,       hxc_retrieval_range_resources rrr
1313 ,       hxc_latest_details tbb_latest ';
1314 
1315       l_where                 VARCHAR2 (1500)
1316                := '
1317       WHERE   rr.retrieval_range_id = :p_rr_id
1318       AND
1319               rrr.retrieval_range_id = rr.retrieval_range_id
1320       AND
1321               tbb_latest.resource_id = rrr.resource_id    AND
1322               tbb_latest.approval_status <> ''ERROR''       AND
1323         tbb_latest.last_update_date >= :p_since_date ';
1324 
1325       l_day_ex                VARCHAR2 (200)
1326          := '
1327 AND
1328         tbb_latest.start_time
1329         BETWEEN :p_start_date AND :p_end_date	AND
1330         tbb_latest.stop_time
1331         BETWEEN :p_start_date AND :p_end_date ';
1332       l_day_in                VARCHAR2 (200)
1333          := '
1334 AND
1335         :p_start_date <= tbb_latest.stop_time	AND
1336         :p_end_date   >= tbb_latest.start_time ';
1337       l_not_exists            VARCHAR2 (450)
1338          := '
1339 AND NOT EXISTS (select ''x''
1340 			FROM	hxc_transaction_details txd
1341 			,	hxc_transactions tx
1342 			WHERE	tx.transaction_process_id	= :p_process_id
1343 			AND	tx.type				= ''RETRIEVAL''
1344 			AND	tx.status			= ''SUCCESS''
1345 			AND	tx.transaction_id		= txd.transaction_id
1346 			AND	txd.status			= ''SUCCESS''
1347 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
1348 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number) ';
1349       t_tbb_id                DBMS_SQL.number_table;
1350       t_tbb_ovn               DBMS_SQL.number_table;
1351       l_start_date            DATE;
1352       l_end_date              DATE;
1353       l_csr                   INTEGER;
1354       l_rows_fetched          INTEGER;
1355       l_dummy                 INTEGER;
1356       l_app_set               VARCHAR2 (200);
1357       l_ret_range_query       VARCHAR2 (3000);
1358       l_ret_criteria_clause   VARCHAR2 (1000);
1359    BEGIN
1360       l_ret_criteria_clause := hxc_generic_retrieval_utils.get_ret_criteria;
1361 
1362       IF g_debug
1363       THEN
1364          hr_utility.TRACE ('Entering populate_ret_range_blks');
1365       END IF;
1366 
1367 -- only use temp table for processes which loop
1368       IF (g_params.p_process IN
1369              ('BEE Retrieval Process',
1370               'Apply Schedule Rules',
1371               'Purchasing Retrieval Process',
1372               'Projects Retrieval Process'
1373              )
1374          )
1375       THEN
1376          IF g_debug
1377          THEN
1378             hr_utility.TRACE ('starting to build query');
1379          END IF;
1380 
1381          IF (g_params.l_using_dates)
1382          THEN
1383             IF g_debug
1384             THEN
1385                hr_utility.TRACE ('Using Dates');
1386             END IF;
1387 
1388             l_start_date :=
1389                          NVL (g_params.p_start_date, hr_general.start_of_time);
1390             l_end_date := NVL (g_params.p_end_date, hr_general.end_of_time);
1391          END IF;
1392 
1393          IF g_debug
1394          THEN
1395             hr_utility.TRACE ('About to delete rows');
1396          END IF;
1397 
1401          l_app_set :=
1398          DELETE FROM hxc_retrieval_range_blks;
1399 
1400 -- build query
1402                      g_app_set_id_string (g_retrieval_tr_id).app_set_id_string;
1403 
1404 -- Bind ALL variables needed by the query
1405          IF (g_params.p_rerun_flag = 'Y')
1406          THEN
1407             NULL;
1408          ELSIF (NOT g_params.l_using_dates)
1409          THEN
1410             l_ret_range_query :=
1411                   l_select_from
1412                || l_where
1413                || l_not_exists
1414                || l_app_set
1415                || l_ret_criteria_clause;
1416          ELSIF (g_params.p_scope IN ('TIME', 'DAY', 'DETAIL'))
1417          THEN
1418             IF (g_params.p_clusive = 'EX')
1419             THEN
1420                l_ret_range_query :=
1421                      l_select_from
1422                   || l_where
1423                   || l_day_ex
1424                   || l_not_exists
1425                   || l_app_set
1426                   || l_ret_criteria_clause;
1427             ELSIF (g_params.p_clusive = 'IN')
1428             THEN
1429                l_ret_range_query :=
1430                      l_select_from
1431                   || l_where
1432                   || l_day_in
1433                   || l_not_exists
1434                   || l_app_set
1435                   || l_ret_criteria_clause;
1436             ELSE
1437                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
1438                fnd_message.raise_error;
1439             END IF;
1440          ELSE
1441             fnd_message.set_name ('HXC', 'HXC_0015_GNRET_INVLD_P_SCOPE');
1442             fnd_message.raise_error;
1443          END IF;
1444 
1445          IF g_debug
1446          THEN
1447             hr_utility.TRACE ('dynamic ret range blk sql is ');
1448             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1, 250));
1449             hr_utility.TRACE (SUBSTR (l_ret_range_query, 251, 250));
1450             hr_utility.TRACE (SUBSTR (l_ret_range_query, 501, 250));
1451             hr_utility.TRACE (SUBSTR (l_ret_range_query, 751, 250));
1452             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1001, 250));
1453             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1251, 250));
1454             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1501, 250));
1455             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1751, 250));
1456          END IF;
1457 
1458          insert_query (l_ret_range_query, 'RET_RANGE_BLKS');
1459 -- now fetch and insert the rows
1460          l_rows_fetched := 100;
1461          l_csr := DBMS_SQL.open_cursor;
1462          DBMS_SQL.parse (l_csr, l_ret_range_query, DBMS_SQL.native);
1463          DBMS_SQL.bind_variable (l_csr,
1464                                  ':p_process_id',
1465                                  g_retrieval_process_id
1466                                 );
1467          DBMS_SQL.bind_variable (l_csr, ':p_since_date', g_params.since_date);
1468          DBMS_SQL.bind_variable (l_csr, ':p_rr_id', l_pkg_retrieval_range_id);
1469 
1470          IF (g_params.l_using_dates)
1471          THEN
1472             DBMS_SQL.bind_variable (l_csr, ':p_start_date', l_start_date);
1473             DBMS_SQL.bind_variable (l_csr, ':p_end_date', l_end_date);
1474          END IF;
1475 
1476          IF g_ret_criteria.gre_id IS NOT NULL
1477          THEN
1478             DBMS_SQL.bind_variable (l_csr, ':p_gre_id',
1479                                     g_ret_criteria.gre_id);
1480          END IF;
1481 
1482          IF g_ret_criteria.payroll_id IS NOT NULL
1483          THEN
1484             DBMS_SQL.bind_variable (l_csr,
1485                                     ':p_payroll_id',
1486                                     g_ret_criteria.payroll_id
1487                                    );
1488          END IF;
1489 
1490          IF g_ret_criteria.location_id IS NOT NULL
1491          THEN
1492             DBMS_SQL.bind_variable (l_csr,
1493                                     ':p_location_id',
1494                                     g_ret_criteria.location_id
1495                                    );
1496          END IF;
1497 
1498          IF g_ret_criteria.organization_id IS NOT NULL
1499          THEN
1500             DBMS_SQL.bind_variable (l_csr,
1501                                     ':p_org_id',
1502                                     g_ret_criteria.organization_id
1503                                    );
1504          END IF;
1505 
1506          DBMS_SQL.define_array (c                => l_csr,
1507                                 POSITION         => 1,
1508                                 n_tab            => t_tbb_id,
1509                                 cnt              => 100,
1510                                 lower_bound      => 1
1511                                );
1512          DBMS_SQL.define_array (c                => l_csr,
1513                                 POSITION         => 2,
1514                                 n_tab            => t_tbb_ovn,
1515                                 cnt              => 100,
1516                                 lower_bound      => 1
1517                                );
1518          l_dummy := DBMS_SQL.EXECUTE (l_csr);
1519 
1520 -- loop to ensure we fetch all the rows
1521          WHILE (l_rows_fetched = 100)
1522          LOOP
1523             l_rows_fetched := DBMS_SQL.fetch_rows (l_csr);
1524 
1528                                       POSITION      => 1,
1525             IF (l_rows_fetched > 0)
1526             THEN
1527                DBMS_SQL.column_value (c             => l_csr,
1529                                       n_tab         => t_tbb_id
1530                                      );
1531                DBMS_SQL.column_value (c             => l_csr,
1532                                       POSITION      => 2,
1533                                       n_tab         => t_tbb_ovn
1534                                      );
1535                -- populate retrieval range blks
1536                FORALL rrx IN t_tbb_id.FIRST .. t_tbb_id.LAST
1537                   INSERT INTO hxc_retrieval_range_blks
1538                               (time_building_block_id, object_version_number
1539                               )
1540                        VALUES (t_tbb_id (rrx), t_tbb_ovn (rrx)
1541                               );
1542                t_tbb_id.DELETE;
1543                t_tbb_ovn.DELETE;
1544             END IF;                                        -- l_rows_fetch = 0
1545          END LOOP;                               -- dynamic fetch of resources
1546 
1547          DBMS_SQL.close_cursor (l_csr);
1548       ELSE
1549          -- Retrievals which do not loop do not use
1550          -- this new table
1551          NULL;
1552       END IF;                                       -- check retrieval process
1553 /*
1554 
1555 if g_debug then
1556    hr_utility.trace('Here is the table ');
1557 end if;
1558 open csr_get_ret_Range_blks;
1559 
1560 fetch csr_get_ret_range_blks into l_ret_range_rec;
1561 
1562 WHILE csr_get_ret_range_blks%FOUND
1563 LOOP
1564 
1565    if g_debug then
1566       hr_utility.trace('ret range blks is '||l_ret_range_rec.tbb_id||':'||l_ret_range_rec.tbb_ovn);
1567    end if;
1568 
1569    fetch csr_get_ret_range_blks into l_ret_range_rec;
1570 
1571 END LOOP;
1572 
1573 close csr_get_ret_range_blks;
1574 
1575 */
1576    END populate_ret_range_blks;
1577 
1578    PROCEDURE populate_max_ovn (p_where_clause VARCHAR2)
1579    IS
1580       CURSOR csr_get_max_ovn_debug
1581       IS
1582          SELECT time_building_block_id || ':' || max_ovn ovn
1583            FROM hxc_max_ovn;
1584 
1585       CURSOR csr_get_max_ovn_rrb (p_retrieval_process_id NUMBER)
1586       IS
1587          SELECT   /*+ ORDERED INDEX(TXD) INDEX(TX) USE_NL(TXD, TX) */
1588                   txd.time_building_block_id,
1589                   NVL (MAX (txd.time_building_block_ovn), 0)
1590              FROM hxc_retrieval_range_blks rrb,
1591                   hxc_transaction_details txd,
1592                   hxc_transactions tx
1593             WHERE tx.transaction_process_id = p_retrieval_process_id
1594               AND tx.TYPE = 'RETRIEVAL'
1595               AND tx.status = 'SUCCESS'
1596               AND tx.transaction_id = txd.transaction_id
1597               AND txd.status = 'SUCCESS'
1598               AND rrb.time_building_block_id = txd.time_building_block_id
1599               AND rrb.object_version_number > txd.time_building_block_ovn
1600          GROUP BY txd.time_building_block_id;
1601 
1602      CURSOR csr_get_max_ovn_day (
1603               p_retrieval_process_id   NUMBER,
1604               p_start_date             DATE,
1605               p_end_date               DATE,
1606               p_since_date             DATE
1607            )
1608            IS
1609               SELECT   txd.time_building_block_id,
1610                        NVL (MAX (txd.time_building_block_ovn), 0)
1611                   FROM hxc_transaction_details txd, hxc_transactions tx
1612                  WHERE tx.transaction_process_id = p_retrieval_process_id
1613                    AND tx.TYPE = 'RETRIEVAL'
1614                    AND tx.status = 'SUCCESS'
1615                    AND tx.transaction_id = txd.transaction_id
1616                    AND txd.status = 'SUCCESS'
1617                    AND EXISTS (
1618                           SELECT 'x'
1619                             FROM hxc_latest_details tbb_det
1620                            WHERE tbb_det.start_time <= p_end_date
1621                              AND tbb_det.stop_time >= p_start_date
1622                              AND tbb_det.last_update_date > p_since_date
1623                              AND tbb_det.time_building_block_id =
1624                                                          txd.time_building_block_id
1625                              AND tbb_det.object_version_number >
1626                                                         txd.time_building_block_ovn
1627                              AND tbb_det.resource_id BETWEEN l_pkg_range_start
1628                                                          AND l_pkg_range_stop)
1629          GROUP BY txd.time_building_block_id;
1630 
1631      CURSOR csr_get_max_ovn (p_retrieval_process_id NUMBER, p_since_date DATE)
1632            IS
1633               SELECT   txd.time_building_block_id,
1634                        NVL (MAX (txd.time_building_block_ovn), 0)
1635                   FROM hxc_transaction_details txd, hxc_transactions tx
1636                  WHERE tx.transaction_process_id = p_retrieval_process_id
1637                    AND tx.TYPE = 'RETRIEVAL'
1638                    AND tx.status = 'SUCCESS'
1639                    AND tx.transaction_id = txd.transaction_id
1640                    AND txd.status = 'SUCCESS'
1641                    AND EXISTS (
1645                                                          txd.time_building_block_id
1642                           SELECT 'x'
1643                             FROM hxc_latest_details tbb_det
1644                            WHERE tbb_det.time_building_block_id =
1646                              AND tbb_det.last_update_date > p_since_date
1647                              AND tbb_det.object_version_number >
1648                                                         txd.time_building_block_ovn
1649                              AND tbb_det.resource_id BETWEEN l_pkg_range_start
1650                                                          AND l_pkg_range_stop)
1651          GROUP BY txd.time_building_block_id;
1652 
1653       l_max_ovn         csr_get_max_ovn_debug%ROWTYPE;
1654 
1655       TYPE tab_max_ovn_bb_id IS TABLE OF hxc_time_building_blocks.time_building_block_id%TYPE
1656          INDEX BY BINARY_INTEGER;
1657 
1658       TYPE tab_max_ovn IS TABLE OF hxc_time_building_blocks.object_version_number%TYPE
1659          INDEX BY BINARY_INTEGER;
1660 
1661       t_max_ovn_bb_id   tab_max_ovn_bb_id;
1662       t_max_ovn         tab_max_ovn;
1663       l_cnt             NUMBER (15);
1664       l_start_date      DATE;
1665       l_end_date        DATE;
1666    BEGIN
1667       IF g_debug
1668       THEN
1669          hr_utility.TRACE ('Entering populate_max_ovn');
1670       END IF;
1671 
1672 -- clear out the table
1673       DELETE FROM hxc_max_ovn;
1674 
1675       IF (g_params.p_process IN
1676              ('BEE Retrieval Process',
1677               'Apply Schedule Rules',
1678               'Purchasing Retrieval Process',
1679               'Projects Retrieval Process'
1680              )
1681          )
1682       THEN
1683          OPEN csr_get_max_ovn_rrb (g_retrieval_process_id);
1684 
1685          LOOP
1686             IF g_debug
1687             THEN
1688                hr_utility.TRACE ('in max ovn loop');
1689             END IF;
1690 
1691             FETCH csr_get_max_ovn_rrb
1692             BULK COLLECT INTO t_max_ovn_bb_id, t_max_ovn LIMIT 100;
1693 
1694             IF g_debug
1695             THEN
1696                hr_utility.TRACE (   'fetch count is '
1697                                  || TO_CHAR (t_max_ovn_bb_id.COUNT)
1698                                 );
1699             END IF;
1700 
1701             IF (t_max_ovn_bb_id.COUNT <> 0)
1702             THEN
1703                FORALL x IN t_max_ovn_bb_id.FIRST .. t_max_ovn_bb_id.LAST
1704                   INSERT INTO hxc_max_ovn
1705                               (time_building_block_id, max_ovn
1706                               )
1707                        VALUES (t_max_ovn_bb_id (x), t_max_ovn (x)
1708                               );
1709                t_max_ovn_bb_id.DELETE;
1710                t_max_ovn.DELETE;
1711             END IF;
1712 
1713             EXIT WHEN csr_get_max_ovn_rrb%NOTFOUND;
1714          END LOOP;
1715 
1716          CLOSE csr_get_max_ovn_rrb;
1717       ELSE                                   -- this must be the EAM retrieval
1718          IF (g_params.l_using_dates)
1719          THEN
1720             l_start_date :=
1721                         NVL (g_params.p_start_date, hr_general.start_of_time);
1722             l_end_date := NVL (g_params.p_end_date, hr_general.end_of_time);
1723          END IF;
1724 
1725          IF (g_params.l_using_dates)
1726          THEN
1727             OPEN csr_get_max_ovn_day (g_retrieval_process_id,
1728                                       l_start_date,
1729                                       l_end_date,
1730                                       g_params.since_date
1731                                      );
1732 
1733             LOOP
1734                FETCH csr_get_max_ovn_day
1735                BULK COLLECT INTO t_max_ovn_bb_id, t_max_ovn LIMIT 100;
1736 
1737                IF (t_max_ovn_bb_id.COUNT <> 0)
1738                THEN
1739                   FORALL x IN t_max_ovn_bb_id.FIRST .. t_max_ovn_bb_id.LAST
1740                      INSERT INTO hxc_max_ovn
1741                                  (time_building_block_id, max_ovn
1742                                  )
1743                           VALUES (t_max_ovn_bb_id (x), t_max_ovn (x)
1744                                  );
1745                   t_max_ovn_bb_id.DELETE;
1746                   t_max_ovn.DELETE;
1747                END IF;
1748 
1749                EXIT WHEN csr_get_max_ovn_day%NOTFOUND;
1750             END LOOP;
1751 
1752             CLOSE csr_get_max_ovn_day;
1753          ELSE
1754             OPEN csr_get_max_ovn (g_retrieval_process_id,
1755                                   g_params.since_date);
1756 
1757             LOOP
1758                IF g_debug
1759                THEN
1760                   hr_utility.TRACE ('in max ovn loop');
1761                END IF;
1762 
1763                FETCH csr_get_max_ovn
1764                BULK COLLECT INTO t_max_ovn_bb_id, t_max_ovn LIMIT 100;
1765 
1766                IF g_debug
1767                THEN
1768                   hr_utility.TRACE (   'fetch count is '
1769                                     || TO_CHAR (t_max_ovn_bb_id.COUNT)
1770                                    );
1771                END IF;
1772 
1773                IF (t_max_ovn_bb_id.COUNT <> 0)
1774                THEN
1775                   IF g_debug
1779 
1776                   THEN
1777                      hr_utility.TRACE ('inserting');
1778                   END IF;
1780                   FORALL x IN t_max_ovn_bb_id.FIRST .. t_max_ovn_bb_id.LAST
1781                      INSERT INTO hxc_max_ovn
1782                                  (time_building_block_id, max_ovn
1783                                  )
1784                           VALUES (t_max_ovn_bb_id (x), t_max_ovn (x)
1785                                  );
1786                   t_max_ovn_bb_id.DELETE;
1787                   t_max_ovn.DELETE;
1788                END IF;
1789 
1790                EXIT WHEN csr_get_max_ovn%NOTFOUND;
1791             END LOOP;
1792 
1793             CLOSE csr_get_max_ovn;
1794          END IF;                                                 -- date check
1795       END IF;                                            -- g_params.p_process
1796 /*
1797 open csr_get_max_ovn_debug;
1798 
1799 loop
1800 
1801    fetch csr_get_max_ovn_debug into l_max_ovn;
1802 
1803    if g_debug then
1804       hr_utility.trace(l_max_ovn.ovn);
1805    end if;
1806 
1807    exit when csr_get_max_ovn_debug%NOTFOUND;
1808 
1809 end loop;
1810 
1811 close csr_Get_max_ovn_debug;
1812 
1813 */
1814    END populate_max_ovn;
1815 
1816 -- private procedure
1817 --   audit_transaction
1818 --
1819 -- description
1820 --   manages the transactions for each building block retrieved.
1821 --   In Insert mode, inserts the transactions details bulk bound
1822 --   In update mode, updates the transactions bulk bound after the
1823 --   recipient API has updated the global PL/SQL table
1824 --   In rollback mode deletes the transaction details
1825 --
1826 --   NOTE: the global PL/SQL transaction detail table is maintained
1827 --   within the copy bld blks procedure.
1828 --
1829 -- parameters
1830 --   p_mode    - Insert or Update the transactions
1831 --   p_transaction_process_id - transaction_process_id
1832 --   p_status     - status of the transaction
1833 --   p_description   - exception description
1834 --   p_rollback      - rollback TRUE/FALSE
1835    PROCEDURE audit_transaction (
1836       p_mode                     IN   VARCHAR2,
1837       p_transaction_process_id   IN   NUMBER DEFAULT NULL,
1838       p_status                   IN   VARCHAR2 DEFAULT NULL,
1839       p_description              IN   VARCHAR2 DEFAULT NULL,
1840       p_rollback                 IN   BOOLEAN DEFAULT FALSE
1841    )
1842    IS
1843       PRAGMA AUTONOMOUS_TRANSACTION;
1844       l_tx_id                 hxc_transactions.transaction_id%TYPE;
1845       l_time_max              INTEGER;
1846       l_day_max               INTEGER;
1847       l_detail_max            INTEGER;
1848       l_error_max             INTEGER;
1849       l_proc                  VARCHAR2 (72);
1850       l_temp_transaction_id   t_transaction_id;
1851    BEGIN                                                  -- audit transaction
1852       IF g_debug
1853       THEN
1854          l_proc := g_package || 'audit_transaction';
1855          hr_utility.set_location ('Entering ' || l_proc, 10);
1856          hr_utility.TRACE ('Audit Transaction Params');
1857          hr_utility.TRACE ('p_mode is ' || p_mode);
1858          hr_utility.TRACE (   'p_transaction_process_id is '
1859                            || TO_CHAR (p_transaction_process_id)
1860                           );
1861          hr_utility.TRACE ('p_status is ' || p_status);
1862          hr_utility.TRACE ('p_description is ' || p_description);
1863          hr_utility.TRACE (   'Global Transaction ID is '
1864                            || TO_CHAR
1865                                    (hxc_generic_retrieval_pkg.g_transaction_id)
1866                           );
1867       END IF;
1868 
1869       l_time_max := hxc_generic_retrieval_pkg.t_tx_time_bb_id.COUNT;
1870       l_day_max := hxc_generic_retrieval_pkg.t_tx_day_bb_id.COUNT;
1871       l_detail_max := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT;
1872       l_error_max := hxc_generic_retrieval_pkg.t_tx_error_bb_id.COUNT;
1873 
1874       IF (p_mode = 'I')                                 -- insert transactions
1875       THEN
1876 -- check to see if header already inserted
1877          IF (hxc_generic_retrieval_pkg.g_transaction_id IS NOT NULL)
1878          THEN
1879             IF g_debug
1880             THEN
1881                hr_utility.set_location ('Processing ' || l_proc, 7);
1882             END IF;
1883 
1884             -- already inserted - lets update it!
1885             UPDATE hxc_transactions
1886                SET status = p_status,
1887                    exception_description = p_description
1888              WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
1889          ELSE
1890             IF g_debug
1891             THEN
1892                hr_utility.set_location ('Processing ' || l_proc, 20);
1893             END IF;
1894 
1895             OPEN csr_get_tx_id;
1896 
1897             FETCH csr_get_tx_id
1898              INTO hxc_generic_retrieval_pkg.g_transaction_id;
1899 
1900             CLOSE csr_get_tx_id;
1901 
1902             IF g_debug
1903             THEN
1904                hr_utility.set_location ('Processing ' || l_proc, 30);
1905             END IF;
1906 
1907             INSERT INTO hxc_transactions
1908                         (transaction_id,
1909                          transaction_process_id, transaction_date,
1913                  VALUES (hxc_generic_retrieval_pkg.g_transaction_id,
1910                          transaction_code,
1911                          TYPE, status, exception_description
1912                         )
1914                          p_transaction_process_id, SYSDATE,
1915                          NVL (g_params.p_transaction_code,
1916                               TO_CHAR (SYSDATE, 'DD/MM/YYYY')
1917                              ),
1918                          'RETRIEVAL', p_status, p_description
1919                         );
1920 
1921             IF g_debug
1922             THEN
1923                hr_utility.set_location ('Processing ' || l_proc, 40);
1924             END IF;
1925          END IF;                                     -- transaction id IS NULL
1926 
1927          IF l_error_max <> 0
1928          THEN
1929             IF g_debug
1930             THEN
1931                hr_utility.set_location ('Processing ' || l_proc, 85);
1932             END IF;
1933 
1934 -- now let's bulk fetch all the transaction detail id
1935             OPEN csr_get_tx_detail_id (l_error_max);
1936 
1937             FETCH csr_get_tx_detail_id
1938             BULK COLLECT INTO l_temp_transaction_id;
1939 
1940             CLOSE csr_get_tx_detail_id;
1941 
1942             hxc_generic_retrieval_pkg.t_tx_error_transaction_id :=
1943                                                          l_temp_transaction_id;
1944 
1945             IF g_debug
1946             THEN
1947                hr_utility.set_location ('Processing ' || l_proc, 90);
1948             END IF;
1949 
1950             FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
1951                INSERT INTO hxc_transaction_details
1952                            (transaction_detail_id,
1953                             time_building_block_id,
1954                             time_building_block_ovn,
1955                             transaction_id,
1956                             status,
1957                             exception_description
1958                            )
1959                     VALUES (hxc_generic_retrieval_pkg.t_tx_error_transaction_id
1960                                                                      (tx_error),
1961                             hxc_generic_retrieval_pkg.t_tx_error_bb_id
1962                                                                      (tx_error),
1963                             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn
1964                                                                      (tx_error),
1965                             hxc_generic_retrieval_pkg.g_transaction_id,
1966                             hxc_generic_retrieval_pkg.t_tx_error_status
1967                                                                      (tx_error),
1968                             hxc_generic_retrieval_pkg.t_tx_error_exception
1969                                                                      (tx_error)
1970                            );
1971 -- given we are only going to do this once and the recipient app does not need
1972 -- to maintain these statuses we can delete the arrays
1973             hxc_generic_retrieval_pkg.t_tx_error_transaction_id.DELETE;
1974             hxc_generic_retrieval_pkg.t_tx_error_bb_id.DELETE;
1975             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn.DELETE;
1976             hxc_generic_retrieval_pkg.t_tx_error_status.DELETE;
1977             hxc_generic_retrieval_pkg.t_tx_error_exception.DELETE;
1978 
1979             IF g_debug
1980             THEN
1981                hr_utility.set_location ('Processing ' || l_proc, 100);
1982             END IF;
1983          END IF;                                           -- l_error_max <> 0
1984       ELSIF (p_mode = 'U')                              -- update transactions
1985       THEN
1986          IF g_debug
1987          THEN
1988             hr_utility.set_location ('Processing ' || l_proc, 110);
1989          END IF;
1990 
1991          OPEN csr_get_tx_id;
1992 
1993          FETCH csr_get_tx_id
1994           INTO l_tx_id;
1995 
1996          CLOSE csr_get_tx_id;
1997 
1998          INSERT INTO hxc_transactions
1999                      (transaction_id, transaction_process_id,
2000                       transaction_date, TYPE, status,
2001                       exception_description
2002                      )
2003               VALUES (l_tx_id, p_transaction_process_id,
2004                       SYSDATE, 'RETRIEVAL_STATUS_UPDATE', p_status,
2005                       p_description
2006                      );
2007 
2008          IF (p_description IS NULL OR p_description LIKE '%ORA-20001%')
2009          THEN
2010             -- insure we do not write over a meaningful excpetion already
2011             -- set within the retrieval
2012             UPDATE hxc_transactions
2013                SET status = p_status
2014              WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
2015          ELSE
2016             -- record the proper exception most likely thrown by the recipient
2017             -- application code
2021              WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
2018             UPDATE hxc_transactions
2019                SET status = p_status,
2020                    exception_description = p_description
2022          END IF;
2023 
2024          IF g_debug
2025          THEN
2026             hr_utility.set_location ('Processing ' || l_proc, 130);
2027          END IF;
2028 
2029 -- check to see if any tx time details
2030          IF l_time_max <> 0
2031          THEN
2032 -- now let's bulk fetch all the transaction detail id
2033             OPEN csr_get_tx_detail_id (l_time_max);
2034 
2035             FETCH csr_get_tx_detail_id
2036             BULK COLLECT INTO l_temp_transaction_id;
2037 
2038             CLOSE csr_get_tx_detail_id;
2039 
2040             hxc_generic_retrieval_pkg.t_tx_time_transaction_id :=
2041                                                         l_temp_transaction_id;
2042 
2043             IF g_debug
2044             THEN
2045                hr_utility.set_location ('Processing ' || l_proc, 50);
2046             END IF;
2047 
2048             FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_time_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_time_transaction_id.LAST
2049                INSERT INTO hxc_transaction_details
2050                            (transaction_detail_id,
2051                             time_building_block_id,
2052                             time_building_block_ovn,
2053                             transaction_id,
2054                             status,
2055                             exception_description
2056                            )
2057                     VALUES (hxc_generic_retrieval_pkg.t_tx_time_transaction_id
2058                                                                     (tx_detail),
2059                             hxc_generic_retrieval_pkg.t_tx_time_bb_id
2060                                                                     (tx_detail),
2061                             hxc_generic_retrieval_pkg.t_tx_time_bb_ovn
2062                                                                     (tx_detail),
2063                             hxc_generic_retrieval_pkg.g_transaction_id,
2064                             hxc_generic_retrieval_pkg.t_tx_time_status
2065                                                                     (tx_detail),
2066                             hxc_generic_retrieval_pkg.t_tx_time_exception
2067                                                                     (tx_detail)
2068                            );
2069          END IF;                                            -- l_time_max <> 0
2070 
2071 -- check to see if any tx day details
2072          IF l_day_max <> 0
2073          THEN
2074 -- now let's bulk fetch all the transaction detail id
2075             OPEN csr_get_tx_detail_id (l_day_max);
2076 
2077             FETCH csr_get_tx_detail_id
2078             BULK COLLECT INTO l_temp_transaction_id;
2079 
2080             CLOSE csr_get_tx_detail_id;
2081 
2082             hxc_generic_retrieval_pkg.t_tx_day_transaction_id :=
2083                                                         l_temp_transaction_id;
2084 
2085             IF g_debug
2086             THEN
2087                hr_utility.set_location ('Processing ' || l_proc, 60);
2088             END IF;
2089 
2090             FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_day_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_day_transaction_id.LAST
2091                INSERT INTO hxc_transaction_details
2092                            (transaction_detail_id,
2093                             time_building_block_id,
2094                             time_building_block_ovn,
2095                             transaction_id,
2096                             status,
2097                             exception_description
2098                            )
2099                     VALUES (hxc_generic_retrieval_pkg.t_tx_day_transaction_id
2100                                                                     (tx_detail),
2101                             hxc_generic_retrieval_pkg.t_tx_day_bb_id
2102                                                                     (tx_detail),
2103                             hxc_generic_retrieval_pkg.t_tx_day_bb_ovn
2104                                                                     (tx_detail),
2105                             hxc_generic_retrieval_pkg.g_transaction_id,
2106                             hxc_generic_retrieval_pkg.t_tx_day_status
2107                                                                     (tx_detail),
2108                             hxc_generic_retrieval_pkg.t_tx_day_exception
2109                                                                     (tx_detail)
2110                            );
2111          END IF;                                             -- l_day_max <> 0
2112 
2113 -- check to see if any tx detail details
2114          IF l_detail_max <> 0
2115          THEN
2116 -- now let's bulk fetch all the transaction detail id
2117             OPEN csr_get_tx_detail_id (l_detail_max);
2118 
2119             FETCH csr_get_tx_detail_id
2120             BULK COLLECT INTO l_temp_transaction_id;
2121 
2122             CLOSE csr_get_tx_detail_id;
2123 
2124             hxc_generic_retrieval_pkg.t_tx_detail_transaction_id :=
2125                                                         l_temp_transaction_id;
2126 
2127             IF g_debug
2128             THEN
2132             FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.LAST
2129                hr_utility.set_location ('Processing ' || l_proc, 70);
2130             END IF;
2131 
2133                INSERT INTO hxc_transaction_details
2134                            (transaction_detail_id,
2135                             time_building_block_id,
2136                             time_building_block_ovn,
2137                             transaction_id,
2138                             status,
2139                             exception_description
2140                            )
2141                     VALUES (hxc_generic_retrieval_pkg.t_tx_detail_transaction_id
2142                                                                     (tx_detail),
2143                             hxc_generic_retrieval_pkg.t_tx_detail_bb_id
2144                                                                     (tx_detail),
2145                             hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn
2146                                                                     (tx_detail),
2147                             hxc_generic_retrieval_pkg.g_transaction_id,
2148                             hxc_generic_retrieval_pkg.t_tx_detail_status
2149                                                                     (tx_detail),
2150                             hxc_generic_retrieval_pkg.t_tx_detail_exception
2151                                                                     (tx_detail)
2152                            );
2153 
2154             IF g_debug
2155             THEN
2156                hr_utility.set_location ('Processing ' || l_proc, 75);
2157             END IF;
2158          END IF;                                          -- l_detail_max <> 0
2159 
2160          IF g_debug
2161          THEN
2162             hr_utility.set_location ('Processing ' || l_proc, 80);
2163          END IF;
2164 
2165          IF l_error_max <> 0
2166          THEN
2167             IF g_debug
2168             THEN
2169                hr_utility.set_location ('Processing ' || l_proc, 85);
2170             END IF;
2171 
2172 -- now let's bulk fetch all the transaction detail id
2173             OPEN csr_get_tx_detail_id (l_error_max);
2174 
2175             FETCH csr_get_tx_detail_id
2176             BULK COLLECT INTO l_temp_transaction_id;
2177 
2178             CLOSE csr_get_tx_detail_id;
2179 
2180             hxc_generic_retrieval_pkg.t_tx_error_transaction_id :=
2181                                                          l_temp_transaction_id;
2182 
2183             IF g_debug
2184             THEN
2185                hr_utility.set_location ('Processing ' || l_proc, 90);
2186             END IF;
2187 
2188             FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
2189                INSERT INTO hxc_transaction_details
2190                            (transaction_detail_id,
2191                             time_building_block_id,
2192                             time_building_block_ovn,
2193                             transaction_id,
2194                             status,
2195                             exception_description
2196                            )
2197                     VALUES (hxc_generic_retrieval_pkg.t_tx_error_transaction_id
2198                                                                      (tx_error),
2199                             hxc_generic_retrieval_pkg.t_tx_error_bb_id
2200                                                                      (tx_error),
2201                             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn
2202                                                                      (tx_error),
2203                             hxc_generic_retrieval_pkg.g_transaction_id,
2204                             hxc_generic_retrieval_pkg.t_tx_error_status
2205                                                                      (tx_error),
2206                             hxc_generic_retrieval_pkg.t_tx_error_exception
2207                                                                      (tx_error)
2208                            );
2209 -- given we are only going to do this once and the recipient app does not need
2210 -- to maintain these statuses we can delete the arrays
2211             hxc_generic_retrieval_pkg.t_tx_error_transaction_id.DELETE;
2212             hxc_generic_retrieval_pkg.t_tx_error_bb_id.DELETE;
2213             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn.DELETE;
2214             hxc_generic_retrieval_pkg.t_tx_error_status.DELETE;
2215             hxc_generic_retrieval_pkg.t_tx_error_exception.DELETE;
2216 
2217             IF g_debug
2218             THEN
2219                hr_utility.set_location ('Processing ' || l_proc, 100);
2220             END IF;
2221          END IF;                                           -- l_error_max <> 0
2222       END IF;                                                        -- p_mode
2223 
2224       IF g_debug
2225       THEN
2226          hr_utility.TRACE ('Committing !!!');
2227       END IF;
2228 
2229       COMMIT;
2230    END audit_transaction;
2231 
2232 -- private procedure
2233 --   chk_retrieval_process
2234 --
2235 -- description
2236 --   This checks that the retrieval process passed in P_PROCESS exists
2237 --   in hxc retrieval_processes. If it does exists it returns the
2238 --   mapping id associated with the process. The mapping id is tested
2242 --   p_retrieval_process   - process name (P_PROCESS)
2239 --   for null to determine if the processes exists
2240 --
2241 -- parameters
2243 --   p_retrieval_process_id   - retrieval process id (OUT only)
2244 --   p_retrieval_tr_id          - retrieval time recipient id (OUT only)
2245 --   p_mapping_id    - mapping id (OUT only)
2246    PROCEDURE chk_retrieval_process (
2247       p_retrieval_process                      hxc_retrieval_processes.NAME%TYPE,
2248       p_retrieval_process_id   IN OUT NOCOPY   hxc_retrieval_processes.retrieval_process_id%TYPE,
2249       p_retrieval_tr_id        IN OUT NOCOPY   hxc_retrieval_processes.time_recipient_id%TYPE,
2250       p_mapping_id             IN OUT NOCOPY   hxc_mappings.mapping_id%TYPE
2251    )
2252    IS
2253 --
2254       l_proc         VARCHAR2 (72);
2255 
2256 --
2257       CURSOR csr_get_otm_mapping
2258       IS
2259          SELECT -1, rtr.time_recipient_id, rtr.mapping_id
2260            FROM hxc_retrieval_processes rtr
2261           WHERE rtr.NAME = 'BEE Retrieval Process';
2262 
2263       CURSOR csr_chk_retrieval
2264       IS
2265          SELECT rtr.retrieval_process_id, rtr.time_recipient_id,
2266                 rtr.mapping_id
2267            FROM hxc_retrieval_processes rtr
2268           WHERE rtr.NAME = p_retrieval_process;
2269 
2270 --
2271       l_mapping_id   NUMBER (15)   := NULL;
2272 --
2273    BEGIN                                              -- chk_retrieval_process
2274       IF g_debug
2275       THEN
2276          l_proc := g_package || 'chk_retrieval_process';
2277          hr_utility.set_location ('Entering ' || l_proc, 10);
2278       END IF;
2279 
2280       IF (p_retrieval_process = 'Apply Schedule Rules')
2281       THEN
2282          OPEN csr_get_otm_mapping;
2283 
2284          FETCH csr_get_otm_mapping
2285           INTO p_retrieval_process_id, p_retrieval_tr_id, p_mapping_id;
2286 
2287          CLOSE csr_get_otm_mapping;
2288       ELSE
2289          OPEN csr_chk_retrieval;
2290 
2291          FETCH csr_chk_retrieval
2292           INTO p_retrieval_process_id, p_retrieval_tr_id, p_mapping_id;
2293 
2294          CLOSE csr_chk_retrieval;
2295       END IF;
2296 
2297 -- set locking mode
2298       IF (p_retrieval_process IN
2299                             ('BEE Retrieval Process', 'Apply Schedule Rules')
2300          )
2301       THEN
2302          hxc_generic_retrieval_pkg.g_lock_type :=
2303                                    hxc_lock_util.c_plsql_pay_retrieval_action;
2304       ELSIF (p_retrieval_process = 'Projects Retrieval Process')
2305       THEN
2306          hxc_generic_retrieval_pkg.g_lock_type :=
2307                                     hxc_lock_util.c_plsql_pa_retrieval_action;
2308       ELSIF (p_retrieval_process = 'Purchasing Retrieval Process')
2309       THEN
2310          hxc_generic_retrieval_pkg.g_lock_type :=
2311                                     hxc_lock_util.c_plsql_po_retrieval_action;
2312       ELSE
2313          hxc_generic_retrieval_pkg.g_lock_type :=
2314                                    hxc_lock_util.c_plsql_eam_retrieval_action;
2315       END IF;
2316 
2317       IF g_debug
2318       THEN
2319          hr_utility.set_location ('Leaving ' || l_proc, 30);
2320       END IF;
2321 --
2322    END chk_retrieval_process;
2323 
2324 -- private procedure
2325 --   populate_query_table
2326 --
2327 -- description
2328 --   the dynamic query bulk collects the data into arrays. This procedure copies
2329 --   the arrays into a single table of records to make datamanagment and
2330 --   manipulation easier. It also deletes the arrays thus saving on memory.
2331 --
2332 -- parameters
2333 --   None
2334    PROCEDURE populate_query_table
2335    IS
2336       l_proc    VARCHAR2 (72) := g_package || 'populate_query_table';
2337       l_ind     PLS_INTEGER;
2338       l_dummy   NUMBER (1);
2339    BEGIN
2340       IF (t_timecard_bb_id.COUNT <> 0)
2341       THEN
2342          l_ind := NVL (t_bb.LAST, 0) + 1;
2343 
2344          FOR x IN t_timecard_bb_id.FIRST .. t_timecard_bb_id.LAST
2345          LOOP
2346             t_bb (l_ind).time_bb_id := t_timecard_bb_id (x);
2347             t_bb (l_ind).time_ovn := t_timecard_ovn (x);
2348             t_bb (l_ind).time_max_ovn := t_timecard_max_ovn (x);
2349             t_bb (l_ind).time_start_time := t_timecard_start_time (x);
2350             t_bb (l_ind).time_stop_time := t_timecard_stop_time (x);
2351             t_bb (l_ind).time_comment_text := t_timecard_comment_text (x);
2352             t_bb (l_ind).time_deleted := t_timecard_deleted (x);
2353             t_bb (l_ind).day_bb_id := t_day_bb_id (x);
2354             t_bb (l_ind).day_start_time := t_day_start_time (x);
2355             t_bb (l_ind).day_stop_time := t_day_stop_time (x);
2356             t_bb (l_ind).day_ovn := t_day_ovn (x);
2357             t_bb (l_ind).day_max_ovn := t_day_max_ovn (x);
2358             t_bb (l_ind).detail_bb_id := t_detail_bb_id (x);
2359             t_bb (l_ind).detail_parent_bb_id := t_detail_parent_id (x);
2360             t_bb (l_ind).detail_resource_type := t_detail_resource_type (x);
2361             t_bb (l_ind).detail_resource_id := t_detail_resource_id (x);
2362             t_bb (l_ind).detail_comment_text := t_detail_comment_text (x);
2363             t_bb (l_ind).detail_start_time := t_detail_start_time (x);
2364             t_bb (l_ind).detail_stop_time := t_detail_stop_time (x);
2368             t_bb (l_ind).detail_ovn := t_detail_ovn (x);
2365             t_bb (l_ind).detail_measure := t_detail_measure (x);
2366             t_bb (l_ind).detail_scope := t_detail_scope (x);
2367             t_bb (l_ind).detail_type := t_detail_type (x);
2369             t_bb (l_ind).detail_max_ovn := t_detail_max_ovn (x);
2370             t_bb (l_ind).detail_deleted := t_detail_deleted (x);
2371             t_bb (l_ind).detail_uom := t_detail_uom (x);
2372             t_bb (l_ind).detail_date_from := t_detail_date_from (x);
2373             t_bb (l_ind).detail_date_to := t_detail_date_to (x);
2374             t_bb (l_ind).detail_approval_status :=
2375                                                  t_detail_approval_status (x);
2376             t_bb (l_ind).detail_approval_style_id :=
2377                                                t_detail_approval_style_id (x);
2378             t_bb (l_ind).detail_ta_id := t_detail_ta_id (x);
2379             t_bb (l_ind).detail_bld_blk_info_type_id :=
2380                                             t_detail_bld_blk_info_type_id (x);
2381             t_bb (l_ind).detail_attribute1 := t_detail_attribute1 (x);
2382             t_bb (l_ind).detail_attribute2 := t_detail_attribute2 (x);
2383             t_bb (l_ind).detail_attribute3 := t_detail_attribute3 (x);
2384             t_bb (l_ind).detail_attribute4 := t_detail_attribute4 (x);
2385             t_bb (l_ind).detail_attribute5 := t_detail_attribute5 (x);
2386             t_bb (l_ind).detail_attribute6 := t_detail_attribute6 (x);
2387             t_bb (l_ind).detail_attribute7 := t_detail_attribute7 (x);
2388             t_bb (l_ind).detail_attribute8 := t_detail_attribute8 (x);
2389             t_bb (l_ind).detail_attribute9 := t_detail_attribute9 (x);
2390             t_bb (l_ind).detail_attribute10 := t_detail_attribute10 (x);
2391             t_bb (l_ind).detail_attribute11 := t_detail_attribute11 (x);
2392             t_bb (l_ind).detail_attribute12 := t_detail_attribute12 (x);
2393             t_bb (l_ind).detail_attribute13 := t_detail_attribute13 (x);
2394             t_bb (l_ind).detail_attribute14 := t_detail_attribute14 (x);
2395             t_bb (l_ind).detail_attribute15 := t_detail_attribute15 (x);
2396             t_bb (l_ind).detail_attribute16 := t_detail_attribute16 (x);
2397             t_bb (l_ind).detail_attribute17 := t_detail_attribute17 (x);
2398             t_bb (l_ind).detail_attribute18 := t_detail_attribute18 (x);
2399             t_bb (l_ind).detail_attribute19 := t_detail_attribute19 (x);
2400             t_bb (l_ind).detail_attribute20 := t_detail_attribute20 (x);
2401             t_bb (l_ind).detail_attribute21 := t_detail_attribute21 (x);
2402             t_bb (l_ind).detail_attribute22 := t_detail_attribute22 (x);
2403             t_bb (l_ind).detail_attribute23 := t_detail_attribute23 (x);
2404             t_bb (l_ind).detail_attribute24 := t_detail_attribute24 (x);
2405             t_bb (l_ind).detail_attribute25 := t_detail_attribute25 (x);
2406             t_bb (l_ind).detail_attribute26 := t_detail_attribute26 (x);
2407             t_bb (l_ind).detail_attribute27 := t_detail_attribute27 (x);
2408             t_bb (l_ind).detail_attribute28 := t_detail_attribute28 (x);
2409             t_bb (l_ind).detail_attribute29 := t_detail_attribute29 (x);
2410             t_bb (l_ind).detail_attribute30 := t_detail_attribute30 (x);
2411             t_bb (l_ind).detail_attribute_category :=
2412                                               t_detail_attribute_category (x);
2413             l_dummy :=
2414                initialise_g_resource
2415                              (p_resource_id      => t_bb (l_ind).detail_resource_id
2416                              );
2417             hxc_generic_retrieval_utils.g_resources
2418                                                (t_bb (l_ind).detail_resource_id
2419                                                ).start_time :=
2420                LEAST
2421                   (t_bb (l_ind).time_start_time,
2422                    hxc_generic_retrieval_utils.g_resources
2423                                                (t_bb (l_ind).detail_resource_id
2424                                                ).start_time
2425                   );
2426             hxc_generic_retrieval_utils.g_resources
2427                                                (t_bb (l_ind).detail_resource_id
2428                                                ).stop_time :=
2429                GREATEST
2430                   (t_bb (l_ind).time_stop_time,
2431                    hxc_generic_retrieval_utils.g_resources
2432                                                (t_bb (l_ind).detail_resource_id
2433                                                ).stop_time
2434                   );
2435             l_ind := l_ind + 1;
2436          END LOOP;
2437 
2438 -- now delete tables
2439 
2440          -- delete time card scope arrays
2441          t_timecard_bb_id.DELETE;
2442          t_timecard_ovn.DELETE;
2443          t_timecard_max_ovn.DELETE;
2444          t_timecard_start_time.DELETE;
2445          t_timecard_stop_time.DELETE;
2446          t_timecard_comment_text.DELETE;
2447          t_timecard_deleted.DELETE;
2448          t_day_bb_id.DELETE;
2449          t_day_start_time.DELETE;
2450          t_day_stop_time.DELETE;
2451          t_day_ovn.DELETE;
2452          t_day_max_ovn.DELETE;
2453          t_detail_bb_id.DELETE;
2454          t_detail_parent_id.DELETE;
2455          t_detail_resource_type.DELETE;
2456          t_detail_resource_id.DELETE;
2457          t_detail_comment_text.DELETE;
2458          t_detail_start_time.DELETE;
2459          t_detail_stop_time.DELETE;
2460          t_detail_measure.DELETE;
2461          t_detail_scope.DELETE;
2465          t_detail_max_ovn.DELETE;
2462          t_detail_type.DELETE;
2463          t_detail_ovn.DELETE;
2464          t_detail_deleted.DELETE;
2466          t_detail_uom.DELETE;
2467          t_detail_date_from.DELETE;
2468          t_detail_date_to.DELETE;
2469          t_detail_approval_status.DELETE;
2470          t_detail_approval_style_id.DELETE;
2471          t_detail_ta_id.DELETE;
2472          t_detail_bld_blk_info_type_id.DELETE;
2473          t_detail_attribute1.DELETE;
2474          t_detail_attribute2.DELETE;
2475          t_detail_attribute3.DELETE;
2476          t_detail_attribute4.DELETE;
2477          t_detail_attribute5.DELETE;
2478          t_detail_attribute6.DELETE;
2479          t_detail_attribute7.DELETE;
2480          t_detail_attribute8.DELETE;
2481          t_detail_attribute9.DELETE;
2482          t_detail_attribute10.DELETE;
2483          t_detail_attribute11.DELETE;
2484          t_detail_attribute12.DELETE;
2485          t_detail_attribute13.DELETE;
2486          t_detail_attribute14.DELETE;
2487          t_detail_attribute15.DELETE;
2488          t_detail_attribute16.DELETE;
2489          t_detail_attribute17.DELETE;
2490          t_detail_attribute18.DELETE;
2491          t_detail_attribute19.DELETE;
2492          t_detail_attribute20.DELETE;
2493          t_detail_attribute21.DELETE;
2494          t_detail_attribute22.DELETE;
2495          t_detail_attribute23.DELETE;
2496          t_detail_attribute24.DELETE;
2497          t_detail_attribute25.DELETE;
2498          t_detail_attribute26.DELETE;
2499          t_detail_attribute27.DELETE;
2500          t_detail_attribute28.DELETE;
2501          t_detail_attribute29.DELETE;
2502          t_detail_attribute30.DELETE;
2503          t_detail_attribute_category.DELETE;
2504       END IF;                                   -- t_timecard_bb_id.COUNT <> 0
2505    END populate_query_table;
2506 
2507 -- private procedure
2508 --   populate_attributes
2509 --
2510 -- description
2511 --   This procedure is used to populate the global PL/SQL tables which
2512 --   contain the attribution for each time building block stored in
2513 --   HXC_TIME_ATTRIBUTES.
2514 --   The procedure is called each time a new time attribute id is found
2515 --   when processing the rows returned in the main query. Then, for each
2516 --   segment/attribute in the mapping for the process, copies the associated
2517 --   value and field name to a global PL/SQL table for use later by the
2518 --   recipient API. The global PL/SQL table destination varies upon the SCOPE
2519 --   and the NEW parameters. SCOPE, reflects the building block scope i.e. is
2520 --   this a new time attribute associated with a building block of scope TIME
2521 --   The NEW parameter refers to whether this a attribution for current building
2522 --   block or the prior or old building block which is passed back in the case
2523 --   of an INCREMENTAL retrieval
2524 --
2525 --   Parameters
2526 --     p_building_block_id - time building block id (foreign key in PL/SQL table)
2527 --     p_attribute_table   - table of all time building blocks and attributes
2528 --     p_cnt         - index of p_attribute_table
2529 --     p_scope       - scope of the time building block
2530 --     p_new         - are these attributes for old or new bld blks?
2531    PROCEDURE populate_attributes (
2532       p_building_block_id   NUMBER,
2533       p_attribute_table     t_all_building_blocks,
2534       p_cnt                 INTEGER,
2535       p_scope               VARCHAR2,
2536       p_new                 VARCHAR2
2537    )
2538    IS
2539       l_att_cnt                PLS_INTEGER;
2540       l_bld_blk_info_type_id   hxc_time_attributes.bld_blk_info_type_id%TYPE;
2541       l_attribute_category     VARCHAR2 (100);
2542       l_proc                   VARCHAR2 (72)
2543                                         := g_package || 'populate_attributes';
2544    BEGIN
2545       IF p_scope = 'DETAIL'
2546       THEN
2547          FOR MAP IN
2548             g_field_mappings_table.FIRST .. g_field_mappings_table.LAST
2549          LOOP
2550             IF (p_scope = 'DETAIL' AND p_new = 'Y')
2551             THEN
2552                l_att_cnt :=
2553                     NVL (hxc_generic_retrieval_pkg.t_detail_attributes.LAST,
2554                          0
2555                         )
2556                   + 1;
2557                l_bld_blk_info_type_id :=
2558                          p_attribute_table (p_cnt).detail_bld_blk_info_type_id;
2559             ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2560             THEN
2561                l_att_cnt :=
2562                     NVL
2563                        (hxc_generic_retrieval_pkg.t_old_detail_attributes.LAST,
2564                         0
2565                        )
2566                   + 1;
2567                l_bld_blk_info_type_id :=
2568                          p_attribute_table (p_cnt).detail_bld_blk_info_type_id;
2569             END IF;
2570 
2571             -- for each field mapping assign the value back to the
2572             -- attribute table
2573             IF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE_CATEGORY'
2574                )
2575             THEN
2576                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2577                                                         l_bld_blk_info_type_id
2578                   )
2579                THEN
2580                   -- WWB 3791698 - OIT to OTL migration fix to handle pre-pending of PAEXPITDFF
2581                   --               to existing contexts
2585                                                           p_building_block_id;
2582                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2583                   THEN
2584                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2586                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2587                         hxc_deposit_wrapper_utilities.get_dupdff_name
2588                            (p_attribute_table (p_cnt).detail_attribute_category
2589                            );
2590                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2591                                        g_field_mappings_table (MAP).field_name;
2592                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2593                                           g_field_mappings_table (MAP).CONTEXT;
2594                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2595                                          g_field_mappings_table (MAP).CATEGORY;
2596                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2597                   THEN
2598                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2599                                                                    (l_att_cnt).bb_id :=
2600                                                           p_building_block_id;
2601                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2602                                                                    (l_att_cnt).VALUE :=
2603                         hxc_deposit_wrapper_utilities.get_dupdff_name
2604                            (p_attribute_table (p_cnt).detail_attribute_category
2605                            );
2606                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2607                                                                     (l_att_cnt).field_name :=
2608                                        g_field_mappings_table (MAP).field_name;
2609                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2610                                                                     (l_att_cnt).CONTEXT :=
2611                                           g_field_mappings_table (MAP).CONTEXT;
2612                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2613                                                                     (l_att_cnt).CATEGORY :=
2614                                          g_field_mappings_table (MAP).CATEGORY;
2615                   END IF;
2616                END IF;
2617             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE1')
2618             THEN
2619                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2620                                                         l_bld_blk_info_type_id
2621                   )
2622                THEN
2623                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2624                   THEN
2625                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2626                                                           p_building_block_id;
2627                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2628                                   p_attribute_table (p_cnt).detail_attribute1;
2629                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2630                                       g_field_mappings_table (MAP).field_name;
2631                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2632                                          g_field_mappings_table (MAP).CONTEXT;
2633                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2634                                         g_field_mappings_table (MAP).CATEGORY;
2635                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2636                   THEN
2637                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2638                                                                    (l_att_cnt).bb_id :=
2639                                                           p_building_block_id;
2640                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2641                                                                    (l_att_cnt).VALUE :=
2642                                   p_attribute_table (p_cnt).detail_attribute1;
2643                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2644                                                                    (l_att_cnt).field_name :=
2645                                       g_field_mappings_table (MAP).field_name;
2646                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2647                                                                    (l_att_cnt).CONTEXT :=
2648                                          g_field_mappings_table (MAP).CONTEXT;
2649                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2650                                                                    (l_att_cnt).CATEGORY :=
2651                                         g_field_mappings_table (MAP).CATEGORY;
2652                   END IF;
2653                END IF;
2654             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE2')
2655             THEN
2656                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2657                                                         l_bld_blk_info_type_id
2658                   )
2659                THEN
2660                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2661                   THEN
2662                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2663                                                           p_building_block_id;
2667                                       g_field_mappings_table (MAP).field_name;
2664                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2665                                   p_attribute_table (p_cnt).detail_attribute2;
2666                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2668                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2669                                          g_field_mappings_table (MAP).CONTEXT;
2670                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2671                                         g_field_mappings_table (MAP).CATEGORY;
2672                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2673                   THEN
2674                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2675                                                                    (l_att_cnt).bb_id :=
2676                                                           p_building_block_id;
2677                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2678                                                                    (l_att_cnt).VALUE :=
2679                                   p_attribute_table (p_cnt).detail_attribute2;
2680                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2681                                                                    (l_att_cnt).field_name :=
2682                                       g_field_mappings_table (MAP).field_name;
2683                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2684                                                                    (l_att_cnt).CONTEXT :=
2685                                          g_field_mappings_table (MAP).CONTEXT;
2686                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2687                                                                    (l_att_cnt).CATEGORY :=
2688                                         g_field_mappings_table (MAP).CATEGORY;
2689                   END IF;
2690                END IF;
2691             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE3')
2692             THEN
2693                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2694                                                         l_bld_blk_info_type_id
2695                   )
2696                THEN
2697                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2698                   THEN
2699                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2700                                                           p_building_block_id;
2701                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2702                                   p_attribute_table (p_cnt).detail_attribute3;
2703                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2704                                       g_field_mappings_table (MAP).field_name;
2705                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2706                                          g_field_mappings_table (MAP).CONTEXT;
2707                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2708                                         g_field_mappings_table (MAP).CATEGORY;
2709                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2710                   THEN
2711                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2712                                                                    (l_att_cnt).bb_id :=
2713                                                           p_building_block_id;
2714                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2715                                                                    (l_att_cnt).VALUE :=
2716                                   p_attribute_table (p_cnt).detail_attribute3;
2717                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2718                                                                    (l_att_cnt).field_name :=
2719                                       g_field_mappings_table (MAP).field_name;
2720                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2721                                                                    (l_att_cnt).CONTEXT :=
2722                                          g_field_mappings_table (MAP).CONTEXT;
2723                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2724                                                                    (l_att_cnt).CATEGORY :=
2725                                         g_field_mappings_table (MAP).CATEGORY;
2726                   END IF;
2727                END IF;
2728             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE4')
2729             THEN
2730                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2731                                                         l_bld_blk_info_type_id
2732                   )
2733                THEN
2734                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2735                   THEN
2736                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2737                                                           p_building_block_id;
2738                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2739                                   p_attribute_table (p_cnt).detail_attribute4;
2740                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2741                                       g_field_mappings_table (MAP).field_name;
2742                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2746                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2743                                          g_field_mappings_table (MAP).CONTEXT;
2744                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2745                                         g_field_mappings_table (MAP).CATEGORY;
2747                   THEN
2748                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2749                                                                    (l_att_cnt).bb_id :=
2750                                                           p_building_block_id;
2751                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2752                                                                    (l_att_cnt).VALUE :=
2753                                   p_attribute_table (p_cnt).detail_attribute4;
2754                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2755                                                                    (l_att_cnt).field_name :=
2756                                       g_field_mappings_table (MAP).field_name;
2757                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2758                                                                    (l_att_cnt).CONTEXT :=
2759                                          g_field_mappings_table (MAP).CONTEXT;
2760                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2761                                                                    (l_att_cnt).CATEGORY :=
2762                                         g_field_mappings_table (MAP).CATEGORY;
2763                   END IF;
2764                END IF;
2765             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE5')
2766             THEN
2767                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2768                                                         l_bld_blk_info_type_id
2769                   )
2770                THEN
2771                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2772                   THEN
2773                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2774                                                           p_building_block_id;
2775                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2776                                   p_attribute_table (p_cnt).detail_attribute5;
2777                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2778                                       g_field_mappings_table (MAP).field_name;
2779                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2780                                          g_field_mappings_table (MAP).CONTEXT;
2781                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2782                                         g_field_mappings_table (MAP).CATEGORY;
2783                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2784                   THEN
2785                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2786                                                                    (l_att_cnt).bb_id :=
2787                                                           p_building_block_id;
2788                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2789                                                                    (l_att_cnt).VALUE :=
2790                                   p_attribute_table (p_cnt).detail_attribute5;
2791                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2792                                                                    (l_att_cnt).field_name :=
2793                                       g_field_mappings_table (MAP).field_name;
2794                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2795                                                                    (l_att_cnt).CONTEXT :=
2796                                          g_field_mappings_table (MAP).CONTEXT;
2797                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2798                                                                    (l_att_cnt).CATEGORY :=
2799                                         g_field_mappings_table (MAP).CATEGORY;
2800                   END IF;
2801                END IF;
2802             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE6')
2803             THEN
2804                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2805                                                         l_bld_blk_info_type_id
2806                   )
2807                THEN
2808                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2809                   THEN
2810                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2811                                                           p_building_block_id;
2812                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2813                                   p_attribute_table (p_cnt).detail_attribute6;
2814                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2815                                       g_field_mappings_table (MAP).field_name;
2816                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2817                                          g_field_mappings_table (MAP).CONTEXT;
2818                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2819                                         g_field_mappings_table (MAP).CATEGORY;
2820                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2821                   THEN
2822                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2823                                                                    (l_att_cnt).bb_id :=
2827                                   p_attribute_table (p_cnt).detail_attribute6;
2824                                                           p_building_block_id;
2825                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2826                                                                    (l_att_cnt).VALUE :=
2828                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2829                                                                    (l_att_cnt).field_name :=
2830                                       g_field_mappings_table (MAP).field_name;
2831                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2832                                                                    (l_att_cnt).CONTEXT :=
2833                                          g_field_mappings_table (MAP).CONTEXT;
2834                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2835                                                                    (l_att_cnt).CATEGORY :=
2836                                         g_field_mappings_table (MAP).CATEGORY;
2837                   END IF;
2838                END IF;
2839             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE7')
2840             THEN
2841                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2842                                                         l_bld_blk_info_type_id
2843                   )
2844                THEN
2845                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2846                   THEN
2847                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2848                                                           p_building_block_id;
2849                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2850                                   p_attribute_table (p_cnt).detail_attribute7;
2851                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2852                                       g_field_mappings_table (MAP).field_name;
2853                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2854                                          g_field_mappings_table (MAP).CONTEXT;
2855                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2856                                         g_field_mappings_table (MAP).CATEGORY;
2857                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2858                   THEN
2859                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2860                                                                    (l_att_cnt).bb_id :=
2861                                                           p_building_block_id;
2862                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2863                                                                    (l_att_cnt).VALUE :=
2864                                   p_attribute_table (p_cnt).detail_attribute7;
2865                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2866                                                                    (l_att_cnt).field_name :=
2867                                       g_field_mappings_table (MAP).field_name;
2868                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2869                                                                    (l_att_cnt).CONTEXT :=
2870                                          g_field_mappings_table (MAP).CONTEXT;
2871                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2872                                                                    (l_att_cnt).CATEGORY :=
2873                                         g_field_mappings_table (MAP).CATEGORY;
2874                   END IF;
2875                END IF;
2876             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE8')
2877             THEN
2878                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2879                                                         l_bld_blk_info_type_id
2880                   )
2881                THEN
2882                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2883                   THEN
2884                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2885                                                           p_building_block_id;
2886                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2887                                   p_attribute_table (p_cnt).detail_attribute8;
2888                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2889                                       g_field_mappings_table (MAP).field_name;
2890                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2891                                          g_field_mappings_table (MAP).CONTEXT;
2892                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2893                                         g_field_mappings_table (MAP).CATEGORY;
2894                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2895                   THEN
2896                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2897                                                                    (l_att_cnt).bb_id :=
2898                                                           p_building_block_id;
2899                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2900                                                                    (l_att_cnt).VALUE :=
2901                                   p_attribute_table (p_cnt).detail_attribute8;
2902                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2906                                                                    (l_att_cnt).CONTEXT :=
2903                                                                    (l_att_cnt).field_name :=
2904                                       g_field_mappings_table (MAP).field_name;
2905                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2907                                          g_field_mappings_table (MAP).CONTEXT;
2908                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2909                                                                    (l_att_cnt).CATEGORY :=
2910                                         g_field_mappings_table (MAP).CATEGORY;
2911                   END IF;
2912                END IF;
2913             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE9')
2914             THEN
2915                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2916                                                         l_bld_blk_info_type_id
2917                   )
2918                THEN
2919                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2920                   THEN
2921                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2922                                                           p_building_block_id;
2923                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2924                                   p_attribute_table (p_cnt).detail_attribute9;
2925                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2926                                       g_field_mappings_table (MAP).field_name;
2927                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2928                                          g_field_mappings_table (MAP).CONTEXT;
2929                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2930                                         g_field_mappings_table (MAP).CATEGORY;
2931                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2932                   THEN
2933                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2934                                                                    (l_att_cnt).bb_id :=
2935                                                           p_building_block_id;
2936                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2937                                                                    (l_att_cnt).VALUE :=
2938                                   p_attribute_table (p_cnt).detail_attribute9;
2939                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2940                                                                    (l_att_cnt).field_name :=
2941                                       g_field_mappings_table (MAP).field_name;
2942                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2943                                                                    (l_att_cnt).CONTEXT :=
2944                                          g_field_mappings_table (MAP).CONTEXT;
2945                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2946                                                                    (l_att_cnt).CATEGORY :=
2947                                         g_field_mappings_table (MAP).CATEGORY;
2948                   END IF;
2949                END IF;
2950             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE10')
2951             THEN
2952                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2953                                                         l_bld_blk_info_type_id
2954                   )
2955                THEN
2956                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2957                   THEN
2958                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2959                                                           p_building_block_id;
2960                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2961                                  p_attribute_table (p_cnt).detail_attribute10;
2962                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
2963                                       g_field_mappings_table (MAP).field_name;
2964                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
2965                                          g_field_mappings_table (MAP).CONTEXT;
2966                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
2967                                         g_field_mappings_table (MAP).CATEGORY;
2968                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
2969                   THEN
2970                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2971                                                                    (l_att_cnt).bb_id :=
2972                                                           p_building_block_id;
2973                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2974                                                                    (l_att_cnt).VALUE :=
2975                                  p_attribute_table (p_cnt).detail_attribute10;
2976                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2977                                                                    (l_att_cnt).field_name :=
2978                                       g_field_mappings_table (MAP).field_name;
2979                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2980                                                                    (l_att_cnt).CONTEXT :=
2981                                          g_field_mappings_table (MAP).CONTEXT;
2982                      hxc_generic_retrieval_pkg.t_old_detail_attributes
2986                END IF;
2983                                                                    (l_att_cnt).CATEGORY :=
2984                                         g_field_mappings_table (MAP).CATEGORY;
2985                   END IF;
2987             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE11')
2988             THEN
2989                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
2990                                                         l_bld_blk_info_type_id
2991                   )
2992                THEN
2993                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
2994                   THEN
2995                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
2996                                                           p_building_block_id;
2997                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
2998                                  p_attribute_table (p_cnt).detail_attribute11;
2999                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3000                                       g_field_mappings_table (MAP).field_name;
3001                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3002                                          g_field_mappings_table (MAP).CONTEXT;
3003                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3004                                         g_field_mappings_table (MAP).CATEGORY;
3005                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3006                   THEN
3007                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3008                                                                    (l_att_cnt).bb_id :=
3009                                                           p_building_block_id;
3010                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3011                                                                    (l_att_cnt).VALUE :=
3012                                  p_attribute_table (p_cnt).detail_attribute11;
3013                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3014                                                                    (l_att_cnt).field_name :=
3015                                       g_field_mappings_table (MAP).field_name;
3016                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3017                                                                    (l_att_cnt).CONTEXT :=
3018                                          g_field_mappings_table (MAP).CONTEXT;
3019                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3020                                                                    (l_att_cnt).CATEGORY :=
3021                                         g_field_mappings_table (MAP).CATEGORY;
3022                   END IF;
3023                END IF;
3024             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE12')
3025             THEN
3026                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3027                                                         l_bld_blk_info_type_id
3028                   )
3029                THEN
3030                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3031                   THEN
3032                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3033                                                           p_building_block_id;
3034                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3035                                  p_attribute_table (p_cnt).detail_attribute12;
3036                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3037                                       g_field_mappings_table (MAP).field_name;
3038                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3039                                          g_field_mappings_table (MAP).CONTEXT;
3040                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3041                                         g_field_mappings_table (MAP).CATEGORY;
3042                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3043                   THEN
3044                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3045                                                                    (l_att_cnt).bb_id :=
3046                                                           p_building_block_id;
3047                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3048                                                                    (l_att_cnt).VALUE :=
3049                                  p_attribute_table (p_cnt).detail_attribute12;
3050                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3051                                                                    (l_att_cnt).field_name :=
3052                                       g_field_mappings_table (MAP).field_name;
3053                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3054                                                                    (l_att_cnt).CONTEXT :=
3055                                          g_field_mappings_table (MAP).CONTEXT;
3056                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3057                                                                    (l_att_cnt).CATEGORY :=
3058                                         g_field_mappings_table (MAP).CATEGORY;
3059                   END IF;
3060                END IF;
3061             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE13')
3062             THEN
3063                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3064                                                         l_bld_blk_info_type_id
3065                   )
3069                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3066                THEN
3067                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3068                   THEN
3070                                                           p_building_block_id;
3071                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3072                                  p_attribute_table (p_cnt).detail_attribute13;
3073                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3074                                       g_field_mappings_table (MAP).field_name;
3075                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3076                                          g_field_mappings_table (MAP).CONTEXT;
3077                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3078                                         g_field_mappings_table (MAP).CATEGORY;
3079                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3080                   THEN
3081                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3082                                                                    (l_att_cnt).bb_id :=
3083                                                           p_building_block_id;
3084                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3085                                                                    (l_att_cnt).VALUE :=
3086                                  p_attribute_table (p_cnt).detail_attribute13;
3087                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3088                                                                    (l_att_cnt).field_name :=
3089                                       g_field_mappings_table (MAP).field_name;
3090                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3091                                                                    (l_att_cnt).CONTEXT :=
3092                                          g_field_mappings_table (MAP).CONTEXT;
3093                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3094                                                                    (l_att_cnt).CATEGORY :=
3095                                         g_field_mappings_table (MAP).CATEGORY;
3096                   END IF;
3097                END IF;
3098             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE14')
3099             THEN
3100                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3101                                                         l_bld_blk_info_type_id
3102                   )
3103                THEN
3104                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3105                   THEN
3106                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3107                                                           p_building_block_id;
3108                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3109                                  p_attribute_table (p_cnt).detail_attribute14;
3110                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3111                                       g_field_mappings_table (MAP).field_name;
3112                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3113                                          g_field_mappings_table (MAP).CONTEXT;
3114                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3115                                         g_field_mappings_table (MAP).CATEGORY;
3116                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3117                   THEN
3118                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3119                                                                    (l_att_cnt).bb_id :=
3120                                                           p_building_block_id;
3121                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3122                                                                    (l_att_cnt).VALUE :=
3123                                  p_attribute_table (p_cnt).detail_attribute14;
3124                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3125                                                                    (l_att_cnt).field_name :=
3126                                       g_field_mappings_table (MAP).field_name;
3127                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3128                                                                    (l_att_cnt).CONTEXT :=
3129                                          g_field_mappings_table (MAP).CONTEXT;
3130                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3131                                                                    (l_att_cnt).CATEGORY :=
3132                                         g_field_mappings_table (MAP).CATEGORY;
3133                   END IF;
3134                END IF;
3135             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE15')
3136             THEN
3137                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3138                                                         l_bld_blk_info_type_id
3139                   )
3140                THEN
3141                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3142                   THEN
3143                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3144                                                           p_building_block_id;
3145                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3149                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3146                                  p_attribute_table (p_cnt).detail_attribute15;
3147                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3148                                       g_field_mappings_table (MAP).field_name;
3150                                          g_field_mappings_table (MAP).CONTEXT;
3151                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3152                                         g_field_mappings_table (MAP).CATEGORY;
3153                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3154                   THEN
3155                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3156                                                                    (l_att_cnt).bb_id :=
3157                                                           p_building_block_id;
3158                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3159                                                                    (l_att_cnt).VALUE :=
3160                                  p_attribute_table (p_cnt).detail_attribute15;
3161                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3162                                                                    (l_att_cnt).field_name :=
3163                                       g_field_mappings_table (MAP).field_name;
3164                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3165                                                                    (l_att_cnt).CONTEXT :=
3166                                          g_field_mappings_table (MAP).CONTEXT;
3167                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3168                                                                    (l_att_cnt).CATEGORY :=
3169                                         g_field_mappings_table (MAP).CATEGORY;
3170                   END IF;
3171                END IF;
3172             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE16')
3173             THEN
3174                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3175                                                         l_bld_blk_info_type_id
3176                   )
3177                THEN
3178                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3179                   THEN
3180                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3181                                                           p_building_block_id;
3182                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3183                                  p_attribute_table (p_cnt).detail_attribute16;
3184                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3185                                       g_field_mappings_table (MAP).field_name;
3186                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3187                                          g_field_mappings_table (MAP).CONTEXT;
3188                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3189                                         g_field_mappings_table (MAP).CATEGORY;
3190                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3191                   THEN
3192                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3193                                                                    (l_att_cnt).bb_id :=
3194                                                           p_building_block_id;
3195                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3196                                                                    (l_att_cnt).VALUE :=
3197                                  p_attribute_table (p_cnt).detail_attribute16;
3198                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3199                                                                    (l_att_cnt).field_name :=
3200                                       g_field_mappings_table (MAP).field_name;
3201                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3202                                                                    (l_att_cnt).CONTEXT :=
3203                                          g_field_mappings_table (MAP).CONTEXT;
3204                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3205                                                                    (l_att_cnt).CATEGORY :=
3206                                         g_field_mappings_table (MAP).CATEGORY;
3207                   END IF;
3208                END IF;
3209             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE17')
3210             THEN
3211                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3212                                                         l_bld_blk_info_type_id
3213                   )
3214                THEN
3215                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3216                   THEN
3217                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3218                                                           p_building_block_id;
3219                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3220                                  p_attribute_table (p_cnt).detail_attribute17;
3221                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3222                                       g_field_mappings_table (MAP).field_name;
3223                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3224                                          g_field_mappings_table (MAP).CONTEXT;
3225                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3229                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3226                                         g_field_mappings_table (MAP).CATEGORY;
3227                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3228                   THEN
3230                                                                    (l_att_cnt).bb_id :=
3231                                                           p_building_block_id;
3232                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3233                                                                    (l_att_cnt).VALUE :=
3234                                  p_attribute_table (p_cnt).detail_attribute17;
3235                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3236                                                                    (l_att_cnt).field_name :=
3237                                       g_field_mappings_table (MAP).field_name;
3238                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3239                                                                    (l_att_cnt).CONTEXT :=
3240                                          g_field_mappings_table (MAP).CONTEXT;
3241                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3242                                                                    (l_att_cnt).CATEGORY :=
3243                                         g_field_mappings_table (MAP).CATEGORY;
3244                   END IF;
3245                END IF;
3246             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE18')
3247             THEN
3248                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3249                                                         l_bld_blk_info_type_id
3250                   )
3251                THEN
3252                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3253                   THEN
3254                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3255                                                           p_building_block_id;
3256                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3257                                  p_attribute_table (p_cnt).detail_attribute18;
3258                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3259                                       g_field_mappings_table (MAP).field_name;
3260                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3261                                          g_field_mappings_table (MAP).CONTEXT;
3262                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3263                                         g_field_mappings_table (MAP).CATEGORY;
3264                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3265                   THEN
3266                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3267                                                                    (l_att_cnt).bb_id :=
3268                                                           p_building_block_id;
3269                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3270                                                                    (l_att_cnt).VALUE :=
3271                                  p_attribute_table (p_cnt).detail_attribute18;
3272                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3273                                                                    (l_att_cnt).field_name :=
3274                                       g_field_mappings_table (MAP).field_name;
3275                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3276                                                                    (l_att_cnt).CONTEXT :=
3277                                          g_field_mappings_table (MAP).CONTEXT;
3278                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3279                                                                    (l_att_cnt).CATEGORY :=
3280                                         g_field_mappings_table (MAP).CATEGORY;
3281                   END IF;
3282                END IF;
3283             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE19')
3284             THEN
3285                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3286                                                         l_bld_blk_info_type_id
3287                   )
3288                THEN
3289                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3290                   THEN
3291                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3292                                                           p_building_block_id;
3293                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3294                                  p_attribute_table (p_cnt).detail_attribute19;
3295                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3296                                       g_field_mappings_table (MAP).field_name;
3297                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3298                                          g_field_mappings_table (MAP).CONTEXT;
3299                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3300                                         g_field_mappings_table (MAP).CATEGORY;
3301                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3302                   THEN
3303                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3304                                                                    (l_att_cnt).bb_id :=
3305                                                           p_building_block_id;
3306                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3307                                                                    (l_att_cnt).VALUE :=
3311                                       g_field_mappings_table (MAP).field_name;
3308                                  p_attribute_table (p_cnt).detail_attribute19;
3309                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3310                                                                    (l_att_cnt).field_name :=
3312                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3313                                                                    (l_att_cnt).CONTEXT :=
3314                                          g_field_mappings_table (MAP).CONTEXT;
3315                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3316                                                                    (l_att_cnt).CATEGORY :=
3317                                         g_field_mappings_table (MAP).CATEGORY;
3318                   END IF;
3319                END IF;
3320             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE20')
3321             THEN
3322                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3323                                                         l_bld_blk_info_type_id
3324                   )
3325                THEN
3326                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3327                   THEN
3328                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3329                                                           p_building_block_id;
3330                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3331                                  p_attribute_table (p_cnt).detail_attribute20;
3332                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3333                                       g_field_mappings_table (MAP).field_name;
3334                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3335                                          g_field_mappings_table (MAP).CONTEXT;
3336                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3337                                         g_field_mappings_table (MAP).CATEGORY;
3338                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3339                   THEN
3340                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3341                                                                    (l_att_cnt).bb_id :=
3342                                                           p_building_block_id;
3343                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3344                                                                    (l_att_cnt).VALUE :=
3345                                  p_attribute_table (p_cnt).detail_attribute20;
3346                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3347                                                                    (l_att_cnt).field_name :=
3348                                       g_field_mappings_table (MAP).field_name;
3349                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3350                                                                    (l_att_cnt).CONTEXT :=
3351                                          g_field_mappings_table (MAP).CONTEXT;
3352                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3353                                                                    (l_att_cnt).CATEGORY :=
3354                                         g_field_mappings_table (MAP).CATEGORY;
3355                   END IF;
3356                END IF;
3357             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE21')
3358             THEN
3359                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3360                                                         l_bld_blk_info_type_id
3361                   )
3362                THEN
3363                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3364                   THEN
3365                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3366                                                           p_building_block_id;
3367                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3368                                  p_attribute_table (p_cnt).detail_attribute21;
3369                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3370                                       g_field_mappings_table (MAP).field_name;
3371                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3372                                          g_field_mappings_table (MAP).CONTEXT;
3373                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3374                                         g_field_mappings_table (MAP).CATEGORY;
3375                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3376                   THEN
3377                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3378                                                                    (l_att_cnt).bb_id :=
3379                                                           p_building_block_id;
3380                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3381                                                                    (l_att_cnt).VALUE :=
3382                                  p_attribute_table (p_cnt).detail_attribute21;
3383                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3384                                                                    (l_att_cnt).field_name :=
3385                                       g_field_mappings_table (MAP).field_name;
3386                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3387                                                                    (l_att_cnt).CONTEXT :=
3391                                         g_field_mappings_table (MAP).CATEGORY;
3388                                          g_field_mappings_table (MAP).CONTEXT;
3389                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3390                                                                    (l_att_cnt).CATEGORY :=
3392                   END IF;
3393                END IF;
3394             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE22')
3395             THEN
3396                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3397                                                         l_bld_blk_info_type_id
3398                   )
3399                THEN
3400                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3401                   THEN
3402                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3403                                                           p_building_block_id;
3404                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3405                                  p_attribute_table (p_cnt).detail_attribute22;
3406                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3407                                       g_field_mappings_table (MAP).field_name;
3408                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3409                                          g_field_mappings_table (MAP).CONTEXT;
3410                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3411                                         g_field_mappings_table (MAP).CATEGORY;
3412                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3413                   THEN
3414                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3415                                                                    (l_att_cnt).bb_id :=
3416                                                           p_building_block_id;
3417                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3418                                                                    (l_att_cnt).VALUE :=
3419                                  p_attribute_table (p_cnt).detail_attribute22;
3420                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3421                                                                    (l_att_cnt).field_name :=
3422                                       g_field_mappings_table (MAP).field_name;
3423                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3424                                                                    (l_att_cnt).CONTEXT :=
3425                                          g_field_mappings_table (MAP).CONTEXT;
3426                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3427                                                                    (l_att_cnt).CATEGORY :=
3428                                         g_field_mappings_table (MAP).CATEGORY;
3429                   END IF;
3430                END IF;
3431             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE23')
3432             THEN
3433                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3434                                                         l_bld_blk_info_type_id
3435                   )
3436                THEN
3437                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3438                   THEN
3439                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3440                                                           p_building_block_id;
3441                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3442                                  p_attribute_table (p_cnt).detail_attribute23;
3443                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3444                                       g_field_mappings_table (MAP).field_name;
3445                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3446                                          g_field_mappings_table (MAP).CONTEXT;
3447                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3448                                         g_field_mappings_table (MAP).CATEGORY;
3449                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3450                   THEN
3451                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3452                                                                    (l_att_cnt).bb_id :=
3453                                                           p_building_block_id;
3454                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3455                                                                    (l_att_cnt).VALUE :=
3456                                  p_attribute_table (p_cnt).detail_attribute23;
3457                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3458                                                                    (l_att_cnt).field_name :=
3459                                       g_field_mappings_table (MAP).field_name;
3460                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3461                                                                    (l_att_cnt).CONTEXT :=
3462                                          g_field_mappings_table (MAP).CONTEXT;
3463                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3464                                                                    (l_att_cnt).CATEGORY :=
3465                                         g_field_mappings_table (MAP).CATEGORY;
3466                   END IF;
3467                END IF;
3468             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE24')
3469             THEN
3470                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3474                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3471                                                         l_bld_blk_info_type_id
3472                   )
3473                THEN
3475                   THEN
3476                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3477                                                           p_building_block_id;
3478                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3479                                  p_attribute_table (p_cnt).detail_attribute24;
3480                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3481                                       g_field_mappings_table (MAP).field_name;
3482                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3483                                          g_field_mappings_table (MAP).CONTEXT;
3484                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3485                                         g_field_mappings_table (MAP).CATEGORY;
3486                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3487                   THEN
3488                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3489                                                                    (l_att_cnt).bb_id :=
3490                                                           p_building_block_id;
3491                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3492                                                                    (l_att_cnt).VALUE :=
3493                                  p_attribute_table (p_cnt).detail_attribute24;
3494                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3495                                                                    (l_att_cnt).field_name :=
3496                                       g_field_mappings_table (MAP).field_name;
3497                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3498                                                                    (l_att_cnt).CONTEXT :=
3499                                          g_field_mappings_table (MAP).CONTEXT;
3500                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3501                                                                    (l_att_cnt).CATEGORY :=
3502                                         g_field_mappings_table (MAP).CATEGORY;
3503                   END IF;
3504                END IF;
3505             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE25')
3506             THEN
3507                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3508                                                         l_bld_blk_info_type_id
3509                   )
3510                THEN
3511                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3512                   THEN
3513                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3514                                                           p_building_block_id;
3515                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3516                                  p_attribute_table (p_cnt).detail_attribute25;
3517                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3518                                       g_field_mappings_table (MAP).field_name;
3519                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3520                                          g_field_mappings_table (MAP).CONTEXT;
3521                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3522                                         g_field_mappings_table (MAP).CATEGORY;
3523                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3524                   THEN
3525                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3526                                                                    (l_att_cnt).bb_id :=
3527                                                           p_building_block_id;
3528                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3529                                                                    (l_att_cnt).VALUE :=
3530                                  p_attribute_table (p_cnt).detail_attribute25;
3531                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3532                                                                    (l_att_cnt).field_name :=
3533                                       g_field_mappings_table (MAP).field_name;
3534                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3535                                                                    (l_att_cnt).CONTEXT :=
3536                                          g_field_mappings_table (MAP).CONTEXT;
3537                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3538                                                                    (l_att_cnt).CATEGORY :=
3539                                         g_field_mappings_table (MAP).CATEGORY;
3540                   END IF;
3541                END IF;
3542             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE26')
3543             THEN
3544                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3545                                                         l_bld_blk_info_type_id
3546                   )
3547                THEN
3548                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3549                   THEN
3550                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3551                                                           p_building_block_id;
3552                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3553                                  p_attribute_table (p_cnt).detail_attribute26;
3557                                          g_field_mappings_table (MAP).CONTEXT;
3554                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3555                                       g_field_mappings_table (MAP).field_name;
3556                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3558                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3559                                         g_field_mappings_table (MAP).CATEGORY;
3560                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3561                   THEN
3562                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3563                                                                    (l_att_cnt).bb_id :=
3564                                                           p_building_block_id;
3565                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3566                                                                    (l_att_cnt).VALUE :=
3567                                  p_attribute_table (p_cnt).detail_attribute26;
3568                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3569                                                                    (l_att_cnt).field_name :=
3570                                       g_field_mappings_table (MAP).field_name;
3571                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3572                                                                    (l_att_cnt).CONTEXT :=
3573                                          g_field_mappings_table (MAP).CONTEXT;
3574                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3575                                                                    (l_att_cnt).CATEGORY :=
3576                                         g_field_mappings_table (MAP).CATEGORY;
3577                   END IF;
3578                END IF;
3579             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE27')
3580             THEN
3581                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3582                                                         l_bld_blk_info_type_id
3583                   )
3584                THEN
3585                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3586                   THEN
3587                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3588                                                           p_building_block_id;
3589                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3590                                  p_attribute_table (p_cnt).detail_attribute27;
3591                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3592                                       g_field_mappings_table (MAP).field_name;
3593                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3594                                          g_field_mappings_table (MAP).CONTEXT;
3595                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3596                                         g_field_mappings_table (MAP).CATEGORY;
3597                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3598                   THEN
3599                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3600                                                                    (l_att_cnt).bb_id :=
3601                                                           p_building_block_id;
3602                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3603                                                                    (l_att_cnt).VALUE :=
3604                                  p_attribute_table (p_cnt).detail_attribute27;
3605                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3606                                                                    (l_att_cnt).field_name :=
3607                                       g_field_mappings_table (MAP).field_name;
3608                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3609                                                                    (l_att_cnt).CONTEXT :=
3610                                          g_field_mappings_table (MAP).CONTEXT;
3611                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3612                                                                    (l_att_cnt).CATEGORY :=
3613                                         g_field_mappings_table (MAP).CATEGORY;
3614                   END IF;
3615                END IF;
3616             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE28')
3617             THEN
3618                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3619                                                         l_bld_blk_info_type_id
3620                   )
3621                THEN
3622                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3623                   THEN
3624                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3625                                                           p_building_block_id;
3626                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3627                                  p_attribute_table (p_cnt).detail_attribute28;
3628                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3629                                       g_field_mappings_table (MAP).field_name;
3630                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3631                                          g_field_mappings_table (MAP).CONTEXT;
3632                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3633                                         g_field_mappings_table (MAP).CATEGORY;
3634                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3638                                                           p_building_block_id;
3635                   THEN
3636                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3637                                                                    (l_att_cnt).bb_id :=
3639                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3640                                                                    (l_att_cnt).VALUE :=
3641                                  p_attribute_table (p_cnt).detail_attribute28;
3642                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3643                                                                    (l_att_cnt).field_name :=
3644                                       g_field_mappings_table (MAP).field_name;
3645                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3646                                                                    (l_att_cnt).CONTEXT :=
3647                                          g_field_mappings_table (MAP).CONTEXT;
3648                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3649                                                                    (l_att_cnt).CATEGORY :=
3650                                         g_field_mappings_table (MAP).CATEGORY;
3651                   END IF;
3652                END IF;
3653             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE29')
3654             THEN
3655                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3656                                                         l_bld_blk_info_type_id
3657                   )
3658                THEN
3659                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3660                   THEN
3661                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3662                                                           p_building_block_id;
3663                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3664                                  p_attribute_table (p_cnt).detail_attribute29;
3665                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3666                                       g_field_mappings_table (MAP).field_name;
3667                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3668                                          g_field_mappings_table (MAP).CONTEXT;
3669                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3670                                         g_field_mappings_table (MAP).CATEGORY;
3671                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3672                   THEN
3673                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3674                                                                    (l_att_cnt).bb_id :=
3675                                                           p_building_block_id;
3676                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3677                                                                    (l_att_cnt).VALUE :=
3678                                  p_attribute_table (p_cnt).detail_attribute29;
3679                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3680                                                                    (l_att_cnt).field_name :=
3681                                       g_field_mappings_table (MAP).field_name;
3682                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3683                                                                    (l_att_cnt).CONTEXT :=
3684                                          g_field_mappings_table (MAP).CONTEXT;
3685                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3686                                                                    (l_att_cnt).CATEGORY :=
3687                                         g_field_mappings_table (MAP).CATEGORY;
3688                   END IF;
3689                END IF;
3690             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE30')
3691             THEN
3692                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3693                                                         l_bld_blk_info_type_id
3694                   )
3695                THEN
3696                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3697                   THEN
3698                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3699                                                           p_building_block_id;
3700                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3701                                  p_attribute_table (p_cnt).detail_attribute30;
3702                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3703                                       g_field_mappings_table (MAP).field_name;
3704                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3705                                          g_field_mappings_table (MAP).CONTEXT;
3706                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3707                                         g_field_mappings_table (MAP).CATEGORY;
3708                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3709                   THEN
3710                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3711                                                                    (l_att_cnt).bb_id :=
3712                                                           p_building_block_id;
3713                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3717                                                                    (l_att_cnt).field_name :=
3714                                                                    (l_att_cnt).VALUE :=
3715                                  p_attribute_table (p_cnt).detail_attribute30;
3716                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3718                                       g_field_mappings_table (MAP).field_name;
3719                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3720                                                                    (l_att_cnt).CONTEXT :=
3721                                          g_field_mappings_table (MAP).CONTEXT;
3722                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3723                                                                    (l_att_cnt).CATEGORY :=
3724                                         g_field_mappings_table (MAP).CATEGORY;
3725                   END IF;
3726                END IF;
3727             END IF;
3728          END LOOP;
3729       END IF;                                           --  p_scope = 'DETAIL'
3730    END populate_attributes;
3731 
3732 -- private procedure
3733 --   query_it
3734 --
3735 -- description
3736 --   This is the heart of the retrieval process. It retrieves and sorts the time
3737 --   building blocks.
3738 --   Retrieval:
3739 --   The dynanmic SQL is parsed and executed and the dbms_sql arrays defined
3740 --   and initialised. Once all the rows have been fetched the data is moved into
3741 --   one PL/SQL table (see populate_query_table).
3742 --   Sorting:
3743 --   Since the bld blks are retrieved in one query there is some data repetition.
3744 --   We loop through all the rows returned and note when the bld blk id changes
3745 --   at the TIME, DAY and DETAIL scopes and then and only then copy the bld blk
3746 --   to the appropriate global PL/SQL table. At any time a bld blk is copied,
3747 --   any bld blks in the hierarchy above are also copied. The decision to
3748 --   copy a bld blk or not is based upon the max ovn column also populated in the
3749 --   query. For the incremental retrieval this is the ovn of the bld blk last transferred.
3750 --   If they are the same, we do nothing, if it is smaller than the actual ovn then
3751 --   the bld blk has changed and we must transfer. When the retrieval is not incremental
3752 --   then the function max ovn is replaced by the actual ovn + 1 such that we always
3753 --   transfer the bld blk.
3754 --
3755 -- parameters
3756 --   p_query   - the dynamic sql to be run
3757    PROCEDURE query_it (p_query IN VARCHAR2)
3758    IS
3759 --
3760 -- define local variables
3761 --
3762       l_proc                      VARCHAR2 (72);
3763       l_query_text                VARCHAR2 (32000)                 := p_query;
3764       l_copy_old                  VARCHAR2 (1)                         := 'N';
3765       l_count                     PLS_INTEGER;
3766       l_ind                       PLS_INTEGER;
3767       l_number_format 		  varchar2(2);
3768       l_att26    		  number;
3769 -- timecard scope building block local variables
3770       l_old_timecard_bb_id        hxc_time_building_blocks.time_building_block_id%TYPE
3771                                                                         := -1;
3772       l_old_day_bb_id             hxc_time_building_blocks.time_building_block_id%TYPE
3773                                                                         := -1;
3774       l_old_detail_bb_id          hxc_time_building_blocks.time_building_block_id%TYPE
3775                                                                         := -1;
3776 -- timecard scope attribute local variables
3777       l_old_timecard_ta_id        hxc_time_attributes.time_attribute_id%TYPE
3778                                                                         := -1;
3779       l_old_day_ta_id             hxc_time_attributes.time_attribute_id%TYPE
3780                                                                         := -1;
3781       l_old_detail_ta_id          hxc_time_attributes.time_attribute_id%TYPE
3782                                                                         := -1;
3783 -- tables and temporary table local variables
3784       t_attribute_field_name      tab_ta_field_name;
3785       t_attribute_value           tab_ta_attribute;
3786       l_gaz_index                 INTEGER;
3787 -- dynamic SQL local variables
3788       l_csr                       INTEGER;
3789       l_max_array_size            INTEGER;
3790       l_estimated_array_size      INTEGER                                := 0;
3791       l_rows_fetched              INTEGER;
3792       l_dummy                     INTEGER;
3793       l_timecard_copied           VARCHAR2 (1)                         := 'N';
3794       l_day_copied                VARCHAR2 (1)                         := 'N';
3795       l_detail_copied             VARCHAR2 (1)                         := 'N';
3796       l_time_att_copied           VARCHAR2 (1)                         := 'N';
3797       l_day_att_copied            VARCHAR2 (1)                         := 'N';
3798       l_detail_att_copied         VARCHAR2 (1)                         := 'N';
3799       l_bld_blks_to_transfer      VARCHAR2 (1)                         := 'N';
3800 
3801 -- table and variable for the time/day/detail bld blk info type registers
3802       TYPE t_bld_blk_info_type_id IS TABLE OF hxc_bld_blk_info_types.bld_blk_info_type_id%TYPE
3803          INDEX BY BINARY_INTEGER;
3804 
3805       t_time_bld_blk_info         t_bld_blk_info_type_id;
3806       t_day_bld_blk_info          t_bld_blk_info_type_id;
3807       t_detail_bld_blk_info       t_bld_blk_info_type_id;
3808       l_bld_blk_info_index        PLS_INTEGER;
3809       e_no_timecards              EXCEPTION;
3813       l_ret_rules                 hxc_generic_retrieval_utils.t_ret_rule;
3810       e_no_bld_blks_to_transfer   EXCEPTION;
3811       -- used in incremental when we fetched but no ovn diffs
3812       l_prefs                     hxc_generic_retrieval_utils.t_pref;
3814       l_rtr_outcomes              hxc_generic_retrieval_utils.t_rtr_outcome;
3815       l_errors                    hxc_generic_retrieval_utils.t_errors;
3816       l_timecard_retrieve         BOOLEAN;
3817       l_day_retrieve              BOOLEAN;
3818       l_error_flag                BOOLEAN;
3819       l_tc_locked                 BOOLEAN;
3820       l_tc_first_lock             BOOLEAN;
3821       l_range                     VARCHAR2 (15);
3822       l_already_multiplied        varchar2(1) := 'N';
3823       l_detail_index              number;
3824 
3825       l_detail_bld_blk_idx	  PLS_INTEGER;
3826       l_bb_skipped_reason	  VARCHAR2(80);
3827 
3828       CURSOR csr_how_big_is_htbb
3829       IS
3830          SELECT COUNT (*)
3831            FROM hxc_time_building_blocks
3832           WHERE SCOPE = 'TIMECARD';
3833 
3834     CURSOR get_session_number_format
3835     is
3836     SELECT value
3837     FROM nls_session_parameters
3838     WHERE parameter = 'NLS_NUMERIC_CHARACTERS';
3839 
3840       l_htbb_size                 NUMBER;
3841 
3842 -- define private procedures
3843 
3844       -- private procedure
3845 --   copy_bld_blks
3846 --
3847 -- description
3848 --   Populates the global bld blks PL/SQL tables with the appropriate bld blk information
3849 --   Also maintains the global transaction detail PL/SQL table for each bld blk
3850 --
3851 -- parameters
3852 --   p_bld_blks_table   - PL/SQL table of all bld blk rows
3853 --   pscope    - scope of the bld blk to be copied
3854 --   p_copied     - copied flag used to prevent data duplication in tables
3855 --   p_cnt     - index for p_bld blks_table
3856 --   p_copy_old      - flag to indicate whether or not to maintain the 'old'
3857 --       - bld blks PL/SQL table
3858       PROCEDURE copy_bld_blks (
3859          p_bld_blks_table                   t_all_building_blocks,
3860          p_scope                            VARCHAR2,
3861          p_copied           IN OUT NOCOPY   VARCHAR2,
3862          p_cnt                              INTEGER,
3863          p_copy_old                         VARCHAR2,
3864          p_errors           IN OUT NOCOPY   hxc_generic_retrieval_utils.t_errors,
3865          p_error                            BOOLEAN
3866       )
3867       IS
3868          l_bld_blk_index       PLS_INTEGER;
3869          l_old_bld_blk_index   PLS_INTEGER;
3870          l_error_index         PLS_INTEGER;
3871          l_proc                VARCHAR2 (72) := g_package || 'copy_bld_blks';
3872       BEGIN
3873          IF (p_scope = 'TIME')
3874          THEN
3875             l_bld_blk_index :=
3876                    NVL (hxc_generic_retrieval_pkg.t_tx_time_bb_id.LAST, 0)
3877                    + 1;
3878          ELSIF (p_scope = 'DAY')
3879          THEN
3880             l_bld_blk_index :=
3881                     NVL (hxc_generic_retrieval_pkg.t_tx_day_bb_id.LAST, 0)
3882                     + 1;
3883          ELSIF (p_scope = 'DETAIL')
3884          THEN
3885             l_bld_blk_index :=
3886                  NVL (hxc_generic_retrieval_pkg.t_detail_bld_blks.LAST, 0)
3887                  + 1;
3888          END IF;
3889 
3890          l_error_index :=
3891                    NVL (hxc_generic_retrieval_pkg.t_tx_error_bb_id.LAST, 0)
3892                    + 1;
3893 
3894          IF (p_scope = 'TIME' AND p_copied = 'N')
3895          THEN
3896             hxc_generic_retrieval_pkg.t_time_bld_blks (t_bb (p_cnt).time_bb_id
3897                                                       ).start_time :=
3898                                                   t_bb (p_cnt).time_start_time;
3899             hxc_generic_retrieval_pkg.t_time_bld_blks (t_bb (p_cnt).time_bb_id).stop_time :=
3900                                                    t_bb (p_cnt).time_stop_time;
3901             hxc_generic_retrieval_pkg.t_time_bld_blks (t_bb (p_cnt).time_bb_id).comment_text :=
3902                                                 t_bb (p_cnt).time_comment_text;
3903 
3904             -- audit the transaction
3905             IF (NOT p_error)
3906             THEN
3907                hxc_generic_retrieval_pkg.t_tx_time_bb_id (l_bld_blk_index) :=
3908                                                       t_bb (p_cnt).time_bb_id;
3909                hxc_generic_retrieval_pkg.t_tx_time_bb_ovn (l_bld_blk_index) :=
3910                                                         t_bb (p_cnt).time_ovn;
3911                hxc_generic_retrieval_pkg.t_tx_time_status (l_bld_blk_index) :=
3912                                                                 'IN PROGRESS';
3913                hxc_generic_retrieval_pkg.t_tx_time_exception (l_bld_blk_index) :=
3914                                                                          NULL;
3915             ELSE
3916                hxc_generic_retrieval_pkg.t_tx_error_bb_id (l_error_index) :=
3917                                                       t_bb (p_cnt).time_bb_id;
3918                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn (l_error_index) :=
3919                                                         t_bb (p_cnt).time_ovn;
3920                hxc_generic_retrieval_pkg.t_tx_error_status (l_error_index) :=
3921                                                                      'ERRORS';
3922                hxc_generic_retrieval_pkg.t_tx_error_exception (l_error_index) :=
3923                   p_errors (t_bb (p_cnt).detail_resource_id).exception_description;
3924             END IF;
3925 
3929             -- audit the transaction
3926             p_copied := 'Y';
3927          ELSIF (p_scope = 'DAY' AND p_copied = 'N')
3928          THEN
3930             IF (NOT p_error)
3931             THEN
3932                hxc_generic_retrieval_pkg.t_tx_day_parent_id (l_bld_blk_index) :=
3933                                                       t_bb (p_cnt).time_bb_id;
3934                hxc_generic_retrieval_pkg.t_tx_day_bb_id (l_bld_blk_index) :=
3935                                                        t_bb (p_cnt).day_bb_id;
3936                hxc_generic_retrieval_pkg.t_tx_day_bb_ovn (l_bld_blk_index) :=
3937                                                          t_bb (p_cnt).day_ovn;
3938                hxc_generic_retrieval_pkg.t_tx_day_status (l_bld_blk_index) :=
3939                                                                 'IN PROGRESS';
3940                hxc_generic_retrieval_pkg.t_tx_day_exception (l_bld_blk_index) :=
3941                                                                          NULL;
3942             ELSE
3943                hxc_generic_retrieval_pkg.t_tx_error_bb_id (l_error_index) :=
3944                                                        t_bb (p_cnt).day_bb_id;
3945                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn (l_error_index) :=
3946                                                          t_bb (p_cnt).day_ovn;
3947                hxc_generic_retrieval_pkg.t_tx_error_status (l_error_index) :=
3948                                                                      'ERRORS';
3949                hxc_generic_retrieval_pkg.t_tx_error_exception (l_error_index) :=
3950                                                                          NULL;
3951             END IF;
3952 
3953             p_copied := 'Y';
3954          ELSIF (p_scope = 'DETAIL' AND p_copied = 'N')
3955          THEN
3956             IF (NOT p_error)
3957             THEN
3958                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).bb_id :=
3959                                                     t_bb (p_cnt).detail_bb_id;
3960                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).parent_bb_id :=
3961                                              t_bb (p_cnt).detail_parent_bb_id;
3962                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).resource_type :=
3963                                             t_bb (p_cnt).detail_resource_type;
3964                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).resource_id :=
3965                                               t_bb (p_cnt).detail_resource_id;
3966                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).comment_text :=
3967                                              t_bb (p_cnt).detail_comment_text;
3968                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).start_time :=
3969                                                   t_bb (p_cnt).day_start_time;
3970                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).stop_time :=
3971                                                    t_bb (p_cnt).day_stop_time;
3972                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).measure :=
3973                                                   t_bb (p_cnt).detail_measure;
3974                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).uom :=
3975                                                       t_bb (p_cnt).detail_uom;
3976 
3977                IF (t_bb (p_cnt).detail_type = 'RANGE')
3978                THEN
3979                   hxc_generic_retrieval_pkg.t_detail_bld_blks
3980                                                              (l_bld_blk_index).start_time :=
3981                                                t_bb (p_cnt).detail_start_time;
3982                   hxc_generic_retrieval_pkg.t_detail_bld_blks
3983                                                              (l_bld_blk_index).stop_time :=
3984                                                 t_bb (p_cnt).detail_stop_time;
3985                   hxc_generic_retrieval_pkg.t_detail_bld_blks
3986                                                              (l_bld_blk_index).measure :=
3987                        (  t_bb (p_cnt).detail_stop_time
3988                         - t_bb (p_cnt).detail_start_time
3989                        )
3990                      * 24;
3991                   hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).uom :=
3992                                                                        'HOURS';
3993                END IF;
3994 
3995                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).SCOPE :=
3996                                                      t_bb (p_cnt).detail_scope;
3997                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).TYPE :=
3998                                                       t_bb (p_cnt).detail_type;
3999                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).deleted :=
4000                                                    t_bb (p_cnt).detail_deleted;
4001                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).ovn :=
4002                                                        t_bb (p_cnt).detail_ovn;
4003                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).timecard_bb_id :=
4004                                                        t_bb (p_cnt).time_bb_id;
4005                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).timecard_ovn :=
4006                                                          t_bb (p_cnt).time_ovn;
4007                -- set the bld blks to transfer flag if any DETAIL bld blks to transfer
4008                l_bld_blks_to_transfer := 'Y';
4009 
4010 -- maintain arrays for old building block
4014                   t_old_detail_seq (l_old_bld_blk_index) :=
4011                IF (p_copy_old = 'Y')
4012                THEN
4013                   l_old_bld_blk_index := NVL (t_old_detail_bb_id.LAST, 0) + 1;
4015                                                           l_old_bld_blk_index;
4016                   t_old_detail_bb_id (l_old_bld_blk_index) :=
4017                                                     t_bb (p_cnt).detail_bb_id;
4018                   t_old_detail_ovn (l_old_bld_blk_index) :=
4019                                                   t_bb (p_cnt).detail_max_ovn;
4020                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4021                                                              (l_bld_blk_index).changed :=
4022                                                                           'Y';
4023                ELSE
4024                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4025                                                              (l_bld_blk_index).changed :=
4026                                                                           'N';
4027                END IF;
4028             END IF;                                          -- if not p_error
4029 
4030             -- audit the transaction
4031             IF (NOT p_error)
4032             THEN
4033                hxc_generic_retrieval_pkg.t_tx_detail_parent_id
4034                                                              (l_bld_blk_index) :=
4035                                                        t_bb (p_cnt).day_bb_id;
4036                hxc_generic_retrieval_pkg.t_tx_detail_bb_id (l_bld_blk_index) :=
4037                                                     t_bb (p_cnt).detail_bb_id;
4038                hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn (l_bld_blk_index) :=
4039                                                       t_bb (p_cnt).detail_ovn;
4040                hxc_generic_retrieval_pkg.t_tx_detail_status (l_bld_blk_index) :=
4041                                                                 'IN PROGRESS';
4042                hxc_generic_retrieval_pkg.t_tx_detail_exception
4043                                                              (l_bld_blk_index) :=
4044                                                                          NULL;
4045             ELSE
4046                hxc_generic_retrieval_pkg.t_tx_error_bb_id (l_error_index) :=
4047                                                     t_bb (p_cnt).detail_bb_id;
4048                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn (l_error_index) :=
4049                                                       t_bb (p_cnt).detail_ovn;
4050                hxc_generic_retrieval_pkg.t_tx_error_status (l_error_index) :=
4051                                                                      'ERRORS';
4052                hxc_generic_retrieval_pkg.t_tx_error_exception (l_error_index) :=
4053                                                                          NULL;
4054             END IF;
4055 
4056             p_copied := 'Y';
4057          END IF;
4058       END copy_bld_blks;
4059 
4060 -- private function
4061 --   att_copied_before ?
4062 --
4063 -- description
4064 --   Polls the temporary attribute PL/SQL table to ensure that this attribute has not been copied
4065 --   already.
4066 --   Returns TRUE if copied before, FALSE, if not
4067 --
4068 -- parameters
4069 --   p_scope   - scope
4070 --   p_bld_blk_info_type_id - bld blk info type id
4071       FUNCTION att_copied_before (
4072          p_scope                  VARCHAR2,
4073          p_bld_blk_info_type_id   hxc_bld_blk_info_types.bld_blk_info_type_id%TYPE
4074       )
4075          RETURN BOOLEAN
4076 
4077       IS
4078       BEGIN
4079          IF p_scope = 'TIME'
4080          THEN
4081             IF t_time_bld_blk_info.COUNT <> 0
4082             THEN
4083                FOR x IN t_time_bld_blk_info.FIRST .. t_time_bld_blk_info.LAST
4084                LOOP
4085                   IF t_time_bld_blk_info (x) = p_bld_blk_info_type_id
4086                   THEN
4087                      RETURN TRUE;
4088                   END IF;
4089                END LOOP;
4090 
4091                RETURN FALSE;
4092             ELSE
4093                RETURN FALSE;
4094             END IF;
4095          ELSIF p_scope = 'DAY'
4096          THEN
4097             IF t_day_bld_blk_info.COUNT <> 0
4098             THEN
4099                FOR x IN t_day_bld_blk_info.FIRST .. t_day_bld_blk_info.LAST
4100                LOOP
4101                   IF t_day_bld_blk_info (x) = p_bld_blk_info_type_id
4102                   THEN
4103                      RETURN TRUE;
4104                   END IF;
4105                END LOOP;
4106 
4107                RETURN FALSE;
4108             ELSE
4109                RETURN FALSE;
4110             END IF;
4111          ELSIF p_scope = 'DETAIL'
4112          THEN
4113             IF t_detail_bld_blk_info.COUNT <> 0
4114             THEN
4115                FOR x IN
4116                   t_detail_bld_blk_info.FIRST .. t_detail_bld_blk_info.LAST
4117                LOOP
4118                   IF t_detail_bld_blk_info (x) = p_bld_blk_info_type_id
4119                   THEN
4120                      RETURN TRUE;
4121                   END IF;
4122                END LOOP;
4123 
4124                RETURN FALSE;
4125             ELSE
4126                RETURN FALSE;
4127             END IF;
4128          END IF;
4129       END att_copied_before;
4130 
4131    BEGIN                                                           -- query_it
4132       IF g_debug
4133       THEN
4137 
4134          l_proc := g_package || 'query_it';
4135          hr_utility.set_location ('Entering ' || l_proc, 10);
4136       END IF;
4138     OPEN get_session_number_format;
4139     FETCH get_session_number_format into l_number_format;
4140     CLOSE get_session_number_format;
4141 
4142       l_max_array_size := 100;
4143       l_rows_fetched := l_max_array_size;
4144 
4145       IF g_debug
4146       THEN
4147          hr_utility.set_location ('Processing ' || l_proc, 20);
4148       END IF;
4149 
4150       l_csr := DBMS_SQL.open_cursor;
4151 
4152       IF g_debug
4153       THEN
4154          hr_utility.set_location ('Processing ' || l_proc, 30);
4155       END IF;
4156 
4157       DBMS_SQL.parse (l_csr, l_query_text, DBMS_SQL.native);
4158 
4159 -- bind variables needed by all queries
4160       IF (g_params.p_process IN
4161              ('Projects Retrieval Process',
4162               'BEE Retrieval Process',
4163               'Apply Schedule Rules',
4164               'Purchasing Retrieval Process'
4165              )
4166          )
4167       THEN
4168          NULL;                 -- no more binds - bound in pop ret range blks
4169       ELSE
4170          DBMS_SQL.bind_variable (l_csr, ':p_lower_range', l_pkg_range_start);
4171          DBMS_SQL.bind_variable (l_csr, ':p_upper_range', l_pkg_range_stop);
4172 
4173          IF (g_params.p_incremental = 'Y')
4174          THEN
4175             DBMS_SQL.bind_variable (l_csr,
4176                                     ':p_process_id',
4177                                     g_retrieval_process_id
4178                                    );
4179          END IF;
4180 
4181          -- bind the start and end date parameters
4182          IF g_debug
4183          THEN
4184             hr_utility.set_location ('Processing ' || l_proc, 35);
4185          END IF;
4186 
4187          IF (    (    g_params.p_start_date IS NOT NULL
4188                   AND g_params.p_end_date IS NOT NULL
4189                  )
4190              AND (g_params.p_rerun_flag = 'N')
4191             )
4192          THEN
4193             DBMS_SQL.bind_variable (l_csr,
4194                                     ':p_start_date',
4195                                     g_params.p_start_date
4196                                    );
4197             DBMS_SQL.bind_variable (l_csr, ':p_end_date', g_params.p_end_date);
4198          END IF;
4199       END IF;
4200 
4201       IF g_debug
4202       THEN
4203          hr_utility.set_location ('Processing ' || l_proc, 37);
4204       END IF;
4205 
4206       IF (g_params.p_rerun_flag = 'Y')
4207       THEN
4208          DBMS_SQL.bind_variable (l_csr,
4209                                  ':p_transaction_code',
4210                                  g_params.p_transaction_code
4211                                 );
4212       END IF;
4213 
4214 -- define arrays for each item in the select list
4215       IF g_debug
4216       THEN
4217          hr_utility.set_location ('Processing ' || l_proc, 40);
4218       END IF;
4219 
4220       DBMS_SQL.define_array (c                => l_csr,
4221                              POSITION         => 1,
4222                              n_tab            => t_timecard_bb_id,
4223                              cnt              => l_max_array_size,
4224                              lower_bound      => 1
4225                             );
4226       DBMS_SQL.define_array (c                => l_csr,
4227                              POSITION         => 2,
4228                              n_tab            => t_timecard_ovn,
4229                              cnt              => l_max_array_size,
4230                              lower_bound      => 1
4231                             );
4232       DBMS_SQL.define_array (c                => l_csr,
4233                              POSITION         => 3,
4234                              n_tab            => t_day_bb_id,
4235                              cnt              => l_max_array_size,
4236                              lower_bound      => 1
4237                             );
4238       DBMS_SQL.define_array (c                => l_csr,
4239                              POSITION         => 4,
4240                              n_tab            => t_day_ovn,
4241                              cnt              => l_max_array_size,
4242                              lower_bound      => 1
4243                             );
4244       DBMS_SQL.define_array (c                => l_csr,
4245                              POSITION         => 5,
4246                              d_tab            => t_day_start_time,
4247                              cnt              => l_max_array_size,
4248                              lower_bound      => 1
4249                             );
4250       DBMS_SQL.define_array (c                => l_csr,
4251                              POSITION         => 6,
4252                              d_tab            => t_day_stop_time,
4253                              cnt              => l_max_array_size,
4254                              lower_bound      => 1
4255                             );
4256       DBMS_SQL.define_array (c                => l_csr,
4257                              POSITION         => 7,
4258                              n_tab            => t_detail_bb_id,
4259                              cnt              => l_max_array_size,
4260                              lower_bound      => 1
4261                             );
4262       DBMS_SQL.define_array (c                => l_csr,
4263                              POSITION         => 8,
4267                             );
4264                              n_tab            => t_detail_ovn,
4265                              cnt              => l_max_array_size,
4266                              lower_bound      => 1
4268       DBMS_SQL.define_array (c                => l_csr,
4269                              POSITION         => 9,
4270                              n_tab            => t_detail_parent_id,
4271                              cnt              => l_max_array_size,
4272                              lower_bound      => 1
4273                             );
4274       DBMS_SQL.define_array (c                => l_csr,
4275                              POSITION         => 10,
4276                              c_tab            => t_detail_resource_type,
4277                              cnt              => l_max_array_size,
4278                              lower_bound      => 1
4279                             );
4280       DBMS_SQL.define_array (c                => l_csr,
4281                              POSITION         => 11,
4282                              n_tab            => t_detail_resource_id,
4283                              cnt              => l_max_array_size,
4284                              lower_bound      => 1
4285                             );
4286       DBMS_SQL.define_array (c                => l_csr,
4287                              POSITION         => 12,
4288                              c_tab            => t_detail_comment_text,
4289                              cnt              => l_max_array_size,
4290                              lower_bound      => 1
4291                             );
4292       DBMS_SQL.define_array (c                => l_csr,
4293                              POSITION         => 13,
4294                              d_tab            => t_detail_start_time,
4295                              cnt              => l_max_array_size,
4296                              lower_bound      => 1
4297                             );
4298       DBMS_SQL.define_array (c                => l_csr,
4299                              POSITION         => 14,
4300                              d_tab            => t_detail_stop_time,
4301                              cnt              => l_max_array_size,
4302                              lower_bound      => 1
4303                             );
4304       DBMS_SQL.define_array (c                => l_csr,
4305                              POSITION         => 15,
4306                              n_tab            => t_detail_measure,
4307                              cnt              => l_max_array_size,
4308                              lower_bound      => 1
4309                             );
4310       DBMS_SQL.define_array (c                => l_csr,
4311                              POSITION         => 16,
4312                              c_tab            => t_detail_scope,
4313                              cnt              => l_max_array_size,
4314                              lower_bound      => 1
4315                             );
4316       DBMS_SQL.define_array (c                => l_csr,
4317                              POSITION         => 17,
4318                              c_tab            => t_detail_type,
4319                              cnt              => l_max_array_size,
4320                              lower_bound      => 1
4321                             );
4322       DBMS_SQL.define_array (c                => l_csr,
4323                              POSITION         => 18,
4324                              n_tab            => t_detail_ta_id,
4325                              cnt              => l_max_array_size,
4326                              lower_bound      => 1
4327                             );
4328       DBMS_SQL.define_array (c                => l_csr,
4329                              POSITION         => 19,
4330                              n_tab            => t_detail_bld_blk_info_type_id,
4331                              cnt              => l_max_array_size,
4332                              lower_bound      => 1
4333                             );
4334       DBMS_SQL.define_array (c                => l_csr,
4335                              POSITION         => 20,
4336                              c_tab            => t_detail_attribute1,
4337                              cnt              => l_max_array_size,
4338                              lower_bound      => 1
4339                             );
4340       DBMS_SQL.define_array (c                => l_csr,
4341                              POSITION         => 21,
4342                              c_tab            => t_detail_attribute2,
4343                              cnt              => l_max_array_size,
4344                              lower_bound      => 1
4345                             );
4346       DBMS_SQL.define_array (c                => l_csr,
4347                              POSITION         => 22,
4348                              c_tab            => t_detail_attribute3,
4349                              cnt              => l_max_array_size,
4350                              lower_bound      => 1
4351                             );
4352       DBMS_SQL.define_array (c                => l_csr,
4353                              POSITION         => 23,
4354                              c_tab            => t_detail_attribute4,
4355                              cnt              => l_max_array_size,
4356                              lower_bound      => 1
4357                             );
4358       DBMS_SQL.define_array (c                => l_csr,
4359                              POSITION         => 24,
4360                              c_tab            => t_detail_attribute5,
4361                              cnt              => l_max_array_size,
4362                              lower_bound      => 1
4363                             );
4367                              cnt              => l_max_array_size,
4364       DBMS_SQL.define_array (c                => l_csr,
4365                              POSITION         => 25,
4366                              c_tab            => t_detail_attribute6,
4368                              lower_bound      => 1
4369                             );
4370       DBMS_SQL.define_array (c                => l_csr,
4371                              POSITION         => 26,
4372                              c_tab            => t_detail_attribute7,
4373                              cnt              => l_max_array_size,
4374                              lower_bound      => 1
4375                             );
4376       DBMS_SQL.define_array (c                => l_csr,
4377                              POSITION         => 27,
4378                              c_tab            => t_detail_attribute8,
4379                              cnt              => l_max_array_size,
4380                              lower_bound      => 1
4381                             );
4382       DBMS_SQL.define_array (c                => l_csr,
4383                              POSITION         => 28,
4384                              c_tab            => t_detail_attribute9,
4385                              cnt              => l_max_array_size,
4386                              lower_bound      => 1
4387                             );
4388       DBMS_SQL.define_array (c                => l_csr,
4389                              POSITION         => 29,
4390                              c_tab            => t_detail_attribute10,
4391                              cnt              => l_max_array_size,
4392                              lower_bound      => 1
4393                             );
4394       DBMS_SQL.define_array (c                => l_csr,
4395                              POSITION         => 30,
4396                              c_tab            => t_detail_attribute11,
4397                              cnt              => l_max_array_size,
4398                              lower_bound      => 1
4399                             );
4400       DBMS_SQL.define_array (c                => l_csr,
4401                              POSITION         => 31,
4402                              c_tab            => t_detail_attribute12,
4403                              cnt              => l_max_array_size,
4404                              lower_bound      => 1
4405                             );
4406       DBMS_SQL.define_array (c                => l_csr,
4407                              POSITION         => 32,
4408                              c_tab            => t_detail_attribute13,
4409                              cnt              => l_max_array_size,
4410                              lower_bound      => 1
4411                             );
4412       DBMS_SQL.define_array (c                => l_csr,
4413                              POSITION         => 33,
4414                              c_tab            => t_detail_attribute14,
4415                              cnt              => l_max_array_size,
4416                              lower_bound      => 1
4417                             );
4418       DBMS_SQL.define_array (c                => l_csr,
4419                              POSITION         => 34,
4420                              c_tab            => t_detail_attribute15,
4421                              cnt              => l_max_array_size,
4422                              lower_bound      => 1
4423                             );
4424       DBMS_SQL.define_array (c                => l_csr,
4425                              POSITION         => 35,
4426                              c_tab            => t_detail_attribute16,
4427                              cnt              => l_max_array_size,
4428                              lower_bound      => 1
4429                             );
4430       DBMS_SQL.define_array (c                => l_csr,
4431                              POSITION         => 36,
4432                              c_tab            => t_detail_attribute17,
4433                              cnt              => l_max_array_size,
4434                              lower_bound      => 1
4435                             );
4436       DBMS_SQL.define_array (c                => l_csr,
4437                              POSITION         => 37,
4438                              c_tab            => t_detail_attribute18,
4439                              cnt              => l_max_array_size,
4440                              lower_bound      => 1
4441                             );
4442       DBMS_SQL.define_array (c                => l_csr,
4443                              POSITION         => 38,
4444                              c_tab            => t_detail_attribute19,
4445                              cnt              => l_max_array_size,
4446                              lower_bound      => 1
4447                             );
4448       DBMS_SQL.define_array (c                => l_csr,
4449                              POSITION         => 39,
4450                              c_tab            => t_detail_attribute20,
4451                              cnt              => l_max_array_size,
4452                              lower_bound      => 1
4453                             );
4454       DBMS_SQL.define_array (c                => l_csr,
4455                              POSITION         => 40,
4456                              c_tab            => t_detail_attribute21,
4457                              cnt              => l_max_array_size,
4458                              lower_bound      => 1
4459                             );
4460       DBMS_SQL.define_array (c                => l_csr,
4461                              POSITION         => 41,
4462                              c_tab            => t_detail_attribute22,
4466       DBMS_SQL.define_array (c                => l_csr,
4463                              cnt              => l_max_array_size,
4464                              lower_bound      => 1
4465                             );
4467                              POSITION         => 42,
4468                              c_tab            => t_detail_attribute23,
4469                              cnt              => l_max_array_size,
4470                              lower_bound      => 1
4471                             );
4472       DBMS_SQL.define_array (c                => l_csr,
4473                              POSITION         => 43,
4474                              c_tab            => t_detail_attribute24,
4475                              cnt              => l_max_array_size,
4476                              lower_bound      => 1
4477                             );
4478       DBMS_SQL.define_array (c                => l_csr,
4479                              POSITION         => 44,
4480                              c_tab            => t_detail_attribute25,
4481                              cnt              => l_max_array_size,
4482                              lower_bound      => 1
4483                             );
4484       DBMS_SQL.define_array (c                => l_csr,
4485                              POSITION         => 45,
4486                              c_tab            => t_detail_attribute26,
4487                              cnt              => l_max_array_size,
4488                              lower_bound      => 1
4489                             );
4490       DBMS_SQL.define_array (c                => l_csr,
4491                              POSITION         => 46,
4492                              c_tab            => t_detail_attribute27,
4493                              cnt              => l_max_array_size,
4494                              lower_bound      => 1
4495                             );
4496       DBMS_SQL.define_array (c                => l_csr,
4497                              POSITION         => 47,
4498                              c_tab            => t_detail_attribute28,
4499                              cnt              => l_max_array_size,
4500                              lower_bound      => 1
4501                             );
4502       DBMS_SQL.define_array (c                => l_csr,
4503                              POSITION         => 48,
4504                              c_tab            => t_detail_attribute29,
4505                              cnt              => l_max_array_size,
4506                              lower_bound      => 1
4507                             );
4508       DBMS_SQL.define_array (c                => l_csr,
4509                              POSITION         => 49,
4510                              c_tab            => t_detail_attribute30,
4511                              cnt              => l_max_array_size,
4512                              lower_bound      => 1
4513                             );
4514       DBMS_SQL.define_array (c                => l_csr,
4515                              POSITION         => 50,
4516                              d_tab            => t_detail_date_from,
4517                              cnt              => l_max_array_size,
4518                              lower_bound      => 1
4519                             );
4520       DBMS_SQL.define_array (c                => l_csr,
4521                              POSITION         => 51,
4522                              d_tab            => t_detail_date_to,
4523                              cnt              => l_max_array_size,
4524                              lower_bound      => 1
4525                             );
4526       DBMS_SQL.define_array (c                => l_csr,
4527                              POSITION         => 52,
4528                              c_tab            => t_detail_approval_status,
4529                              cnt              => l_max_array_size,
4530                              lower_bound      => 1
4531                             );
4532       DBMS_SQL.define_array (c                => l_csr,
4533                              POSITION         => 53,
4534                              n_tab            => t_detail_approval_style_id,
4535                              cnt              => l_max_array_size,
4536                              lower_bound      => 1
4537                             );
4538       DBMS_SQL.define_array (c                => l_csr,
4539                              POSITION         => 54,
4540                              c_tab            => t_detail_deleted,
4541                              cnt              => l_max_array_size,
4542                              lower_bound      => 1
4543                             );
4544       DBMS_SQL.define_array (c                => l_csr,
4545                              POSITION         => 55,
4546                              c_tab            => t_detail_attribute_category,
4547                              cnt              => l_max_array_size,
4548                              lower_bound      => 1
4549                             );
4550       DBMS_SQL.define_array (c                => l_csr,
4551                              POSITION         => 56,
4552                              n_tab            => t_timecard_max_ovn,
4553                              cnt              => l_max_array_size,
4554                              lower_bound      => 1
4555                             );
4556       DBMS_SQL.define_array (c                => l_csr,
4557                              POSITION         => 57,
4558                              n_tab            => t_day_max_ovn,
4559                              cnt              => l_max_array_size,
4560                              lower_bound      => 1
4561                             );
4565                              cnt              => l_max_array_size,
4562       DBMS_SQL.define_array (c                => l_csr,
4563                              POSITION         => 58,
4564                              n_tab            => t_detail_max_ovn,
4566                              lower_bound      => 1
4567                             );
4568       DBMS_SQL.define_array (c                => l_csr,
4569                              POSITION         => 59,
4570                              c_tab            => t_detail_uom,
4571                              cnt              => l_max_array_size,
4572                              lower_bound      => 1
4573                             );
4574       DBMS_SQL.define_array (c                => l_csr,
4575                              POSITION         => 60,
4576                              d_tab            => t_timecard_start_time,
4577                              cnt              => l_max_array_size,
4578                              lower_bound      => 1
4579                             );
4580       DBMS_SQL.define_array (c                => l_csr,
4581                              POSITION         => 61,
4582                              d_tab            => t_timecard_stop_time,
4583                              cnt              => l_max_array_size,
4584                              lower_bound      => 1
4585                             );
4586       DBMS_SQL.define_array (c                => l_csr,
4587                              POSITION         => 62,
4588                              c_tab            => t_timecard_comment_text,
4589                              cnt              => l_max_array_size,
4590                              lower_bound      => 1
4591                             );
4592       DBMS_SQL.define_array (c                => l_csr,
4593                              POSITION         => 63,
4594                              c_tab            => t_timecard_deleted,
4595                              cnt              => l_max_array_size,
4596                              lower_bound      => 1
4597                             );
4598 
4599       IF g_debug
4600       THEN
4601          hr_utility.set_location ('Processing ' || l_proc, 50);
4602       END IF;
4603 
4604       l_dummy := DBMS_SQL.EXECUTE (l_csr);
4605 
4606       IF g_debug
4607       THEN
4608          hr_utility.set_location ('Processing ' || l_proc, 60);
4609       END IF;
4610 
4611 -- loop to ensure we fetch all the rows
4612       WHILE (l_rows_fetched = l_max_array_size)
4613       LOOP
4614          l_rows_fetched := DBMS_SQL.fetch_rows (l_csr);
4615 
4616          IF (l_rows_fetched = 0 AND t_bb.COUNT = 0)
4617          THEN
4618             DBMS_SQL.close_cursor (l_csr);
4619             RAISE e_no_timecards;
4620          END IF;
4621 
4622          DBMS_SQL.column_value (c             => l_csr,
4623                                 POSITION      => 1,
4624                                 n_tab         => t_timecard_bb_id
4625                                );
4626          DBMS_SQL.column_value (c             => l_csr,
4627                                 POSITION      => 2,
4628                                 n_tab         => t_timecard_ovn
4629                                );
4630          DBMS_SQL.column_value (c             => l_csr,
4631                                 POSITION      => 3,
4632                                 n_tab         => t_day_bb_id
4633                                );
4634          DBMS_SQL.column_value (c             => l_csr, POSITION => 4,
4635                                 n_tab         => t_day_ovn);
4636          DBMS_SQL.column_value (c             => l_csr,
4637                                 POSITION      => 5,
4638                                 d_tab         => t_day_start_time
4639                                );
4640          DBMS_SQL.column_value (c             => l_csr,
4641                                 POSITION      => 6,
4642                                 d_tab         => t_day_stop_time
4643                                );
4644          DBMS_SQL.column_value (c             => l_csr,
4645                                 POSITION      => 7,
4646                                 n_tab         => t_detail_bb_id
4647                                );
4648          DBMS_SQL.column_value (c             => l_csr,
4649                                 POSITION      => 8,
4650                                 n_tab         => t_detail_ovn
4651                                );
4652          DBMS_SQL.column_value (c             => l_csr,
4653                                 POSITION      => 9,
4654                                 n_tab         => t_detail_parent_id
4655                                );
4656          DBMS_SQL.column_value (c             => l_csr,
4657                                 POSITION      => 10,
4658                                 c_tab         => t_detail_resource_type
4659                                );
4660          DBMS_SQL.column_value (c             => l_csr,
4661                                 POSITION      => 11,
4662                                 n_tab         => t_detail_resource_id
4663                                );
4664          DBMS_SQL.column_value (c             => l_csr,
4665                                 POSITION      => 12,
4666                                 c_tab         => t_detail_comment_text
4667                                );
4668          DBMS_SQL.column_value (c             => l_csr,
4669                                 POSITION      => 13,
4670                                 d_tab         => t_detail_start_time
4671                                );
4672          DBMS_SQL.column_value (c             => l_csr,
4673                                 POSITION      => 14,
4677                                 POSITION      => 15,
4674                                 d_tab         => t_detail_stop_time
4675                                );
4676          DBMS_SQL.column_value (c             => l_csr,
4678                                 n_tab         => t_detail_measure
4679                                );
4680          DBMS_SQL.column_value (c             => l_csr,
4681                                 POSITION      => 16,
4682                                 c_tab         => t_detail_scope
4683                                );
4684          DBMS_SQL.column_value (c             => l_csr,
4685                                 POSITION      => 17,
4686                                 c_tab         => t_detail_type
4687                                );
4688          DBMS_SQL.column_value (c             => l_csr,
4689                                 POSITION      => 18,
4690                                 n_tab         => t_detail_ta_id
4691                                );
4692          DBMS_SQL.column_value (c             => l_csr,
4693                                 POSITION      => 19,
4694                                 n_tab         => t_detail_bld_blk_info_type_id
4695                                );
4696          DBMS_SQL.column_value (c             => l_csr,
4697                                 POSITION      => 20,
4698                                 c_tab         => t_detail_attribute1
4699                                );
4700          DBMS_SQL.column_value (c             => l_csr,
4701                                 POSITION      => 21,
4702                                 c_tab         => t_detail_attribute2
4703                                );
4704          DBMS_SQL.column_value (c             => l_csr,
4705                                 POSITION      => 22,
4706                                 c_tab         => t_detail_attribute3
4707                                );
4708          DBMS_SQL.column_value (c             => l_csr,
4709                                 POSITION      => 23,
4710                                 c_tab         => t_detail_attribute4
4711                                );
4712          DBMS_SQL.column_value (c             => l_csr,
4713                                 POSITION      => 24,
4714                                 c_tab         => t_detail_attribute5
4715                                );
4716          DBMS_SQL.column_value (c             => l_csr,
4717                                 POSITION      => 25,
4718                                 c_tab         => t_detail_attribute6
4719                                );
4720          DBMS_SQL.column_value (c             => l_csr,
4721                                 POSITION      => 26,
4722                                 c_tab         => t_detail_attribute7
4723                                );
4724          DBMS_SQL.column_value (c             => l_csr,
4725                                 POSITION      => 27,
4726                                 c_tab         => t_detail_attribute8
4727                                );
4728          DBMS_SQL.column_value (c             => l_csr,
4729                                 POSITION      => 28,
4730                                 c_tab         => t_detail_attribute9
4731                                );
4732          DBMS_SQL.column_value (c             => l_csr,
4733                                 POSITION      => 29,
4734                                 c_tab         => t_detail_attribute10
4735                                );
4736          DBMS_SQL.column_value (c             => l_csr,
4737                                 POSITION      => 30,
4738                                 c_tab         => t_detail_attribute11
4739                                );
4740          DBMS_SQL.column_value (c             => l_csr,
4741                                 POSITION      => 31,
4742                                 c_tab         => t_detail_attribute12
4743                                );
4744          DBMS_SQL.column_value (c             => l_csr,
4745                                 POSITION      => 32,
4746                                 c_tab         => t_detail_attribute13
4747                                );
4748          DBMS_SQL.column_value (c             => l_csr,
4749                                 POSITION      => 33,
4750                                 c_tab         => t_detail_attribute14
4751                                );
4752          DBMS_SQL.column_value (c             => l_csr,
4753                                 POSITION      => 34,
4754                                 c_tab         => t_detail_attribute15
4755                                );
4756          DBMS_SQL.column_value (c             => l_csr,
4757                                 POSITION      => 35,
4758                                 c_tab         => t_detail_attribute16
4759                                );
4760          DBMS_SQL.column_value (c             => l_csr,
4761                                 POSITION      => 36,
4762                                 c_tab         => t_detail_attribute17
4763                                );
4764          DBMS_SQL.column_value (c             => l_csr,
4765                                 POSITION      => 37,
4766                                 c_tab         => t_detail_attribute18
4767                                );
4768          DBMS_SQL.column_value (c             => l_csr,
4769                                 POSITION      => 38,
4770                                 c_tab         => t_detail_attribute19
4771                                );
4772          DBMS_SQL.column_value (c             => l_csr,
4773                                 POSITION      => 39,
4774                                 c_tab         => t_detail_attribute20
4775                                );
4779                                );
4776          DBMS_SQL.column_value (c             => l_csr,
4777                                 POSITION      => 40,
4778                                 c_tab         => t_detail_attribute21
4780          DBMS_SQL.column_value (c             => l_csr,
4781                                 POSITION      => 41,
4782                                 c_tab         => t_detail_attribute22
4783                                );
4784          DBMS_SQL.column_value (c             => l_csr,
4785                                 POSITION      => 42,
4786                                 c_tab         => t_detail_attribute23
4787                                );
4788          DBMS_SQL.column_value (c             => l_csr,
4789                                 POSITION      => 43,
4790                                 c_tab         => t_detail_attribute24
4791                                );
4792          DBMS_SQL.column_value (c             => l_csr,
4793                                 POSITION      => 44,
4794                                 c_tab         => t_detail_attribute25
4795                                );
4796          DBMS_SQL.column_value (c             => l_csr,
4797                                 POSITION      => 45,
4798                                 c_tab         => t_detail_attribute26
4799                                );
4800          DBMS_SQL.column_value (c             => l_csr,
4801                                 POSITION      => 46,
4802                                 c_tab         => t_detail_attribute27
4803                                );
4804          DBMS_SQL.column_value (c             => l_csr,
4805                                 POSITION      => 47,
4806                                 c_tab         => t_detail_attribute28
4807                                );
4808          DBMS_SQL.column_value (c             => l_csr,
4809                                 POSITION      => 48,
4810                                 c_tab         => t_detail_attribute29
4811                                );
4812          DBMS_SQL.column_value (c             => l_csr,
4813                                 POSITION      => 49,
4814                                 c_tab         => t_detail_attribute30
4815                                );
4816          DBMS_SQL.column_value (c             => l_csr,
4817                                 POSITION      => 50,
4818                                 d_tab         => t_detail_date_from
4819                                );
4820          DBMS_SQL.column_value (c             => l_csr,
4821                                 POSITION      => 51,
4822                                 d_tab         => t_detail_date_to
4823                                );
4824          DBMS_SQL.column_value (c             => l_csr,
4825                                 POSITION      => 52,
4826                                 c_tab         => t_detail_approval_status
4827                                );
4828          DBMS_SQL.column_value (c             => l_csr,
4829                                 POSITION      => 53,
4830                                 n_tab         => t_detail_approval_style_id
4831                                );
4832          DBMS_SQL.column_value (c             => l_csr,
4833                                 POSITION      => 54,
4834                                 c_tab         => t_detail_deleted
4835                                );
4836          DBMS_SQL.column_value (c             => l_csr,
4837                                 POSITION      => 55,
4838                                 c_tab         => t_detail_attribute_category
4839                                );
4840          DBMS_SQL.column_value (c             => l_csr,
4841                                 POSITION      => 56,
4842                                 n_tab         => t_timecard_max_ovn
4843                                );
4844          DBMS_SQL.column_value (c             => l_csr,
4845                                 POSITION      => 57,
4846                                 n_tab         => t_day_max_ovn
4847                                );
4848          DBMS_SQL.column_value (c             => l_csr,
4849                                 POSITION      => 58,
4850                                 n_tab         => t_detail_max_ovn
4851                                );
4852          DBMS_SQL.column_value (c             => l_csr,
4853                                 POSITION      => 59,
4854                                 c_tab         => t_detail_uom
4855                                );
4856          DBMS_SQL.column_value (c             => l_csr,
4857                                 POSITION      => 60,
4858                                 d_tab         => t_timecard_start_time
4859                                );
4860          DBMS_SQL.column_value (c             => l_csr,
4861                                 POSITION      => 61,
4862                                 d_tab         => t_timecard_stop_time
4863                                );
4864          DBMS_SQL.column_value (c             => l_csr,
4865                                 POSITION      => 62,
4866                                 c_tab         => t_timecard_comment_text
4867                                );
4868          DBMS_SQL.column_value (c             => l_csr,
4869                                 POSITION      => 63,
4870                                 c_tab         => t_timecard_deleted
4871                                );
4872 -- to make the data more manageable copy the arrays into PL/SQL tables
4873 -- and save space
4874          populate_query_table;
4875       END LOOP;
4876 
4877       DBMS_SQL.close_cursor (l_csr);
4878 
4879       IF g_debug
4880       THEN
4881          hr_utility.set_location ('Processing ' || l_proc, 110);
4885       THEN
4882       END IF;
4883 
4884       IF (g_params.p_incremental = 'N')
4886          -- need to populate resources table since max_ovn was not called
4887          FOR x IN t_bb.FIRST .. t_bb.LAST
4888          LOOP
4889             IF NOT (hxc_generic_retrieval_utils.g_resources.EXISTS
4890                                                    (t_bb (x).detail_resource_id
4891                                                    )
4892                    )
4893             THEN
4894                hxc_generic_retrieval_utils.g_resources
4895                                                   (t_bb (x).detail_resource_id
4896                                                   ).resource_id :=
4897                                                    t_bb (x).detail_resource_id;
4898                hxc_generic_retrieval_utils.g_resources
4899                                                    (t_bb (x).detail_resource_id
4900                                                    ).start_time :=
4901                                                         hr_general.end_of_time;
4902                hxc_generic_retrieval_utils.g_resources
4903                                                    (t_bb (x).detail_resource_id
4904                                                    ).stop_time :=
4905                                                       hr_general.start_of_time;
4906             END IF;
4907          END LOOP;
4908       END IF;
4909 
4910 -- initialise tables
4911       IF g_debug
4912       THEN
4913          hr_utility.TRACE ('Params to parse_resources......');
4914          hr_utility.TRACE ('Process id is '
4915                            || TO_CHAR (g_retrieval_process_id)
4916                           );
4917          hr_utility.TRACE (   'Time Recipient id is '
4918                            || TO_CHAR (g_retrieval_tr_id)
4919                           );
4920       END IF;
4921 
4922       l_prefs.DELETE;
4923       l_ret_rules.DELETE;
4924       l_rtr_outcomes.DELETE;
4925       hxc_generic_retrieval_utils.parse_resources
4926                                       (p_process_id        => g_retrieval_process_id,
4927                                        p_ret_tr_id         => g_retrieval_tr_id,
4928                                        p_prefs             => l_prefs,
4929                                        p_ret_rules         => l_ret_rules,
4930                                        p_rtr_outcomes      => l_rtr_outcomes,
4931                                        p_errors            => l_errors
4932                                       );
4933 
4934       IF g_debug
4935       THEN
4936          hr_utility.TRACE (' *********** - GLOBAL TABLE INFO ************ ');
4937       END IF;
4938 
4939       l_count := hxc_generic_retrieval_utils.g_resources.COUNT;
4940 
4941       IF g_debug
4942       THEN
4943          hr_utility.TRACE ('Resources         : ' || TO_CHAR (l_count));
4944       END IF;
4945 
4946       l_count := t_bb.COUNT;
4947 
4948       IF g_debug
4949       THEN
4950          hr_utility.TRACE ('master bld blks   : ' || TO_CHAR (l_count));
4951       END IF;
4952 
4953       l_count := l_prefs.COUNT;
4954 
4955       IF g_debug
4956       THEN
4957          hr_utility.TRACE ('Prefs             : ' || TO_CHAR (l_count));
4958       END IF;
4959 
4960       l_count := l_ret_rules.COUNT;
4961 
4962       IF g_debug
4963       THEN
4964          hr_utility.TRACE ('Retrieval Rules   : ' || TO_CHAR (l_count));
4965       END IF;
4966 
4967       l_count := l_rtr_outcomes.COUNT;
4968 
4969       IF g_debug
4970       THEN
4971          hr_utility.TRACE ('Ret Rule Outcomes : ' || TO_CHAR (l_count));
4972       END IF;
4973 
4974       l_count := l_errors.COUNT;
4975 
4976       IF g_debug
4977       THEN
4978          hr_utility.TRACE ('Errors : ' || TO_CHAR (l_count));
4979       END IF;
4980 
4981 -- now loop through the table and populate the building block table for those bld blks which have
4982 -- changed
4983       IF g_debug
4984       THEN
4985          hr_utility.TRACE ('');
4986          hr_utility.TRACE ('****** Populating Global PL/SQL tables *******');
4987          hr_utility.TRACE ('');
4988       END IF;
4989 
4990       FOR cnt IN t_bb.FIRST .. t_bb.LAST
4991       LOOP
4992 --if g_debug then
4993    -- hr_utility.set_location('Processing '||l_proc, 130);
4994 --end if;
4995 
4996          -- Intitialise timecard scope variables
4997          IF (t_bb (cnt).time_bb_id <> l_old_timecard_bb_id)
4998          THEN
4999             -- set old time card id and reset copied flag
5000 
5001             --if g_debug then
5002    -- hr_utility.trace('GAZ t bb is '||to_char(t_bb(cnt).time_bb_id));
5003 --end if;
5004             l_timecard_retrieve := TRUE;
5005             l_day_retrieve := TRUE;
5006             l_old_timecard_bb_id := t_bb (cnt).time_bb_id;
5007             l_timecard_copied := 'N';
5008             l_tc_locked := FALSE;
5009             l_tc_first_lock := TRUE;
5010 
5011             IF (l_errors.EXISTS (t_bb (cnt).detail_resource_id))
5012             THEN
5013                l_error_flag := TRUE;
5014             ELSE
5015                l_error_flag := FALSE;
5016             END IF;
5017 
5018             -- clear out table of copied bld blk info types for this bb_id
5019             t_time_bld_blk_info.DELETE;
5020          END IF;                                  -- timecard id changed check
5021 
5022 -- if g_debug then
5026          -- Initialise and maintain DAY scope variables
5023    --hr_utility.set_location('Processing '||l_proc, 140);
5024 --end if;
5025 
5027          IF (t_bb (cnt).day_bb_id <> l_old_day_bb_id)
5028          THEN
5029             -- set count and old bld blk id
5030             l_old_day_bb_id := t_bb (cnt).day_bb_id;
5031             l_day_copied := 'N';
5032             -- clear out table of copied bld blk info types for this bb_id
5033             t_day_bld_blk_info.DELETE;
5034          END IF;
5035 
5036 -- if g_debug then
5037    --hr_utility.set_location('Processing '||l_proc, 160);
5038 --end if;
5039 
5040          -- Maintain Detail building blocks
5041          IF (t_bb (cnt).detail_bb_id <> l_old_detail_bb_id)
5042          THEN
5043             -- set count and old time card id
5044 
5045             -- if g_debug then
5046    --hr_utility.trace('GAZ tbb DETAIL is '||to_char(t_bb(cnt).detail_bb_id));
5047 --end if;
5048             l_old_detail_bb_id := t_bb (cnt).detail_bb_id;
5049             l_detail_copied := 'N';
5050              l_already_multiplied := 'N'; --DAYS Vs HOURS
5051             -- clear out table of copied bld blk info types for this bb_id
5052             t_detail_bld_blk_info.DELETE;
5053             l_day_retrieve := TRUE;
5054 
5055             -- Do not transfer if deleted and never transferred prior
5056             -- ( WWB 3503607 GPM v115.102 )
5057 
5058             l_bb_skipped_reason := null;
5059 
5060             IF (    t_bb (cnt).detail_deleted = 'Y'
5061                 AND t_bb (cnt).detail_max_ovn = 0
5062                )
5063             THEN
5064                l_day_retrieve := FALSE;
5065 
5066                -- Not transferring the deleted entries, but then they might need an adj
5067                -- ustment if the processes are BEE retrieval and Apply Schedules and the
5068                -- preference for Rule evaluation is changed after it its transferred.
5069                -- Checking that up here.
5070 
5071                IF    ( g_params.p_process IN ('BEE Retrieval Process',
5072                                               'Apply Schedule Rules') )
5073                  AND (hxc_generic_retrieval_utils.chk_need_adj( t_bb (cnt).time_bb_id,
5074                                                                 t_bb (cnt).time_ovn,
5075                                                                 t_bb (cnt).detail_resource_id,
5076                                                                 t_bb (cnt).day_start_time,
5077                                                                 t_bb (cnt).detail_bb_id,
5078                                                                 g_retrieval_process_id ) )
5079                THEN
5080                   IF g_debug
5081                   THEN
5082                      hr_utility.trace('Resource '||t_bb (cnt).detail_resource_id||
5083                     'had  a different rules evaluation pref and needs adj this time');
5084                   END IF;
5085                END IF;
5086 
5087 
5088             ELSE
5089                hr_utility.TRACE ('about to call chk retrieve');
5090                hxc_generic_retrieval_utils.chk_retrieve
5091                             (p_resource_id            => t_bb (cnt).detail_resource_id,
5092                              p_bb_status              => t_bb (cnt).detail_approval_status,
5093                              p_bb_deleted             => t_bb (cnt).time_deleted,
5094                              p_bb_start_time          => t_bb (cnt).day_start_time,
5095                              p_bb_stop_time           => t_bb (cnt).day_stop_time,
5096                              p_bb_id                  => t_bb (cnt).detail_bb_id,
5097                              p_bb_ovn                 => t_bb (cnt).detail_ovn,
5098                              p_process                => g_params.p_process,
5099                              p_prefs                  => l_prefs,
5100                              p_ret_rules              => l_ret_rules,
5101                              p_rtr_outcomes           => l_rtr_outcomes,
5102                              p_tc_bb_id               => t_bb (cnt).time_bb_id,
5103                              p_tc_bb_ovn              => t_bb (cnt).time_ovn,
5104                              p_timecard_retrieve      => l_timecard_retrieve,
5105                              p_day_retrieve           => l_day_retrieve,
5106                              p_tc_locked              => l_tc_locked,
5107                              p_tc_first_lock          => l_tc_first_lock,
5108                              p_bb_skipped_reason      => l_bb_skipped_reason
5109                             );
5110                hr_utility.TRACE ('after to call chk retrieve');
5111             END IF;                         -- chk deleted and not transferred
5112 
5113             -- if this detail block has not already been copied and the object version numbers
5114             -- are different then we need this building block and the day and time bld blks
5115 
5116 		if(l_bb_skipped_reason is null) then
5117 			l_bb_skipped_reason := 'Block DELETED and Not Transferred earlier';
5118 		end if;
5119 
5120             IF (   (    (l_detail_copied = 'N')
5121                     AND (t_bb (cnt).detail_ovn > t_bb (cnt).detail_max_ovn)
5122                     AND (l_day_retrieve)
5123                    )
5124                 OR (l_error_flag)
5125                )
5126             THEN
5127                -- maintain time bld blk table
5128 		g_rtr_detail_blks(t_bb(cnt).detail_bb_id).dummy := 'Y';
5129 
5130                /* -- only populate old DETAIL
5131 
5132                      IF ( t_bb(cnt).time_max_ovn <> 0 )
5133                      THEN
5137                      END IF;
5134                         l_copy_old  := 'Y';
5135                      ELSE
5136                         l_copy_old  := 'N';
5138                */
5139                copy_bld_blks (p_bld_blks_table      => t_bb,
5140                               p_scope               => 'TIME',
5141                               p_copied              => l_timecard_copied,
5142                               p_cnt                 => cnt,
5143                               p_copy_old            => 'N',
5144                               p_errors              => l_errors,
5145                               p_error               => l_error_flag
5146                              );
5147                -- maintain day bld blk table
5148 
5149                /* -- Only populate old DETAIL
5150 
5151                      IF ( t_bb(cnt).day_max_ovn <> 0 )
5152                      THEN
5153                         l_copy_old  := 'Y';
5154                      ELSE
5155                         l_copy_old  := 'N';
5156                      END IF;
5157                */
5158                copy_bld_blks (p_bld_blks_table      => t_bb,
5159                               p_scope               => 'DAY',
5160                               p_copied              => l_day_copied,
5161                               p_cnt                 => cnt,
5162                               p_copy_old            => 'N',
5163                               p_errors              => l_errors,
5164                               p_error               => l_error_flag
5165                              );
5166 
5167                IF (t_bb (cnt).detail_max_ovn <> 0)
5168                THEN
5169                   l_copy_old := 'Y';
5170                ELSE
5171                   l_copy_old := 'N';
5172                END IF;
5173 
5174                -- maintain detail bld blk table
5175                copy_bld_blks (p_bld_blks_table      => t_bb,
5176                               p_scope               => 'DETAIL',
5177                               p_copied              => l_detail_copied,
5178                               p_cnt                 => cnt,
5179                               p_copy_old            => l_copy_old,
5180                               p_errors              => l_errors,
5181                               p_error               => l_error_flag
5182                              );
5183 	ELSE
5184 	  IF(NOT (g_rtr_detail_blks.EXISTS(t_bb(cnt).detail_bb_id))) THEN
5185 			l_detail_bld_blk_idx := NVL (hxc_generic_retrieval_pkg.g_detail_skipped.LAST, 0) + 1;
5186 
5187 			hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).resource_id
5188 									:= t_bb(cnt).detail_resource_id;
5189 			hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).timecard_id
5190 									:= t_bb(cnt).time_bb_id;
5191 			hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).timecard_ovn
5192 									:= t_bb(cnt).time_ovn;
5193 			hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).bb_id
5194 									:= t_bb(cnt).detail_bb_id;
5195 			hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).ovn
5196 									:= t_bb(cnt).detail_ovn;
5197 			hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).description
5198 									:= l_bb_skipped_reason;
5199 
5200 	  END IF;
5201             END IF;                                               -- check ovn
5202          END IF;
5203 
5204          --***********DAYS Vs HOURS************
5205          IF g_params.p_process = 'Projects Retrieval Process' THEN
5206 	  l_detail_index := NVL (hxc_generic_retrieval_pkg.t_detail_bld_blks.LAST, 0);
5207 
5208 	 IF l_detail_index<> 0 THEN
5209 
5210 	  IF  hxc_generic_retrieval_pkg.t_detail_bld_blks(l_detail_index).bb_id
5211 		= t_bb(cnt).detail_bb_id  THEN
5212 
5213 		IF l_number_format = ',.'  THEN --EUROPEAN FORMAT
5214 		   l_att26 := to_number(replace(t_bb(cnt).detail_attribute26,'.',','));
5215 		ELSIF  l_number_format = '.,'  THEN --US FORMAT
5216 		   l_att26 := to_number(replace(t_bb(cnt).detail_attribute26,',','.'));
5217 		END IF;
5218 
5219 	      IF nvl(l_att26,1) <> 1 AND l_already_multiplied = 'N' THEN
5220 
5221 		hxc_generic_retrieval_pkg.t_detail_bld_blks(l_detail_index).measure :=
5222 		hxc_generic_retrieval_pkg.t_detail_bld_blks(l_detail_index).measure * l_att26;
5223 
5224 		l_already_multiplied := 'Y';
5225 
5226 	      END IF;
5227 
5228 	  END IF;
5229 	 END IF;
5230 	END IF;
5231         --***********DAYS Vs HOURS************
5232 
5233 -- Maintain Timecard Attribute rows
5234          IF (NOT l_error_flag)
5235          THEN
5236             IF (    l_day_retrieve
5237                 AND (t_bb (cnt).detail_ovn > t_bb (cnt).detail_max_ovn)
5238                )
5239             THEN
5240                -- Maintain Detail Attribute rows
5241 
5242                -- must not forget that there may not be any attributes for the detail scope
5243                -- hence r_csr_tbb.detail_time_attribute_id may be null
5244                IF (    (t_bb (cnt).detail_ta_id <> l_old_detail_ta_id)
5245                    AND (t_bb (cnt).detail_ta_id IS NOT NULL)
5246                   )
5247                THEN
5248                   -- set old time card time attribute id
5249                   l_old_detail_ta_id := t_bb (cnt).detail_ta_id;
5250 
5251                   IF (att_copied_before
5252                          (p_scope                     => 'DETAIL',
5253                           p_bld_blk_info_type_id      => t_bb (cnt).detail_bld_blk_info_type_id
5254                          )
5255                      )
5256                   THEN
5260                   END IF;
5257                      l_detail_att_copied := 'Y';
5258                   ELSE
5259                      l_detail_att_copied := 'N';
5261 
5262                   -- check to see if these are attributes for a bld blk that needs to be transferred
5263                   IF (l_detail_att_copied = 'N')
5264                   THEN
5265                      -- loop through the global field mappings table to map attribute value to field
5266                      -- name and populate the detail attribute tables
5267                      populate_attributes
5268                               (p_building_block_id      => t_bb (cnt).detail_bb_id,
5269                                p_attribute_table        => t_bb,
5270                                p_cnt                    => cnt,
5271                                p_scope                  => 'DETAIL',
5272                                p_new                    => 'Y'
5273                               );
5274                      l_detail_att_copied := 'Y';
5275                      l_bld_blk_info_index :=
5276                                         NVL (t_detail_bld_blk_info.LAST, 0)
5277                                         + 1;
5278                      t_detail_bld_blk_info (l_bld_blk_info_index) :=
5279                                         t_bb (cnt).detail_bld_blk_info_type_id;
5280                   END IF;
5281                END IF;
5282             END IF;                     -- l_day_retrieve and detail ovn check
5283          END IF;                                    -- IF ( NOT l_error_flag )
5284       END LOOP;                                                -- csr_tbb loop
5285 
5286 -- check to see if out of any of the timecards retrieved in the query were
5287 -- copied to the global PL/SQL tables
5288       IF (l_bld_blks_to_transfer = 'N')
5289       THEN
5290          RAISE e_no_bld_blks_to_transfer;
5291       ELSE
5292          hxc_generic_retrieval_pkg.g_no_timecards := FALSE;
5293          hxc_generic_retrieval_pkg.g_overall_no_timecards := FALSE;
5294       END IF;
5295 
5296       IF g_debug
5297       THEN
5298          hr_utility.TRACE (' *********** - GLOBAL TABLE INFO ************ ');
5299       END IF;
5300 
5301       l_count := hxc_generic_retrieval_pkg.t_detail_bld_blks.COUNT;
5302 
5303       IF g_debug
5304       THEN
5305          hr_utility.TRACE ('DETAIL bld blks       : ' || TO_CHAR (l_count));
5306       END IF;
5307 
5308       l_count := hxc_generic_retrieval_pkg.t_detail_attributes.COUNT;
5309 
5310       IF g_debug
5311       THEN
5312          hr_utility.TRACE ('DETAIL attributes     : ' || TO_CHAR (l_count));
5313       END IF;
5314 
5315       l_count := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT;
5316 
5317       IF g_debug
5318       THEN
5319          hr_utility.TRACE ('DETAIL txd count is ' || TO_CHAR (l_count));
5320       END IF;
5321 
5322       l_count := hxc_generic_retrieval_pkg.t_tx_error_bb_id.COUNT;
5323 
5324       IF g_debug
5325       THEN
5326          hr_utility.TRACE ('ERROR txd count is ' || TO_CHAR (l_count));
5327       END IF;
5328 
5329 -- delete the table
5330       t_bb.DELETE;
5331 
5332       IF g_debug
5333       THEN
5334          hr_utility.set_location ('Leaving ' || l_proc, 200);
5335       END IF;
5336    EXCEPTION
5337       WHEN e_no_timecards
5338       THEN
5339          hxc_generic_retrieval_utils.g_resources.DELETE;
5340 
5341          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
5342          THEN
5343             audit_transaction
5344                          (p_mode                        => 'I'       -- Insert
5345                                                               ,
5346                           p_transaction_process_id      => g_retrieval_process_id,
5347                           p_status                      => 'WARNINGS',
5348                           p_description                 => 'HXC_0012_GNRET_NO_TIMECARDS'
5349                          );
5350          END IF;
5351 
5352          fnd_message.set_name ('HXC', 'HXC_0012_GNRET_NO_TIMECARDS');
5353          fnd_message.raise_error;
5354       WHEN e_no_bld_blks_to_transfer
5355       THEN
5356          t_bb.DELETE;
5357          hxc_generic_retrieval_utils.g_resources.DELETE;
5358 
5359          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
5360          THEN
5361             audit_transaction
5362                          (p_mode                        => 'I'       -- Insert
5363                                                               ,
5364                           p_transaction_process_id      => g_retrieval_process_id,
5365                           p_status                      => 'WARNINGS',
5366                           p_description                 => 'HXC_0013_GNRET_NO_BLD_BLKS'
5367                          );
5368          ELSIF (l_errors.COUNT <> 0)
5369          THEN
5370             -- Must maintain the errors WWB 3517746
5371             audit_transaction
5372                          (p_mode                        => 'I'       -- Insert
5373                                                               ,
5374                           p_transaction_process_id      => g_retrieval_process_id,
5375                           p_status                      => 'WARNINGS',
5376                           p_description                 => 'HXC_0013_GNRET_NO_BLD_BLKS'
5377                          );
5378          END IF;
5379 
5380          fnd_message.set_name ('HXC', 'HXC_0013_GNRET_NO_BLD_BLKS');
5381          fnd_message.raise_error;
5382       WHEN OTHERS
5383       THEN
5384          audit_transaction
5388                           p_status                      => 'WARNINGS',
5385                          (p_mode                        => 'I'       -- Insert
5386                                                               ,
5387                           p_transaction_process_id      => g_retrieval_process_id,
5389                           p_description                 => SUBSTR (SQLERRM,
5390                                                                    1,
5391                                                                    2000
5392                                                                   )
5393                          );
5394          RAISE;
5395    END query_it;
5396 
5397 -- private procedure
5398 --   query_old_timecard
5399 --
5400 -- description
5401 --   this queries the bld blk last transferred.
5402 --   we populate a temporary table with the bld blk id and ovn
5403 --   of the last transferred bld blk and then bulk collect
5404 --
5405 -- parameters
5406 --   none
5407    PROCEDURE query_old_timecard
5408    IS
5409       PRAGMA AUTONOMOUS_TRANSACTION;
5410 --
5411 -- define local variables
5412 --
5413       l_proc                       VARCHAR2 (100);
5414 
5415       CURSOR gaz_chk_tmp_table
5416       IS
5417          SELECT 'x'
5418            FROM hxc_tmp_bld_blks;
5419 
5420       CURSOR csr_get_old_detail_bld_blks
5421       IS
5422          SELECT   /*+ ORDERED  INDEX(TBB) INDEX(DAY) USE_NL(TBB, DAY) */
5423                   tbb.time_building_block_id, tbb.object_version_number,
5424                   tbb.parent_building_block_id, tbb.resource_type,
5425                   tbb.resource_id, tbb.comment_text,
5426                   DECODE (tbb.TYPE,
5427                           'MEASURE', DAY.start_time,
5428                           tbb.start_time
5429                          ),
5430                   DECODE (tbb.TYPE, 'MEASURE', DAY.stop_time, tbb.stop_time),
5431                   DECODE (tbb.TYPE,
5432                           'MEASURE', tbb.measure,
5433                           (tbb.stop_time - tbb.start_time
5434                           ) * 24
5435                          ),
5436                   tbb.SCOPE, tbb.TYPE,
5437                   DECODE (tbb.TYPE, 'MEASURE', tbb.unit_of_measure, 'HOURS'),
5438                   tbb.date_from, tbb.date_to, tbb.approval_status,
5439                   tbb.approval_style_id
5440              FROM hxc_tmp_bld_blks tmp,
5441                   hxc_time_building_blocks tbb,
5442                   hxc_time_building_blocks DAY
5443             WHERE tbb.time_building_block_id = tmp.time_building_block_id
5444               AND tbb.object_version_number = tmp.time_building_block_ovn
5445               AND DAY.time_building_block_id = tbb.parent_building_block_id
5446               AND DAY.object_version_number = tbb.parent_building_block_ovn
5447          ORDER BY tmp.seq;
5448 
5449       CURSOR csr_get_old_attributes
5450       IS
5451          SELECT   /*+ ORDERED  INDEX(TAU) INDEX(TA) USE_NL(TAU, TA) */
5452                   tmp.time_building_block_id, ta.bld_blk_info_type_id,
5453                   ta.attribute_category, ta.attribute1, ta.attribute2,
5454                   ta.attribute3, ta.attribute4, ta.attribute5, ta.attribute6,
5455                   ta.attribute7, ta.attribute8, ta.attribute9, ta.attribute10,
5456                   ta.attribute11, ta.attribute12, ta.attribute13,
5457                   ta.attribute14, ta.attribute15, ta.attribute16,
5458                   ta.attribute17, ta.attribute18, ta.attribute19,
5459                   ta.attribute20, ta.attribute21, ta.attribute22,
5460                   ta.attribute23, ta.attribute24, ta.attribute25,
5461                   ta.attribute26, ta.attribute27, ta.attribute28,
5462                   ta.attribute29, ta.attribute30
5463              FROM hxc_tmp_bld_blks tmp,
5464                   hxc_time_attribute_usages tau,
5465                   hxc_time_attributes ta
5466             WHERE tau.time_building_block_id = tmp.time_building_block_id
5467               AND tau.time_building_block_ovn = tmp.time_building_block_ovn
5468               AND ta.time_attribute_id = tau.time_attribute_id
5469          ORDER BY tmp.seq;
5470 
5471       l_index                      PLS_INTEGER;
5472       l_dummy                      VARCHAR2 (1);
5473 
5474 -- bulk collect collections
5475       TYPE t_old_bld_blk_bb_id IS TABLE OF hxc_time_building_blocks.time_building_block_id%TYPE
5476          INDEX BY BINARY_INTEGER;
5477 
5478       TYPE t_old_bld_blk_bb_ovn IS TABLE OF hxc_time_building_blocks.object_version_number%TYPE
5479          INDEX BY BINARY_INTEGER;
5480 
5481       TYPE t_old_bld_blk_parent_id IS TABLE OF hxc_time_building_blocks.parent_building_block_id%TYPE
5482          INDEX BY BINARY_INTEGER;
5483 
5484       TYPE t_old_bld_blk_resource_type IS TABLE OF hxc_time_building_blocks.resource_type%TYPE
5485          INDEX BY BINARY_INTEGER;
5486 
5487       TYPE t_old_bld_blk_resource_id IS TABLE OF hxc_time_building_blocks.resource_id%TYPE
5488          INDEX BY BINARY_INTEGER;
5489 
5490       TYPE t_old_bld_blk_comment_text IS TABLE OF hxc_time_building_blocks.comment_text%TYPE
5491          INDEX BY BINARY_INTEGER;
5492 
5493       TYPE t_old_bld_blk_start_time IS TABLE OF hxc_time_building_blocks.start_time%TYPE
5494          INDEX BY BINARY_INTEGER;
5495 
5496       TYPE t_old_bld_blk_stop_time IS TABLE OF hxc_time_building_blocks.stop_time%TYPE
5497          INDEX BY BINARY_INTEGER;
5498 
5499       TYPE t_old_bld_blk_measure IS TABLE OF hxc_time_building_blocks.measure%TYPE
5500          INDEX BY BINARY_INTEGER;
5501 
5505       TYPE t_old_bld_blk_type IS TABLE OF hxc_time_building_blocks.TYPE%TYPE
5502       TYPE t_old_bld_blk_scope IS TABLE OF hxc_time_building_blocks.SCOPE%TYPE
5503          INDEX BY BINARY_INTEGER;
5504 
5506          INDEX BY BINARY_INTEGER;
5507 
5508       TYPE t_old_bld_blk_uom IS TABLE OF hxc_time_building_blocks.unit_of_measure%TYPE
5509          INDEX BY BINARY_INTEGER;
5510 
5511       TYPE t_old_bld_blk_date_from IS TABLE OF hxc_time_building_blocks.date_from%TYPE
5512          INDEX BY BINARY_INTEGER;
5513 
5514       TYPE t_old_bld_blk_date_to IS TABLE OF hxc_time_building_blocks.date_to%TYPE
5515          INDEX BY BINARY_INTEGER;
5516 
5517       TYPE t_old_bld_blk_app_status IS TABLE OF hxc_time_building_blocks.approval_status%TYPE
5518          INDEX BY BINARY_INTEGER;
5519 
5520       TYPE t_old_bld_blk_app_style_id IS TABLE OF hxc_time_building_blocks.approval_style_id%TYPE
5521          INDEX BY BINARY_INTEGER;
5522 
5523       TYPE t_old_bld_blk_bb_info_type_id IS TABLE OF hxc_time_attributes.bld_blk_info_type_id%TYPE
5524          INDEX BY BINARY_INTEGER;
5525 
5526       TYPE t_old_bld_blk_att_cat IS TABLE OF hxc_time_attributes.attribute_category%TYPE
5527          INDEX BY BINARY_INTEGER;
5528 
5529       TYPE t_old_bld_blk_attribute1 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5530          INDEX BY BINARY_INTEGER;
5531 
5532       TYPE t_old_bld_blk_attribute2 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5533          INDEX BY BINARY_INTEGER;
5534 
5535       TYPE t_old_bld_blk_attribute3 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5536          INDEX BY BINARY_INTEGER;
5537 
5538       TYPE t_old_bld_blk_attribute4 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5539          INDEX BY BINARY_INTEGER;
5540 
5541       TYPE t_old_bld_blk_attribute5 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5542          INDEX BY BINARY_INTEGER;
5543 
5544       TYPE t_old_bld_blk_attribute6 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5545          INDEX BY BINARY_INTEGER;
5546 
5547       TYPE t_old_bld_blk_attribute7 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5548          INDEX BY BINARY_INTEGER;
5549 
5550       TYPE t_old_bld_blk_attribute8 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5551          INDEX BY BINARY_INTEGER;
5552 
5553       TYPE t_old_bld_blk_attribute9 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5554          INDEX BY BINARY_INTEGER;
5555 
5556       TYPE t_old_bld_blk_attribute10 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5557          INDEX BY BINARY_INTEGER;
5558 
5559       TYPE t_old_bld_blk_attribute11 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5560          INDEX BY BINARY_INTEGER;
5561 
5562       TYPE t_old_bld_blk_attribute12 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5563          INDEX BY BINARY_INTEGER;
5564 
5565       TYPE t_old_bld_blk_attribute13 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5566          INDEX BY BINARY_INTEGER;
5567 
5568       TYPE t_old_bld_blk_attribute14 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5569          INDEX BY BINARY_INTEGER;
5570 
5571       TYPE t_old_bld_blk_attribute15 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5572          INDEX BY BINARY_INTEGER;
5573 
5574       TYPE t_old_bld_blk_attribute16 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5575          INDEX BY BINARY_INTEGER;
5576 
5577       TYPE t_old_bld_blk_attribute17 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5578          INDEX BY BINARY_INTEGER;
5579 
5580       TYPE t_old_bld_blk_attribute18 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5581          INDEX BY BINARY_INTEGER;
5582 
5583       TYPE t_old_bld_blk_attribute19 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5584          INDEX BY BINARY_INTEGER;
5585 
5586       TYPE t_old_bld_blk_attribute20 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5587          INDEX BY BINARY_INTEGER;
5588 
5589       TYPE t_old_bld_blk_attribute21 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5590          INDEX BY BINARY_INTEGER;
5591 
5592       TYPE t_old_bld_blk_attribute22 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5593          INDEX BY BINARY_INTEGER;
5594 
5598       TYPE t_old_bld_blk_attribute24 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5595       TYPE t_old_bld_blk_attribute23 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5596          INDEX BY BINARY_INTEGER;
5597 
5599          INDEX BY BINARY_INTEGER;
5600 
5601       TYPE t_old_bld_blk_attribute25 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5602          INDEX BY BINARY_INTEGER;
5603 
5604       TYPE t_old_bld_blk_attribute26 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5605          INDEX BY BINARY_INTEGER;
5606 
5607       TYPE t_old_bld_blk_attribute27 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5608          INDEX BY BINARY_INTEGER;
5609 
5610       TYPE t_old_bld_blk_attribute28 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5611          INDEX BY BINARY_INTEGER;
5612 
5613       TYPE t_old_bld_blk_attribute29 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5614          INDEX BY BINARY_INTEGER;
5615 
5616       TYPE t_old_bld_blk_attribute30 IS TABLE OF hxc_time_attributes.attribute1%TYPE
5617          INDEX BY BINARY_INTEGER;
5618 
5619       t_old_bb_id                  t_old_bld_blk_bb_id;
5620       t_old_bb_ovn                 t_old_bld_blk_bb_ovn;
5621       t_old_att_bb_id              t_old_bld_blk_bb_id;
5622       t_old_parent_id              t_old_bld_blk_parent_id;
5623       t_old_resource_type          t_old_bld_blk_resource_type;
5624       t_old_resource_id            t_old_bld_blk_resource_id;
5625       t_old_comment_text           t_old_bld_blk_comment_text;
5626       t_old_start_time             t_old_bld_blk_start_time;
5627       t_old_stop_time              t_old_bld_blk_stop_time;
5628       t_old_measure                t_old_bld_blk_measure;
5629       t_old_scope                  t_old_bld_blk_scope;
5630       t_old_type                   t_old_bld_blk_type;
5631       t_old_uom                    t_old_bld_blk_uom;
5632       t_old_date_from              t_old_bld_blk_date_from;
5633       t_old_date_to                t_old_bld_blk_date_to;
5634       t_old_approval_status        t_old_bld_blk_app_status;
5635       t_old_approval_style_id      t_old_bld_blk_app_style_id;
5636       t_old_bld_blk_info_type_id   t_old_bld_blk_bb_info_type_id;
5637       t_old_attribute_category     t_old_bld_blk_att_cat;
5638       t_old_attribute1             t_old_bld_blk_attribute1;
5639       t_old_attribute2             t_old_bld_blk_attribute2;
5640       t_old_attribute3             t_old_bld_blk_attribute3;
5641       t_old_attribute4             t_old_bld_blk_attribute4;
5642       t_old_attribute5             t_old_bld_blk_attribute5;
5643       t_old_attribute6             t_old_bld_blk_attribute6;
5644       t_old_attribute7             t_old_bld_blk_attribute7;
5645       t_old_attribute8             t_old_bld_blk_attribute8;
5646       t_old_attribute9             t_old_bld_blk_attribute9;
5647       t_old_attribute10            t_old_bld_blk_attribute10;
5648       t_old_attribute11            t_old_bld_blk_attribute11;
5649       t_old_attribute12            t_old_bld_blk_attribute12;
5650       t_old_attribute13            t_old_bld_blk_attribute13;
5651       t_old_attribute14            t_old_bld_blk_attribute14;
5652       t_old_attribute15            t_old_bld_blk_attribute15;
5653       t_old_attribute16            t_old_bld_blk_attribute16;
5654       t_old_attribute17            t_old_bld_blk_attribute17;
5655       t_old_attribute18            t_old_bld_blk_attribute18;
5656       t_old_attribute19            t_old_bld_blk_attribute19;
5657       t_old_attribute20            t_old_bld_blk_attribute20;
5658       t_old_attribute21            t_old_bld_blk_attribute21;
5659       t_old_attribute22            t_old_bld_blk_attribute22;
5660       t_old_attribute23            t_old_bld_blk_attribute23;
5661       t_old_attribute24            t_old_bld_blk_attribute24;
5662       t_old_attribute25            t_old_bld_blk_attribute25;
5663       t_old_attribute26            t_old_bld_blk_attribute26;
5664       t_old_attribute27            t_old_bld_blk_attribute27;
5665       t_old_attribute28            t_old_bld_blk_attribute28;
5666       t_old_attribute29            t_old_bld_blk_attribute29;
5667       t_old_attribute30            t_old_bld_blk_attribute30;
5668       l_range_increment            NUMBER                        := 100;
5669       l_lower_range                PLS_INTEGER;
5670       l_upper_range                PLS_INTEGER;
5671       l_bb_index                   PLS_INTEGER;
5672       l_already_multiplied         varchar2(1) := 'N';
5673       l_detail_index               number := 0;
5674       l_old_detail_bb_id           number := -1;
5675       l_number_format              varchar2(2);
5676       l_att26			   number;
5677    BEGIN
5678 -- populate temporary table for detail scope
5679       l_index := t_old_detail_bb_id.COUNT;
5680 
5681       IF g_debug
5682       THEN
5683          l_proc := g_package || 'query_old_timecard';
5684          hr_utility.set_location ('Processing ' || l_proc, 180);
5685       END IF;
5686 
5687       IF (l_index <> 0)
5688       THEN
5689          l_lower_range := t_old_detail_bb_id.FIRST;
5690          l_upper_range :=
5691             LEAST (t_old_detail_bb_id.LAST,
5692                    l_lower_range + l_range_increment);
5693 
5694          WHILE l_lower_range <= t_old_detail_bb_id.LAST
5695          LOOP
5696             FORALL x IN l_lower_range .. l_upper_range
5697                INSERT INTO hxc_tmp_bld_blks
5698                            (seq, time_building_block_id,
5699                             time_building_block_ovn
5700                            )
5701                     VALUES (t_old_detail_seq (x), t_old_detail_bb_id (x),
5702                             t_old_detail_ovn (x)
5703                            );
5704 
5708             END IF;
5705             IF g_debug
5706             THEN
5707                hr_utility.set_location ('Processing ' || l_proc, 190);
5709 
5710             OPEN csr_get_old_detail_bld_blks;
5711 
5712             FETCH csr_get_old_detail_bld_blks
5713             BULK COLLECT INTO t_old_bb_id, t_old_bb_ovn, t_old_parent_id,
5714                    t_old_resource_type, t_old_resource_id, t_old_comment_text,
5715                    t_old_start_time, t_old_stop_time, t_old_measure,
5716                    t_old_scope, t_old_type, t_old_uom, t_old_date_from,
5717                    t_old_date_to, t_old_approval_status,
5718                    t_old_approval_style_id;
5719 
5720             CLOSE csr_get_old_detail_bld_blks;
5721 
5722             IF g_debug
5723             THEN
5724                hr_utility.set_location ('Processing ' || l_proc, 200);
5725             END IF;
5726 
5727             OPEN csr_get_old_attributes;
5728 
5729             FETCH csr_get_old_attributes
5730             BULK COLLECT INTO t_old_att_bb_id, t_old_bld_blk_info_type_id,
5731                    t_old_attribute_category, t_old_attribute1,
5732                    t_old_attribute2, t_old_attribute3, t_old_attribute4,
5733                    t_old_attribute5, t_old_attribute6, t_old_attribute7,
5734                    t_old_attribute8, t_old_attribute9, t_old_attribute10,
5735                    t_old_attribute11, t_old_attribute12, t_old_attribute13,
5736                    t_old_attribute14, t_old_attribute15, t_old_attribute16,
5737                    t_old_attribute17, t_old_attribute18, t_old_attribute19,
5738                    t_old_attribute20, t_old_attribute21, t_old_attribute22,
5739                    t_old_attribute23, t_old_attribute24, t_old_attribute25,
5740                    t_old_attribute26, t_old_attribute27, t_old_attribute28,
5741                    t_old_attribute29, t_old_attribute30;
5742 
5743             CLOSE csr_get_old_attributes;
5744 
5745             IF g_debug
5746             THEN
5747                hr_utility.set_location (   'gaz - old att table is '
5748                                         || TO_CHAR (t_old_att_bb_id.COUNT),
5749                                         999
5750                                        );
5751             END IF;
5752 
5753 -- commit and in doing so clear out temp table
5754             COMMIT;
5755 
5756 -- gaz - test to make sure tmp table is defined correctly in case
5757             OPEN gaz_chk_tmp_table;
5758 
5759             FETCH gaz_chk_tmp_table
5760              INTO l_dummy;
5761 
5762             IF gaz_chk_tmp_table%FOUND
5763             THEN
5764                CLOSE gaz_chk_tmp_table;
5765 
5766                fnd_message.set_name ('HXC', 'HXC_TMP_BLD_BLKS_NOT_TMP');
5767                fnd_message.raise_error;
5768             END IF;
5769 
5770             CLOSE gaz_chk_tmp_table;
5771 
5772 -- populate old bld blk PL/SQL table
5773             IF g_debug
5774             THEN
5775                hr_utility.set_location ('Processing ' || l_proc, 210);
5776             END IF;
5777 	    l_detail_index := l_lower_range-1;	--DAYS Vs HOURS
5778             l_bb_index := l_lower_range;
5779 
5780             FOR x IN t_old_bb_id.FIRST .. t_old_bb_id.LAST
5781             LOOP
5782                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).bb_id :=
5783                                                               t_old_bb_id (x);
5784                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).ovn :=
5785                                                              t_old_bb_ovn (x);
5786                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).parent_bb_id :=
5787                                                           t_old_parent_id (x);
5788                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).resource_type :=
5789                                                       t_old_resource_type (x);
5790                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).resource_id :=
5791                                                         t_old_resource_id (x);
5792                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).comment_text :=
5793                                                        t_old_comment_text (x);
5794                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).start_time :=
5795                                                          t_old_start_time (x);
5796                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).stop_time :=
5797                                                           t_old_stop_time (x);
5798                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).measure :=
5799                                                             t_old_measure (x);
5800                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).SCOPE :=
5801                                                               t_old_scope (x);
5802                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).TYPE :=
5803                                                                t_old_type (x);
5804                l_bb_index := l_bb_index + 1;
5805             END LOOP;
5806 
5807             IF g_debug
5808             THEN
5809                hr_utility.set_location ('Processing ' || l_proc, 220);
5810             END IF;
5811 
5812             l_index := hxc_generic_retrieval_pkg.t_old_detail_bld_blks.COUNT;
5813 
5814             IF g_debug
5815             THEN
5816                hr_utility.set_location
5820                                );
5817                                (   'gaz GLOBAL old DETAIL bld blk count is '
5818                                 || TO_CHAR (l_index),
5819                                 999
5821             END IF;
5822 
5823             l_index := hxc_generic_retrieval_pkg.t_old_detail_attributes.COUNT;
5824 
5825             IF g_debug
5826             THEN
5827                hr_utility.set_location (   'gaz time att count is '
5828                                         || TO_CHAR (l_index),
5829                                         999
5830                                        );
5831             END IF;
5832 
5833             IF (t_old_att_bb_id.COUNT <> 0)
5834             THEN
5835                IF g_debug
5836                THEN
5837                   hr_utility.set_location ('Processing ' || l_proc, 230);
5838                END IF;
5839 
5840                FOR x IN t_old_att_bb_id.FIRST .. t_old_att_bb_id.LAST
5841                LOOP
5842                   t_bb (x).detail_bb_id := t_old_att_bb_id (x);
5843                   t_bb (x).detail_bld_blk_info_type_id :=
5844                                                t_old_bld_blk_info_type_id (x);
5845                   t_bb (x).detail_attribute_category :=
5846                                                  t_old_attribute_category (x);
5847                   t_bb (x).detail_attribute1 := t_old_attribute1 (x);
5848                   t_bb (x).detail_attribute2 := t_old_attribute2 (x);
5849                   t_bb (x).detail_attribute3 := t_old_attribute3 (x);
5850                   t_bb (x).detail_attribute4 := t_old_attribute4 (x);
5851                   t_bb (x).detail_attribute5 := t_old_attribute5 (x);
5852                   t_bb (x).detail_attribute6 := t_old_attribute6 (x);
5853                   t_bb (x).detail_attribute7 := t_old_attribute7 (x);
5854                   t_bb (x).detail_attribute8 := t_old_attribute8 (x);
5855                   t_bb (x).detail_attribute9 := t_old_attribute9 (x);
5856                   t_bb (x).detail_attribute10 := t_old_attribute10 (x);
5857                   t_bb (x).detail_attribute11 := t_old_attribute11 (x);
5858                   t_bb (x).detail_attribute12 := t_old_attribute12 (x);
5859                   t_bb (x).detail_attribute13 := t_old_attribute13 (x);
5860                   t_bb (x).detail_attribute14 := t_old_attribute14 (x);
5861                   t_bb (x).detail_attribute15 := t_old_attribute15 (x);
5862                   t_bb (x).detail_attribute16 := t_old_attribute16 (x);
5863                   t_bb (x).detail_attribute17 := t_old_attribute17 (x);
5864                   t_bb (x).detail_attribute18 := t_old_attribute18 (x);
5865                   t_bb (x).detail_attribute19 := t_old_attribute19 (x);
5866                   t_bb (x).detail_attribute20 := t_old_attribute20 (x);
5867                   t_bb (x).detail_attribute21 := t_old_attribute21 (x);
5868                   t_bb (x).detail_attribute22 := t_old_attribute22 (x);
5869                   t_bb (x).detail_attribute23 := t_old_attribute23 (x);
5870                   t_bb (x).detail_attribute24 := t_old_attribute24 (x);
5871                   t_bb (x).detail_attribute25 := t_old_attribute25 (x);
5872                   t_bb (x).detail_attribute26 := t_old_attribute26 (x);
5873                   t_bb (x).detail_attribute27 := t_old_attribute27 (x);
5874                   t_bb (x).detail_attribute28 := t_old_attribute28 (x);
5875                   t_bb (x).detail_attribute29 := t_old_attribute29 (x);
5876                   t_bb (x).detail_attribute30 := t_old_attribute30 (x);
5877 
5878                   --********DAYS Vs HOURS*******
5879                  IF g_params.p_process = 'Projects Retrieval Process' THEN
5880 		  IF (t_bb (x).detail_bb_id <> l_old_detail_bb_id) then
5881 			l_old_detail_bb_id := t_bb (x).detail_bb_id;
5882 			l_already_multiplied := 'N';
5883 			l_detail_index :=l_detail_index+1;
5884 		  END IF;
5885 
5886 		  IF l_detail_index BETWEEN hxc_generic_retrieval_pkg.t_old_detail_bld_blks.FIRST
5887 		      AND hxc_generic_retrieval_pkg.t_old_detail_bld_blks.LAST
5888 		  THEN
5889 
5890 		     IF  hxc_generic_retrieval_pkg.t_old_detail_bld_blks(l_detail_index).bb_id =
5891 				t_bb(x).detail_bb_id THEN
5892 
5893 			IF l_number_format = ',.'  THEN --EUROPEAN FORMAT
5894 			   l_att26 := to_number(replace(t_bb(x).detail_attribute26,'.',','));
5895 		        ELSIF  l_number_format = '.,'  THEN --US FORMAT
5896 			   l_att26 := to_number(replace(t_bb(x).detail_attribute26,',','.'));
5897 			END IF;
5898 			 IF NVL(l_att26,1) <> 1 AND l_already_multiplied = 'N' THEN
5899 
5900 			hxc_generic_retrieval_pkg.t_old_detail_bld_blks(l_detail_index).measure :=
5901 			hxc_generic_retrieval_pkg.t_old_detail_bld_blks(l_detail_index).measure *
5902 			l_att26;
5903 
5904 			l_already_multiplied := 'Y';
5905 
5906 			 END IF;
5907 		     END IF;
5908 
5909 		  END IF;
5910 		 END IF;
5911 		  --********DAYS VS HOURS*******
5912 
5913 
5914                END LOOP;
5915 
5916                l_index := hxc_generic_retrieval_pkg.t_bb.COUNT;
5917 
5918                IF g_debug
5919                THEN
5920                   hr_utility.set_location (   'gaz t bb count is '
5921                                            || TO_CHAR (l_index),
5922                                            999
5923                                           );
5924                END IF;
5925 
5926                IF g_debug
5927                THEN
5928                   hr_utility.set_location ('Processing ' || l_proc, 240);
5929                END IF;
5930 
5931                FOR x IN t_bb.FIRST .. t_bb.LAST
5935                                  p_attribute_table        => t_bb,
5932                LOOP
5933                   populate_attributes
5934                                 (p_building_block_id      => t_bb (x).detail_bb_id,
5936                                  p_cnt                    => x,
5937                                  p_scope                  => 'DETAIL',
5938                                  p_new                    => 'N'
5939                                 );
5940                END LOOP;
5941             END IF;                          -- ( t_old_att_bb_id.COUNT <> 0 )
5942 
5943             IF g_debug
5944             THEN
5945                hr_utility.set_location ('Processing ' || l_proc, 250);
5946             END IF;
5947 
5948 -- truncate temporary tables and delete arrays and table
5949             t_bb.DELETE;
5950             t_old_bb_id.DELETE;
5951             t_old_att_bb_id.DELETE;
5952             t_old_parent_id.DELETE;
5953             t_old_resource_type.DELETE;
5954             t_old_resource_id.DELETE;
5955             t_old_comment_text.DELETE;
5956             t_old_start_time.DELETE;
5957             t_old_stop_time.DELETE;
5958             t_old_measure.DELETE;
5959             t_old_scope.DELETE;
5960             t_old_type.DELETE;
5961             t_old_uom.DELETE;
5962             t_old_date_from.DELETE;
5963             t_old_date_to.DELETE;
5964             t_old_approval_status.DELETE;
5965             t_old_approval_style_id.DELETE;
5966             t_old_bld_blk_info_type_id.DELETE;
5967             t_old_attribute1.DELETE;
5968             t_old_attribute2.DELETE;
5969             t_old_attribute3.DELETE;
5970             t_old_attribute4.DELETE;
5971             t_old_attribute5.DELETE;
5972             t_old_attribute6.DELETE;
5973             t_old_attribute7.DELETE;
5974             t_old_attribute8.DELETE;
5975             t_old_attribute9.DELETE;
5976             t_old_attribute10.DELETE;
5977             t_old_attribute11.DELETE;
5978             t_old_attribute12.DELETE;
5979             t_old_attribute13.DELETE;
5980             t_old_attribute14.DELETE;
5981             t_old_attribute15.DELETE;
5982             t_old_attribute16.DELETE;
5983             t_old_attribute17.DELETE;
5984             t_old_attribute18.DELETE;
5985             t_old_attribute19.DELETE;
5986             t_old_attribute20.DELETE;
5987             t_old_attribute21.DELETE;
5988             t_old_attribute22.DELETE;
5989             t_old_attribute23.DELETE;
5990             t_old_attribute24.DELETE;
5991             t_old_attribute25.DELETE;
5992             t_old_attribute26.DELETE;
5993             t_old_attribute27.DELETE;
5994             t_old_attribute28.DELETE;
5995             t_old_attribute29.DELETE;
5996             t_old_attribute30.DELETE;
5997             l_lower_range := l_upper_range + 1;
5998             l_upper_range :=
5999                LEAST (l_upper_range + l_range_increment,
6000                       t_old_detail_bb_id.LAST
6001                      );
6002          END LOOP;           -- while l_lower_range <= t_old_detail_bb_id.LAST
6003 
6004          IF g_debug
6005          THEN
6006             hr_utility.set_location ('Processing ' || l_proc, 260);
6007          END IF;
6008       END IF;                                           -- IF ( l_index <> 0 )
6009 --if g_debug then
6010    -- hr_utility.set_location('Processing '||l_proc, 270);
6011 --end if;
6012    END query_old_timecard;
6013 
6014 --
6015 -- procedure
6016 --   execute_retrieval_process
6017 --
6018 -- description
6019 --   this is the main procedure for the retrieval process. The basic process
6020 --   flow is as follows
6021 --
6022 --       check the retrieval process is registered
6023 --       (chk_retrieval_process)
6024 --          |
6025 --       check no other retrieval running
6026 --    (check_concurrency_ok)
6027 --       |
6028 --              audit the transaction header
6029 --                      |
6030 --    get the field mappings for this retrieval process
6031 --    and populate global PL/SQL table
6032 --    (get_field_mappings)
6033 --       |
6034 --    parse the user defined WHERE clause
6035 --    (parse_it)
6036 --       |
6037 --    build the dynamic SQL query based on parameters passed
6038 --    (build_query)
6039 --       |
6040 --    execute the query
6041 --    (query_it)
6042 --       |
6043 --    populate the transaction tables
6044 --    (audit_transaction)
6045 --          |
6046 --    query the old time card if appropriate
6047 --    (query_old_timecard)
6048 --
6049 --
6050 --
6051 -- parameters
6052 --   p_process    - name of the process registered in hxc_retrieval_processes
6053 --   p_transaction_code - user defined transaction code used for rerun
6054 --   p_start_date - start date of the retrieval window
6055 --   p_end_date      - end date of the retrieval window
6056 --   p_incremental   - incremental (Y/N)
6057 --   p_rerun_flag - rerun flag (Y/N)
6058 --   p_where_clause  - user specified where clause
6059 --   p_scope      - driving scope - which bld blk scope we drive the date window
6060 --   p_clusive    - INclusive or EXclusive dates in the date window
6061 --         (i.e. INclude or EXClude bld blks which do not completely
6062 --                         fit in the date window)
6063 --
6064    PROCEDURE execute_retrieval_process (
6068       p_end_date           IN   DATE DEFAULT NULL,
6065       p_process            IN   hxc_retrieval_processes.NAME%TYPE,
6066       p_transaction_code   IN   VARCHAR2,
6067       p_start_date         IN   DATE DEFAULT NULL,
6069       p_incremental        IN   VARCHAR2 DEFAULT 'Y',
6070       p_rerun_flag         IN   VARCHAR2 DEFAULT 'N',
6071       p_where_clause       IN   VARCHAR2,
6072       p_scope              IN   VARCHAR2 DEFAULT 'DAY',
6073       p_clusive            IN   VARCHAR2 DEFAULT 'EX',
6074       p_unique_params      IN   VARCHAR2 DEFAULT NULL,
6075       p_since_date         IN   VARCHAR2 DEFAULT NULL
6076    )
6077    IS
6078 -- debug local variables
6079       l_debug                      VARCHAR2 (1);
6080       l_gaz_cnt                    PLS_INTEGER;
6081       l_gaz_att                    PLS_INTEGER;
6082       loop_ok                      BOOLEAN                            := TRUE;
6083       l_message_table              hxc_message_table_type;
6084       l_boolean                    BOOLEAN;
6085       l_bld_blks                   hxc_generic_retrieval_pkg.t_building_blocks;
6086       l_atts                       hxc_generic_retrieval_pkg.t_time_attribute;
6087       l_att_index                  PLS_INTEGER                          := -1;
6088 
6089       CURSOR csr_debug
6090       IS
6091          SELECT 'Y'
6092            FROM hxc_debug
6093           WHERE process = 'RETRIEVAL' AND TRUNC (debug_date) =
6094                                                               TRUNC (SYSDATE);
6095 
6096       l_sql                        VARCHAR2 (2000);
6097       l_since_date                 VARCHAR2 (100);
6098       l_proc                       VARCHAR2 (72)
6099                                   := g_package || 'execute_retrieval_process';
6100       l_mapping_id                 hxc_mappings.mapping_id%TYPE       := NULL;
6101       l_ret_id                     hxc_retrieval_processes.retrieval_process_id%TYPE;
6102       e_retrieval_not_registered   EXCEPTION;
6103       e_process_already_running    EXCEPTION;
6104       l_where_clause_blk           VARCHAR2 (2000);
6105       l_where_clause_att           VARCHAR2 (2000);
6106       l_dynamic_query              VARCHAR2 (32000);
6107       l_transaction_id             NUMBER (15);
6108 
6109 -- define private functions and procedures
6110 
6111       -- private function
6112 --   build_query
6113 --
6114 -- description
6115 --   This function builds the dynamic query based on the parameters passed
6116 --   to the retrieval API.
6117 --   The query is broken down into its component forms of SELECT, FROM, WHERE
6118 --   and ORDER BY. The WHERE predicates are further broken down into timecard
6119 --   scopes. There are two SELECT portions, one for incremental and one for
6120 --   non incremental
6121 -- l_incremental_select
6122 -- l_select
6123 --   There are three FROMs, one for the rerun retrieval, one for the non incremental
6124 --   and one for the incremental
6125 -- l_from
6126 --      l_incremental_from
6127 --      l_rerun
6128 --   Since we also control which scope of building block we are interested
6129 --   in the time window restricting upon the WHERE is broken down into
6130 --   bld blks scopes. Furthermore, within this the user is able to specify
6131 --   whether or not the date range is INclusive or EXclusive of time bld
6132 --   blks
6133 -- l_time
6134 -- l_time_ex
6135 -- l_time_in
6136 -- l_day
6137 -- l_day_ex
6138 -- l_day_in
6139 -- l_detail
6140 -- l_detail_ex
6141 -- l_detail_in
6142 --   Finally the order by which currently is static.
6143 -- l_order_by
6144 --
6145 -- Parameters
6146 --   p_where_clause - the recipient API defined where clause
6147       FUNCTION build_query (
6148          p_where_clause_blk   VARCHAR2,
6149          p_where_clause_att   VARCHAR2
6150       )
6151          RETURN VARCHAR2
6152       IS
6153          l_hint                  VARCHAR2 (170)
6154             := '
6155 SELECT /*+ ordered use_nl( tbb
6156              detail_block detail_usage detail_att
6157              day_block timecard_block
6158              detail_max_ovn ) */ ';
6159          l_incremental_select    VARCHAR2 (1860)
6160             := '
6161 	timecard_block.time_building_block_id
6162 ,	timecard_block.object_version_number
6163 ,	day_block.time_building_block_id
6164 ,	day_block.object_version_number
6165 ,	day_block.start_time
6166 ,	day_block.stop_time
6167 ,	detail_block.time_building_block_id
6168 ,	detail_block.object_version_number
6169 ,	detail_block.parent_building_block_id
6170 ,	detail_block.resource_type
6171 ,	detail_block.resource_id
6172 ,	detail_block.comment_text
6173 ,	detail_block.start_time
6174 ,	detail_block.stop_time
6175 ,	detail_block.measure
6176 ,	detail_block.scope
6177 ,	detail_block.type
6178 ,	detail_att.time_attribute_id
6179 ,	detail_att.bld_blk_info_type_id
6180 ,	detail_att.attribute1
6181 ,	detail_att.attribute2
6182 ,	detail_att.attribute3
6183 ,	detail_att.attribute4
6184 ,	detail_att.attribute5
6185 ,	detail_att.attribute6
6186 ,	detail_att.attribute7
6187 ,	detail_att.attribute8
6188 ,	detail_att.attribute9
6189 ,	detail_att.attribute10
6190 ,	detail_att.attribute11
6191 ,	detail_att.attribute12
6192 ,	detail_att.attribute13
6193 ,	detail_att.attribute14
6194 ,	detail_att.attribute15
6195 ,	detail_att.attribute16
6196 ,	detail_att.attribute17
6197 ,	detail_att.attribute18
6198 ,	detail_att.attribute19
6199 ,	detail_att.attribute20
6203 ,	detail_att.attribute24
6200 ,	detail_att.attribute21
6201 ,	detail_att.attribute22
6202 ,	detail_att.attribute23
6204 ,	detail_att.attribute25
6205 ,	detail_att.attribute26
6206 ,	detail_att.attribute27
6207 ,	detail_att.attribute28
6208 ,	detail_att.attribute29
6209 ,	detail_att.attribute30
6210 ,	detail_block.date_from
6211 ,	detail_block.date_to
6212 ,	detail_block.approval_status
6213 ,	detail_block.approval_style_id
6214 ,	DECODE ( detail_block.date_to, hr_general.end_of_time, ''N'', ''Y'' )
6215 ,	detail_att.attribute_category
6216 ,       1
6217 ,       1
6218 ,       NVL(detail_max_ovn.max_ovn, 0)
6219 ,	detail_block.unit_of_measure
6220 ,	timecard_block.start_time
6221 ,	timecard_block.stop_time
6222 ,       timecard_block.comment_text
6223 ,	DECODE ( timecard_block.date_to, hr_general.end_of_time, ''N'', ''Y'' ) ';
6224          l_select                VARCHAR2 (1945)
6225             := '
6226 SELECT /*+ ordered use_nl(
6227              detail_block detail_usage detail_att
6228              day_block timecard_block
6229              detail_max_ovn ) */
6230 	timecard_block.time_building_block_id
6231 ,	timecard_block.object_version_number
6232 ,	day_block.time_building_block_id
6233 ,	day_block.object_version_number
6234 ,	day_block.start_time
6235 ,	day_block.stop_time
6236 ,	detail_block.time_building_block_id
6237 ,	detail_block.object_version_number
6238 ,	detail_block.parent_building_block_id
6239 ,	detail_block.resource_type
6240 ,	detail_block.resource_id
6241 ,	detail_block.comment_text
6242 ,	detail_block.start_time
6243 ,	detail_block.stop_time
6244 ,	detail_block.measure
6245 ,	detail_block.scope
6246 ,	detail_block.type
6247 ,	detail_att.time_attribute_id
6248 ,	detail_att.bld_blk_info_type_id
6249 ,	detail_att.attribute1
6250 ,	detail_att.attribute2
6251 ,	detail_att.attribute3
6252 ,	detail_att.attribute4
6253 ,	detail_att.attribute5
6254 ,	detail_att.attribute6
6255 ,	detail_att.attribute7
6256 ,	detail_att.attribute8
6257 ,	detail_att.attribute9
6258 ,	detail_att.attribute10
6259 ,	detail_att.attribute11
6260 ,	detail_att.attribute12
6261 ,	detail_att.attribute13
6262 ,	detail_att.attribute14
6263 ,	detail_att.attribute15
6264 ,	detail_att.attribute16
6265 ,	detail_att.attribute17
6266 ,	detail_att.attribute18
6267 ,	detail_att.attribute19
6268 ,	detail_att.attribute20
6269 ,	detail_att.attribute21
6270 ,	detail_att.attribute22
6271 ,	detail_att.attribute23
6272 ,	detail_att.attribute24
6273 ,	detail_att.attribute25
6274 ,	detail_att.attribute26
6275 ,	detail_att.attribute27
6276 ,	detail_att.attribute28
6277 ,	detail_att.attribute29
6278 ,	detail_att.attribute30
6279 ,	detail_block.date_from
6280 ,	detail_block.date_to
6281 ,	detail_block.approval_status
6282 ,	detail_block.approval_style_id
6283 ,	DECODE ( detail_block.date_to, hr_general.end_of_time, ''N'', ''Y'' )
6284 ,	detail_att.attribute_category
6285 ,       1
6286 ,       1
6287 ,	detail_block.object_version_number -1
6288 ,	detail_block.unit_of_measure
6289 ,	timecard_block.start_time
6290 ,	timecard_block.stop_time
6291 ,       timecard_block.comment_text
6292 ,	DECODE ( timecard_block.date_to, hr_general.end_of_time, ''N'', ''Y'' ) ';
6293          l_from                  VARCHAR2 (200)
6294             := '
6295 FROM
6296 	hxc_time_building_blocks	timecard_block
6297 ,	hxc_time_building_blocks	day_block
6298 ,	Hxc_time_building_blocks	detail_block
6299 ,	Hxc_time_attribute_usages	detail_usage
6300 ,	Hxc_time_attributes		detail_att';
6301          l_inline_view_range     VARCHAR2 (800)
6302             := '
6303 FROM
6304 	(select /*+ no_merge ordered */
6305         time_building_block_id,
6306 	object_version_number
6307 from 	Hxc_latest_details tbb_latest
6308 where	tbb_latest.resource_id BETWEEN :p_lower_range and :p_upper_range
6309 and     tbb_latest.approval_status <> ''ERROR''
6310 AND	NOT EXISTS (select ''x''
6311 			FROM	hxc_transaction_details txd
6312 			,	hxc_transactions tx
6313 			WHERE	tx.transaction_process_id	= :p_process_id
6314 			AND	tx.type				= ''RETRIEVAL''
6315 			AND	tx.status			= ''SUCCESS''
6316 			AND	tx.transaction_id		= txd.transaction_id
6317 			AND	txd.status			= ''SUCCESS''
6318 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
6319 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
6320 		)
6321 ';
6322          l_inline_view           VARCHAR2 (2000)
6323 	             := '
6324 	 FROM
6325 	 	(select /*+ no_merge ordered */
6326 	         tbb_latest.time_building_block_id,
6327 	 	tbb_latest.object_version_number
6328 	 from 	hxc_retrieval_ranges rr,
6329 	         hxc_retrieval_range_resources rrr,
6330 	         hxc_latest_details tbb_latest
6331 	 where	rr.retrieval_range_id = :p_rr_id AND
6332 	         rr.retrieval_range_id = rrr.retrieval_range_id AND
6333 	         tbb_latest.resource_id = rrr.resource_id AND
6334 	         tbb_latest.last_update_date > :p_since_date
6335 	         AND tbb_latest.approval_status <> ''ERROR''
6336 	 AND	NOT EXISTS (select ''x''
6337 	 			FROM	hxc_transaction_details txd
6338 	 			,	hxc_transactions tx
6339 	 			WHERE	tx.transaction_process_id	= :p_process_id
6340 	 			AND	tx.type				= ''RETRIEVAL''
6341 	 			AND	tx.status			= ''SUCCESS''
6342 	 			AND	tx.transaction_id		= txd.transaction_id
6343 	 			AND	txd.status			= ''SUCCESS''
6347 ';
6344 	 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
6345 	 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
6346 	 		)
6348          l_noloop_from           VARCHAR2 (250)
6349             := '
6350  ) tbb
6351 ,	Hxc_time_building_blocks        detail_block
6352 ,	Hxc_time_attribute_usages	detail_usage
6353 ,	Hxc_time_attributes		detail_att
6354 ,	hxc_time_building_blocks	day_block
6355 ,	hxc_time_building_blocks	timecard_block
6356 ,	hxc_max_ovn			detail_max_ovn';
6357          l_incremental_from      VARCHAR2 (400)
6358             := '
6359 FROM
6360         hxc_retrieval_range_blks        tbb
6361 ,	Hxc_time_building_blocks        detail_block
6362 ,	Hxc_time_attribute_usages	detail_usage
6363 ,	Hxc_time_attributes		detail_att
6364 ,	hxc_time_building_blocks	day_block
6365 ,	hxc_time_building_blocks	timecard_block
6366 ,	hxc_latest_details    hld
6367 ,	hxc_max_ovn			detail_max_ovn';
6368          l_time                  VARCHAR2 (400)
6369             := '
6370 WHERE
6371         timecard_block.scope = ''TIMECARD'' AND
6372         timecard_block.approval_status <> ''ERROR'' AND
6373         timecard_block.object_version_number = (
6374                 SELECT  /*+ no_unnest */ MAX ( tovn.object_version_number )
6375                 FROM    hxc_time_building_blocks tovn
6376                 WHERE   tovn.time_building_block_id = timecard_block.time_building_block_id ) ';
6377          l_time_ex               VARCHAR2 (560)
6378             := '
6379 WHERE
6380         timecard_block.scope = ''TIMECARD'' AND
6381         timecard_block.approval_status <> ''ERROR'' AND
6382         timecard_block.object_version_number = (
6383                 SELECT   /*+ no_unnest */ MAX ( tovn.object_version_number )
6384                 FROM    hxc_time_building_blocks tovn
6385                 WHERE   tovn.time_building_block_id = timecard_block.time_building_block_id )
6386 AND
6387         timecard_block.start_time
6388         BETWEEN :p_start_date AND :p_end_date AND
6389         timecard_block.stop_time
6390         BETWEEN :p_start_date AND :p_end_date ';
6391          l_time_in               VARCHAR2 (650)
6392             := '
6393 WHERE
6394         timecard_block.scope = ''TIMECARD'' AND
6395         timecard_block.approval_status <> ''ERROR'' AND
6396         timecard_block.object_version_number = (
6397                 SELECT   /*+ no_unnest */ MAX ( tovn.object_version_number )
6398 		FROM    hxc_time_building_blocks tovn
6399                 WHERE   tovn.time_building_block_id = timecard_block.time_building_block_id )
6400         AND
6401         :p_start_date   <=      timecard_block.stop_time   AND
6402         :p_end_date     >=      timecard_block.start_time ';
6403          l_day                   VARCHAR2 (600)
6404             := '
6405 AND
6406         day_block.parent_building_block_id
6407                                 = timecard_block.time_building_block_id AND
6408         day_block.scope         = ''DAY'' AND
6409         day_block.approval_status <> ''ERROR'' AND
6410         day_block.object_version_number = (
6411                 SELECT  /*+ no_unnest */ MAX ( dyovn.object_version_number )
6412 		FROM    hxc_time_building_blocks dyovn
6413                 WHERE   dyovn.time_building_block_id = day_block.time_building_block_id ) ';
6414          l_detail                VARCHAR2 (350)
6415             := '
6416 AND
6417         detail_block.parent_building_block_id  = day_block.time_building_block_id
6418 AND
6419         detail_usage.time_building_block_id  = detail_block.time_building_block_id AND
6420         detail_usage.time_building_block_ovn = detail_block.object_version_number
6421 AND
6422         detail_att.time_attribute_id = detail_usage.time_attribute_id';
6423          l_inline_day_ex         VARCHAR2 (200)
6424             := '
6425 AND
6426         tbb_latest.start_time
6427         BETWEEN :p_start_date AND :p_end_date	AND
6428         tbb_latest.stop_time
6429         BETWEEN :p_start_date AND :p_end_date ';
6430          l_inline_day_in         VARCHAR2 (200)
6431             := '
6432 AND
6433         :p_start_date <= tbb_latest.stop_time	AND
6434         :p_end_date   >= tbb_latest.start_time ';
6435          l_rerun                 VARCHAR2 (1100)
6436             := '
6437 FROM
6438 	hxc_time_attributes		detail_att
6439 ,	hxc_time_attribute_usages	detail_usage
6440 ,	hxc_time_building_blocks	detail_block
6441 ,	hxc_time_building_blocks	day_block
6442 ,	hxc_time_attributes		timecard_att
6443 ,	hxc_transaction_details		txd
6444 ,	hxc_transactions		tx
6445 WHERE
6446 	tx.transaction_code	= :p_transaction_code
6447 AND
6448 	txd.transaction_id	= tx.transaction_id
6449 AND
6450 	timecard_block.time_building_block_id	= txd.time_building_block_id	AND
6451 	timecard_block.object_version_number	= txd.time_building_block_ovn	AND
6452 	timecard_block.scope 	= ''TIMECARD''
6453 AND
6454 	day_block.parent_building_block_id
6455 				= timecard_block.time_building_block_id AND
6456 	day_block.scope		= ''DAY''	AND
6457 	day_block.time_building_block_id	= txd.time_building_block_id	AND
6458 	day_block.object_version_number		= txd.time_building_block_ovn
6459 AND
6460 	detail_block.parent_building_block_id	= day_block.time_building_block_id AND
6461 	detail_block.scope			= ''DETAIL'' AND
6462 	detail_block.time_building_block_id	= txd.time_building_block_id	AND
6463 	detail_block.object_version_number	= txd.time_building_block_ovn';
6464 -- GPM v115.41
6465          /*l_not_exists            VARCHAR2 (500)
6466             := '
6467  AND
6468     detail_max_ovn.time_building_block_id(+) = detail_block.time_building_block_id
6469 AND
6470 	detail_block.time_building_block_id = tbb.time_building_block_id AND
6471 	detail_block.object_version_number  = tbb.object_version_number';*/
6472 
6473 	l_not_exists            VARCHAR2 (500)
6474 		             := '
6475 		  AND
6476 		     detail_max_ovn.time_building_block_id(+) = detail_block.time_building_block_id
6477 		 AND
6478 		 	detail_block.time_building_block_id = tbb.time_building_block_id AND
6479 		 	detail_block.object_version_number  = tbb.object_version_number
6480 		 	AND( ( detail_block.start_time IS NOT NULL AND detail_block.stop_time IS NOT NULL )
6481 		 	OR (detail_block.measure IS NOT NULL))
6482 	';
6483 
6484          l_latest_double_check   VARCHAR2 (400)
6485             := ' AND detail_block.time_building_block_id = hld.time_building_block_id
6486                  AND detail_block.object_version_number  = hld.object_version_number';
6487          l_order_by              VARCHAR2 (200)
6488             := '
6489 ORDER BY
6490         timecard_block.resource_id
6491 ,	timecard_block.start_time
6492 ,       timecard_block.time_building_block_id
6493 ,       day_block.start_time
6494 ,	detail_block.time_building_block_id';
6495          l_time_store_query      VARCHAR2 (32000);
6496          l_inline_day            VARCHAR2 (200)   := ' ';
6497          l_app_set               VARCHAR2 (200);
6498       BEGIN                                                     -- build query
6499 --Elp changes sonarasi 14-Mar-2003
6500 --A string of application set ids like (1,2,3,5) etc are obtained for the corresponding time
6501 --recipient id of the application. As per ELP changes, the Application Set Id for the detail,
6502 --day and timecard scopes are added in hxc_time_building_blocks table. Here we retrieve only
6503 --blocks that the Retrieval Application is interested in. So we just add to the where clause
6504 --to compare if the detail building block's application set id is within the list of
6505 --application set ids generated for the corresponding time recipient.
6506          l_app_set :=
6507                     g_app_set_id_string (g_retrieval_tr_id).app_set_id_string;
6508 
6509 --Elp changes sonarasi over
6510          IF (g_params.p_rerun_flag = 'Y')
6511          THEN
6512             l_time_store_query := l_select || l_rerun || l_order_by;
6513          ELSIF (g_params.p_start_date IS NULL AND g_params.p_end_date IS NULL
6514                )
6515          THEN
6516             l_time_store_query := l_time || l_day || l_detail;
6517          ELSIF (g_params.p_scope = 'TIME')
6518          THEN
6519             IF (g_params.p_clusive = 'EX')
6520             THEN
6521                l_time_store_query := l_time_ex || l_day || l_detail;
6522             ELSIF (g_params.p_clusive = 'IN')
6523             THEN
6524                l_time_store_query := l_time_in || l_day || l_detail;
6525             ELSE
6526                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
6527                fnd_message.raise_error;
6528             END IF;
6529          ELSIF (g_params.p_scope = 'DAY')
6530          THEN
6531             IF (g_params.p_clusive = 'EX')
6532             THEN
6533                l_time_store_query := l_time || l_day || l_detail;
6534                l_inline_day := l_inline_day_ex;
6535             ELSIF (g_params.p_clusive = 'IN')
6536             THEN
6537                l_time_store_query := l_time || l_day || l_detail;
6538                l_inline_day := l_inline_day_in;
6539             ELSE
6540                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
6544          THEN
6541                fnd_message.raise_error;
6542             END IF;
6543          ELSIF (g_params.p_scope = 'DETAIL')
6545             IF (g_params.p_clusive = 'EX')
6546             THEN
6547                l_time_store_query := l_time || l_day || l_detail;
6548                l_inline_day := l_inline_day_ex;
6549             ELSIF (g_params.p_clusive = 'IN')
6550             THEN
6551                l_time_store_query := l_time || l_day || l_detail;
6552                l_inline_day := l_inline_day_in;
6553             ELSE
6554                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
6555                fnd_message.raise_error;
6556             END IF;
6557          ELSE
6558             fnd_message.set_name ('HXC', 'HXC_0015_GNRET_INVLD_P_SCOPE');
6559             fnd_message.raise_error;
6560          END IF;
6561 
6562          IF (g_params.p_rerun_flag = 'N')
6563          THEN
6564             IF (g_params.p_incremental = 'Y')
6565             THEN
6566                IF (g_params.p_process IN
6567                             ('BEE Retrieval Process', 'Apply Schedule Rules')
6568                   )
6569                THEN
6570                   -- since the Transfer from OTL to BEE default where is a resource id filter
6571                   -- there is no need to include this in this query since it has already been
6572                   -- applied to populate the hxc retrieval range resource table
6573                   l_time_store_query :=
6574                         l_hint
6575                      || l_incremental_select
6576                      || l_incremental_from
6577                      || l_time_store_query
6578                      || l_not_exists
6579                      || l_latest_double_check
6580                      || l_order_by;
6581                ELSIF (g_params.p_process IN
6582                          ('Purchasing Retrieval Process',
6583                           'Projects Retrieval Process'
6584                          )
6585                      )
6586                THEN
6587                   -- Applications whose default where does not filter on person and LOOP
6588                   l_time_store_query :=
6589                         l_hint
6590                      || l_incremental_select
6591                      || l_incremental_from
6592                      || l_time_store_query
6593                      || p_where_clause_blk
6594                      || p_where_clause_att
6595                      || l_not_exists
6596                      || l_latest_double_check
6597                      || l_order_by;
6598                ELSIF (g_params.p_process IN ('Maintenance Retrieval Process')
6599                      )
6600                THEN
6601                   -- Applications which do not LOOP
6602                   l_time_store_query :=
6603                         l_hint
6604                      || l_incremental_select
6605                      || l_inline_view_range
6606                      || l_inline_day
6607                      || l_app_set
6608                      || p_where_clause_blk
6609                      || l_noloop_from
6610                      || l_time_store_query
6611                      || p_where_clause_att
6612                      || l_not_exists
6613                      || l_order_by;
6614                ELSE
6615                   fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
6616                   fnd_message.set_token ('PROCEDURE', 'Integration catch');
6617                   fnd_message.set_token ('STEP', ': whereclause');
6618                   fnd_message.raise_error;
6619                END IF;
6620             ELSE
6621                l_time_store_query :=
6622                      l_select
6623                   || l_from
6624                   || l_time_store_query
6625                   || l_app_set
6626                   || p_where_clause_blk
6627                   || p_where_clause_att
6628                   || l_order_by;
6629             END IF;
6630          END IF;
6631 
6632          RETURN l_time_store_query;
6633       END build_query;
6634 
6635       FUNCTION check_concurrency_ok (
6636          p_process_id          NUMBER,
6637          p_retrieval_process   VARCHAR2,
6638          p_where_clause        VARCHAR2,
6639          p_unique_params       VARCHAR2
6640       )
6641          RETURN BOOLEAN
6642       IS
6643          CURSOR chk_transaction
6644          IS
6645             SELECT transaction_id
6646               FROM hxc_transactions tx
6647              WHERE transaction_process_id = p_process_id
6648                AND status = 'IN PROGRESS';
6649 
6650          CURSOR csr_chk_where_clause (
6651             p_transaction_id   NUMBER,
6652             p_where_clause     VARCHAR2,
6653             p_unique_params    VARCHAR2
6654          )
6655          IS
6656             SELECT 'x'
6657               FROM hxc_retrieval_ranges rr
6658              WHERE rr.transaction_id = p_transaction_id
6659                AND (   rr.where_clause = p_where_clause
6660                     OR (p_where_clause IS NULL AND rr.where_clause IS NULL)
6661                    )
6662                AND (   rr.unique_params = p_unique_params
6663                     OR (p_unique_params IS NULL AND rr.unique_params IS NULL
6664                        )
6665                    );
6666 
6667          CURSOR csr_chk_range_exists (p_transaction_id NUMBER)
6668          IS
6669             SELECT TO_CHAR (SYSDATE, 'HH24:MI:SS DD-MON-YY')
6670               FROM hxc_retrieval_ranges
6671              WHERE transaction_id = p_transaction_id;
6672 
6673          l_transaction_id   hxc_transactions.transaction_id%TYPE;
6674          l_bee_ok           VARCHAR2 (1);
6675          l_cnt              PLS_INTEGER                            := 0;
6676          l_no_ranges        BOOLEAN                                := TRUE;
6677          l_dummy            VARCHAR2 (20);
6678       BEGIN                                            -- check concurrency ok
6679          IF g_debug
6680          THEN
6681             hr_utility.TRACE (   'in check concurrency - process id is   '
6682                               || TO_CHAR (p_process_id)
6683                              );
6684             hr_utility.TRACE (   'in check concurrency - retrieval id is '
6685                               || p_retrieval_process
6686                              );
6687             hr_utility.TRACE (   'in check concurrency - where clause is '
6688                               || SUBSTR (p_where_clause, 1, 300)
6689                              );
6690          END IF;
6691 
6692          OPEN chk_transaction;
6693 
6694          FETCH chk_transaction
6695           INTO l_transaction_id;
6696 
6697          CLOSE chk_transaction;
6698 
6699 -- if another process is running check to see if the transfer batch size is
6700 -- set otherwise the processes will conflict
6701          IF g_debug
6702          THEN
6703             hr_utility.TRACE ('l running is ' || TO_CHAR (l_transaction_id));
6704          END IF;
6705 
6706          IF (p_retrieval_process = 'Projects Retrieval Process')
6707          THEN
6708             RETURN TRUE;
6709          END IF;
6710 
6711 -- check the unique params
6712          IF (    p_retrieval_process IN
6713                             ('Apply Schedule Rules', 'BEE Retrieval Process')
6714              AND l_transaction_id IS NOT NULL
6715             )
6716          THEN
6717             IF g_debug
6718             THEN
6719                hr_utility.TRACE ('Checking BEE');
6720             END IF;
6721 
6722             -- make sure that ranges have been inserted already by the IN PROGRESS
6723             -- process
6724             WHILE l_no_ranges
6725             LOOP
6726                IF g_debug
6727                THEN
6728                   hr_utility.TRACE ('looking for ranges');
6729                END IF;
6730 
6731                OPEN csr_chk_range_exists (l_transaction_id);
6732 
6733                FETCH csr_chk_range_exists
6734                 INTO l_dummy;
6735 
6736                IF (csr_chk_range_exists%NOTFOUND)
6737                THEN
6738                   IF g_debug
6739                   THEN
6740                      hr_utility.TRACE (   'No ranges yet for '
6741                                        || TO_CHAR (l_transaction_id)
6742                                       );
6743                   END IF;
6744 
6745                   l_cnt := l_cnt + 1;
6746 
6747                   IF (l_cnt > 100000)
6748                   THEN
6749                      fnd_message.set_name ('HXC', 'HXC_RET_NO_RANGES');
6750                      fnd_message.set_token ('TERM_TIME', l_dummy);
6751                      fnd_message.raise_error;
6752                   END IF;
6753                ELSE
6754                   IF g_debug
6755                   THEN
6756                      hr_utility.TRACE ('found ranges');
6757                   END IF;
6758 
6759                   l_no_ranges := FALSE;
6760                END IF;
6761 
6762                CLOSE csr_chk_range_exists;
6763             END LOOP;
6764 
6765             OPEN csr_chk_where_clause (p_transaction_id      => l_transaction_id,
6766                                        p_where_clause        => p_where_clause,
6767                                        p_unique_params       => p_unique_params
6768                                       );
6769 
6770             FETCH csr_chk_where_clause
6771              INTO l_bee_ok;
6772 
6773             CLOSE csr_chk_where_clause;
6774 
6775             IF g_debug
6776             THEN
6780 
6777                hr_utility.TRACE ('l bee ok is ' || l_bee_ok);
6778             END IF;
6779          END IF;
6781          IF (   (    l_transaction_id IS NOT NULL
6782                  AND p_retrieval_process NOT IN
6783                             ('Apply Schedule Rules', 'BEE Retrieval Process')
6784                 )
6785              OR (l_transaction_id IS NOT NULL AND l_bee_ok IS NULL)
6786             )
6787          THEN
6788             IF g_debug
6789             THEN
6790                hr_utility.TRACE ('FALSE');
6791             END IF;
6792 
6793             RETURN FALSE;
6794          ELSE
6795             IF g_debug
6796             THEN
6797                hr_utility.TRACE ('TRUE');
6798             END IF;
6799 
6800             RETURN TRUE;
6801          END IF;
6802       END check_concurrency_ok;
6803 
6804 -- private procedure
6805 --   chk_a_and_r_overlap
6806 --
6807 -- description
6808 --   Archive and Restore validation to check if the date params
6809 --   include any Archive and Restore period.
6810 --   Writes message to the log
6811 --
6812 -- parameters
6813 --   p_start_date, p_end_date
6814       PROCEDURE check_a_and_r_overlap (p_start_date DATE, p_end_date DATE)
6815       IS
6816          CURSOR chk_a_and_r_overlap (p_start_date DATE, p_end_date DATE)
6817          IS
6818             SELECT 'x'
6819               FROM hxc_data_sets hds
6820              WHERE hds.start_date <= p_end_date
6821                AND hds.end_date >= p_start_date
6822                AND hds.status IN
6823                       ('OFF_LINE', 'RESTORE_IN_PROGRESS',
6824                        'BACKUP_IN_PROGRESS');
6825 
6826          l_message_text   VARCHAR2 (2000);
6827          l_start_date     DATE := NVL (p_start_date, hr_general.start_of_time);
6828          l_end_date       DATE     := NVL (p_end_date, hr_general.end_of_time);
6829       BEGIN
6830          IF g_debug
6831          THEN
6832             hr_utility.TRACE ('Entering chk_a_and_r_overlap');
6833          END IF;
6834 
6835          OPEN chk_a_and_r_overlap (l_start_date, l_end_date);
6836 
6837          FETCH chk_a_and_r_overlap
6838           INTO l_message_text;
6839 
6840          IF (chk_a_and_r_overlap%FOUND)
6841          THEN
6842             fnd_message.set_name ('HXC', 'HXC_RET_ARCHIVE_DATA');
6843             l_message_text := SUBSTR (fnd_message.get (), 1, 2000);
6844             fnd_file.put_line (fnd_file.LOG, l_message_text);
6845          END IF;
6846 
6847          CLOSE chk_a_and_r_overlap;
6848 
6849          IF g_debug
6850          THEN
6851             hr_utility.TRACE ('Leaving chk_a_and_r_overlap');
6852          END IF;
6853       END check_a_and_r_overlap;
6854 
6855 -- private procedure
6856 --   get_field_mappings
6857 --
6858 -- description
6859 --   Retrieves the mapping components for a given mapping_id
6860 --   and populates the Global PL/SQL table g_field_mappings
6861 --   table
6862 --
6863 -- parameters
6864 --   p_mapping_id   - mapping_id
6865       FUNCTION get_field_mappings (p_mapping_id hxc_mappings.mapping_id%TYPE)
6866          RETURN t_field_mappings
6867       IS
6868 --
6869          l_mapping_record   r_field_mappings;
6870          l_mappings_table   t_field_mappings;
6871 
6872 --
6873          CURSOR csr_get_mappings
6874          IS
6875             SELECT   mpc.bld_blk_info_type_id, UPPER (mpc.field_name),
6876                      mpc.SEGMENT, bbit.bld_blk_info_type CONTEXT,
6877                      bbitu.building_block_category CATEGORY
6878                 FROM hxc_bld_blk_info_type_usages bbitu,
6879                      hxc_bld_blk_info_types bbit,
6880                      hxc_mapping_components mpc,
6881                      hxc_mapping_comp_usages mcu,
6882                      hxc_mappings MAP
6883                WHERE MAP.mapping_id = p_mapping_id
6884                  AND mcu.mapping_id = MAP.mapping_id
6885                  AND mpc.mapping_component_id = mcu.mapping_component_id
6886                  AND bbit.bld_blk_info_type_id = mpc.bld_blk_info_type_id
6887                  AND bbitu.bld_blk_info_type_id = bbit.bld_blk_info_type_id
6888             ORDER BY 1, 2, 3;
6889 
6890          l_table_index      NUMBER           := 0;
6891          l_proc             VARCHAR2 (72);
6892       BEGIN                                              -- get field mappings
6893          IF g_debug
6894          THEN
6895             l_proc := g_package || 'get_field_mappings';
6896             hr_utility.set_location ('Entering ' || l_proc, 10);
6897          END IF;
6898 
6899          OPEN csr_get_mappings;
6900 
6901          FETCH csr_get_mappings
6902           INTO l_mapping_record;
6903 
6904          IF csr_get_mappings%NOTFOUND
6905          THEN
6906             fnd_message.set_name ('HXC', 'HXC_0016_GNRET_NO_MAPPINGS');
6907             fnd_message.raise_error;
6908 
6909             CLOSE csr_get_mappings;
6910          END IF;
6911 
6912          LOOP
6913             IF g_debug
6914             THEN
6915                hr_utility.set_location ('Processing ' || l_proc, 20);
6916             END IF;
6917 
6918             l_table_index := l_table_index + 1;
6919             l_mappings_table (l_table_index) := l_mapping_record;
6920 
6921             FETCH csr_get_mappings
6922              INTO l_mapping_record;
6923 
6924             EXIT WHEN csr_get_mappings%NOTFOUND;
6925          END LOOP;
6926 
6927          CLOSE csr_get_mappings;
6928 
6929          IF g_debug
6930          THEN
6931             hr_utility.set_location ('Leaving ' || l_proc, 30);
6932          END IF;
6933 
6934          RETURN l_mappings_table;
6935       END get_field_mappings;
6936 
6937       PROCEDURE maintain_globals
6938       IS
6939       BEGIN
6940          g_conc_request_id := fnd_profile.VALUE ('CONC_REQUEST_ID');
6941 
6942          IF g_debug
6943          THEN
6944             hr_utility.TRACE ('Conc Req ID is ' || TO_CHAR (g_conc_request_id)
6945                              );
6946          END IF;
6947 
6948 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
6949 		|| ' > maintain_globals > Conc Req ID is ' || TO_CHAR (g_conc_request_id));
6950 
6951          g_params.p_process := NULL;
6952          g_params.p_transaction_code := NULL;
6953          g_params.p_incremental := NULL;
6954          g_params.p_rerun_flag := NULL;
6955          g_params.p_where_clause := NULL;
6956          g_params.p_scope := NULL;
6957          g_params.p_clusive := NULL;
6958          g_params.p_unique_params := NULL;
6959          g_transaction_id := NULL;
6960          hxc_generic_retrieval_pkg.t_detail_bld_blks.DELETE;
6961          hxc_generic_retrieval_pkg.t_old_detail_bld_blks.DELETE;
6962          hxc_generic_retrieval_pkg.t_detail_attributes.DELETE;
6963          hxc_generic_retrieval_pkg.t_old_detail_attributes.DELETE;
6964          hxc_generic_retrieval_pkg.t_time_bld_blks.DELETE;
6965          t_old_detail_seq.DELETE;
6966          t_old_detail_bb_id.DELETE;
6967          t_old_detail_ovn.DELETE;
6968          hxc_generic_retrieval_pkg.t_tx_time_bb_id.DELETE;
6969          hxc_generic_retrieval_pkg.t_tx_time_bb_ovn.DELETE;
6970          hxc_generic_retrieval_pkg.t_tx_time_transaction_id.DELETE;
6971          hxc_generic_retrieval_pkg.t_tx_time_status.DELETE;
6972          hxc_generic_retrieval_pkg.t_tx_time_exception.DELETE;
6973          hxc_generic_retrieval_pkg.t_tx_day_bb_id.DELETE;
6974          hxc_generic_retrieval_pkg.t_tx_day_parent_id.DELETE;
6975          hxc_generic_retrieval_pkg.t_tx_day_bb_ovn.DELETE;
6976          hxc_generic_retrieval_pkg.t_tx_day_transaction_id.DELETE;
6977          hxc_generic_retrieval_pkg.t_tx_day_status.DELETE;
6978          hxc_generic_retrieval_pkg.t_tx_day_exception.DELETE;
6979          hxc_generic_retrieval_pkg.t_tx_detail_bb_id.DELETE;
6980          hxc_generic_retrieval_pkg.t_tx_detail_parent_id.DELETE;
6981          hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn.DELETE;
6982          hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.DELETE;
6983          hxc_generic_retrieval_pkg.t_tx_detail_status.DELETE;
6984          hxc_generic_retrieval_pkg.t_tx_detail_exception.DELETE;
6985          t_bb.DELETE;
6986          hxc_generic_retrieval_pkg.g_no_timecards := TRUE;
6987          hxc_generic_retrieval_utils.g_resources.DELETE;
6988 
6989 	 hxc_generic_retrieval_pkg.g_detail_skipped.DELETE;
6990 
6991          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
6992          THEN
6993             g_retrieval_process_id := NULL;
6994             g_retrieval_tr_id := NULL;
6995             g_field_mappings_table.DELETE;
6996          END IF;
6997       END maintain_globals;
6998 
6999 -- private function get_valid_app_sets
7000 -- (added for ELP related changes to the retrieval process 14-Mar-2003 sonarasi)
7004 -- time recipient. If the process is 'Apply Schedule Rules' or 'BEE Retrieval Process'
7001 --
7002 -- description
7003 -- This function is used to return a string of valid application set ids for a given
7005 -- then we have an additional requirement. i,e the list of application set ids for
7006 -- hr time recipient needs to be added to the list.
7007 -- Parameters
7008 --  p_retrieval_process : The Retrieval Process Name
7009 --  p_retrieval_tr_id   : The time recipient id of the application.
7010       FUNCTION get_valid_app_sets (
7011          p_retrieval_process   hxc_retrieval_processes.NAME%TYPE,
7012          p_retrieval_tr_id     NUMBER
7013       )
7014          RETURN VARCHAR2
7015       IS
7016          CURSOR c_application_set_id (
7017             p_ret_tr_id_1   NUMBER,
7018             p_ret_tr_id_2   NUMBER
7019          )
7020          IS
7021             SELECT DISTINCT application_set_id
7022                        FROM hxc_application_set_comps_v
7023                       WHERE time_recipient_id IN
7024                                               (p_ret_tr_id_1, p_ret_tr_id_2);
7025 
7026          CURSOR csr_get_tr_id (p_application_id NUMBER)
7027          IS
7028             SELECT tr.time_recipient_id
7029               FROM hxc_time_recipients tr
7030              WHERE tr.application_id = p_application_id;
7031 
7032          l_application_set_id_string   VARCHAR2 (200)                   := '';
7033          l_ret_tr_id                   NUMBER            := p_retrieval_tr_id;
7034          l_hr_tr                       hxc_time_recipients.time_recipient_id%TYPE;
7035          l_ret_tr_id_1                 NUMBER            := p_retrieval_tr_id;
7036          l_ret_tr_id_2                 NUMBER                         := NULL;
7037       BEGIN
7038 -- if the process is BEE retrieval process then we need to add the application set ids of
7039 -- corresponding to hr time recipient id also.
7040          IF (p_retrieval_process IN
7041                             ('Apply Schedule Rules', 'BEE Retrieval Process')
7042             )
7043          THEN
7044             OPEN csr_get_tr_id (800);
7045 
7046             FETCH csr_get_tr_id
7047              INTO l_hr_tr;
7048 
7049             IF (csr_get_tr_id%NOTFOUND)
7050             THEN
7051                CLOSE csr_get_tr_id;
7052 
7053                fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7054                fnd_message.set_token ('PROCEDURE', l_proc);
7055                fnd_message.set_token ('STEP', 'no HR Time Recipient ID');
7056                fnd_message.raise_error;
7057             END IF;
7058 
7059             CLOSE csr_get_tr_id;
7060 
7061             l_ret_tr_id_2 := l_hr_tr;
7062          END IF;
7063 
7064          FOR l_rec IN c_application_set_id (l_ret_tr_id_1, l_ret_tr_id_2)
7065          LOOP
7066             l_application_set_id_string :=
7067                l_application_set_id_string || ',' || l_rec.application_set_id;
7068          END LOOP;
7069 
7070          l_application_set_id_string :=
7071                ' AND
7072 tbb_latest.application_set_id IN ('
7073             || SUBSTR (l_application_set_id_string, 2)
7074             || ')';
7075          RETURN l_application_set_id_string;
7076       END get_valid_app_sets;
7077    BEGIN                                          -- execute retrieval process
7078 -- this is to handle the case where the OTLR and BEE are processed in
7079 -- the loop
7080       g_debug := hr_utility.debug_enabled;
7081 
7082       IF (    g_params.p_process <> p_process
7083           AND hxc_generic_retrieval_pkg.g_in_loop
7084          )
7085       THEN
7086          -- reset global looping variables
7087          hxc_generic_retrieval_pkg.g_in_loop := FALSE;
7088          hxc_generic_retrieval_pkg.g_last_chunk := FALSE;
7089          hxc_generic_retrieval_pkg.g_no_timecards := TRUE;
7090          hxc_generic_retrieval_pkg.g_overall_no_timecards := TRUE;
7091       END IF;
7092 
7093 fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
7094       || ' ******** OTL Processing Starts ******');
7095 
7096       maintain_globals;
7097 
7098       IF (    hxc_generic_retrieval_pkg.g_in_loop
7099           AND hxc_generic_retrieval_pkg.g_last_chunk
7100          )
7101       THEN
7102          -- do nothing, this is the last iteration, we are in a loop and the last chunk
7103          -- has already been processed
7104          NULL;
7105       ELSE
7106          g_params.p_process := p_process;
7107          g_params.p_transaction_code := p_transaction_code;
7108          g_params.p_incremental := p_incremental;
7109          g_params.p_rerun_flag := p_rerun_flag;
7110          g_params.p_where_clause := p_where_clause;
7111          g_params.p_scope := p_scope;
7112          g_params.p_clusive := p_clusive;
7113          g_params.p_unique_params := p_unique_params;
7114          g_params.transfer_batch_size :=
7115                                fnd_profile.VALUE ('HXC_RETRIEVAL_BATCH_SIZE');
7116          g_params.retrieval_options :=
7117                     NVL (fnd_profile.VALUE ('HXC_RETRIEVAL_OPTIONS'), 'BOTH');
7118 
7119          IF (p_since_date IS NULL)
7120          THEN
7121             -- then get value from the profile option
7122             l_since_date :=
7123                NVL (SUBSTR (fnd_profile.VALUE ('HXC_RETRIEVAL_CHANGES_DATE'),
7124                             1,
7128                    );
7125                             3
7126                            ),
7127                     60
7129 
7130             BEGIN
7131                SELECT TO_NUMBER (l_since_date)
7132                  INTO l_since_date
7133                  FROM DUAL;
7134             EXCEPTION
7135                WHEN OTHERS
7136                THEN
7137                   l_since_date := 60;
7138             END;
7139 
7140             g_params.since_date := SYSDATE - TO_NUMBER (l_since_date);
7141          ELSE
7142             g_params.since_date :=
7143                               TO_DATE (p_since_date, 'RRRR/MM/DD HH24:MI:SS');
7144          END IF;
7145 
7146          IF g_debug
7147          THEN
7148             hr_utility.TRACE (   'final since date is '
7149                               || TO_CHAR (g_params.since_date,
7150                                           'hh24:mi:ss dd-mon-yy'
7151                                          )
7152                              );
7153          END IF;
7154 
7155          IF (p_start_date IS NOT NULL AND p_end_date IS NOT NULL)
7156          THEN
7157             g_params.p_start_date := TRUNC (p_start_date);
7158             g_params.p_end_date :=
7159                TO_DATE (   TO_CHAR (TRUNC (p_end_date), 'DD/MM/YYYY')
7160                         || ' 23:59:59',
7161                         'DD/MM/YYYY HH24:MI:SS'
7162                        );
7163             g_params.l_using_dates := TRUE;
7164          ELSIF (p_start_date IS NOT NULL AND p_end_date IS NULL)
7165          THEN
7166             g_params.p_start_date := TRUNC (p_start_date);
7167             g_params.p_end_date :=
7168                TO_DATE (   TO_CHAR (TRUNC (hr_general.end_of_time),
7169                                     'DD/MM/YYYY'
7170                                    )
7171                         || ' 23:59:59',
7172                         'DD/MM/YYYY HH24:MI:SS'
7173                        );
7174             g_params.l_using_dates := TRUE;
7175          ELSIF (p_start_date IS NULL AND p_end_date IS NOT NULL)
7176          THEN
7177             g_params.p_start_date := hr_general.start_of_time;
7178             g_params.p_end_date :=
7179                TO_DATE (   TO_CHAR (TRUNC (p_end_date), 'DD/MM/YYYY')
7180                         || ' 23:59:59',
7181                         'DD/MM/YYYY HH24:MI:SS'
7182                        );
7183             g_params.l_using_dates := TRUE;
7184          ELSE
7185             g_params.p_start_date := NULL;
7186             g_params.p_end_date := NULL;
7187             g_params.l_using_dates := FALSE;
7188          END IF;
7189 
7190 -- check archived and restore over lap
7191          IF (    (NOT hxc_generic_retrieval_pkg.g_in_loop)
7192              AND (   (    g_params.retrieval_options = 'BOTH'
7193                       AND NOT g_params.p_process = 'BEE Retrieval Process'
7194                      )
7195                   OR (    g_params.retrieval_options = 'BEE'
7196                       AND g_params.p_process = 'BEE Retrieval Process'
7197                      )
7198                   OR (    g_params.retrieval_options = 'OTLR'
7199                       AND g_params.p_process = 'Apply Schedule Rules'
7200                      )
7201                   OR (g_params.p_process NOT IN
7202                             ('BEE Retrieval Process', 'Apply Schedule Rules')
7203                      )
7204                  )
7205             )
7206          THEN
7207             -- only want to do this once for the first loop since the params
7208             -- do not change for each loop and once for the Transfer Time from OTL to BEE
7209             check_a_and_r_overlap (g_params.p_start_date,
7210                                    g_params.p_end_date);
7211          END IF;
7212 
7213 -- check to see if we want to turn trace on
7214          OPEN csr_debug;
7215 
7216          FETCH csr_debug
7217           INTO l_debug;
7218 
7219          CLOSE csr_debug;
7220 
7221          IF l_debug = 'Y'
7222          THEN
7223             glb_debug := TRUE;
7224 
7225             IF g_debug
7226             THEN
7227                hr_utility.trace_on
7228                               (trace_mode              => NULL,
7229                                session_identifier      => NVL
7230                                                              (p_transaction_code,
7231                                                               'RETRIEVAL'
7232                                                              )
7233                               );
7234             END IF;
7235          END IF;
7236 
7237          IF g_debug
7238          THEN
7239             hr_utility.set_location ('Entering ' || l_proc, 10);
7240          END IF;
7241 
7242          IF (   g_params.p_transaction_code LIKE 'GAZ%'
7243              OR g_params.p_transaction_code IS NULL
7244             )
7245          THEN
7246             NULL;
7247 --l_alter_session := 'alter session set sql_trace TRUE';
7248 
7249          --execute immediate l_alter_session;
7250          END IF;
7251 
7252          IF g_debug
7253          THEN
7254             hr_utility.TRACE ('****  Retrieval Params are.... ****');
7255             hr_utility.TRACE ('');
7256             hr_utility.TRACE ('Process is          :' || g_params.p_process);
7257             hr_utility.TRACE (   'Transaction code is :'
7258                               || g_params.p_transaction_code
7259                              );
7260             hr_utility.TRACE ('Start Date is       :' || g_params.p_start_date);
7261             hr_utility.TRACE ('End Date is         :' || g_params.p_end_date);
7262             hr_utility.TRACE ('Incremental is      :'
7263                               || g_params.p_incremental
7264                              );
7265             hr_utility.TRACE ('Rerun Flag is       :' || g_params.p_rerun_flag);
7266             hr_utility.TRACE (   'Where Clause is     :'
7267                               || SUBSTR (g_params.p_where_clause, 1, 200)
7268                              );
7269             hr_utility.TRACE (SUBSTR (g_params.p_where_clause, 201, 200));
7270             hr_utility.TRACE (SUBSTR (g_params.p_where_clause, 401, 200));
7271             hr_utility.TRACE ('Scope is            :' || g_params.p_scope);
7272             hr_utility.TRACE ('Clusive is          :' || g_params.p_clusive);
7273             hr_utility.TRACE ('');
7274             hr_utility.TRACE ('****  Retrieval LOOPING GLOBALS are.... ****');
7275          END IF;
7276 
7277          IF (g_in_loop)
7278          THEN
7279             IF g_debug
7280             THEN
7281                hr_utility.TRACE ('G_IN_LOOP is TRUE');
7282             END IF;
7283          ELSE
7284             IF g_debug
7285             THEN
7286                hr_utility.TRACE ('G_IN_LOOP is FALSE');
7287             END IF;
7288          END IF;
7289 
7290          IF (g_last_chunk)
7291          THEN
7292             IF g_debug
7293             THEN
7294                hr_utility.TRACE ('G_LAST_CHUNK is TRUE');
7295             END IF;
7296          ELSE
7297             IF g_debug
7298             THEN
7299                hr_utility.TRACE ('G_LAST_CHUNK is FALSE');
7300             END IF;
7301          END IF;
7302 
7303          IF (g_no_timecards)
7304          THEN
7305             IF g_debug
7306             THEN
7307                hr_utility.TRACE ('G_NO_TIMECARDS is TRUE');
7308             END IF;
7309          ELSE
7310             IF g_debug
7311             THEN
7312                hr_utility.TRACE ('G_NO_TIMECARDS is FALSE');
7313             END IF;
7314          END IF;
7315 
7316          IF (g_overall_no_timecards)
7317          THEN
7318             IF g_debug
7319             THEN
7320                hr_utility.TRACE ('G_OVERALL_NO_TIMECARDS is TRUE');
7321             END IF;
7322          ELSE
7323             IF g_debug
7324             THEN
7325                hr_utility.TRACE ('G_OVERALL_NO_TIMECARDS is FALSE');
7326             END IF;
7327          END IF;
7328 
7329          IF g_debug
7330          THEN
7331             hr_utility.TRACE (   'l_range_start is '
7332                               || TO_CHAR (l_pkg_range_start)
7333                              );
7334             hr_utility.TRACE ('l_range_stop is ' || TO_CHAR (l_pkg_range_stop));
7335          END IF;
7336 
7337          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
7338          THEN
7339             -- check that the process is registered and return the mapping id
7340             -- and retrieval_process id
7341             chk_retrieval_process
7342                            (p_retrieval_process         => p_process,
7343                             p_retrieval_process_id      => g_retrieval_process_id,
7344                             p_retrieval_tr_id           => g_retrieval_tr_id,
7345                             p_mapping_id                => l_mapping_id
7346                            );
7347 
7348             IF g_debug
7349             THEN
7350                hr_utility.set_location ('Processing ' || l_proc, 20);
7351             END IF;
7352 
7353             -- check to see if mapping_id exists and thus retrieval process registered
7354             IF (l_mapping_id IS NULL)
7355             THEN
7356                RAISE e_retrieval_not_registered;
7357             END IF;
7358 
7359 -- now check to see if this retrieval is already running
7360 -- only need to do this if NOT the 'Projects Retrieval Process'
7361             IF g_debug
7362             THEN
7363                hr_utility.set_location ('Processing ' || l_proc, 30);
7364             END IF;
7365 
7366             IF (g_params.p_process = 'Apply Schedule Rules')
7367             THEN
7368                SELECT rp.retrieval_process_id
7369                  INTO l_ret_id
7370                  FROM hxc_retrieval_processes rp
7371                 WHERE rp.NAME = 'BEE Retrieval Process';
7372 
7373                -- check to see that the last retrieval completed normally
7374                hxc_generic_retrieval_utils.RECOVERY
7375                                       (p_process_id      => g_retrieval_process_id,
7376                                        p_process         => p_process
7377                                       );
7378 
7379                IF NOT check_concurrency_ok
7380                                   (p_process_id             => g_retrieval_process_id,
7381                                    p_retrieval_process      => g_params.p_process,
7382                                    p_where_clause           => g_params.p_where_clause,
7383                                    p_unique_params          => g_params.p_unique_params
7384                                   )
7385                THEN
7386                   RAISE e_process_already_running;
7387                END IF;
7388 
7389                IF (g_params.retrieval_options = 'BOTH')
7390                THEN
7391                   hxc_generic_retrieval_utils.RECOVERY
7392                                         (p_process_id      => l_ret_id,
7393                                          p_process         => 'BEE Retrieval Process'
7394                                         );
7395 
7396                   -- check that the BEE Retrieval isn't also running
7397                   IF NOT check_concurrency_ok
7398                               (p_process_id             => l_ret_id,
7399                                p_retrieval_process      => 'BEE Retrieval Process',
7400                                p_where_clause           => g_params.p_where_clause,
7401                                p_unique_params          => g_params.p_unique_params
7402                               )
7403                   THEN
7404                      RAISE e_process_already_running;
7405                   END IF;
7406                END IF;
7407             ELSIF (g_params.p_process = 'BEE Retrieval Process')
7408             THEN
7409                -- check the HXC_RETRIEVAL_OPTIONS profile value
7410                IF (g_params.retrieval_options = 'BEE')
7411                THEN
7412                   -- Apply Schedule Rules was not called
7413                   hxc_generic_retrieval_utils.RECOVERY
7414                                      (p_process_id      => g_retrieval_process_id,
7415                                       p_process         => p_process
7416                                      );
7417 
7418                   IF NOT check_concurrency_ok
7419                                   (p_process_id             => g_retrieval_process_id,
7420                                    p_retrieval_process      => g_params.p_process,
7421                                    p_where_clause           => g_params.p_where_clause,
7422                                    p_unique_params          => g_params.p_unique_params
7423                                   )
7424                   THEN
7425                      RAISE e_process_already_running;
7426                   END IF;
7427                ELSE
7428                   -- we have already checked the BEE Retrieval when the process
7429                   -- started and cleaned up if appropriate
7430                   NULL;
7431                END IF;
7432             ELSE
7433                hxc_generic_retrieval_utils.RECOVERY
7434                                      (p_process_id      => g_retrieval_process_id,
7435                                       p_process         => p_process
7436                                      );
7437 
7438                IF NOT check_concurrency_ok
7439                                   (p_process_id             => g_retrieval_process_id,
7440                                    p_retrieval_process      => g_params.p_process,
7441                                    p_where_clause           => g_params.p_where_clause,
7442                                    p_unique_params          => g_params.p_unique_params
7443                                   )
7444                THEN
7445                   RAISE e_process_already_running;
7446                END IF;
7447             END IF;
7448          END IF;     -- IF ( NOT hxc_generic_retrieval_process_pkg.G_IN_LOOP )
7449 
7450 -- audit the transaction (header)
7451          audit_transaction
7452                           (p_mode                        => 'I'      -- Insert
7453                                                                ,
7454                            p_transaction_process_id      => g_retrieval_process_id,
7455                            p_status                      => 'IN PROGRESS',
7456                            p_description                 => ''
7457                           );
7458 
7462          END IF;
7459          IF g_debug
7460          THEN
7461             hr_utility.set_location ('Processing ' || l_proc, 40);
7463 
7464          IF NOT hxc_generic_retrieval_pkg.g_in_loop
7465          THEN
7466 --Elp changes sonarasi 14-Mar-2003
7467 --Now that we have the time recipient id, let us find out the application set id string.
7468 --We call the get_valid_app_sets function to get the application set id string
7469 --However we do a check here to see if the application set id string has already been
7470 --obtained..Only if it is not obtained do we hit the database to find it.
7471 --Note : g_app_set_id_string is indexed on g_retrieval_tr_id
7472             IF NOT (g_app_set_id_string.EXISTS (g_retrieval_tr_id))
7473             THEN
7474                g_app_set_id_string (g_retrieval_tr_id).app_set_id_string :=
7475                   get_valid_app_sets (p_retrieval_process      => p_process,
7476                                       p_retrieval_tr_id        => g_retrieval_tr_id
7477                                      );
7478             END IF;
7479 
7480 --Elp changes sonarasi over
7481 
7482             --  get the field mappings associated with the mapping id
7483 --  This populates the global table g_field_mappings_table
7484             g_field_mappings_table :=
7485                              get_field_mappings (p_mapping_id      => l_mapping_id);
7486          END IF;                    -- NOT hxc_generic_retrieval_pkg.G_IN_LOOP
7487 
7488 -- parse the where clause and build the final query for execution
7489          l_where_clause_blk := LTRIM (RTRIM (p_where_clause));
7490          l_where_clause_att := LTRIM (RTRIM (p_where_clause));
7491          parse_it (p_where_clause_blk      => l_where_clause_blk,
7492                    p_where_clause_att      => l_where_clause_att
7493                   );
7494          l_where_clause_blk := replace_timecard_string (l_where_clause_blk);
7495 
7496          IF g_debug
7497          THEN
7498             hr_utility.set_location ('Processing ' || l_proc, 60);
7499          END IF;
7500 
7501          l_dynamic_query :=
7502             build_query (p_where_clause_blk      => l_where_clause_blk,
7503                          p_where_clause_att      => l_where_clause_att
7504                         );
7505 
7506          IF g_debug
7507          THEN
7508             hr_utility.set_location ('Processing ' || l_proc, 70);
7509          END IF;
7510 
7511 -- lets see the query
7512          insert_query (l_dynamic_query, 'QUERY');
7513          maintain_chunks (p_where_clause => p_where_clause);
7514          populate_ret_range_blks;
7515          populate_max_ovn (p_where_clause => p_where_clause);
7516 
7517 -- get the bulding blocks
7518 -- execute the query, populate the tables
7519          IF (hxc_generic_retrieval_pkg.g_in_loop)
7520          THEN
7521             IF g_debug
7522             THEN
7523                hr_utility.set_location ('Processing ' || l_proc, 71);
7524             END IF;
7525 
7526             WHILE (hxc_generic_retrieval_pkg.g_no_timecards)
7527             LOOP
7528                IF g_debug
7529                THEN
7530                   hr_utility.set_location ('Processing ' || l_proc, 72);
7531                END IF;
7532 
7533                BEGIN
7534                   query_it (p_query => l_dynamic_query);
7535                EXCEPTION
7536                   WHEN OTHERS
7537                   THEN
7538                      IF g_debug
7539                      THEN
7540                         hr_utility.TRACE (   'query EXCEPTION is '
7541                                           || SUBSTR (SQLERRM, 1, 60)
7542                                          );
7543                         hr_utility.TRACE (   'query EXCEPTION is '
7544                                           || SUBSTR (SQLERRM, 61, 120)
7545                                          );
7546                         hr_utility.TRACE (   'query EXCEPTION is '
7547                                           || SUBSTR (SQLERRM, 121, 180)
7548                                          );
7549                         hr_utility.TRACE (   'query EXCEPTION is '
7550                                           || SUBSTR (SQLERRM, 181, 240)
7551                                          );
7552                      END IF;
7553 
7554                      IF (    (   SQLERRM LIKE
7555                                       'ORA-20001: HXC_0013_GNRET_NO_BLD_BLKS%'
7556                               OR SQLERRM LIKE
7557                                      'ORA-20001: HXC_0012_GNRET_NO_TIMECARDS%'
7558                              )
7559                          AND (NOT hxc_generic_retrieval_pkg.g_last_chunk)
7560                         )
7561                      THEN
7562                         IF g_debug
7563                         THEN
7564                            hr_utility.set_location ('Processing ' || l_proc,
7565                                                     73
7566                                                    );
7567                         END IF;
7568 
7569                         maintain_chunks (p_where_clause => p_where_clause);
7570                         populate_ret_range_blks;
7571                         populate_max_ovn (p_where_clause => p_where_clause);
7572                      ELSIF (   SQLERRM LIKE
7573                                       'ORA-20001: HXC_0013_GNRET_NO_BLD_BLKS%'
7574                             OR SQLERRM LIKE
7578                         IF g_debug
7575                                      'ORA-20001: HXC_0012_GNRET_NO_TIMECARDS%'
7576                            )
7577                      THEN
7579                         THEN
7580                            hr_utility.set_location ('Processing ' || l_proc,
7581                                                     74
7582                                                    );
7583                         END IF;
7584 
7585                         IF (hxc_generic_retrieval_pkg.g_overall_no_timecards
7586                            )
7587                         THEN
7588                            IF g_debug
7589                            THEN
7590                               hr_utility.set_location ('Processing ' || l_proc,
7591                                                        75
7592                                                       );
7593                            END IF;
7594 
7595                            -- this is the last chunk and there have been no timecards
7596                            fnd_message.raise_error;
7597                            -- GPM v115.41
7598                            EXIT;
7599                         ELSE
7600                            -- last chunk and there were timecards but just not in this
7601                            -- this iteration
7602                            EXIT;
7603                         END IF;
7604                      ELSE
7605                         IF g_debug
7606                         THEN
7607                            hr_utility.set_location ('Processing ' || l_proc,
7608                                                     76
7609                                                    );
7610                         END IF;
7611 
7612                         audit_transaction
7613                            (p_mode                        => 'I'     -- Insert
7614                                                                 ,
7615                             p_transaction_process_id      => g_retrieval_process_id,
7616                             p_status                      => 'ERRORS',
7617                             p_description                 => SUBSTR (SQLERRM,
7618                                                                      1,
7619                                                                      2000
7620                                                                     )
7621                            );
7622                         RAISE;
7623                      END IF;
7624                END;
7625             END LOOP;
7626          ELSE
7627             IF g_debug
7628             THEN
7629                hr_utility.set_location ('Processing ' || l_proc, 77);
7630             END IF;
7631 
7632             query_it (p_query => l_dynamic_query);
7633          END IF;
7634 
7635          IF g_debug
7636          THEN
7637             hr_utility.set_location ('Processing ' || l_proc, 80);
7638          END IF;
7639 
7640          IF (NOT hxc_generic_retrieval_pkg.g_last_chunk)
7641          THEN
7642             IF (g_params.p_incremental = 'Y')
7643             THEN
7644                query_old_timecard;
7645             END IF;
7646          END IF;          -- IF ( NOT hxc_generic_retrieval_pkg.G_LAST_CHUNK )
7647 
7648          IF g_debug
7649          THEN
7650             hr_utility.set_location ('Processing ' || l_proc, 100);
7651          END IF;
7652       END IF;
7653 
7654 -- ( hxc_generic_retrieval_pkg.G_IN_LOOP AND hxc_generic_retrieval_pkg.G_LAST_CHUNK );
7655 
7656       -- before we pass control to the recipient application check to make sure the conc
7657 -- process has not been terminated
7658 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
7659 	    || ' > SKIPPED Blocks COUNT > ' || hxc_generic_retrieval_pkg.g_detail_skipped.COUNT);
7660 
7661 	IF(hxc_generic_retrieval_pkg.g_detail_skipped.COUNT > 0) THEN
7662 
7663 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
7664 	    || ' > ******* Printing SKIPPED Detail Blocks *******');
7665 
7666 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
7667 
7668 	fnd_file.put_line(fnd_file.log, '     RESOURCE ID   '
7669 				     || '     TIMECARD      '
7670 				     || '     DETAIL        '
7671 				     || '     REMARKS       ');
7672 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
7673 
7674 	FOR i IN hxc_generic_retrieval_pkg.g_detail_skipped.FIRST .. hxc_generic_retrieval_pkg.g_detail_skipped.LAST
7675 	LOOP
7676 
7677 	fnd_file.put_line(fnd_file.log, '     '
7678 	    ||hxc_generic_retrieval_pkg.g_detail_skipped(i).resource_id
7679 	    || '           '
7680 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id
7681 	    || ' ['
7682 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_ovn
7683 	    || ']          '
7684 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).bb_id
7685 	    || ' ['
7686 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).ovn
7687 	    || ']          '
7688 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).description);
7689 
7690 	END LOOP;
7691 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
7692 	END IF;
7693 
7697 	IF(hxc_generic_retrieval_pkg.t_detail_bld_blks.COUNT > 0) THEN
7694 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
7695 	    || ' > Blocks COUNT being passed to RECIPIENT APPLICATION > ' || hxc_generic_retrieval_pkg.t_detail_bld_blks.COUNT);
7696 
7698 
7699 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
7700 	    || ' > ******* Passing the following blocks for RETRIEVAL *******');
7701 
7702 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
7703 	fnd_file.put_line(fnd_file.log, '     RESOURCE ID   '
7704 				     || '     TIMECARD      '
7705 				     || '     DETAIL        ');
7706 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
7707 
7708 	FOR i IN hxc_generic_retrieval_pkg.t_detail_bld_blks.FIRST .. hxc_generic_retrieval_pkg.t_detail_bld_blks.LAST
7709 	LOOP
7710 
7711 	fnd_file.put_line(fnd_file.log, '     '
7712 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).resource_id
7713 	    || '          '
7714 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_bb_id
7715 	    || ' ['
7716 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_ovn
7717 	    || ']        '
7718 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).bb_id
7719 	    || ' ['
7720 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).ovn
7721 	    || '] ');
7722 
7723 	END LOOP;
7724 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
7725 
7726 	END IF;
7727 
7728       IF (hxc_generic_retrieval_utils.chk_terminated (g_conc_request_id))
7729       THEN
7730          fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7731          fnd_message.set_token ('PROCEDURE', 'Generic Retrieval');
7732          fnd_message.set_token ('STEP', ': Process Terminated');
7733          fnd_message.raise_error;
7734       END IF;
7735    EXCEPTION
7736       WHEN e_retrieval_not_registered
7737       THEN
7738          fnd_message.set_name ('HXC', 'HXC_0011_GNRET_NOT_REGISTERED');
7739          fnd_message.raise_error;
7740       WHEN e_process_already_running
7741       THEN
7742          fnd_message.set_name ('HXC', 'HXC_0017_GNRET_PROCESS_RUNNING');
7743          fnd_message.raise_error;
7744       WHEN e_no_ranges
7745       THEN
7746          fnd_message.set_name ('HXC', 'HXC_0012_GNRET_NO_TIMECARDS');
7747          fnd_message.raise_error;
7748       WHEN OTHERS
7749       THEN
7750          audit_transaction
7751                          (p_mode                        => 'I'       -- Insert
7752                                                               ,
7753                           p_transaction_process_id      => g_retrieval_process_id,
7754                           p_status                      => 'ERRORS',
7755                           p_description                 => SUBSTR (SQLERRM,
7756                                                                    1,
7757                                                                    2000
7758                                                                   )
7759                          );
7760 -- now we need to unlock any TCs which were locked
7761          hxc_lock_api.release_lock
7762             (p_row_lock_id              => NULL,
7763              p_process_locker_type      => hxc_generic_retrieval_pkg.g_lock_type,
7764              p_transaction_lock_id      => hxc_generic_retrieval_pkg.g_transaction_id,
7765              p_released_success         => l_boolean
7766             );
7767          RAISE;
7768 --
7769    END execute_retrieval_process;
7770 
7771 -- private procedure
7772 --    delete_retrieval_ranges
7773 --
7774 -- description
7775 --    Deletes retrieval_ranges which is filled up by each retrieval process id
7776 --    Gets called when the transaction is updated with either 'SUCESS' or 'DELETE'
7777 --    from update_transaction_status
7778 --    Deletes based on concurrent process id which is unique for each process
7779 --    Ref. Bug 5669202
7780   PROCEDURE delete_retrieval_ranges (p_transaction_id IN hxc_transactions.transaction_id%TYPE)
7781   IS
7782   PRAGMA AUTONOMOUS_TRANSACTION;
7783   BEGIN
7784 
7785        DELETE FROM HXC_RETRIEVAL_RANGE_RESOURCES
7786        WHERE RETRIEVAL_RANGE_ID IN
7787            ( SELECT RETRIEVAL_RANGE_ID
7788              FROM HXC_RETRIEVAL_RANGES
7789              WHERE CONC_REQUEST_ID = g_conc_request_id
7790 	     AND   TRANSACTION_ID = p_transaction_id);
7791 
7792        DELETE FROM HXC_RETRIEVAL_RANGES
7793        WHERE  CONC_REQUEST_ID = g_conc_request_id
7794        AND    TRANSACTION_ID = p_transaction_id;
7795 
7796        COMMIT;
7797   END delete_retrieval_ranges;
7798 
7799 -- public procedure
7800 --   update_transaction_status
7801 --
7802 -- description
7803 --   Wrapper process such that audit transaction can be called externally.
7804 --   Updates the transactions for the retrieval once the recipient API has
7805 --   processed all the time bld blks. This procedure is called from the
7806 --   recipient API. The retrieval has already populated a global PL/SQL table
7807 --   with transaction details for each bld blk. The recipient API will have
7808 --   maintained this table appropriately. All this process does is
7809 --   update the transaction bulk bound (for performance) and maintain the
7813 -- Parameters
7810 --   transaction header records. unless of course the retrieval is being
7811 --   rolled back in which case all the detail records are deleted.
7812 --
7814 --   p_process - retrieval process name
7815 --   p_status  - the status of the overall retrieval
7816 --   p_exception_description - exception description
7817 --   p_rollback - is the retrieval being rolled back
7818    PROCEDURE update_transaction_status (
7819       p_process                 hxc_retrieval_processes.NAME%TYPE,
7820       p_status                  hxc_transactions.status%TYPE,
7821       p_exception_description   hxc_transactions.exception_description%TYPE,
7822       p_rollback                BOOLEAN DEFAULT FALSE
7823    )
7824    IS
7825 -- going to call the chk_retrieval_process procedure - do not need mapping id
7826       l_process_id            hxc_retrieval_processes.retrieval_process_id%TYPE;
7827       l_mapping_id            hxc_mappings.mapping_id%TYPE;
7828       l_tx_id                 hxc_transactions.transaction_id%TYPE;
7829       l_proc                  VARCHAR2 (72);
7830       l_time_max              INTEGER;
7831       l_day_max               INTEGER;
7832       l_detail_max            INTEGER;
7833       l_error_max             INTEGER;
7834       l_lock_ind              PLS_INTEGER;
7835       l_message_table         hxc_message_table_type;
7836       l_boolean               BOOLEAN;
7837       l_temp_transaction_id   t_transaction_id;
7838       l_ranges_to_process     number;
7839    BEGIN
7840       g_debug := hr_utility.debug_enabled;
7841 
7842       IF g_debug
7843       THEN
7844          l_proc := g_package || 'update_transaction_status';
7845          hr_utility.TRACE ('In Update Transaction Status');
7846       END IF;
7847 
7848 -- get the process id
7849       chk_retrieval_process (p_retrieval_process         => p_process,
7850                              p_retrieval_process_id      => l_process_id,
7851                              p_retrieval_tr_id           => g_retrieval_tr_id,
7852                              p_mapping_id                => l_mapping_id
7853                             );
7854 
7855 -- now call the audit transaction appropriately
7856       IF g_debug
7857       THEN
7858          hr_utility.set_location ('Processing ' || l_proc, 110);
7859       END IF;
7860 
7861       -- Bug 6914381
7862       -- If any transaction resulted in error, there is no need to
7863       -- do a reversal entry.  Hence delete the same record from
7864       -- HXC_BEE_PREF_ADJ_LINES.
7865       -- Do it only for Xfer time from OTL to BEE.
7866 
7867       IF g_params.p_process IN ('BEE Retrieval Process', 'Apply Schedule Rules')
7868       THEN
7869          IF hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT > 0
7870          THEN
7871             FORALL i IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST..
7872                                 hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
7873 
7874                 DELETE FROM hxc_bee_pref_adj_lines
7875                    WHERE detail_bb_id = t_tx_detail_bb_id(i)
7876                      AND batch_source = DECODE(g_params.p_process,
7877                                               'BEE Retrieval Process', 'OTM',
7878                                               'Apply Schedule Rules' , 'Time Store')
7879                      AND t_tx_detail_status(i) = 'ERRORS'                         ;
7880          END IF;
7881       END IF;
7882 
7883       IF (p_status = 'ERRORS')
7884       THEN
7885          -- call audit transaction
7886          -- we want to commit these transactions for audit purposes
7887          -- before the process rolls them back
7888          audit_transaction (p_mode                        => 'U'     -- update
7889                                                                 ,
7890                             p_transaction_process_id      => l_process_id,
7891                             p_status                      => p_status,
7892                             p_description                 => p_exception_description,
7893                             p_rollback                    => p_rollback
7894                            );
7895       ELSE
7896          -- retrieval was successful - do the same work as audit_transaction except
7897          -- allow the recipient application commit the data.
7898          l_time_max := hxc_generic_retrieval_pkg.t_tx_time_bb_id.COUNT;
7899          l_day_max := hxc_generic_retrieval_pkg.t_tx_day_bb_id.COUNT;
7900          l_detail_max := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT;
7901          l_error_max := hxc_generic_retrieval_pkg.t_tx_error_bb_id.COUNT;
7902 
7903          OPEN csr_get_tx_id;
7904 
7905          FETCH csr_get_tx_id
7906           INTO l_tx_id;
7907 
7908          CLOSE csr_get_tx_id;
7909 
7910          INSERT INTO hxc_transactions
7911                      (transaction_id, transaction_process_id,
7912                       transaction_date, TYPE, status,
7913                       exception_description
7914                      )
7915               VALUES (l_tx_id, l_process_id,
7916                       SYSDATE, 'RETRIEVAL_STATUS_UPDATE', p_status,
7917                       p_exception_description
7918                      );
7919 
7920          UPDATE hxc_transactions
7921             SET status = p_status,
7922                 exception_description = p_exception_description
7923           WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
7924 
7925          IF NOT p_rollback
7929                hr_utility.set_location ('Processing ' || l_proc, 130);
7926          THEN
7927             IF g_debug
7928             THEN
7930             END IF;
7931 
7932 -- check to see if any tx time details
7933             IF l_time_max <> 0
7934             THEN
7935 -- now let's bulk fetch all the transaction detail id
7936                OPEN csr_get_tx_detail_id (l_time_max);
7937 
7938                FETCH csr_get_tx_detail_id
7939                BULK COLLECT INTO l_temp_transaction_id;
7940 
7941                CLOSE csr_get_tx_detail_id;
7942 
7943                hxc_generic_retrieval_pkg.t_tx_time_transaction_id :=
7944                                                         l_temp_transaction_id;
7945 
7946                IF g_debug
7947                THEN
7948                   hr_utility.set_location ('Processing ' || l_proc, 50);
7949                END IF;
7950 
7951                FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_time_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_time_transaction_id.LAST
7952                   INSERT INTO hxc_transaction_details
7953                               (transaction_detail_id,
7954                                time_building_block_id,
7955                                time_building_block_ovn,
7956                                transaction_id,
7957                                status,
7958                                exception_description
7959                               )
7960                        VALUES (hxc_generic_retrieval_pkg.t_tx_time_transaction_id
7961                                                                     (tx_detail),
7962                                hxc_generic_retrieval_pkg.t_tx_time_bb_id
7963                                                                     (tx_detail),
7964                                hxc_generic_retrieval_pkg.t_tx_time_bb_ovn
7965                                                                     (tx_detail),
7966                                hxc_generic_retrieval_pkg.g_transaction_id,
7967                                hxc_generic_retrieval_pkg.t_tx_time_status
7968                                                                     (tx_detail),
7969                                hxc_generic_retrieval_pkg.t_tx_time_exception
7970                                                                     (tx_detail)
7971                               );
7972             END IF;                                         -- l_time_max <> 0
7973 
7974 -- check to see if any tx day details
7975             IF l_day_max <> 0
7976             THEN
7977 -- now let's bulk fetch all the transaction detail id
7978                OPEN csr_get_tx_detail_id (l_day_max);
7979 
7980                FETCH csr_get_tx_detail_id
7981                BULK COLLECT INTO l_temp_transaction_id;
7982 
7983                CLOSE csr_get_tx_detail_id;
7984 
7985                hxc_generic_retrieval_pkg.t_tx_day_transaction_id :=
7986                                                         l_temp_transaction_id;
7987 
7988                IF g_debug
7989                THEN
7990                   hr_utility.set_location ('Processing ' || l_proc, 60);
7991                END IF;
7992 
7993                FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_day_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_day_transaction_id.LAST
7994                   INSERT INTO hxc_transaction_details
7995                               (transaction_detail_id,
7996                                time_building_block_id,
7997                                time_building_block_ovn,
7998                                transaction_id,
7999                                status,
8000                                exception_description
8001                               )
8002                        VALUES (hxc_generic_retrieval_pkg.t_tx_day_transaction_id
8003                                                                     (tx_detail),
8004                                hxc_generic_retrieval_pkg.t_tx_day_bb_id
8005                                                                     (tx_detail),
8006                                hxc_generic_retrieval_pkg.t_tx_day_bb_ovn
8010                                                                     (tx_detail),
8007                                                                     (tx_detail),
8008                                hxc_generic_retrieval_pkg.g_transaction_id,
8009                                hxc_generic_retrieval_pkg.t_tx_day_status
8011                                hxc_generic_retrieval_pkg.t_tx_day_exception
8012                                                                     (tx_detail)
8013                               );
8014             END IF;                                          -- l_day_max <> 0
8015 
8016 -- check to see if any tx detail details
8017             IF l_detail_max <> 0
8018             THEN
8019 -- now let's bulk fetch all the transaction detail id
8020                OPEN csr_get_tx_detail_id (l_detail_max);
8021 
8022                FETCH csr_get_tx_detail_id
8023                BULK COLLECT INTO l_temp_transaction_id;
8024 
8025                CLOSE csr_get_tx_detail_id;
8026 
8027                hxc_generic_retrieval_pkg.t_tx_detail_transaction_id :=
8028                                                         l_temp_transaction_id;
8029 
8030                IF g_debug
8031                THEN
8032                   hr_utility.set_location ('Processing ' || l_proc, 70);
8033                END IF;
8034 
8035                FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.LAST
8036                   INSERT INTO hxc_transaction_details
8037                               (transaction_detail_id,
8038                                time_building_block_id,
8039                                time_building_block_ovn,
8040                                transaction_id,
8041                                status,
8042                                exception_description
8043                               )
8044                        VALUES (hxc_generic_retrieval_pkg.t_tx_detail_transaction_id
8045                                                                     (tx_detail),
8046                                hxc_generic_retrieval_pkg.t_tx_detail_bb_id
8047                                                                     (tx_detail),
8048                                hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn
8049                                                                     (tx_detail),
8050                                hxc_generic_retrieval_pkg.g_transaction_id,
8051                                hxc_generic_retrieval_pkg.t_tx_detail_status
8052                                                                     (tx_detail),
8053                                hxc_generic_retrieval_pkg.t_tx_detail_exception
8054                                                                     (tx_detail)
8055                               );
8056 
8057                IF g_debug
8058                THEN
8059                   hr_utility.set_location ('Processing ' || l_proc, 75);
8060                END IF;
8061             END IF;                                       -- l_detail_max <> 0
8062 
8063             IF g_debug
8064             THEN
8065                hr_utility.set_location ('Processing ' || l_proc, 80);
8066             END IF;
8067 
8068             IF l_error_max <> 0
8069             THEN
8070                IF g_debug
8071                THEN
8072                   hr_utility.set_location ('Processing ' || l_proc, 85);
8073                END IF;
8074 
8075 -- now let's bulk fetch all the transaction detail id
8076                OPEN csr_get_tx_detail_id (l_error_max);
8077 
8078                FETCH csr_get_tx_detail_id
8079                BULK COLLECT INTO l_temp_transaction_id;
8080 
8081                CLOSE csr_get_tx_detail_id;
8082 
8083                hxc_generic_retrieval_pkg.t_tx_error_transaction_id :=
8084                                                          l_temp_transaction_id;
8085 
8086                IF g_debug
8087                THEN
8088                   hr_utility.set_location ('Processing ' || l_proc, 90);
8089                END IF;
8090 
8091                FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
8092                   INSERT INTO hxc_transaction_details
8093                               (transaction_detail_id,
8094                                time_building_block_id,
8095                                time_building_block_ovn,
8096                                transaction_id,
8097                                status,
8098                                exception_description
8099                               )
8100                        VALUES (hxc_generic_retrieval_pkg.t_tx_error_transaction_id
8101                                                                      (tx_error),
8102                                hxc_generic_retrieval_pkg.t_tx_error_bb_id
8103                                                                      (tx_error),
8104                                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn
8105                                                                      (tx_error),
8106                                hxc_generic_retrieval_pkg.g_transaction_id,
8107                                hxc_generic_retrieval_pkg.t_tx_error_status
8108                                                                      (tx_error),
8109                                hxc_generic_retrieval_pkg.t_tx_error_exception
8110                                                                      (tx_error)
8114                hxc_generic_retrieval_pkg.t_tx_error_transaction_id.DELETE;
8111                               );
8112 -- given we are only going to do this once and the recipient app does not need
8113 -- to maintain these statuses we can delete the arrays
8115                hxc_generic_retrieval_pkg.t_tx_error_bb_id.DELETE;
8116                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn.DELETE;
8117                hxc_generic_retrieval_pkg.t_tx_error_status.DELETE;
8118                hxc_generic_retrieval_pkg.t_tx_error_exception.DELETE;
8119 
8120                IF g_debug
8121                THEN
8122                   hr_utility.set_location ('Processing ' || l_proc, 100);
8123                END IF;
8124             END IF;                                        -- l_error_max <> 0
8125          END IF;                                                 -- p_rollback
8126 
8127          IF g_debug
8128          THEN
8129             hr_utility.set_location ('Processing ' || l_proc, 170);
8130          END IF;
8131 
8132          -- need to clean up the hxc retrieval ranges table if the process
8133          -- has errored.
8134          IF (p_status = 'ERRORS')
8135          THEN
8136             UPDATE hxc_retrieval_ranges
8137                SET transaction_id = -1
8138              WHERE retrieval_process_id = l_process_id AND transaction_id = -1;
8139          END IF;
8140       END IF;                                           -- p_status = 'ERRORS'
8141 
8142 -- now we need to unlock any TCs which were locked
8143       hxc_lock_api.release_lock
8144          (p_row_lock_id              => NULL,
8145           p_process_locker_type      => hxc_generic_retrieval_pkg.g_lock_type,
8146           p_transaction_lock_id      => hxc_generic_retrieval_pkg.g_transaction_id,
8147           p_released_success         => l_boolean
8148          );
8149 
8150 	--bug 5669202
8151 
8152 	IF ((p_status = 'SUCCESS' OR p_status = 'ERRORS') AND l_process_id <> -1)
8153 	-- DO NOT DELETE FOR 'IN PROGRESS' TRANSACTIONS
8154         THEN
8155                IF g_debug
8156                THEN
8157                        hr_utility.TRACE ('g_conc_request_id is ' || g_conc_request_id);
8158                END IF;
8159 
8160                delete_retrieval_ranges (hxc_generic_retrieval_pkg.g_transaction_id);
8161 
8162                IF g_debug
8163                THEN
8164                        hr_utility.set_location ('Processing ' || l_proc, 200);
8165                END IF;
8166         ELSE
8167                IF g_debug
8168                THEN
8169                        hr_utility.set_location ('Processing ' || l_proc, 250);
8170                END IF;
8171         END IF;
8172 
8173       IF (hxc_generic_retrieval_utils.chk_terminated
8174                                          (fnd_profile.VALUE ('CONC_REQUEST_ID')
8175                                          )
8176          )
8177       THEN
8178          fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8179          fnd_message.set_token ('PROCEDURE', 'Generic Retrieval');
8180          fnd_message.set_token ('STEP', ': Process Terminated');
8181          fnd_message.raise_error;
8182       END IF;
8183 
8184 
8185 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
8186 	    || ' > Blocks COUNT of TRANSACTION DETAILS > ' || hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.COUNT);
8187 
8188 	IF(hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.COUNT > 0) THEN
8189 
8190 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
8191 	    || ' > ******* Details Recevied from the RECIPIENT APPLICATION *******');
8192 
8193 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8194 	fnd_file.put_line(fnd_file.log, '     DETAIL      '
8195 				     || '     TRANSACTON ID      '
8196 				     || '     STATUS        '
8197 				     || '     DESCRIPTION       ');
8198 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8199 
8200 	FOR i IN hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.LAST
8201 	LOOP
8202 
8203 	fnd_file.put_line(fnd_file.log,
8204 	     '     '
8205 	    || hxc_generic_retrieval_pkg.t_tx_detail_bb_id(i)
8206 	    || ' ['
8207 	    || hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn(i)
8208 	    || ']       '
8209 	    || hxc_generic_retrieval_pkg.t_tx_detail_transaction_id(i)
8210 	    || '        '
8211 	    || hxc_generic_retrieval_pkg.t_tx_detail_status(i)
8212 	    || '        '
8213 	    || hxc_generic_retrieval_pkg.t_tx_detail_exception(i));
8214 
8215 	END LOOP;
8216 
8217 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8218 
8219 	END IF;
8220 
8221 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
8222 	    || ' > ERRORed BLOCK count > ' || hxc_generic_retrieval_pkg.t_tx_error_transaction_id.COUNT);
8223 
8224 	IF(hxc_generic_retrieval_pkg.t_tx_error_transaction_id.COUNT > 0) THEN
8225 
8226 	fnd_file.put_line(fnd_file.log, fnd_date.date_to_canonical(SYSDATE)
8227 	    || ' > ******* The following blocks are in ERROR *******');
8228 
8229 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8230 	fnd_file.put_line(fnd_file.log, '     DETAIL      '
8231 				     || '     TRANSACTON ID      '
8232 				     || '     STATUS        '
8236 	FOR i IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
8233 				     || '     DESCRIPTION       ');
8234 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8235 
8237 	LOOP
8238 
8239 	fnd_file.put_line(fnd_file.log,
8240 	    '    '
8241 	    || hxc_generic_retrieval_pkg.t_tx_error_bb_id(i)
8242 	    || ' ['
8243 	    || hxc_generic_retrieval_pkg.t_tx_error_bb_ovn(i)
8244 	    || ']       '
8245 	    || hxc_generic_retrieval_pkg.t_tx_error_transaction_id(i)
8246 	    || '        '
8247 	    || hxc_generic_retrieval_pkg.t_tx_error_status(i)
8248 	    || '        '
8249 	    || hxc_generic_retrieval_pkg.t_tx_error_exception(i));
8250 
8251 	END LOOP;
8252 
8253 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8254 
8255 	END IF;
8256 
8257       IF g_debug
8258       THEN
8259          hr_utility.TRACE ('Leaving Update Transaction Status');
8260       END IF;
8261    END update_transaction_status;
8262 END hxc_generic_retrieval_pkg;