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.48.12020000.7 2013/03/27 08:37:00 asrajago 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    -- Bug 9346163
126    -- Rewrote the cursor to pick nextval(s) from the sequence.
127    -- The old cursor would not return values in case the table in the FROM
128    -- clause is empty. While it is a bad idea to use a physical table
129    -- in such a case, using a transactional table is asking for trouble.
130    -- Dual with Connect by would give the same result and is safe.
131 
132    /*
133    CURSOR csr_get_tx_detail_id (p_max BINARY_INTEGER)
134    IS
135       SELECT /*+ INDEX_FFS(TXD HXC_TRANSACTION_DETAILS_PK) *
136              hxc_transaction_details_s.NEXTVAL
137         FROM hxc_transaction_details txd
138        WHERE ROWNUM <= p_max;
139    */
140 
141    CURSOR csr_get_tx_detail_id (p_max BINARY_INTEGER)
142    IS
143       SELECT hxc_transaction_details_s.NEXTVAL
144         FROM SYS.DUAL
145      CONNECT BY LEVEL <= p_max ;
146 
147    g_conc_request_id               NUMBER (15);
148 
149    PROCEDURE insert_query (p_query LONG
150 /*PROFILER(457): LONG (advise: migrate to LOB) is Oracle 7.0 (deprecated in 8.1.5) */
151                                        , p_type VARCHAR2)
152    IS
153       PRAGMA AUTONOMOUS_TRANSACTION;
154    BEGIN
155       DELETE FROM hxc_debug_text
156             WHERE process = 'RETRIEVAL' AND TYPE = p_type;
157 
158       INSERT INTO hxc_debug_text
159                   (process, TYPE, text
160                   )
161            VALUES ('RETRIEVAL', p_type, p_query
162                   );
163 
164       COMMIT;
165    END insert_query;
166 
167    FUNCTION initialise_g_resource (p_resource_id NUMBER)
168       RETURN NUMBER
169    IS
170    BEGIN
171 -- just in case deterministic is not working use EXISTS
172       IF (NOT hxc_generic_retrieval_utils.g_resources.EXISTS (p_resource_id)
173          )
174       THEN
175          hxc_generic_retrieval_utils.g_resources (p_resource_id).resource_id :=
176                                                                 p_resource_id;
177          -- NOTE: these setting are not the wrong way round
178          -- need a date for when the first LEAST/GREATEST comparison is done, so we always get the
179          -- TC start/stop time
180          hxc_generic_retrieval_utils.g_resources (p_resource_id).start_time :=
181                                                        hr_general.end_of_time;
182          hxc_generic_retrieval_utils.g_resources (p_resource_id).stop_time :=
183                                                      hr_general.start_of_time;
184       END IF;
185 
186       RETURN 1;
187    END initialise_g_resource;
188 
189    FUNCTION replace_timecard_string (p_where VARCHAR2)
190       RETURN VARCHAR2
191    IS
192       l_where   VARCHAR2 (2000);
193    BEGIN
194       IF (g_params.p_process = 'Maintenance Retrieval Process')
195       THEN
196          l_where := REPLACE (p_where, 'TIMECARD_BLOCK', 'tbb_latest');
197          l_where := REPLACE (l_where, 'DAY_BLOCK', 'tbb_latest');
198          l_where := REPLACE (l_where, 'DETAIL_BLOCK', 'tbb_latest');
199       ELSE
200          l_where := REPLACE (p_where, 'TIMECARD_BLOCK', 'tbb');
201          l_where := REPLACE (l_where, 'DAY_BLOCK', 'tbb');
202          l_where := REPLACE (l_where, 'DETAIL_BLOCK', 'tbb');
203       END IF;
204 
205       RETURN l_where;
206    END replace_timecard_string;
207 
208 -- private procedure
209 --    parse_it
210 --
211 -- description
212 --    Used to parse the application specific WHERE clause
213 --    passed to the generic retrieval
214 --
215 -- parameters
216 --   p_where_clause  -  the application specific WHERE clause
217    PROCEDURE parse_it (
218       p_where_clause_blk   IN OUT NOCOPY   VARCHAR2,
219       p_where_clause_att   IN OUT NOCOPY   VARCHAR2
220    )
221    IS
222       l_text   VARCHAR2 (2000);
223       l_proc   VARCHAR2 (72);
224 
225       PROCEDURE translate_it (
226          p_text       IN OUT NOCOPY   VARCHAR2,
227          p_text_blk   IN OUT NOCOPY   VARCHAR2,
228          p_text_att   IN OUT NOCOPY   VARCHAR2
229       )
230       IS
231 --
232          l_proc                          VARCHAR2 (72);
233          l_start_position                NUMBER (4);
234          l_end_position                  NUMBER (4);
235          l_new_start_position            NUMBER (4);
236          l_absolute_start_position       NUMBER (4);
237          l_absolute_end_position         NUMBER (4);
238          l_blk_absolute_start_position   NUMBER (4);
239          l_blk_absolute_end_position     NUMBER (4);
240          l_att_absolute_start_position   NUMBER (4);
241          l_att_absolute_end_position     NUMBER (4);
242          l_placeholder                   VARCHAR2 (100);
243          l_predicate                     VARCHAR2 (2000);
244          l_attribute                     VARCHAR2 (15);
245          l_table_dot_column              VARCHAR2 (2000);
246          l_blk_table_dot_column          VARCHAR2 (2000);
247          l_att_table_dot_column          VARCHAR2 (2000);
248          l_info_type_id                  hxc_bld_blk_info_types.bld_blk_info_type_id%TYPE;
249          l_detail_exists                 VARCHAR2 (400)
250             := '
251  EXISTS ( select 1 from hxc_time_attribute_usages usage,
252                         hxc_time_attributes att
253           where usage.time_building_Block_id  = detail_block.time_building_block_id AND
254                 usage.time_building_block_ovn = detail_block.object_version_number
255           and
256                 att.time_attribute_id = usage.time_attribute_id and
257                 att.';
258          l_exists                        VARCHAR2 (400)
259             := '
260  EXISTS ( select 1 from hxc_time_attribute_usages usage,
261                         hxc_time_attributes att
262           where usage.time_building_Block_id  = timecard_block.time_building_block_id AND
263                 usage.time_building_block_ovn = timecard_block.object_version_number
264           and
265                 att.time_attribute_id = usage.time_attribute_id and
266                 att.';
267       BEGIN                                                    -- translate_it
268          IF g_debug
269          THEN
270             l_proc := g_package || 'translate_it';
271             hr_utility.set_location ('Entering ' || l_proc, 10);
272          END IF;
273 
274 -- placeholder is delimited by [ ], find the delimited string
275          l_start_position := INSTR (p_text, '[', 1, 1) + 1;
276          l_end_position :=
277                  ((INSTR (p_text, ']', 1, 1) - INSTR (p_text, '[', 1, 1)) - 1
278                  );
279          l_placeholder := SUBSTR (p_text, l_start_position, l_end_position);
280 
281          IF g_debug
282          THEN
283             hr_utility.set_location ('Processing ' || l_proc, 20);
284          END IF;
285 
286 -- predicate is delimited by {}, find the predicate
287          l_start_position := INSTR (p_text, '{', 1, 1) + 1;
288          l_end_position :=
289                  ((INSTR (p_text, '}', 1, 1) - INSTR (p_text, '{', 1, 1)) - 1
290                  );
291          l_predicate := SUBSTR (p_text, l_start_position, l_end_position);
292 
293          IF g_debug
294          THEN
295             hr_utility.set_location ('Processing ' || l_proc, 30);
296          END IF;
297 
298 -- now that we have the string ensure it is not a reserved keyword.
299 -- if it is then we can leave it be, otherwise we need to map this
300 -- against the field mappings
301          IF (UPPER (l_placeholder) IN
302                 ('TIMECARD_BLOCK.COMMENT_TEXT',
303                  'TIMECARD_BLOCK.RESOURCE_TYPE',
304                  'TIMECARD_BLOCK.RESOURCE_ID',
305                  'DAY_BLOCK.COMMENT_TEXT',
306                  'DAY_BLOCK.RESOURCE_TYPE',
307                  'DAY_BLOCK.RESOURCE_ID',
308                  'DETAIL_BLOCK.COMMENT_TEXT',
309                  'DETAIL_BLOCK.RESOURCE_TYPE',
310                  'DETAIL_BLOCK.RESOURCE_ID'
311                 )
312             )
313          THEN
314             l_table_dot_column := l_placeholder || ' ' || l_predicate;
315             l_blk_table_dot_column := l_placeholder || ' ' || l_predicate;
316          ELSE
317             -- find which attribute it is associated with by looping through the mappings table
318             FOR map_cnt IN
319                g_field_mappings_table.FIRST .. g_field_mappings_table.LAST
320             LOOP
321                IF g_debug
322                THEN
323                   hr_utility.set_location ('Processing ' || l_proc, 40);
324                END IF;
325 
326                -- check to see if placeholder matches field name
327                IF (g_field_mappings_table (map_cnt).field_name =
328                                                          UPPER (l_placeholder)
329                   )
330                THEN
331                   l_attribute := g_field_mappings_table (map_cnt).ATTRIBUTE;
332                   l_info_type_id :=
333                         g_field_mappings_table (map_cnt).bld_blk_info_type_id;
334                   EXIT;
335                END IF;
336             END LOOP;
337 
338             IF g_debug
339             THEN
340                hr_utility.set_location ('Processing ' || l_proc, 50);
341             END IF;
342 
343             IF (g_params.p_process = 'Projects Retrieval Process')
344             THEN
345                l_table_dot_column :=
346                      l_exists
347                   || l_attribute
348                   || ' '
349                   || l_predicate
350                   || ' and att.bld_blk_info_type_id = '
351                   || l_info_type_id
352                   || ' ) ';
353                l_att_table_dot_column :=
354                      l_exists
355                   || l_attribute
356                   || ' '
357                   || l_predicate
358                   || ' and att.bld_blk_info_type_id = '
359                   || l_info_type_id
360                   || ' ) ';
361             ELSE
362                l_table_dot_column :=
363                      l_detail_exists
364                   || l_attribute
365                   || ' '
366                   || l_predicate
367                   || ' and att.bld_blk_info_type_id = '
368                   || l_info_type_id
369                   || ' ) ';
370                l_att_table_dot_column :=
371                      l_detail_exists
372                   || l_attribute
373                   || ' '
374                   || l_predicate
375                   || ' and att.bld_blk_info_type_id = '
376                   || l_info_type_id
377                   || ' ) ';
378             END IF;
379          END IF;                                       -- UPPER( l_placeholder
380 
381          IF g_debug
382          THEN
383             hr_utility.set_location ('Processing ' || l_proc, 60);
384          END IF;
385 
386 -- now replace the placeholder with the table dot column expression and remove the predicate all together
387          l_absolute_start_position := INSTR (p_text, '[', 1, 1);
388          l_absolute_end_position := INSTR (p_text, '}', 1, 1) + 1;
389          p_text :=
390                REPLACE (SUBSTR (p_text, 1, l_absolute_start_position), '[')
391             || ' '
392             || l_table_dot_column
393             || ' '
394             || SUBSTR (p_text, l_absolute_end_position);
395          l_blk_absolute_start_position := INSTR (p_text_blk, '[', 1, 1);
396          l_blk_absolute_end_position := INSTR (p_text_blk, '}', 1, 1) + 1;
397          l_att_absolute_start_position := INSTR (p_text_att, '[', 1, 1);
398          l_att_absolute_end_position := INSTR (p_text_att, '}', 1, 1) + 1;
399 
400 -- This next seciton of code is to support EAM which can pass a mixture of both ATTribute and
401 -- BLK level where clause.
402          IF (    l_blk_absolute_start_position >= 5
403              AND l_blk_table_dot_column IS NULL
404             )
405          THEN
406             l_new_start_position :=
407                INSTR (p_text_blk,
408                       'AND',
409                       (l_blk_absolute_start_position - 4),
410                       1
411                      );
412 
413             IF (l_new_start_position <> 0)
414             THEN
415                l_blk_absolute_start_position := l_new_start_position - 1;
416             END IF;
417          ELSIF (    l_blk_absolute_start_position = 5
418                 AND l_blk_table_dot_column IS NOT NULL
419                )
420          THEN
421             l_blk_absolute_start_position := 0;
422          END IF;
423 
424          IF (    l_att_absolute_start_position >= 5
425              AND l_att_table_dot_column IS NULL
426             )
427          THEN
428             l_new_start_position :=
429                INSTR (p_text_att,
430                       'AND',
431                       (l_att_absolute_start_position - 4),
432                       1
433                      );
434 
435             IF (l_new_start_position <> 0)
436             THEN
437                l_att_absolute_start_position := l_new_start_position - 1;
438             END IF;
439          ELSIF (    l_att_absolute_start_position = 5
440                 AND l_att_table_dot_column IS NOT NULL
441                )
442          THEN
443             l_att_absolute_start_position := 0;
444          END IF;
445 
446          p_text_blk :=
447             LTRIM (RTRIM (   REPLACE (SUBSTR (p_text_blk,
448                                               1,
449                                               l_blk_absolute_start_position
450                                              ),
451                                       '['
452                                      )
453                           || ' '
454                           || l_blk_table_dot_column
455                           || ' '
456                           || SUBSTR (p_text_blk, l_blk_absolute_end_position)
457                          )
458                   );
459          p_text_att :=
460             LTRIM (RTRIM (   REPLACE (SUBSTR (p_text_att,
461                                               1,
462                                               l_att_absolute_start_position
463                                              ),
464                                       '['
465                                      )
466                           || ' '
467                           || l_att_table_dot_column
468                           || ' '
469                           || SUBSTR (p_text_att, l_att_absolute_end_position)
470                          )
471                   );
472       END translate_it;
473    BEGIN                                                           -- parse it
474       IF g_debug
475       THEN
476          l_proc := g_package || 'parse_it';
477          hr_utility.set_location ('Entering ' || l_proc, 10);
478       END IF;
479 
480       l_text := p_where_clause_blk;
481 
482 -- first check that there is something to decode
483       IF INSTR (l_text, '[', 1, 1) <> 0
484       THEN
485          WHILE INSTR (l_text, '[', 1, 1) <> 0
486          LOOP
487             translate_it (p_text          => l_text,
488                           p_text_blk      => p_where_clause_blk,
489                           p_text_att      => p_where_clause_att
490                          );
491 
492             IF g_debug
493             THEN
494                hr_utility.TRACE ('where blk is ' || p_where_clause_blk);
495                hr_utility.TRACE ('where att is ' || p_where_clause_att);
496             END IF;
497          END LOOP;
498       END IF;
499 
500       IF g_debug
501       THEN
502          hr_utility.set_location ('Leaving ' || l_proc, 20);
503       END IF;
504 
505 -- using length since the ASCII new line is left when the WHERE has carriage returns
506       IF (LENGTH (LTRIM (RTRIM (p_where_clause_att))) > 5)
507       THEN
508          p_where_clause_att := ' AND ' || p_where_clause_att || ' ';
509       END IF;
510 
511       IF (LENGTH (LTRIM (RTRIM (p_where_clause_blk))) > 5)
512       THEN
513          p_where_clause_blk := ' AND ' || p_where_clause_blk || ' ';
514       END IF;
515    END parse_it;
516 
517    PROCEDURE maintain_ranges (
518       p_process_id                     NUMBER,
519       p_range_start    IN OUT NOCOPY   NUMBER,
520       p_range_stop     IN OUT NOCOPY   NUMBER,
521       p_where_clause                   VARCHAR2
522    )
523    IS
524       PRAGMA AUTONOMOUS_TRANSACTION;
525       l_proc                    VARCHAR2 (72);
526 
527       CURSOR csr_get_next_range
528       IS
529          SELECT        rr.retrieval_range_id, rr.range_start, rr.range_stop
530                   FROM hxc_retrieval_ranges rr
531                  WHERE rr.retrieval_process_id = p_process_id
532                    AND rr.transaction_id = 0
533                    AND (   rr.where_clause = g_params.p_where_clause
534                         OR rr.where_clause IS NULL
535                        )
536               ORDER BY rr.seq
537          FOR UPDATE OF transaction_id NOWAIT;
538 
539       r_range                   csr_get_next_range%ROWTYPE;
540       l_dummy                   VARCHAR2 (1);
541       l_cnt                     PLS_INTEGER                               := 0;
542       l_not_maintained_ranges   BOOLEAN                                := TRUE;
543       l_first_resource_id       hxc_time_building_blocks.resource_id%TYPE;
544       l_last_resource_id        hxc_time_building_blocks.resource_id%TYPE;
545       l_dynamic_sql             VARCHAR2 (32000);
546       l_range_start             NUMBER;
547       l_range_stop              NUMBER;
548 
549       TYPE tab_rr_id IS TABLE OF hxc_retrieval_ranges.retrieval_range_id%TYPE
550          INDEX BY BINARY_INTEGER;
551 
552       TYPE tab_retrieval_process_id IS TABLE OF hxc_retrieval_ranges.retrieval_process_id%TYPE
553          INDEX BY BINARY_INTEGER;
554 
555       TYPE tab_range_start IS TABLE OF hxc_retrieval_ranges.range_start%TYPE
556          INDEX BY BINARY_INTEGER;
557 
558       TYPE tab_range_stop IS TABLE OF hxc_retrieval_ranges.range_stop%TYPE
559          INDEX BY BINARY_INTEGER;
560 
561       TYPE tab_seq IS TABLE OF hxc_retrieval_ranges.seq%TYPE
562          INDEX BY BINARY_INTEGER;
563 
564       TYPE tab_where_clause IS TABLE OF hxc_retrieval_ranges.where_clause%TYPE
565          INDEX BY BINARY_INTEGER;
566 
567       TYPE r_resource_id IS RECORD (
568          resource_id   NUMBER (15)
569       );
570 
571       TYPE tab_resource_id IS TABLE OF r_resource_id
572          INDEX BY BINARY_INTEGER;
573 
574       t_rr_id                   tab_rr_id;
575       t_retrieval_process_id    tab_retrieval_process_id;
576       t_range_start             tab_range_start;
577       t_range_stop              tab_range_stop;
578       t_seq                     tab_seq;
579       t_where_clause            tab_where_clause;
580       t_resource_id_bulk        tab_resource_id;
581       t_resource_id             DBMS_SQL.number_table;
582       t_retrieval_range_id      DBMS_SQL.number_table;
583       l_resource_list           DBMS_SQL.number_table;
584       l_rows_fetched            INTEGER;
585       l_csr                     INTEGER;
586       l_since_date              DATE;
587       x                         PLS_INTEGER                               := 0;
588       l_chunk_size              NUMBER;
589       l_rr_id                   NUMBER (15);
590       l_ind                     PLS_INTEGER;
591 
592 -- private procedure
593 --   generate_resource_sql
594 --
595 -- description
596 --   returns the dynamic SQL used to generate the resource list
597 --
598       PROCEDURE generate_resource_sql (
599          p_dynamic_sql         IN OUT NOCOPY   VARCHAR2,
600          p_first_resource_id   IN OUT NOCOPY   NUMBER,
601          p_last_resource_id    IN OUT NOCOPY   NUMBER,
602          p_where_clause                        VARCHAR2
603       )
604       IS
605          l_proc                VARCHAR2 (72);
606 
607          CURSOR csr_get_range (p_range VARCHAR2)
608          IS
609             SELECT TYPE
610               FROM hxc_debug_text
611              WHERE process = p_range;
612 
613          -- Bug 8888911
614          -- Cursor to pick up all application sets for this process.
615          CURSOR get_app_sets ( p_process  VARCHAR2)
616              IS   SELECT has.application_set_id
617                     FROM hxc_retrieval_processes hrp,
618                   	     hxc_application_set_comps_v has
619                    WHERE hrp.name = DECODE(p_process,
620                                            'Apply Schedule Rules','BEE Retrieval Process',
621                                            p_process)
622                      AND hrp.time_recipient_id = has.time_recipient_id;
623 
624 
625 
626          l_first_resource_id   hxc_time_building_blocks.resource_id%TYPE
627                                                                         := -1;
628          l_last_resource_id    hxc_time_building_blocks.resource_id%TYPE
629                                                                         := -1;
630          l_where_blk           VARCHAR2 (2000);
631          l_where_att           VARCHAR2 (2000);
632          l_dynamic_sql         VARCHAR2 (32000);
633          l_range_caveat        BOOLEAN                               := FALSE;
634          l_root                VARCHAR2 (2500)
635             := '
636 SELECT DISTINCT tbb.resource_id
637 FROM   hxc_latest_details tbb
638 WHERE  tbb.last_update_date > :p_since_date ';
639 
640 
641 -- Bug 9394444
642 -- Retrieval performance upgrade, using the new tables in these new sql strings.
643 l_root_pa               VARCHAR2(2500)
644 := '
645 SELECT DISTINCT tbb.resource_id
646 FROM   hxc_pa_latest_details tbb
647 WHERE  tbb.last_update_date > :p_since_date ';
648 
649 l_root_pay               VARCHAR2(2500)
650 := '
651 SELECT DISTINCT tbb.resource_id
652 FROM   hxc_pay_latest_details tbb
653 WHERE  tbb.last_update_date > :p_since_date ';
654 
655 
656          l_root_day            VARCHAR2 (2500)
657             := '
658 SELECT DISTINCT tbb.resource_id
659 FROM   hxc_latest_details tbb
660 WHERE  tbb.last_update_date > :p_since_date ';
661 
662 
663 -- Bug 9394444
664          l_root_day_pa            VARCHAR2 (2500)
665             := '
666 SELECT DISTINCT tbb.resource_id
667 FROM   hxc_pa_latest_details tbb
668 WHERE  tbb.last_update_date > :p_since_date ';
669 
670          l_root_day_pay            VARCHAR2 (2500)
671             := '
672 SELECT DISTINCT tbb.resource_id
673 FROM   hxc_pay_latest_details tbb
674 WHERE  tbb.last_update_date > :p_since_date ';
675 
676          l_order_by            VARCHAR2 (100)                := ' ORDER BY 1';
677 
678 
679          -- Bug 8888911
680          -- New variables added for processing Org and appln stripping.
681          l_org_strip           VARCHAR2(500);
682          l_appln_strip         VARCHAR2(500) :=
683       ' AND tbb.application_set_id IN (';
684          l_rtp_id              NUMBER;
685 
686          -- Bug 9662478
687 
688          -- Bug 12700547
689          -- Added hints
690          l_rdb_process_sql     VARCHAR2(32000) :=
691 ' INSERT INTO hxc_rdb_process_timecards
692               (timecard_id,
693                resource_id,
694                start_time,
695                stop_time,
696                stage,
697                request_id,
698                ret_user_id,
699                process)
700 SELECT /*+ INDEX(tbb LATEST_DETAILS_N2)
701            INDEX(sum HXC_TIME_BUILDING_BLOCKS_PK) */
702        DISTINCT tbb.timecard_id,
703                sum.resource_id,
704                sum.start_time,
705                TRUNC(sum.stop_time),
706                ''PENDING'',
707                fnd_global.conc_request_id,
708                fnd_global.user_id,
709                RETRIEVALPROCESS
710   FROM LATEST_DETAILS tbb,
711        hxc_time_building_blocks sum
712  WHERE sum.resource_id = tbb.resource_id
713    AND sum.time_building_block_id = tbb.timecard_id
714    AND tbb.last_update_date > :p_since_date';
715 
716 
717           -- Bug 9458888
718           -- Used for Retrieval Dashboard process tab.
719 
720           PROCEDURE mark_for_retrieval(p_since_date  IN DATE,
721                                        p_sql         IN VARCHAR2,
722                                        p_start_date  IN DATE DEFAULT NULL,
723                                        p_end_date    IN DATE DEFAULT NULL)
724           IS
725 
726           PRAGMA AUTONOMOUS_TRANSACTION;
727           l_sql VARCHAR2(32000);
728           -- Bug 9494444
729           -- Added new parameter for post retrieval processing
730           l_request_id  NUMBER;
731 
732            -- Bug 12919783
733            -- Added for Rollback
734            CURSOR get_request_date
735                IS SELECT requested_start_date
736                     FROM fnd_concurrent_requests
737                    WHERE request_id = FND_GLOBAL.conc_request_id;
738 
739           l_request_date  DATE;
740 
741 
742 
743           BEGIN
744 
745               IF g_debug
746               THEN
747                  hr_utility.trace('P_start_date '||p_start_date);
748                  hr_utility.trace('P_end_date   '||p_end_date);
749               END IF;
750 
751               IF p_start_date IS NULL
752                 AND p_end_date IS NULL
753               THEN
754                   IF g_debug
755                   THEN
756                      hr_utility.trace(p_sql);
757                   END IF;
758                   EXECUTE IMMEDIATE p_sql USING p_since_date;
759               ELSIF p_start_date IS NULL
760                AND p_end_date IS NOT NULL
761               THEN
762                   l_sql := p_sql|| ' AND  tbb.start_time <= :p_end_date ';
763                   IF g_debug
764                   THEN
765                      hr_utility.trace(l_sql);
766                   END IF;
767                   EXECUTE IMMEDIATE l_sql USING p_since_date, p_end_date ;
768               ELSIF p_start_date IS NOT NULL
769                AND p_end_date IS NULL
770               THEN
771                   l_sql := p_sql|| ' AND  tbb.stop_time >= :p_start_date ';
772                   IF g_debug
773                   THEN
774                      hr_utility.trace(l_sql);
775                   END IF;
776                   EXECUTE IMMEDIATE l_sql USING p_since_date, p_start_date ;
777               ELSIF p_start_date IS NOT NULL
778                AND p_end_date IS NOT NULL
779               THEN
780                   l_sql := p_sql|| ' AND  tbb.stop_time >= :p_start_date ';
781                   l_sql := l_sql|| ' AND  tbb.start_time <= :p_end_date ';
782                   IF g_debug
783                   THEN
784                      hr_utility.trace(l_sql);
785                   END IF;
786                   EXECUTE IMMEDIATE l_sql USING p_since_date, p_start_date, p_end_date ;
787               END IF;
788               COMMIT;
789 
790 
791               -- Bug 9494444
792               -- Added this call to process the Recipient Snapshot.
793               -- Currently this is required only for projects.
794               -- Controlled by the profile option listed below.
795               -- If the profile says NO, insert the request details into the
796               -- below table so that it can process later.
797               IF g_params.p_process = 'Projects Retrieval Process'
798               THEN
799 
800                  IF NVL(FND_PROFILE.VALUE('HXC_PARALLEL_RDB_SNAPSHOT'),'Y') = 'Y'
801                  THEN
802                      l_request_id := FND_REQUEST.SUBMIT_REQUEST(application => 'HXC'
803                                                                ,program     => 'HXCRDBSNP'
804                                                                ,description => NULL
805                                                                ,sub_request => FALSE
806                                                                ,argument1   => FND_GLOBAL.conc_request_id);
807 
808                       COMMIT;
809                  ELSE
810                     INSERT INTO HXC_RDB_PENDING_PROCESSES
811                            ( request_id,
812                              concurrent_program_id,
813                              user_id,
814                              status)
815                     VALUES ( FND_GLOBAL.conc_request_id,
816                              FND_GLOBAL.conc_program_id,
817                              FND_GLOBAL.user_id,
818                              'PENDING_SNAPSHOT');
819                     COMMIT;
820 
821                  END IF;
822 
823               END IF;
824 
825               -- Bug 12919783
826               -- Marking for Rollback
827 
828               IF g_params.p_process IN (  'BEE Retrieval Process',
829                                           'Apply Schedule Rules')
830               THEN
831 
832 
833                 OPEN get_request_date;
834                 FETCH get_request_date INTO l_request_date;
835                 CLOSE get_request_date;
836 
837                 BEGIN
838                     INSERT INTO hxc_retrieval_requests_all
839                            ( request_id,
840                              conc_program_id,
841                              user_id,
842                              request_date,
843                              ret_trans_code)
844                     VALUES ( FND_GLOBAL.conc_request_id,
845                              FND_GLOBAL.conc_program_id,
846                              FND_GLOBAL.user_id,
847                              l_request_date,
848                              g_params.p_transaction_code);
849                     COMMIT;
850 
851                  EXCEPTION
852                     WHEN DUP_VAL_ON_INDEX
853                     THEN
854                       NULL;
855                 END;
856 
857               END IF;
858 
859 
860           END mark_for_retrieval;
861 
862 
863 
864       BEGIN
865          IF g_debug
866          THEN
867             l_proc := g_package || 'generate_resource_sql';
868             hr_utility.TRACE ('in generate resource sql');
869          END IF;
870 
871          -- Bug 9394444
872          -- Description : This bugfix is actually a performance upgrade thru a data model
873          --   change.  HXC_LATEST_DETAILS, which was the driving table for retrieval, is
874          --   now replaced by two separate tables for Payroll and projects.  The bug fix
875          --   only changes the name of the tables in all the dynamic queries used.
876          --   This new upgrade is dependant on the new profile option OTL: Use Upgraded
877          --   Retrieval Process and would work only if the respective upgrades are
878          --   completed, using the OTL: Generic Upgrade Program.
879          --   Upgrades to be completed are
880          --      Retrieval - Payroll Performance Upgrade
881          --      Retrieval - Projects Performance Upgrade.
882 
883          -- If the new datamodel is to be considered, use the new query texts.
884 
885          IF g_params.p_process = 'Projects Retrieval Process'
886           AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PA')
887           AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
888          THEN
889              l_root_day := l_root_day_pa;
890              l_root     := l_root_pa;
891          ELSIF g_params.p_process IN ('BEE Retrieval Process','Apply Schedule Rules')
892           AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PAY')
893           AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
894          THEN
895              l_root_day := l_root_day_pay;
896              l_root     := l_root_pay;
897          END IF;
898 
899 
900          -- Bug 8888911
901          -- Picking up the Org id or BG id to trim hxc_latest_details.
902          -- do this only if the upgrade is complete.
903          IF g_params.p_process = 'Projects Retrieval Process'
904            AND hxc_upgrade_pkg.ret_upgrade_completed
905          THEN
906              IF Pa_Utils.Pa_Morg_Implemented = 'Y'
907              THEN
908                 l_org_strip :=
909                    '  AND tbb.org_id = '||to_char(Pa_Moac_Utils.Get_Current_Org_Id)||' ';
910              ELSE
911                 l_org_strip := ' ';
912              END IF;
913          ELSIF g_params.p_process IN ('BEE Retrieval Process','Apply Schedule Rules')
914            AND hxc_upgrade_pkg.ret_upgrade_completed
915          THEN
916             l_org_strip :=
917               ' AND tbb.business_group_id = '||to_char(fnd_profile.value('PER_BUSINESS_GROUP_ID'))||' ';
918          ELSE
919             l_org_strip := ' ';
920          END IF;
921 
922          OPEN get_app_sets(g_params.p_process);
923          LOOP
924            FETCH get_app_sets INTO l_rtp_id;
925            EXIT WHEN get_app_sets%NOTFOUND;
926            l_appln_strip := l_appln_strip||l_rtp_id||' ,';
927          END LOOP;
928          CLOSE get_app_sets;
929 
930 
931 
932          -- Bug 9920313
933          -- Need to pick up HR process also, from get_valid_app_sets
934          -- But no need to go thru the time recipient, the process will do
935          -- fine.
936          IF g_params.p_process IN  ('BEE Retrieval Process','Apply Schedule Rules')
937          THEN
938             OPEN get_app_sets('HR Retrieval Process');
939             LOOP
940                FETCH get_app_sets INTO l_rtp_id;
941                EXIT WHEN get_app_sets%NOTFOUND;
942                l_appln_strip := l_appln_strip||l_rtp_id||' ,';
943              END LOOP;
944              CLOSE get_app_sets;
945           END IF;
946 
947 
948 
949          l_appln_strip := RTRIM(l_appln_strip,',');
950          l_appln_strip := l_appln_strip||')';
951 
952          -- Bug 8888911
953          -- Also modified creation of l_dynamic_sql below.
954 
955 
956 -- preserve caveat for skipping resources
957          OPEN csr_get_range ('LOWER');
958 
959          FETCH csr_get_range
960           INTO l_first_resource_id;
961 
962          IF (csr_get_range%FOUND)
963          THEN
964             CLOSE csr_get_range;
965 
966             OPEN csr_get_range ('UPPER');
967 
968             FETCH csr_get_range
969              INTO l_last_resource_id;
970 
971             IF (csr_get_range%FOUND)
972             THEN
973                CLOSE csr_get_range;
974 
975                l_range_caveat := TRUE;
976 
977                IF g_debug
978                THEN
979                   hr_utility.TRACE ('Using range caveat');
980                END IF;
981             END IF;
982          ELSE
983             CLOSE csr_get_range;
984          END IF;
985 
986          IF (    (INSTR (UPPER (p_where_clause), 'TIMECARD_ATT') = 0)
987              AND (INSTR (UPPER (p_where_clause), 'DAY_ATT') = 0)
988              AND (INSTR (UPPER (p_where_clause), 'DETAIL_ATT') = 0)
989              AND (INSTR (UPPER (p_where_clause), 'RESOURCE_ID') <> 0)
990             )
991          THEN
992             l_where_blk := LTRIM (RTRIM (p_where_clause));
993             l_where_att := LTRIM (RTRIM (p_where_clause));
994             parse_it (p_where_clause_blk      => l_where_blk,
995                       p_where_clause_att      => l_where_att
996                      );
997 
998             IF g_debug
999             THEN
1000                hr_utility.TRACE ('after parse ');
1001                hr_utility.TRACE (SUBSTR (l_where_blk, 1, 250));
1002             END IF;
1003 
1004             l_where_blk := replace_timecard_string (l_where_blk);
1005 
1006             IF g_debug
1007             THEN
1008                hr_utility.TRACE ('after replace ');
1009                hr_utility.TRACE (SUBSTR (l_where_blk, 1, 250));
1010             END IF;
1011 
1012             IF (g_params.l_using_dates)
1013             THEN
1014                IF g_debug
1015                THEN
1016                   hr_utility.TRACE ('Using Dates');
1017                END IF;
1018 
1019                IF (l_range_caveat)
1020                THEN
1021                   l_dynamic_sql :=
1022                         l_root_day
1023                      || ' '
1024                      || l_where_blk
1025                      || ' and tbb.resource_id between '
1026                      || l_first_resource_id
1027                      || ' AND '
1028                      || l_last_resource_id
1029                      || l_org_strip   -- Bug 8888911
1030                      || l_appln_strip -- Bug 8888911
1031                      || l_order_by;
1032 
1033              -- Bug 9458888
1034              l_rdb_process_sql := l_rdb_process_sql||' '
1035                      || ' '
1036                      || l_where_blk
1037                      || ' and tbb.resource_id between '
1038                      || l_first_resource_id
1039                      || ' AND '
1040                      || l_last_resource_id
1041                      ||l_org_strip||l_appln_strip;
1042                ELSE
1043                   l_dynamic_sql :=
1044                                l_root_day || ' ' || l_where_blk ||l_org_strip||l_appln_strip|| l_order_by; -- Bug 8888911
1045 
1046                   -- Bug 9458888
1047                   l_rdb_process_sql := l_rdb_process_sql||' '|| l_where_blk
1048                                       ||l_org_strip||l_appln_strip;
1049                END IF;
1050             ELSE
1051                IF g_debug
1052                THEN
1053                   hr_utility.TRACE ('Not using dates');
1054                END IF;
1055 
1056                IF (l_range_caveat)
1057                THEN
1058                   l_dynamic_sql :=
1059                         l_root
1060                      || ' '
1061                      || l_where_blk
1062                      || ' and tbb.resource_id between '
1063                      || l_first_resource_id
1064                      || ' AND '
1065                      || l_last_resource_id
1066                      || l_org_strip              -- Bug 8888911
1067                      || l_appln_strip            -- Bug 8888911
1068                      || l_order_by;
1069 
1070                    -- Bug 9458888
1071                    l_rdb_process_sql := l_rdb_process_sql||' '
1072                      || ' '
1073                      || l_where_blk
1074                      || ' and tbb.resource_id between '
1075                      || l_first_resource_id
1076                      || ' AND '
1077                      || l_last_resource_id
1078                      ||l_org_strip||l_appln_strip;
1079                ELSE
1080                   l_dynamic_sql := l_root || ' ' || l_where_blk||l_org_strip||l_appln_strip|| l_order_by; -- Bug 8888911
1081                   -- Bug 9458888
1082                   l_rdb_process_sql := l_rdb_process_sql||' '|| l_where_blk
1083                                        ||l_org_strip||l_appln_strip;
1084                END IF;
1085             END IF;
1086          ELSE
1087             IF (g_params.l_using_dates)
1088             THEN
1089                IF g_debug
1090                THEN
1091                   hr_utility.TRACE ('Using Dates');
1092                END IF;
1093 
1094                IF (l_range_caveat)
1095                THEN
1096                   l_dynamic_sql :=
1097                         l_root_day
1098                      || ' '
1099                      || ' and tbb.resource_id between '
1100                      || l_first_resource_id
1101                      || ' AND '
1102                      || l_last_resource_id
1103                      || l_org_strip         -- Bug 8888911
1104                      || l_appln_strip       -- Bug 8888911
1105                      || l_order_by;
1106 
1107                     -- Bug 9458888
1108                     l_rdb_process_sql := l_rdb_process_sql||' '
1109                      || ' and tbb.resource_id between '
1110                      || l_first_resource_id
1111                      || ' AND '
1112                      || l_last_resource_id
1113                     ||l_org_strip||l_appln_strip;
1114                ELSE
1115                   l_dynamic_sql := l_root_day || ' ' ||l_org_strip||l_appln_strip|| l_order_by;  -- Bug 8888911
1116 
1117                   -- Bug 9458888
1118                   l_rdb_process_sql := l_rdb_process_sql||' '||l_org_strip||l_appln_strip;
1119                END IF;
1120             ELSE
1121                IF g_debug
1122                THEN
1123                   hr_utility.TRACE ('Not using dates');
1124                END IF;
1125 
1126                IF (l_range_caveat)
1127                THEN
1128                   l_dynamic_sql :=
1129                         l_root
1130                      || ' '
1131                      || ' and tbb.resource_id between '
1132                      || l_first_resource_id
1133                      || ' AND '
1134                      || l_last_resource_id
1135                      || l_org_strip              -- Bug 8888911
1136                      || l_appln_strip            -- Bug 8888911
1137                      || l_order_by;
1138 
1139                    -- Bug 9458888
1140                    l_rdb_process_sql := l_rdb_process_sql||' '
1141                      || ' and tbb.resource_id between '
1142                      || l_first_resource_id
1143                      || ' AND '
1144                      || l_last_resource_id
1145                      ||l_org_strip||l_appln_strip;
1146                ELSE
1147                   l_dynamic_sql := l_root || ' '||l_org_strip||l_appln_strip|| l_order_by;  -- Bug 8888911
1148 
1149                   -- Bug 9458888
1150                   l_rdb_process_sql := l_rdb_process_sql||' '
1151                                  ||l_org_strip||l_appln_strip;
1152                END IF;
1153             END IF;
1154          END IF;
1155 
1156          IF g_debug
1157          THEN
1158             hr_utility.TRACE ('dynamic sql is ');
1159             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 1, 250));
1160             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 251, 250));
1161             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 501, 250));
1162             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 751, 250));
1163             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 1001, 250));
1164             hr_utility.TRACE (SUBSTR (l_dynamic_sql, 1251, 250));
1165             hr_utility.TRACE (   'FIRST RESOURCE IS : '
1166                               || TO_CHAR (l_first_resource_id)
1167                              );
1168             hr_utility.TRACE (   'LAST RESOURCE IS  : '
1169                               || TO_CHAR (l_last_resource_id)
1170                              );
1171          END IF;
1172 
1173          p_first_resource_id := l_first_resource_id;
1174          p_last_resource_id := l_last_resource_id;
1175          p_dynamic_sql := l_dynamic_sql;
1176          insert_query (l_dynamic_sql, 'RANGE');
1177 
1178 
1179          -- Bug 9458888
1180          IF g_params.p_process = 'Projects Retrieval Process'
1181           AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PA')
1182          THEN
1183              l_rdb_process_sql := REPLACE(l_rdb_process_sql,'LATEST_DETAILS','HXC_PA_LATEST_DETAILS');
1184              l_rdb_process_sql := REPLACE(l_rdb_process_sql,'RETRIEVALPROCESS',''''||g_params.p_process||'''');
1185              l_rdb_process_sql := l_rdb_process_sql||' '||l_org_strip||l_appln_strip;
1186              mark_for_retrieval(TRUNC(SYSDATE) - fnd_profile.value('HXC_RETRIEVAL_CHANGES_DATE'),
1187                                 l_rdb_process_sql);
1188          ELSIF g_params.p_process IN ('BEE Retrieval Process','Apply Schedule Rules')
1189           AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PAY')
1190          THEN
1191              l_rdb_process_sql := REPLACE(l_rdb_process_sql,'LATEST_DETAILS','HXC_PAY_LATEST_DETAILS');
1192              l_rdb_process_sql := REPLACE(l_rdb_process_sql,'RETRIEVALPROCESS',''''||g_params.p_process||'''');
1193 
1194              mark_for_retrieval(TRUNC(SYSDATE) - fnd_profile.value('HXC_RETRIEVAL_CHANGES_DATE'),
1195                                 l_rdb_process_sql,
1196                                 g_params.p_start_date,
1197                                 g_params.p_end_date);
1198          END IF;
1199 
1200 
1201 
1202       END generate_resource_sql;
1203 
1204       PROCEDURE insert_rr_resources (
1205          p_resource_list   IN              DBMS_SQL.number_table,
1206          p_rr_id           IN OUT NOCOPY   NUMBER
1207       )
1208       IS
1209          CURSOR csr_get_rr_id
1210          IS
1211             SELECT hxc_retrieval_ranges_s.NEXTVAL
1212               FROM DUAL;
1213 
1214          l_rr_id   NUMBER (15);
1215          l_proc    VARCHAR2 (72);
1216       BEGIN
1217          IF g_debug
1218          THEN
1219             l_proc := g_package || '.insert_rr_resources';
1220             hr_utility.set_location ('Entering ' || l_proc, 10);
1221          END IF;
1222 
1223          OPEN csr_get_rr_id;
1224 
1225          FETCH csr_get_rr_id
1226           INTO l_rr_id;
1227 
1228          CLOSE csr_get_rr_id;
1229 
1230          p_rr_id := l_rr_id;
1231          FORALL rrx IN p_resource_list.FIRST .. p_resource_list.LAST
1232             INSERT INTO hxc_retrieval_range_resources
1233                         (retrieval_range_id, resource_id
1234                         )
1235                  VALUES (l_rr_id, p_resource_list (rrx)
1236                         );
1237 
1238          -- Bug 8888911
1239          -- Added this code to store all the resources in this global table.
1240          FOR rrx IN p_resource_list.FIRST..p_resource_list.LAST
1241          LOOP
1242             g_res_list(p_resource_list(rrx)):= l_rr_id;
1243          END LOOP;
1244 
1245          IF g_debug
1246          THEN
1247             hr_utility.set_location ('Leaving ' || l_proc, 10);
1248          END IF;
1249       END insert_rr_resources;
1250 
1251       FUNCTION chk_empty
1252          RETURN BOOLEAN
1253       IS
1254          CURSOR csr_chk_rr
1255          IS
1256             SELECT 'x'
1257               FROM hxc_retrieval_ranges rr
1258              WHERE rr.retrieval_process_id = p_process_id
1259                AND (   rr.where_clause IS NULL
1260                     OR rr.where_clause = g_params.p_where_clause
1261                    )
1262                AND rr.transaction_id = 0;
1263 
1264          CURSOR csr_chk_tx
1265          IS
1266             SELECT 'x'
1267               FROM hxc_transactions tx
1268              WHERE tx.status = 'IN PROGRESS'
1269                AND tx.TYPE = 'RETRIEVAL'
1270                AND tx.transaction_process_id = p_process_id
1271                AND EXISTS (SELECT 'y'
1272                              FROM hxc_retrieval_ranges rr
1273                             WHERE rr.transaction_id = tx.transaction_id
1274                              AND (   rr.where_clause IS NULL
1275                                       OR rr.where_clause = g_params.p_where_clause)
1276                             );
1277 
1278          l_dummy   VARCHAR2 (1);
1279       BEGIN
1280          OPEN csr_chk_tx;
1281 
1282          FETCH csr_chk_tx
1283           INTO l_dummy;
1284 
1285          IF csr_chk_tx%NOTFOUND
1286          THEN
1287             OPEN csr_chk_rr;
1288 
1289             FETCH csr_chk_rr
1290              INTO l_dummy;
1291 
1292             IF csr_chk_rr%NOTFOUND
1293             THEN
1294                CLOSE csr_chk_tx;
1295 
1296                CLOSE csr_chk_rr;
1297 
1298                RETURN TRUE;
1299             END IF;
1300          END IF;
1301 
1302          CLOSE csr_chk_tx;
1303 
1304          RETURN FALSE;
1305       END chk_empty;
1306    BEGIN
1307       g_debug := hr_utility.debug_enabled;
1308 
1309       IF g_debug
1310       THEN
1311          l_proc := g_package || 'maintain_ranges';
1312          hr_utility.set_location ('Processing ' || l_proc, 10);
1313       END IF;
1314 
1315 -- if the table is empty for the retrieval process
1316 -- then insert the rows
1317 
1318       -- NOTE: put this is an anonymous PL/SQL block to handle
1319 --       the ORA-00054: resource busy and acquire with NOWAIT specified
1320 --       exception. If this occurs then we want to requery the table
1321 --       until no exception
1322       IF g_debug
1323       THEN
1324          hr_utility.TRACE ('Entering maintain_ranges');
1325       END IF;
1326 
1327       WHILE l_not_maintained_ranges
1328       LOOP
1329          IF g_debug
1330          THEN
1331             hr_utility.set_location ('Processing ' || l_proc, 20);
1332          END IF;
1333 
1334          BEGIN
1335             IF g_debug
1336             THEN
1337                hr_utility.TRACE ('Locking table');
1338             END IF;
1339 
1340             IF NOT hxc_generic_retrieval_pkg.g_in_loop
1341             THEN
1342                -- LOCK the table
1343                LOCK TABLE hxc_retrieval_ranges
1344                   IN EXCLUSIVE MODE NOWAIT;
1345 
1346                IF g_debug
1347                THEN
1348                   hr_utility.TRACE ('Before chk empty');
1349                END IF;
1350 
1351                IF (chk_empty)
1352                THEN
1353                   generate_resource_sql
1354                                  (p_dynamic_sql            => l_dynamic_sql,
1355                                   p_first_resource_id      => l_first_resource_id,
1356                                   p_last_resource_id       => l_last_resource_id,
1357                                   p_where_clause           => p_where_clause
1358                                  );
1359                   l_chunk_size := g_params.transfer_batch_size;
1360 
1361                   IF g_debug
1362                   THEN
1363                      hr_utility.TRACE (   'Chunk Size Profile Value is '
1364                                        || TO_CHAR (l_chunk_size)
1365                                       );
1366                   END IF;
1367 
1368 
1369                   -- Bug 7595581
1370                   -- Retrieval Log
1371                   -- Bug 9173209
1372                   -- Retrieval Log adjustment
1373                   fnd_file.put_line (fnd_file.LOG,
1374                                         '  '||fnd_date.date_to_canonical (SYSDATE)
1375 			|| ' > Chunk Size Profile Value is '
1376 			|| TO_CHAR (l_chunk_size));
1377 
1378                   IF ((l_chunk_size = 0) OR (l_chunk_size IS NULL))
1379                   THEN
1380                      l_chunk_size := 100;
1381                   END IF;
1382 
1383                   IF g_debug
1384                   THEN
1385                      hr_utility.TRACE ('Inserting rows');
1386                   END IF;
1387 
1388                   -- insert rows
1389                   IF g_debug
1390                   THEN
1391                      hr_utility.TRACE ('using dynamic SQL for resource list');
1392                   END IF;
1393 
1394                   -- use dynamic SQL BULK FETCH to generate resource list
1395                   l_rows_fetched := l_chunk_size;
1396                   l_csr := DBMS_SQL.open_cursor;
1397                   DBMS_SQL.parse (l_csr, l_dynamic_sql, DBMS_SQL.native);
1398                   -- bind variables needed by all queries
1399                   DBMS_SQL.bind_variable (l_csr,
1400                                           ':p_since_date',
1401                                           g_params.since_date
1402                                          );
1403                   -- define arrays for each item in the select list
1404                   DBMS_SQL.define_array (c                => l_csr,
1405                                          POSITION         => 1,
1406                                          n_tab            => t_resource_id,
1407                                          cnt              => l_chunk_size,
1408                                          lower_bound      => 1
1409                                         );
1410                   l_dummy := DBMS_SQL.EXECUTE (l_csr);
1411 
1412                   -- loop to ensure we fetch all the rows
1413                   WHILE (l_rows_fetched = l_chunk_size)
1414                   LOOP
1415                      IF g_debug
1416                      THEN
1417                         hr_utility.TRACE ('in loop');
1418                      END IF;
1419 
1420                      l_rows_fetched := DBMS_SQL.fetch_rows (l_csr);
1421 
1422                      IF g_debug
1423                      THEN
1424                         hr_utility.TRACE (   'rows fetched is '
1425                                           || TO_CHAR (l_rows_fetched)
1426                                          );
1427                      END IF;
1428 
1429                      IF (l_rows_fetched = 0 AND t_range_start.COUNT = 0)
1430                      THEN
1431                         IF g_debug
1432                         THEN
1433                            hr_utility.TRACE ('No ranges !!!');
1434                         END IF;
1435 
1436                         DBMS_SQL.close_cursor (l_csr);
1437                         RAISE e_no_ranges;
1438                      ELSIF (l_rows_fetched > 0)
1439                      THEN
1440                         DBMS_SQL.column_value (c             => l_csr,
1441                                                POSITION      => 1,
1442                                                n_tab         => t_resource_id
1443                                               );
1444                         -- populate retrieval range resources
1445                         l_range_start := t_resource_id (t_resource_id.FIRST);
1446                         l_range_stop := t_resource_id (t_resource_id.LAST);
1447                         insert_rr_resources (p_resource_list      => t_resource_id,
1448                                              p_rr_id              => l_rr_id
1449                                             );
1450                         x := x + 1;
1451 
1452                         IF g_debug
1453                         THEN
1454                            hr_utility.TRACE (   'range_start is '
1455                                              || TO_CHAR (l_range_start)
1456                                             );
1457                            hr_utility.TRACE (   'range_stop  is '
1458                                              || TO_CHAR (l_range_stop)
1459                                             );
1460                         END IF;
1461 
1462                         t_rr_id (x) := l_rr_id;
1463                         t_retrieval_process_id (x) := p_process_id;
1464                         t_range_start (x) := l_range_start;
1465                         t_range_stop (x) := l_range_stop;
1466                         t_seq (x) := x;
1467                         t_where_clause (x) := g_params.p_where_clause;
1468 
1469                         IF g_debug
1470                         THEN
1471                            hr_utility.TRACE (   'loop conditions is '
1472                                              || TO_CHAR (l_rows_fetched)
1473                                              || ':'
1474                                              || TO_CHAR (l_chunk_size)
1475                                             );
1476                         END IF;
1477 
1478                         t_resource_id.DELETE;
1479                      END IF;                               -- l_rows_fetch = 0
1480                   END LOOP;                      -- dynamic fetch of resources
1481 
1482                   IF g_debug
1483                   THEN
1484                      hr_utility.TRACE ('Leaving loop');
1485                   END IF;
1486 
1487                   DBMS_SQL.close_cursor (l_csr);
1488                   -- now insert retrieval ranges
1489                   FORALL rrx IN 1 .. x
1490                      INSERT INTO hxc_retrieval_ranges
1491                                  (retrieval_range_id,
1492                                   retrieval_process_id,
1493                                   range_start, range_stop,
1494                                   seq, transaction_id, where_clause,
1495                                   unique_params, conc_request_id
1496                                  )
1497                           VALUES (t_rr_id (rrx),
1498                                   t_retrieval_process_id (rrx),
1499                                   t_range_start (rrx), t_range_stop (rrx),
1500                                   t_seq (rrx), 0, t_where_clause (rrx),
1501                                   g_params.p_unique_params, g_conc_request_id
1502                                  );
1503 
1504                   IF g_debug
1505                   THEN
1506                      hr_utility.TRACE ('After bulk insert');
1507                   END IF;
1508 
1509                   l_not_maintained_ranges := FALSE;
1510                END IF;                                            -- chk_empty
1511 
1512                IF g_debug
1513                THEN
1514                   hr_utility.set_location ('Processing ' || l_proc, 30);
1515                END IF;
1516             END IF;                 -- NOT hxc_generic_retrieval_pkg.G_IN_LOOP
1517 
1518             IF g_debug
1519             THEN
1520                hr_utility.set_location ('Processing ' || l_proc, 40);
1521                hr_utility.TRACE ('About to get range value');
1522             END IF;
1523 
1524             -- if the table is not empty then select the next row, lock it
1525             -- set the range values and update the row
1526             OPEN csr_get_next_range;
1527 
1528             FETCH csr_get_next_range
1529              INTO r_range;
1530 
1531             IF (csr_get_next_range%FOUND)
1532             THEN
1533                IF g_debug
1534                THEN
1535                   hr_utility.TRACE ('FOUND range value');
1536                END IF;
1537 
1538                -- maintain range
1539                UPDATE hxc_retrieval_ranges rr
1540                   SET rr.transaction_id =
1541                                     hxc_generic_retrieval_pkg.g_transaction_id,
1542                       rr.conc_request_id = g_conc_request_id
1543                 WHERE rr.retrieval_range_id = r_range.retrieval_range_id;
1544 
1545                hxc_generic_retrieval_pkg.g_in_loop := TRUE;
1546                p_range_start := r_range.range_start;
1547                p_range_stop := r_range.range_stop;
1548                l_pkg_retrieval_range_id := r_range.retrieval_range_id;
1549             ELSE
1550                IF g_debug
1551                THEN
1552                   hr_utility.TRACE ('NOT FOUND range value');
1553                END IF;
1554 
1555                -- no more ranges
1556 
1557                -- set the G_IN_LOOP, G_LAST_CHUNK and dummy ranges
1558                hxc_generic_retrieval_pkg.g_in_loop := TRUE;
1559                hxc_generic_retrieval_pkg.g_last_chunk := TRUE;
1560                p_range_start := r_range.range_start;
1561                p_range_stop := r_range.range_stop;
1562                l_pkg_retrieval_range_id := -1;
1563             END IF;
1564 
1565             IF g_debug
1566             THEN
1567                hr_utility.set_location ('Processing ' || l_proc, 50);
1568             END IF;
1569 
1570             CLOSE csr_get_next_range;
1571 
1572             l_not_maintained_ranges := FALSE;
1573             COMMIT;
1574          EXCEPTION
1575             WHEN OTHERS
1576             THEN
1577                -- Bug 9394444
1578                hr_utility.trace(dbms_utility.format_error_backtrace);
1579                IF g_debug
1580                THEN
1581                   hr_utility.TRACE ('sqlerrm is ' || SQLERRM);
1582                   hr_utility.TRACE ('sqlcode is ' || SQLCODE);
1583                END IF;
1584 
1585                IF (SQLCODE = '-54')
1586                THEN
1587                   IF g_debug
1588                   THEN
1589                      hr_utility.TRACE ('TABLE LOCKED!!!!');
1590                   END IF;
1591 
1592                   l_cnt := l_cnt + 1;
1593                   -- wait for 30 seconds before attempting to lock again
1594                   DBMS_LOCK.sleep (30);
1595                ELSE
1596                   RAISE;
1597                END IF;
1598          END;                 -- anonymous PL/SQL block to trap lock exception
1599 
1600          IF g_debug
1601          THEN
1602             hr_utility.set_location ('Processing ' || l_proc, 60);
1603          END IF;
1604 
1605          IF (l_cnt > 60)
1606          THEN
1607             -- after 60 attempts (30 minutes)
1608             fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
1609             fnd_message.set_token ('PROCEDURE', l_proc);
1610             fnd_message.set_token ('STEP', 'cannot maintain ranges');
1611             fnd_message.raise_error;
1612          END IF;
1613 
1614          IF g_debug
1615          THEN
1616             hr_utility.set_location ('Processing ' || l_proc, 70);
1617          END IF;
1618       END LOOP;
1619    END maintain_ranges;
1620 
1621 --   maintain_chunks
1622 --
1623 -- description
1624 --   sets the chunk size based on the profile option
1625 --   sets the ranges for each iteration
1626 --   intialises the following global variables
1627 --
1628 --      G_LAST_CHUNK
1629 --      G_IN_LOOP
1630 --      G_OVERALL_SUCCESS
1631 --
1632 --   NOTE: for now only Projects Retrieval Process uses chunks
1633 --
1634 --
1635 --
1636 -- Parameters
1637 --   None
1638    PROCEDURE maintain_chunks (p_where_clause VARCHAR2)
1639    IS
1640       l_proc   VARCHAR2 (72);
1641    BEGIN
1642       IF g_debug
1643       THEN
1644          l_proc := g_package || 'maintain_chunks';
1645          hr_utility.set_location ('Entering ' || l_proc, 10);
1646       END IF;
1647 
1648       IF (g_params.p_process IN
1649              ('Projects Retrieval Process',
1650               'BEE Retrieval Process',
1651               'Apply Schedule Rules',
1652               'Purchasing Retrieval Process'
1653              )
1654          )
1655       THEN
1656          IF g_debug
1657          THEN
1658             hr_utility.set_location ('Entering ' || l_proc, 20);
1659          END IF;
1660 
1661          maintain_ranges (p_process_id        => g_retrieval_process_id,
1662                           p_range_start       => l_pkg_range_start,
1663                           p_range_stop        => l_pkg_range_stop,
1664                           p_where_clause      => p_where_clause
1665                          );
1666 
1667          IF g_debug
1668          THEN
1669             hr_utility.set_location ('Entering ' || l_proc, 50);
1670          END IF;
1671       ELSE
1672          IF g_debug
1673          THEN
1674             hr_utility.set_location ('Entering ' || l_proc, 80);
1675          END IF;
1676 
1677          -- not the Project Retrieval Process
1678          -- set range to be full range
1679          l_pkg_range_start := 0;
1680          l_pkg_range_stop := 999999999999999999;
1681       END IF;       -- IF ( g_params.p_process = 'Projects Retrieval Process')
1682 
1683       IF g_debug
1684       THEN
1685          hr_utility.TRACE ('');
1686          hr_utility.TRACE ('******* GLOBALS AFTER MAINTAIN CHUNKS ********');
1687       END IF;
1688 
1689       IF (g_in_loop)
1690       THEN
1691          IF g_debug
1692          THEN
1693             hr_utility.TRACE ('G_IN_LOOP is TRUE');
1694          END IF;
1695       ELSE
1696          IF g_debug
1697          THEN
1698             hr_utility.TRACE ('G_IN_LOOP is FALSE');
1699          END IF;
1700       END IF;
1701 
1702       IF (g_last_chunk)
1703       THEN
1704          IF g_debug
1705          THEN
1706             hr_utility.TRACE ('G_LAST_CHUNK is TRUE');
1707          END IF;
1708       ELSE
1709          IF g_debug
1710          THEN
1711             hr_utility.TRACE ('G_LAST_CHUNK is FALSE');
1712          END IF;
1713       END IF;
1714 
1715       IF g_debug
1716       THEN
1717          hr_utility.TRACE ('l_range_start is ' || TO_CHAR (l_pkg_range_start));
1718          hr_utility.TRACE ('l_range_stop is ' || TO_CHAR (l_pkg_range_stop));
1719          hr_utility.TRACE (   'l retrieval range id is '
1720                            || TO_CHAR (l_pkg_retrieval_range_id)
1721                           );
1722       END IF;
1723    END maintain_chunks;
1724 
1725    PROCEDURE populate_ret_range_blks
1726    IS
1727       CURSOR csr_get_ret_range_blks
1728       IS
1729          SELECT TO_CHAR (time_building_block_id) tbb_id,
1730                 TO_CHAR (object_version_number) tbb_ovn
1731            FROM hxc_retrieval_range_blks;
1732 
1733       l_ret_range_rec         csr_get_ret_range_blks%ROWTYPE;
1734       l_select_from           VARCHAR2 (250)
1735          := '
1736 SELECT /*+ ordered */
1737        tbb_latest.time_building_block_id,
1738        tbb_latest.object_version_number insert_latest
1739 FROM    hxc_retrieval_ranges rr
1740 ,       hxc_retrieval_range_resources rrr
1741 ,       hxc_latest_details tbb_latest ';
1742 
1743 -- Bug 9394444
1744 -- The Application specific version of the queries.
1745 
1746       l_select_from_pa           VARCHAR2 (250)
1747          := '
1748 SELECT /*+ ordered */
1749        tbb_latest.time_building_block_id,
1750        tbb_latest.object_version_number insert_latest
1751 FROM    hxc_retrieval_ranges rr
1752 ,       hxc_retrieval_range_resources rrr
1753 ,       hxc_pa_latest_details tbb_latest ';
1754 
1755       l_select_from_pay           VARCHAR2 (250)
1756          := '
1757 SELECT /*+ ordered */
1758        tbb_latest.time_building_block_id,
1759        tbb_latest.object_version_number insert_latest
1760 FROM    hxc_retrieval_ranges rr
1761 ,       hxc_retrieval_range_resources rrr
1762 ,       hxc_pay_latest_details tbb_latest ';
1763 
1764 
1765 
1766       l_where                 VARCHAR2 (1500)
1767                := '
1768       WHERE   rr.retrieval_range_id = :p_rr_id
1769       AND
1770               rrr.retrieval_range_id = rr.retrieval_range_id
1771       AND
1772               tbb_latest.resource_id = rrr.resource_id    AND
1773               tbb_latest.approval_status <> ''ERROR''       AND
1774         tbb_latest.last_update_date >= :p_since_date ';
1775 
1776       l_day_ex                VARCHAR2 (200)
1777          := '
1778 AND
1779         tbb_latest.start_time
1780         BETWEEN :p_start_date AND :p_end_date	AND
1781         tbb_latest.stop_time
1782         BETWEEN :p_start_date AND :p_end_date ';
1783       l_day_in                VARCHAR2 (200)
1784          := '
1785 AND
1786         :p_start_date <= tbb_latest.stop_time	AND
1787         :p_end_date   >= tbb_latest.start_time ';
1788 
1789     -- Modified for Bug 12729548
1790 	  -- Bug 12818509
1791 	  -- Removed the ORDERED hint
1792 	  -- and forced the index.
1793 	l_not_exists            VARCHAR2 (550)
1794          := '
1795 AND NOT EXISTS (select /*+ INDEX(tx HXC_TRANSACTIONS_PK)
1796                        INDEX(txd HXC_TRANSACTION_DETAILS_FK1)*/
1797 					   ''x''
1798 			FROM	hxc_transactions tx
1799 			,	hxc_transaction_details txd
1800 			WHERE	tx.transaction_process_id	= :p_process_id
1801 			AND	tx.type				= ''RETRIEVAL''
1802 			AND	tx.status			= ''SUCCESS''
1803 			AND	tx.transaction_id		= txd.transaction_id
1804 			AND	txd.status			= ''SUCCESS''
1805 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
1806 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number) ';
1807       t_tbb_id                DBMS_SQL.number_table;
1808       t_tbb_ovn               DBMS_SQL.number_table;
1809       l_start_date            DATE;
1810       l_end_date              DATE;
1811       l_csr                   INTEGER;
1812       l_rows_fetched          INTEGER;
1813       l_dummy                 INTEGER;
1814       l_app_set               VARCHAR2 (200);
1815       l_ret_range_query       VARCHAR2 (3000);
1816       l_ret_criteria_clause   VARCHAR2 (1000);
1817 
1818       -- Bug 8888911
1819       l_ind                   BINARY_INTEGER;
1820    BEGIN
1821       l_ret_criteria_clause := hxc_generic_retrieval_utils.get_ret_criteria;
1822 
1823       -- Bug 9394444
1824       -- For respective processes, if the upgraded process is chosen,
1825       -- use the new queries.
1826       -- Here, l_not_exists is not added because these tables are
1827       -- dynamically maintained with only the records left to be retrieved.
1828       IF g_params.p_process = 'Projects Retrieval Process'
1829         AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PA')
1830         AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
1831       THEN
1832           l_select_from := l_select_from_pa;
1833           l_not_exists := ' ';
1834       ELSIF g_params.p_process IN ('BEE Retrieval Process','Apply Schedule Rules')
1835           AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PAY')
1836           AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
1837       THEN
1838           l_select_from := l_select_from_pay;
1839           l_not_exists := ' ';
1840       END IF;
1841 
1842 
1843       -- Bug 8888911
1844       -- Print Skipped blocks here, before processing the next chunk.
1845 
1846       IF(hxc_generic_retrieval_pkg.g_detail_skipped.COUNT > 0)
1847       THEN
1848          	 put_log( '  ===============================================================================================');
1849  	         put_log( '     RESOURCE ID   '
1850 				     || '     TIMECARD      '
1851 				     || '     DETAIL        '
1852 				     || '     REMARKS       ');
1853  	         put_log( '  -----------------------------------------------------------------------------------------------');
1854 
1855                  -- Bug 9458888
1856                  l_skipped_tc_id := VARCHARTAB();
1857                  l_skipped_bb_id := VARCHARTAB();
1858                  l_skipped_bb_ovn := VARCHARTAB();
1859                  l_skipped_desc := VARCHARTAB();
1860                  l_index := 0;
1861 
1862  	         FOR i IN hxc_generic_retrieval_pkg.g_detail_skipped.FIRST .. hxc_generic_retrieval_pkg.g_detail_skipped.LAST
1863  	         LOOP
1864                      put_log( '     '||hxc_generic_retrieval_pkg.g_detail_skipped(i).resource_id
1865 	                             || '           '
1866  	                             || hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id
1867 	                             || ' ['
1868 	                             || hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_ovn
1869 	                             || ']          '
1870 	                             || hxc_generic_retrieval_pkg.g_detail_skipped(i).bb_id
1871 	                             || ' ['
1872 	                             || hxc_generic_retrieval_pkg.g_detail_skipped(i).ovn
1873 	                             || ']          '
1874 	                             || hxc_generic_retrieval_pkg.g_detail_skipped(i).description);
1875 
1876  	              g_temp_tc_list(i) := hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id;
1877 
1878                       l_skipped_tc_id.EXTEND(1);
1879                       l_skipped_bb_id.EXTEND(1);
1880                       l_skipped_bb_ovn.EXTEND(1);
1881                       l_skipped_desc.EXTEND(1);
1882                       l_index := l_index + 1;
1883 
1884                       l_skipped_tc_id(l_index)  := hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id;
1885                       l_skipped_bb_id(l_index)  := hxc_generic_retrieval_pkg.g_detail_skipped(i).bb_id;
1886                       l_skipped_bb_ovn(l_index) := hxc_generic_retrieval_pkg.g_detail_skipped(i).ovn;
1887                       l_skipped_desc(l_index)   := hxc_generic_retrieval_pkg.g_detail_skipped(i).description;
1888 
1889                       hxc_generic_retrieval_pkg.g_detail_skipped.DELETE(i);
1890 	          END LOOP;
1891 
1892 	          update_rdb_status(g_temp_tc_list,
1893 	                            'PENDING',
1894 	                            'SKIPPED');
1895                   g_temp_tc_list.DELETE;
1896 
1897 
1898                   FORALL i IN l_skipped_tc_id.FIRST..l_skipped_tc_id.LAST
1899                       INSERT INTO hxc_rdb_process_details
1900                            ( timecard_id,
1901                              detail_id,
1902                              detail_ovn,
1903                              skipped_reason,
1904                              skip_level,
1905                              ret_user_id,
1906                              request_id ,
1907                              process)
1908                       VALUES ( l_skipped_tc_id(i),
1909                                l_skipped_bb_id (i),
1910                                l_skipped_bb_ovn(i),
1911                                l_skipped_desc(i),
1912                                'OTL_PROC',
1913                                FND_GLOBAL.user_ID,
1914                                FND_GLOBAL.conc_request_id,
1915                                g_params.p_process);
1916     	END IF;
1917    	put_log( '  ===============================================================================================');
1918         put_log(' ');
1919 
1920       -- Bug 8888911
1921       -- Print out the next chunk of records.
1922       IF g_res_list.COUNT > 0
1923       THEN
1924           put_log('  ==================================================================');
1925           put_log('  Process is considering the following resources for this iteration');
1926           put_log('  ------------------------------------------------------------------');
1927       END IF;
1928       l_ind := g_res_list.FIRST;
1929       LOOP
1930          EXIT WHEN NOT g_res_list.EXISTS(l_ind);
1931          IF l_pkg_retrieval_range_id = g_res_list(l_ind)
1932          THEN
1933             put_log('       '||l_ind);
1934             g_res_list.DELETE(l_ind);
1935          END IF;
1936          l_ind := g_res_list.NEXT(l_ind);
1937       END LOOP;
1938       IF g_res_list.COUNT > 0
1939       THEN
1940          put_log('  ==================================================================');
1941       END IF;
1942 
1943       IF g_debug
1944       THEN
1945          hr_utility.TRACE ('Entering populate_ret_range_blks');
1946       END IF;
1947 
1948 -- only use temp table for processes which loop
1949       IF (g_params.p_process IN
1950              ('BEE Retrieval Process',
1951               'Apply Schedule Rules',
1952               'Purchasing Retrieval Process',
1953               'Projects Retrieval Process'
1954              )
1955          )
1956       THEN
1957          IF g_debug
1958          THEN
1959             hr_utility.TRACE ('starting to build query');
1960          END IF;
1961 
1962          IF (g_params.l_using_dates)
1963          THEN
1964             IF g_debug
1965             THEN
1966                hr_utility.TRACE ('Using Dates');
1967             END IF;
1968 
1969             l_start_date :=
1970                          NVL (g_params.p_start_date, hr_general.start_of_time);
1971             l_end_date := NVL (g_params.p_end_date, hr_general.end_of_time);
1972          END IF;
1973 
1974          IF g_debug
1975          THEN
1976             hr_utility.TRACE ('About to delete rows');
1977          END IF;
1978 
1979          DELETE FROM hxc_retrieval_range_blks;
1980 
1981 -- build query
1982          l_app_set :=
1983                      g_app_set_id_string (g_retrieval_tr_id).app_set_id_string;
1984 
1985 -- Bind ALL variables needed by the query
1986          IF (g_params.p_rerun_flag = 'Y')
1987          THEN
1988             NULL;
1989          ELSIF (NOT g_params.l_using_dates)
1990          THEN
1991             l_ret_range_query :=
1992                   l_select_from
1993                || l_where
1994                || l_not_exists
1995                || l_app_set
1996                || l_ret_criteria_clause;
1997          ELSIF (g_params.p_scope IN ('TIME', 'DAY', 'DETAIL'))
1998          THEN
1999             IF (g_params.p_clusive = 'EX')
2000             THEN
2001                l_ret_range_query :=
2002                      l_select_from
2003                   || l_where
2004                   || l_day_ex
2005                   || l_not_exists
2006                   || l_app_set
2007                   || l_ret_criteria_clause;
2008             ELSIF (g_params.p_clusive = 'IN')
2009             THEN
2010                l_ret_range_query :=
2011                      l_select_from
2012                   || l_where
2013                   || l_day_in
2014                   || l_not_exists
2015                   || l_app_set
2016                   || l_ret_criteria_clause;
2017             ELSE
2018                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
2019                fnd_message.raise_error;
2020             END IF;
2021          ELSE
2022             fnd_message.set_name ('HXC', 'HXC_0015_GNRET_INVLD_P_SCOPE');
2023             fnd_message.raise_error;
2024          END IF;
2025 
2026          IF g_debug
2027          THEN
2028             hr_utility.TRACE ('dynamic ret range blk sql is ');
2029             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1, 250));
2030             hr_utility.TRACE (SUBSTR (l_ret_range_query, 251, 250));
2031             hr_utility.TRACE (SUBSTR (l_ret_range_query, 501, 250));
2032             hr_utility.TRACE (SUBSTR (l_ret_range_query, 751, 250));
2033             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1001, 250));
2034             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1251, 250));
2035             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1501, 250));
2036             hr_utility.TRACE (SUBSTR (l_ret_range_query, 1751, 250));
2037          END IF;
2038 
2039          insert_query (l_ret_range_query, 'RET_RANGE_BLKS');
2040 -- now fetch and insert the rows
2041          l_rows_fetched := 100;
2042          l_csr := DBMS_SQL.open_cursor;
2043          DBMS_SQL.parse (l_csr, l_ret_range_query, DBMS_SQL.native);
2044 
2045          -- Bug 9394444
2046          IF ( g_params.p_process = 'Projects Retrieval Process'
2047               AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PA')
2048               AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'    )
2049                OR ( g_params.p_process  IN ( 'BEE Retrieval Process','Apply Schedule Rules')
2050               AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PAY')
2051               AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'    )
2052          THEN
2053              NULL;
2054          ELSE
2055              DBMS_SQL.bind_variable (l_csr,
2056                                  ':p_process_id',
2057                                  g_retrieval_process_id
2058                                 );
2059          END IF;
2060 
2061          DBMS_SQL.bind_variable (l_csr, ':p_since_date', g_params.since_date);
2062          DBMS_SQL.bind_variable (l_csr, ':p_rr_id', l_pkg_retrieval_range_id);
2063 
2064          IF (g_params.l_using_dates)
2065          THEN
2066             DBMS_SQL.bind_variable (l_csr, ':p_start_date', l_start_date);
2067             DBMS_SQL.bind_variable (l_csr, ':p_end_date', l_end_date);
2068          END IF;
2069 
2070          IF g_ret_criteria.gre_id IS NOT NULL
2071          THEN
2072             DBMS_SQL.bind_variable (l_csr, ':p_gre_id',
2073                                     g_ret_criteria.gre_id);
2074          END IF;
2075 
2076          IF g_ret_criteria.payroll_id IS NOT NULL
2077          THEN
2078             DBMS_SQL.bind_variable (l_csr,
2079                                     ':p_payroll_id',
2080                                     g_ret_criteria.payroll_id
2081                                    );
2082          END IF;
2083 
2084          IF g_ret_criteria.location_id IS NOT NULL
2085          THEN
2086             DBMS_SQL.bind_variable (l_csr,
2087                                     ':p_location_id',
2088                                     g_ret_criteria.location_id
2089                                    );
2090          END IF;
2091 
2092          IF g_ret_criteria.organization_id IS NOT NULL
2093          THEN
2094             DBMS_SQL.bind_variable (l_csr,
2095                                     ':p_org_id',
2096                                     g_ret_criteria.organization_id
2097                                    );
2098          END IF;
2099 
2100          DBMS_SQL.define_array (c                => l_csr,
2101                                 POSITION         => 1,
2102                                 n_tab            => t_tbb_id,
2103                                 cnt              => 100,
2104                                 lower_bound      => 1
2105                                );
2106          DBMS_SQL.define_array (c                => l_csr,
2107                                 POSITION         => 2,
2108                                 n_tab            => t_tbb_ovn,
2109                                 cnt              => 100,
2110                                 lower_bound      => 1
2111                                );
2112          l_dummy := DBMS_SQL.EXECUTE (l_csr);
2113 
2114 -- loop to ensure we fetch all the rows
2115          WHILE (l_rows_fetched = 100)
2116          LOOP
2117             l_rows_fetched := DBMS_SQL.fetch_rows (l_csr);
2118 
2119             IF (l_rows_fetched > 0)
2120             THEN
2121                DBMS_SQL.column_value (c             => l_csr,
2122                                       POSITION      => 1,
2123                                       n_tab         => t_tbb_id
2124                                      );
2125                DBMS_SQL.column_value (c             => l_csr,
2126                                       POSITION      => 2,
2127                                       n_tab         => t_tbb_ovn
2128                                      );
2129                -- populate retrieval range blks
2130                FORALL rrx IN t_tbb_id.FIRST .. t_tbb_id.LAST
2131                   INSERT INTO hxc_retrieval_range_blks
2132                               (time_building_block_id, object_version_number
2133                               )
2134                        VALUES (t_tbb_id (rrx), t_tbb_ovn (rrx)
2135                               );
2136                t_tbb_id.DELETE;
2137                t_tbb_ovn.DELETE;
2138             END IF;                                        -- l_rows_fetch = 0
2139          END LOOP;                               -- dynamic fetch of resources
2140 
2141          DBMS_SQL.close_cursor (l_csr);
2142       ELSE
2143          -- Retrievals which do not loop do not use
2144          -- this new table
2145          NULL;
2146       END IF;                                       -- check retrieval process
2147 /*
2148 
2149 if g_debug then
2150    hr_utility.trace('Here is the table ');
2151 end if;
2152 open csr_get_ret_Range_blks;
2153 
2154 fetch csr_get_ret_range_blks into l_ret_range_rec;
2155 
2156 WHILE csr_get_ret_range_blks%FOUND
2157 LOOP
2158 
2159    if g_debug then
2160       hr_utility.trace('ret range blks is '||l_ret_range_rec.tbb_id||':'||l_ret_range_rec.tbb_ovn);
2161    end if;
2162 
2163    fetch csr_get_ret_range_blks into l_ret_range_rec;
2164 
2165 END LOOP;
2166 
2167 close csr_get_ret_range_blks;
2168 
2169 */
2170    END populate_ret_range_blks;
2171 
2172    PROCEDURE populate_max_ovn (p_where_clause VARCHAR2)
2173    IS
2174       CURSOR csr_get_max_ovn_debug
2175       IS
2176          SELECT time_building_block_id || ':' || max_ovn ovn
2177            FROM hxc_max_ovn;
2178 
2179       -- Bug 13705204
2180       -- Modified the hints below to point to the right indexes.
2181       CURSOR csr_get_max_ovn_rrb (p_retrieval_process_id NUMBER)
2182       IS
2183          SELECT   /*+ ORDERED
2184                       INDEX(TXD HXC_TRANSACTION_DETAILS_FK1)
2185                       INDEX(TX HXC_TRANSACTIONS_PK)
2186                       USE_NL(TXD, TX) */
2187                   txd.time_building_block_id,
2188                   NVL (MAX (txd.time_building_block_ovn), 0)
2189              FROM hxc_retrieval_range_blks rrb,
2190                   hxc_transaction_details txd,
2191                   hxc_transactions tx
2192             WHERE tx.transaction_process_id = p_retrieval_process_id
2193               AND tx.TYPE = 'RETRIEVAL'
2194               AND tx.status = 'SUCCESS'
2195               AND tx.transaction_id = txd.transaction_id
2196               AND txd.status = 'SUCCESS'
2197               AND rrb.time_building_block_id = txd.time_building_block_id
2198               AND rrb.object_version_number > txd.time_building_block_ovn
2199          GROUP BY txd.time_building_block_id;
2200 
2201      CURSOR csr_get_max_ovn_day (
2202               p_retrieval_process_id   NUMBER,
2203               p_start_date             DATE,
2204               p_end_date               DATE,
2205               p_since_date             DATE
2206            )
2207            IS
2208               SELECT   txd.time_building_block_id,
2209                        NVL (MAX (txd.time_building_block_ovn), 0)
2210                   FROM hxc_transaction_details txd, hxc_transactions tx
2211                  WHERE tx.transaction_process_id = p_retrieval_process_id
2212                    AND tx.TYPE = 'RETRIEVAL'
2213                    AND tx.status = 'SUCCESS'
2214                    AND tx.transaction_id = txd.transaction_id
2215                    AND txd.status = 'SUCCESS'
2216                    AND EXISTS (
2217                           SELECT 'x'
2218                             FROM hxc_latest_details tbb_det
2219                            WHERE tbb_det.start_time <= p_end_date
2220                              AND tbb_det.stop_time >= p_start_date
2221                              AND tbb_det.last_update_date > p_since_date
2222                              AND tbb_det.time_building_block_id =
2223                                                          txd.time_building_block_id
2224                              AND tbb_det.object_version_number >
2225                                                         txd.time_building_block_ovn
2226                              AND tbb_det.resource_id BETWEEN l_pkg_range_start
2227                                                          AND l_pkg_range_stop)
2228          GROUP BY txd.time_building_block_id;
2229 
2230      CURSOR csr_get_max_ovn (p_retrieval_process_id NUMBER, p_since_date DATE)
2231            IS
2232               SELECT   txd.time_building_block_id,
2233                        NVL (MAX (txd.time_building_block_ovn), 0)
2234                   FROM hxc_transaction_details txd, hxc_transactions tx
2235                  WHERE tx.transaction_process_id = p_retrieval_process_id
2236                    AND tx.TYPE = 'RETRIEVAL'
2237                    AND tx.status = 'SUCCESS'
2238                    AND tx.transaction_id = txd.transaction_id
2239                    AND txd.status = 'SUCCESS'
2240                    AND EXISTS (
2241                           SELECT 'x'
2242                             FROM hxc_latest_details tbb_det
2243                            WHERE tbb_det.time_building_block_id =
2244                                                          txd.time_building_block_id
2245                              AND tbb_det.last_update_date > p_since_date
2246                              AND tbb_det.object_version_number >
2247                                                         txd.time_building_block_ovn
2248                              AND tbb_det.resource_id BETWEEN l_pkg_range_start
2249                                                          AND l_pkg_range_stop)
2250          GROUP BY txd.time_building_block_id;
2251 
2252       l_max_ovn         csr_get_max_ovn_debug%ROWTYPE;
2253 
2254       TYPE tab_max_ovn_bb_id IS TABLE OF hxc_time_building_blocks.time_building_block_id%TYPE
2255          INDEX BY BINARY_INTEGER;
2256 
2257       TYPE tab_max_ovn IS TABLE OF hxc_time_building_blocks.object_version_number%TYPE
2258          INDEX BY BINARY_INTEGER;
2259 
2260       t_max_ovn_bb_id   tab_max_ovn_bb_id;
2261       t_max_ovn         tab_max_ovn;
2262       l_cnt             NUMBER (15);
2263       l_start_date      DATE;
2264       l_end_date        DATE;
2265    BEGIN
2266       IF g_debug
2267       THEN
2268          hr_utility.TRACE ('Entering populate_max_ovn');
2269       END IF;
2270 
2271 -- clear out the table
2272       DELETE FROM hxc_max_ovn;
2273 
2274       IF (g_params.p_process IN
2275              ('BEE Retrieval Process',
2276               'Apply Schedule Rules',
2277               'Purchasing Retrieval Process',
2278               'Projects Retrieval Process'
2279              )
2280          )
2281       THEN
2282          OPEN csr_get_max_ovn_rrb (g_retrieval_process_id);
2283 
2284          LOOP
2285             IF g_debug
2286             THEN
2287                hr_utility.TRACE ('in max ovn loop');
2288             END IF;
2289 
2290             FETCH csr_get_max_ovn_rrb
2291             BULK COLLECT INTO t_max_ovn_bb_id, t_max_ovn LIMIT 100;
2292 
2293             IF g_debug
2294             THEN
2295                hr_utility.TRACE (   'fetch count is '
2296                                  || TO_CHAR (t_max_ovn_bb_id.COUNT)
2297                                 );
2298             END IF;
2299 
2300             IF (t_max_ovn_bb_id.COUNT <> 0)
2301             THEN
2302                FORALL x IN t_max_ovn_bb_id.FIRST .. t_max_ovn_bb_id.LAST
2303                   INSERT INTO hxc_max_ovn
2304                               (time_building_block_id, max_ovn
2305                               )
2306                        VALUES (t_max_ovn_bb_id (x), t_max_ovn (x)
2307                               );
2308                t_max_ovn_bb_id.DELETE;
2309                t_max_ovn.DELETE;
2310             END IF;
2311 
2312             EXIT WHEN csr_get_max_ovn_rrb%NOTFOUND;
2313          END LOOP;
2314 
2315          CLOSE csr_get_max_ovn_rrb;
2316       ELSE                                   -- this must be the EAM retrieval
2317          IF (g_params.l_using_dates)
2318          THEN
2319             l_start_date :=
2320                         NVL (g_params.p_start_date, hr_general.start_of_time);
2321             l_end_date := NVL (g_params.p_end_date, hr_general.end_of_time);
2322          END IF;
2323 
2324          IF (g_params.l_using_dates)
2325          THEN
2326             OPEN csr_get_max_ovn_day (g_retrieval_process_id,
2327                                       l_start_date,
2328                                       l_end_date,
2329                                       g_params.since_date
2330                                      );
2331 
2332             LOOP
2333                FETCH csr_get_max_ovn_day
2334                BULK COLLECT INTO t_max_ovn_bb_id, t_max_ovn LIMIT 100;
2335 
2336                IF (t_max_ovn_bb_id.COUNT <> 0)
2337                THEN
2338                   FORALL x IN t_max_ovn_bb_id.FIRST .. t_max_ovn_bb_id.LAST
2339                      INSERT INTO hxc_max_ovn
2340                                  (time_building_block_id, max_ovn
2341                                  )
2342                           VALUES (t_max_ovn_bb_id (x), t_max_ovn (x)
2343                                  );
2344                   t_max_ovn_bb_id.DELETE;
2345                   t_max_ovn.DELETE;
2346                END IF;
2347 
2348                EXIT WHEN csr_get_max_ovn_day%NOTFOUND;
2349             END LOOP;
2350 
2351             CLOSE csr_get_max_ovn_day;
2352          ELSE
2353             OPEN csr_get_max_ovn (g_retrieval_process_id,
2354                                   g_params.since_date);
2355 
2356             LOOP
2357                IF g_debug
2358                THEN
2359                   hr_utility.TRACE ('in max ovn loop');
2360                END IF;
2361 
2362                FETCH csr_get_max_ovn
2363                BULK COLLECT INTO t_max_ovn_bb_id, t_max_ovn LIMIT 100;
2364 
2365                IF g_debug
2366                THEN
2367                   hr_utility.TRACE (   'fetch count is '
2368                                     || TO_CHAR (t_max_ovn_bb_id.COUNT)
2369                                    );
2370                END IF;
2371 
2372                IF (t_max_ovn_bb_id.COUNT <> 0)
2373                THEN
2374                   IF g_debug
2375                   THEN
2376                      hr_utility.TRACE ('inserting');
2377                   END IF;
2378 
2379                   FORALL x IN t_max_ovn_bb_id.FIRST .. t_max_ovn_bb_id.LAST
2380                      INSERT INTO hxc_max_ovn
2381                                  (time_building_block_id, max_ovn
2382                                  )
2383                           VALUES (t_max_ovn_bb_id (x), t_max_ovn (x)
2384                                  );
2385                   t_max_ovn_bb_id.DELETE;
2386                   t_max_ovn.DELETE;
2387                END IF;
2388 
2389                EXIT WHEN csr_get_max_ovn%NOTFOUND;
2390             END LOOP;
2391 
2392             CLOSE csr_get_max_ovn;
2393          END IF;                                                 -- date check
2394       END IF;                                            -- g_params.p_process
2395 /*
2396 open csr_get_max_ovn_debug;
2397 
2398 loop
2399 
2400    fetch csr_get_max_ovn_debug into l_max_ovn;
2401 
2402    if g_debug then
2403       hr_utility.trace(l_max_ovn.ovn);
2404    end if;
2405 
2406    exit when csr_get_max_ovn_debug%NOTFOUND;
2407 
2408 end loop;
2409 
2410 close csr_Get_max_ovn_debug;
2411 
2412 */
2413    END populate_max_ovn;
2414 
2415 -- private procedure
2416 --   audit_transaction
2417 --
2418 -- description
2419 --   manages the transactions for each building block retrieved.
2420 --   In Insert mode, inserts the transactions details bulk bound
2421 --   In update mode, updates the transactions bulk bound after the
2422 --   recipient API has updated the global PL/SQL table
2423 --   In rollback mode deletes the transaction details
2424 --
2425 --   NOTE: the global PL/SQL transaction detail table is maintained
2426 --   within the copy bld blks procedure.
2427 --
2428 -- parameters
2429 --   p_mode    - Insert or Update the transactions
2430 --   p_transaction_process_id - transaction_process_id
2431 --   p_status     - status of the transaction
2432 --   p_description   - exception description
2433 --   p_rollback      - rollback TRUE/FALSE
2434    PROCEDURE audit_transaction (
2435       p_mode                     IN   VARCHAR2,
2436       p_transaction_process_id   IN   NUMBER DEFAULT NULL,
2437       p_status                   IN   VARCHAR2 DEFAULT NULL,
2438       p_description              IN   VARCHAR2 DEFAULT NULL,
2439       p_rollback                 IN   BOOLEAN DEFAULT FALSE
2440    )
2441    IS
2442       PRAGMA AUTONOMOUS_TRANSACTION;
2443       l_tx_id                 hxc_transactions.transaction_id%TYPE;
2444       l_time_max              INTEGER;
2445       l_day_max               INTEGER;
2446       l_detail_max            INTEGER;
2447       l_error_max             INTEGER;
2448       l_proc                  VARCHAR2 (72);
2449       l_temp_transaction_id   t_transaction_id;
2450    BEGIN                                                  -- audit transaction
2451       IF g_debug
2452       THEN
2453          l_proc := g_package || 'audit_transaction';
2454          hr_utility.set_location ('Entering ' || l_proc, 10);
2455          hr_utility.TRACE ('Audit Transaction Params');
2456          hr_utility.TRACE ('p_mode is ' || p_mode);
2457          hr_utility.TRACE (   'p_transaction_process_id is '
2458                            || TO_CHAR (p_transaction_process_id)
2459                           );
2460          hr_utility.TRACE ('p_status is ' || p_status);
2461          hr_utility.TRACE ('p_description is ' || p_description);
2462          hr_utility.TRACE (   'Global Transaction ID is '
2463                            || TO_CHAR
2464                                    (hxc_generic_retrieval_pkg.g_transaction_id)
2465                           );
2466       END IF;
2467 
2468       l_time_max := hxc_generic_retrieval_pkg.t_tx_time_bb_id.COUNT;
2469       l_day_max := hxc_generic_retrieval_pkg.t_tx_day_bb_id.COUNT;
2470       l_detail_max := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT;
2471       l_error_max := hxc_generic_retrieval_pkg.t_tx_error_bb_id.COUNT;
2472 
2473       IF (p_mode = 'I')                                 -- insert transactions
2474       THEN
2475 -- check to see if header already inserted
2476          IF (hxc_generic_retrieval_pkg.g_transaction_id IS NOT NULL)
2477          THEN
2478             IF g_debug
2479             THEN
2480                hr_utility.set_location ('Processing ' || l_proc, 7);
2481             END IF;
2482 
2483             -- already inserted - lets update it!
2484             UPDATE hxc_transactions
2485                SET status = p_status,
2486                    exception_description = p_description
2487              WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
2488          ELSE
2489             IF g_debug
2490             THEN
2491                hr_utility.set_location ('Processing ' || l_proc, 20);
2492             END IF;
2493 
2494             OPEN csr_get_tx_id;
2495 
2496             FETCH csr_get_tx_id
2497              INTO hxc_generic_retrieval_pkg.g_transaction_id;
2498 
2499             CLOSE csr_get_tx_id;
2500 
2501             IF g_debug
2502             THEN
2503                hr_utility.set_location ('Processing ' || l_proc, 30);
2504             END IF;
2505 
2506             INSERT INTO hxc_transactions
2507                         (transaction_id,
2508                          transaction_process_id, transaction_date,
2509                          transaction_code,
2510                          TYPE, status, exception_description
2511                         )
2512                  VALUES (hxc_generic_retrieval_pkg.g_transaction_id,
2513                          p_transaction_process_id, SYSDATE,
2514                          NVL (g_params.p_transaction_code,
2515                               TO_CHAR (SYSDATE, 'DD/MM/YYYY')
2516                              ),
2517                          'RETRIEVAL', p_status, p_description
2518                         );
2519 
2520             IF g_debug
2521             THEN
2522                hr_utility.set_location ('Processing ' || l_proc, 40);
2523             END IF;
2524          END IF;                                     -- transaction id IS NULL
2525 
2526          IF l_error_max <> 0
2527          THEN
2528             IF g_debug
2529             THEN
2530                hr_utility.set_location ('Processing ' || l_proc, 85);
2531             END IF;
2532 
2533 -- now let's bulk fetch all the transaction detail id
2534             OPEN csr_get_tx_detail_id (l_error_max);
2535 
2536             FETCH csr_get_tx_detail_id
2537             BULK COLLECT INTO l_temp_transaction_id;
2538 
2539             CLOSE csr_get_tx_detail_id;
2540 
2541             hxc_generic_retrieval_pkg.t_tx_error_transaction_id :=
2542                                                          l_temp_transaction_id;
2543 
2544             IF g_debug
2545             THEN
2546                hr_utility.set_location ('Processing ' || l_proc, 90);
2547             END IF;
2548 
2549             FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
2550                INSERT INTO hxc_transaction_details
2551                            (transaction_detail_id,
2552                             time_building_block_id,
2553                             time_building_block_ovn,
2554                             transaction_id,
2555                             status,
2556                             exception_description
2557                            )
2558                     VALUES (hxc_generic_retrieval_pkg.t_tx_error_transaction_id
2559                                                                      (tx_error),
2560                             hxc_generic_retrieval_pkg.t_tx_error_bb_id
2561                                                                      (tx_error),
2562                             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn
2563                                                                      (tx_error),
2564                             hxc_generic_retrieval_pkg.g_transaction_id,
2565                             hxc_generic_retrieval_pkg.t_tx_error_status
2566                                                                      (tx_error),
2567                             hxc_generic_retrieval_pkg.t_tx_error_exception
2568                                                                      (tx_error)
2569                            );
2570 
2571 
2572 
2573 -- given we are only going to do this once and the recipient app does not need
2574 -- to maintain these statuses we can delete the arrays
2575             hxc_generic_retrieval_pkg.t_tx_error_transaction_id.DELETE;
2576             hxc_generic_retrieval_pkg.t_tx_error_bb_id.DELETE;
2577             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn.DELETE;
2578             hxc_generic_retrieval_pkg.t_tx_error_status.DELETE;
2579             hxc_generic_retrieval_pkg.t_tx_error_exception.DELETE;
2580 
2581             IF g_debug
2582             THEN
2583                hr_utility.set_location ('Processing ' || l_proc, 100);
2584             END IF;
2585          END IF;                                           -- l_error_max <> 0
2586       ELSIF (p_mode = 'U')                              -- update transactions
2587       THEN
2588          IF g_debug
2589          THEN
2590             hr_utility.set_location ('Processing ' || l_proc, 110);
2591          END IF;
2592 
2593          OPEN csr_get_tx_id;
2594 
2595          FETCH csr_get_tx_id
2596           INTO l_tx_id;
2597 
2598          CLOSE csr_get_tx_id;
2599 
2600          INSERT INTO hxc_transactions
2601                      (transaction_id, transaction_process_id,
2602                       transaction_date, TYPE, status,
2603                       exception_description
2604                      )
2605               VALUES (l_tx_id, p_transaction_process_id,
2606                       SYSDATE, 'RETRIEVAL_STATUS_UPDATE', p_status,
2607                       p_description
2608                      );
2609 
2610          IF (p_description IS NULL OR p_description LIKE '%ORA-20001%')
2611          THEN
2612             -- insure we do not write over a meaningful excpetion already
2613             -- set within the retrieval
2614             UPDATE hxc_transactions
2615                SET status = p_status
2616              WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
2617          ELSE
2618             -- record the proper exception most likely thrown by the recipient
2619             -- application code
2620             UPDATE hxc_transactions
2621                SET status = p_status,
2622                    exception_description = p_description
2623              WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
2624          END IF;
2625 
2626          IF g_debug
2627          THEN
2628             hr_utility.set_location ('Processing ' || l_proc, 130);
2629          END IF;
2630 
2631 -- check to see if any tx time details
2632          IF l_time_max <> 0
2633          THEN
2634 -- now let's bulk fetch all the transaction detail id
2635             OPEN csr_get_tx_detail_id (l_time_max);
2636 
2637             FETCH csr_get_tx_detail_id
2638             BULK COLLECT INTO l_temp_transaction_id;
2639 
2640             CLOSE csr_get_tx_detail_id;
2641 
2642             hxc_generic_retrieval_pkg.t_tx_time_transaction_id :=
2643                                                         l_temp_transaction_id;
2644 
2645             IF g_debug
2646             THEN
2647                hr_utility.set_location ('Processing ' || l_proc, 50);
2648             END IF;
2649 
2650             FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_time_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_time_transaction_id.LAST
2651                INSERT INTO hxc_transaction_details
2652                            (transaction_detail_id,
2653                             time_building_block_id,
2654                             time_building_block_ovn,
2655                             transaction_id,
2656                             status,
2657                             exception_description
2658                            )
2659                     VALUES (hxc_generic_retrieval_pkg.t_tx_time_transaction_id
2660                                                                     (tx_detail),
2661                             hxc_generic_retrieval_pkg.t_tx_time_bb_id
2662                                                                     (tx_detail),
2663                             hxc_generic_retrieval_pkg.t_tx_time_bb_ovn
2664                                                                     (tx_detail),
2665                             hxc_generic_retrieval_pkg.g_transaction_id,
2666                             hxc_generic_retrieval_pkg.t_tx_time_status
2667                                                                     (tx_detail),
2668                             hxc_generic_retrieval_pkg.t_tx_time_exception
2669                                                                     (tx_detail)
2670                            );
2671          END IF;                                            -- l_time_max <> 0
2672 
2673 -- check to see if any tx day details
2674          IF l_day_max <> 0
2675          THEN
2676 -- now let's bulk fetch all the transaction detail id
2677             OPEN csr_get_tx_detail_id (l_day_max);
2678 
2679             FETCH csr_get_tx_detail_id
2680             BULK COLLECT INTO l_temp_transaction_id;
2681 
2682             CLOSE csr_get_tx_detail_id;
2683 
2684             hxc_generic_retrieval_pkg.t_tx_day_transaction_id :=
2685                                                         l_temp_transaction_id;
2686 
2687             IF g_debug
2688             THEN
2689                hr_utility.set_location ('Processing ' || l_proc, 60);
2690             END IF;
2691 
2692             FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_day_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_day_transaction_id.LAST
2693                INSERT INTO hxc_transaction_details
2694                            (transaction_detail_id,
2695                             time_building_block_id,
2696                             time_building_block_ovn,
2697                             transaction_id,
2698                             status,
2699                             exception_description
2700                            )
2701                     VALUES (hxc_generic_retrieval_pkg.t_tx_day_transaction_id
2702                                                                     (tx_detail),
2703                             hxc_generic_retrieval_pkg.t_tx_day_bb_id
2704                                                                     (tx_detail),
2705                             hxc_generic_retrieval_pkg.t_tx_day_bb_ovn
2706                                                                     (tx_detail),
2707                             hxc_generic_retrieval_pkg.g_transaction_id,
2708                             hxc_generic_retrieval_pkg.t_tx_day_status
2709                                                                     (tx_detail),
2710                             hxc_generic_retrieval_pkg.t_tx_day_exception
2711                                                                     (tx_detail)
2712                            );
2713          END IF;                                             -- l_day_max <> 0
2714 
2715 -- check to see if any tx detail details
2716          IF l_detail_max <> 0
2717          THEN
2718 -- now let's bulk fetch all the transaction detail id
2719             OPEN csr_get_tx_detail_id (l_detail_max);
2720 
2721             FETCH csr_get_tx_detail_id
2722             BULK COLLECT INTO l_temp_transaction_id;
2723 
2724             CLOSE csr_get_tx_detail_id;
2725 
2726             hxc_generic_retrieval_pkg.t_tx_detail_transaction_id :=
2727                                                         l_temp_transaction_id;
2728 
2729             IF g_debug
2730             THEN
2731                hr_utility.set_location ('Processing ' || l_proc, 70);
2732             END IF;
2733 
2734             FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.LAST
2735                INSERT INTO hxc_transaction_details
2736                            (transaction_detail_id,
2737                             time_building_block_id,
2738                             time_building_block_ovn,
2739                             transaction_id,
2740                             status,
2741                             exception_description
2742                            )
2743                     VALUES (hxc_generic_retrieval_pkg.t_tx_detail_transaction_id
2744                                                                     (tx_detail),
2745                             hxc_generic_retrieval_pkg.t_tx_detail_bb_id
2746                                                                     (tx_detail),
2747                             hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn
2748                                                                     (tx_detail),
2749                             hxc_generic_retrieval_pkg.g_transaction_id,
2750                             hxc_generic_retrieval_pkg.t_tx_detail_status
2751                                                                     (tx_detail),
2752                             hxc_generic_retrieval_pkg.t_tx_detail_exception
2753                                                                     (tx_detail)
2754                            );
2755 
2756             IF g_debug
2757             THEN
2758                hr_utility.set_location ('Processing ' || l_proc, 75);
2759             END IF;
2760          END IF;                                          -- l_detail_max <> 0
2761 
2762          IF g_debug
2763          THEN
2764             hr_utility.set_location ('Processing ' || l_proc, 80);
2765          END IF;
2766 
2767          IF l_error_max <> 0
2768          THEN
2769             IF g_debug
2770             THEN
2771                hr_utility.set_location ('Processing ' || l_proc, 85);
2772             END IF;
2773 
2774 -- now let's bulk fetch all the transaction detail id
2775             OPEN csr_get_tx_detail_id (l_error_max);
2776 
2777             FETCH csr_get_tx_detail_id
2778             BULK COLLECT INTO l_temp_transaction_id;
2779 
2780             CLOSE csr_get_tx_detail_id;
2781 
2782             hxc_generic_retrieval_pkg.t_tx_error_transaction_id :=
2783                                                          l_temp_transaction_id;
2784 
2785             IF g_debug
2786             THEN
2787                hr_utility.set_location ('Processing ' || l_proc, 90);
2788             END IF;
2789 
2790             FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
2791                INSERT INTO hxc_transaction_details
2792                            (transaction_detail_id,
2793                             time_building_block_id,
2794                             time_building_block_ovn,
2795                             transaction_id,
2796                             status,
2797                             exception_description
2798                            )
2799                     VALUES (hxc_generic_retrieval_pkg.t_tx_error_transaction_id
2800                                                                      (tx_error),
2801                             hxc_generic_retrieval_pkg.t_tx_error_bb_id
2802                                                                      (tx_error),
2803                             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn
2804                                                                      (tx_error),
2805                             hxc_generic_retrieval_pkg.g_transaction_id,
2806                             hxc_generic_retrieval_pkg.t_tx_error_status
2807                                                                      (tx_error),
2808                             hxc_generic_retrieval_pkg.t_tx_error_exception
2809                                                                      (tx_error)
2810                            );
2811 
2812             -- Bug 9458888
2813             -- Used for Retrieval Dashboard Process Tab
2814             g_temp_tc_list.DELETE;
2815 
2816             -- Bug : 9948863
2817             FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST ..
2818                    hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
2819               UPDATE hxc_rdb_process_details
2820                  SET skipped_reason = SUBSTR(hxc_generic_retrieval_pkg.t_tx_error_exception
2821                                                                      (tx_error),1,149),
2822                      skip_level = 'REC_PROC'
2823                 WHERE detail_id = hxc_generic_retrieval_pkg.t_tx_error_bb_id
2824                                                                      (tx_error)
2825                  AND request_id = FND_GLOBAL.CONC_REQUEST_ID
2826                  AND process = g_params.p_process
2827                  AND ret_user_id = FND_global.user_id
2828            RETURNING timecard_id
2829                 BULK COLLECT INTO g_temp_tc_list ;
2830 
2831             FORALL i IN g_temp_tc_list.FIRST..g_temp_tc_list.LAST
2832               UPDATE hxc_rdb_process_timecards
2833                  SET stage = 'ERRORED'
2834                WHERE timecard_id = g_temp_tc_list(i)
2835                  AND request_id = FND_GLOBAL.CONC_REQUEST_ID
2836                  AND process = g_params.p_process;
2837 
2838 
2839 -- given we are only going to do this once and the recipient app does not need
2840 -- to maintain these statuses we can delete the arrays
2841             hxc_generic_retrieval_pkg.t_tx_error_transaction_id.DELETE;
2842             hxc_generic_retrieval_pkg.t_tx_error_bb_id.DELETE;
2843             hxc_generic_retrieval_pkg.t_tx_error_bb_ovn.DELETE;
2844             hxc_generic_retrieval_pkg.t_tx_error_status.DELETE;
2845             hxc_generic_retrieval_pkg.t_tx_error_exception.DELETE;
2846 
2847             IF g_debug
2848             THEN
2849                hr_utility.set_location ('Processing ' || l_proc, 100);
2850             END IF;
2851          END IF;                                           -- l_error_max <> 0
2852       END IF;                                                        -- p_mode
2853 
2854       IF g_debug
2855       THEN
2856          hr_utility.TRACE ('Committing !!!');
2857       END IF;
2858 
2859       COMMIT;
2860    END audit_transaction;
2861 
2862 -- private procedure
2863 --   chk_retrieval_process
2864 --
2865 -- description
2866 --   This checks that the retrieval process passed in P_PROCESS exists
2867 --   in hxc retrieval_processes. If it does exists it returns the
2868 --   mapping id associated with the process. The mapping id is tested
2869 --   for null to determine if the processes exists
2870 --
2871 -- parameters
2872 --   p_retrieval_process   - process name (P_PROCESS)
2873 --   p_retrieval_process_id   - retrieval process id (OUT only)
2874 --   p_retrieval_tr_id          - retrieval time recipient id (OUT only)
2875 --   p_mapping_id    - mapping id (OUT only)
2876    PROCEDURE chk_retrieval_process (
2877       p_retrieval_process                      hxc_retrieval_processes.NAME%TYPE,
2878       p_retrieval_process_id   IN OUT NOCOPY   hxc_retrieval_processes.retrieval_process_id%TYPE,
2879       p_retrieval_tr_id        IN OUT NOCOPY   hxc_retrieval_processes.time_recipient_id%TYPE,
2880       p_mapping_id             IN OUT NOCOPY   hxc_mappings.mapping_id%TYPE
2881    )
2882    IS
2883 --
2884       l_proc         VARCHAR2 (72);
2885 
2886 --
2887       CURSOR csr_get_otm_mapping
2888       IS
2889          SELECT -1, rtr.time_recipient_id, rtr.mapping_id
2890            FROM hxc_retrieval_processes rtr
2891           WHERE rtr.NAME = 'BEE Retrieval Process';
2892 
2893       CURSOR csr_chk_retrieval
2894       IS
2895          SELECT rtr.retrieval_process_id, rtr.time_recipient_id,
2896                 rtr.mapping_id
2897            FROM hxc_retrieval_processes rtr
2898           WHERE rtr.NAME = p_retrieval_process;
2899 
2900 --
2901       l_mapping_id   NUMBER (15)   := NULL;
2902 --
2903    BEGIN                                              -- chk_retrieval_process
2904       IF g_debug
2905       THEN
2906          l_proc := g_package || 'chk_retrieval_process';
2907          hr_utility.set_location ('Entering ' || l_proc, 10);
2908       END IF;
2909 
2910       IF (p_retrieval_process = 'Apply Schedule Rules')
2911       THEN
2912          OPEN csr_get_otm_mapping;
2913 
2914          FETCH csr_get_otm_mapping
2915           INTO p_retrieval_process_id, p_retrieval_tr_id, p_mapping_id;
2916 
2917          CLOSE csr_get_otm_mapping;
2918       ELSE
2919          OPEN csr_chk_retrieval;
2920 
2921          FETCH csr_chk_retrieval
2922           INTO p_retrieval_process_id, p_retrieval_tr_id, p_mapping_id;
2923 
2924          CLOSE csr_chk_retrieval;
2925       END IF;
2926 
2927 -- set locking mode
2928       IF (p_retrieval_process IN
2929                             ('BEE Retrieval Process', 'Apply Schedule Rules')
2930          )
2931       THEN
2932          hxc_generic_retrieval_pkg.g_lock_type :=
2933                                    hxc_lock_util.c_plsql_pay_retrieval_action;
2934       ELSIF (p_retrieval_process = 'Projects Retrieval Process')
2935       THEN
2936          hxc_generic_retrieval_pkg.g_lock_type :=
2937                                     hxc_lock_util.c_plsql_pa_retrieval_action;
2938       ELSIF (p_retrieval_process = 'Purchasing Retrieval Process')
2939       THEN
2940          hxc_generic_retrieval_pkg.g_lock_type :=
2941                                     hxc_lock_util.c_plsql_po_retrieval_action;
2942       ELSE
2943          hxc_generic_retrieval_pkg.g_lock_type :=
2944                                    hxc_lock_util.c_plsql_eam_retrieval_action;
2945       END IF;
2946 
2947       IF g_debug
2948       THEN
2949          hr_utility.set_location ('Leaving ' || l_proc, 30);
2950       END IF;
2951 --
2952    END chk_retrieval_process;
2953 
2954 -- private procedure
2955 --   populate_query_table
2956 --
2957 -- description
2958 --   the dynamic query bulk collects the data into arrays. This procedure copies
2959 --   the arrays into a single table of records to make datamanagment and
2960 --   manipulation easier. It also deletes the arrays thus saving on memory.
2961 --
2962 -- parameters
2963 --   None
2964    PROCEDURE populate_query_table
2965    IS
2966       l_proc    VARCHAR2 (72) := g_package || 'populate_query_table';
2967       l_ind     PLS_INTEGER;
2968       l_dummy   NUMBER (1);
2969    BEGIN
2970       IF (t_timecard_bb_id.COUNT <> 0)
2971       THEN
2972          l_ind := NVL (t_bb.LAST, 0) + 1;
2973 
2974          FOR x IN t_timecard_bb_id.FIRST .. t_timecard_bb_id.LAST
2975          LOOP
2976             t_bb (l_ind).time_bb_id := t_timecard_bb_id (x);
2977             t_bb (l_ind).time_ovn := t_timecard_ovn (x);
2978             t_bb (l_ind).time_max_ovn := t_timecard_max_ovn (x);
2979             t_bb (l_ind).time_start_time := t_timecard_start_time (x);
2980             t_bb (l_ind).time_stop_time := t_timecard_stop_time (x);
2981             t_bb (l_ind).time_comment_text := t_timecard_comment_text (x);
2982             t_bb (l_ind).time_deleted := t_timecard_deleted (x);
2983             t_bb (l_ind).day_bb_id := t_day_bb_id (x);
2984             t_bb (l_ind).day_start_time := t_day_start_time (x);
2985             t_bb (l_ind).day_stop_time := t_day_stop_time (x);
2986             t_bb (l_ind).day_ovn := t_day_ovn (x);
2987             t_bb (l_ind).day_max_ovn := t_day_max_ovn (x);
2988             t_bb (l_ind).detail_bb_id := t_detail_bb_id (x);
2989             t_bb (l_ind).detail_parent_bb_id := t_detail_parent_id (x);
2990             t_bb (l_ind).detail_resource_type := t_detail_resource_type (x);
2991             t_bb (l_ind).detail_resource_id := t_detail_resource_id (x);
2992             t_bb (l_ind).detail_comment_text := t_detail_comment_text (x);
2993             t_bb (l_ind).detail_start_time := t_detail_start_time (x);
2994             t_bb (l_ind).detail_stop_time := t_detail_stop_time (x);
2995             t_bb (l_ind).detail_measure := t_detail_measure (x);
2996             t_bb (l_ind).detail_scope := t_detail_scope (x);
2997             t_bb (l_ind).detail_type := t_detail_type (x);
2998             t_bb (l_ind).detail_ovn := t_detail_ovn (x);
2999             t_bb (l_ind).detail_max_ovn := t_detail_max_ovn (x);
3000             t_bb (l_ind).detail_deleted := t_detail_deleted (x);
3001             t_bb (l_ind).detail_uom := t_detail_uom (x);
3002             t_bb (l_ind).detail_date_from := t_detail_date_from (x);
3003             t_bb (l_ind).detail_date_to := t_detail_date_to (x);
3004             t_bb (l_ind).detail_approval_status :=
3005                                                  t_detail_approval_status (x);
3006             t_bb (l_ind).detail_approval_style_id :=
3007                                                t_detail_approval_style_id (x);
3008             t_bb (l_ind).detail_ta_id := t_detail_ta_id (x);
3009             t_bb (l_ind).detail_bld_blk_info_type_id :=
3010                                             t_detail_bld_blk_info_type_id (x);
3011             t_bb (l_ind).detail_attribute1 := t_detail_attribute1 (x);
3012             t_bb (l_ind).detail_attribute2 := t_detail_attribute2 (x);
3013             t_bb (l_ind).detail_attribute3 := t_detail_attribute3 (x);
3014             t_bb (l_ind).detail_attribute4 := t_detail_attribute4 (x);
3015             t_bb (l_ind).detail_attribute5 := t_detail_attribute5 (x);
3016             t_bb (l_ind).detail_attribute6 := t_detail_attribute6 (x);
3017             t_bb (l_ind).detail_attribute7 := t_detail_attribute7 (x);
3018             t_bb (l_ind).detail_attribute8 := t_detail_attribute8 (x);
3019             t_bb (l_ind).detail_attribute9 := t_detail_attribute9 (x);
3020             t_bb (l_ind).detail_attribute10 := t_detail_attribute10 (x);
3021             t_bb (l_ind).detail_attribute11 := t_detail_attribute11 (x);
3022             t_bb (l_ind).detail_attribute12 := t_detail_attribute12 (x);
3023             t_bb (l_ind).detail_attribute13 := t_detail_attribute13 (x);
3024             t_bb (l_ind).detail_attribute14 := t_detail_attribute14 (x);
3025             t_bb (l_ind).detail_attribute15 := t_detail_attribute15 (x);
3026             t_bb (l_ind).detail_attribute16 := t_detail_attribute16 (x);
3027             t_bb (l_ind).detail_attribute17 := t_detail_attribute17 (x);
3028             t_bb (l_ind).detail_attribute18 := t_detail_attribute18 (x);
3029             t_bb (l_ind).detail_attribute19 := t_detail_attribute19 (x);
3030             t_bb (l_ind).detail_attribute20 := t_detail_attribute20 (x);
3031             t_bb (l_ind).detail_attribute21 := t_detail_attribute21 (x);
3032             t_bb (l_ind).detail_attribute22 := t_detail_attribute22 (x);
3033             t_bb (l_ind).detail_attribute23 := t_detail_attribute23 (x);
3034             t_bb (l_ind).detail_attribute24 := t_detail_attribute24 (x);
3035             t_bb (l_ind).detail_attribute25 := t_detail_attribute25 (x);
3036             t_bb (l_ind).detail_attribute26 := t_detail_attribute26 (x);
3037             t_bb (l_ind).detail_attribute27 := t_detail_attribute27 (x);
3038             t_bb (l_ind).detail_attribute28 := t_detail_attribute28 (x);
3039             t_bb (l_ind).detail_attribute29 := t_detail_attribute29 (x);
3040             t_bb (l_ind).detail_attribute30 := t_detail_attribute30 (x);
3041             t_bb (l_ind).detail_attribute_category :=
3042                                               t_detail_attribute_category (x);
3043             l_dummy :=
3044                initialise_g_resource
3045                              (p_resource_id      => t_bb (l_ind).detail_resource_id
3046                              );
3047             hxc_generic_retrieval_utils.g_resources
3048                                                (t_bb (l_ind).detail_resource_id
3049                                                ).start_time :=
3050                LEAST
3051                   (t_bb (l_ind).time_start_time,
3052                    hxc_generic_retrieval_utils.g_resources
3053                                                (t_bb (l_ind).detail_resource_id
3054                                                ).start_time
3055                   );
3056             hxc_generic_retrieval_utils.g_resources
3057                                                (t_bb (l_ind).detail_resource_id
3058                                                ).stop_time :=
3059                GREATEST
3060                   (t_bb (l_ind).time_stop_time,
3061                    hxc_generic_retrieval_utils.g_resources
3062                                                (t_bb (l_ind).detail_resource_id
3063                                                ).stop_time
3064                   );
3065             l_ind := l_ind + 1;
3066          END LOOP;
3067 
3068 -- now delete tables
3069 
3070          -- delete time card scope arrays
3071          t_timecard_bb_id.DELETE;
3072          t_timecard_ovn.DELETE;
3073          t_timecard_max_ovn.DELETE;
3074          t_timecard_start_time.DELETE;
3075          t_timecard_stop_time.DELETE;
3076          t_timecard_comment_text.DELETE;
3077          t_timecard_deleted.DELETE;
3078          t_day_bb_id.DELETE;
3079          t_day_start_time.DELETE;
3080          t_day_stop_time.DELETE;
3081          t_day_ovn.DELETE;
3082          t_day_max_ovn.DELETE;
3083          t_detail_bb_id.DELETE;
3084          t_detail_parent_id.DELETE;
3085          t_detail_resource_type.DELETE;
3086          t_detail_resource_id.DELETE;
3087          t_detail_comment_text.DELETE;
3088          t_detail_start_time.DELETE;
3089          t_detail_stop_time.DELETE;
3090          t_detail_measure.DELETE;
3091          t_detail_scope.DELETE;
3092          t_detail_type.DELETE;
3093          t_detail_ovn.DELETE;
3094          t_detail_deleted.DELETE;
3095          t_detail_max_ovn.DELETE;
3096          t_detail_uom.DELETE;
3097          t_detail_date_from.DELETE;
3098          t_detail_date_to.DELETE;
3099          t_detail_approval_status.DELETE;
3100          t_detail_approval_style_id.DELETE;
3101          t_detail_ta_id.DELETE;
3102          t_detail_bld_blk_info_type_id.DELETE;
3103          t_detail_attribute1.DELETE;
3104          t_detail_attribute2.DELETE;
3105          t_detail_attribute3.DELETE;
3106          t_detail_attribute4.DELETE;
3107          t_detail_attribute5.DELETE;
3108          t_detail_attribute6.DELETE;
3109          t_detail_attribute7.DELETE;
3110          t_detail_attribute8.DELETE;
3111          t_detail_attribute9.DELETE;
3112          t_detail_attribute10.DELETE;
3113          t_detail_attribute11.DELETE;
3114          t_detail_attribute12.DELETE;
3115          t_detail_attribute13.DELETE;
3116          t_detail_attribute14.DELETE;
3117          t_detail_attribute15.DELETE;
3118          t_detail_attribute16.DELETE;
3119          t_detail_attribute17.DELETE;
3120          t_detail_attribute18.DELETE;
3121          t_detail_attribute19.DELETE;
3122          t_detail_attribute20.DELETE;
3123          t_detail_attribute21.DELETE;
3124          t_detail_attribute22.DELETE;
3125          t_detail_attribute23.DELETE;
3126          t_detail_attribute24.DELETE;
3127          t_detail_attribute25.DELETE;
3128          t_detail_attribute26.DELETE;
3129          t_detail_attribute27.DELETE;
3130          t_detail_attribute28.DELETE;
3131          t_detail_attribute29.DELETE;
3132          t_detail_attribute30.DELETE;
3133          t_detail_attribute_category.DELETE;
3134       END IF;                                   -- t_timecard_bb_id.COUNT <> 0
3135    END populate_query_table;
3136 
3137 -- private procedure
3138 --   populate_attributes
3139 --
3140 -- description
3141 --   This procedure is used to populate the global PL/SQL tables which
3142 --   contain the attribution for each time building block stored in
3143 --   HXC_TIME_ATTRIBUTES.
3144 --   The procedure is called each time a new time attribute id is found
3145 --   when processing the rows returned in the main query. Then, for each
3146 --   segment/attribute in the mapping for the process, copies the associated
3147 --   value and field name to a global PL/SQL table for use later by the
3148 --   recipient API. The global PL/SQL table destination varies upon the SCOPE
3149 --   and the NEW parameters. SCOPE, reflects the building block scope i.e. is
3150 --   this a new time attribute associated with a building block of scope TIME
3151 --   The NEW parameter refers to whether this a attribution for current building
3152 --   block or the prior or old building block which is passed back in the case
3153 --   of an INCREMENTAL retrieval
3154 --
3155 --   Parameters
3156 --     p_building_block_id - time building block id (foreign key in PL/SQL table)
3157 --     p_attribute_table   - table of all time building blocks and attributes
3158 --     p_cnt         - index of p_attribute_table
3159 --     p_scope       - scope of the time building block
3160 --     p_new         - are these attributes for old or new bld blks?
3161    PROCEDURE populate_attributes (
3162       p_building_block_id   NUMBER,
3163       p_attribute_table     t_all_building_blocks,
3164       p_cnt                 INTEGER,
3165       p_scope               VARCHAR2,
3166       p_new                 VARCHAR2
3167    )
3168    IS
3169       l_att_cnt                PLS_INTEGER;
3170       l_bld_blk_info_type_id   hxc_time_attributes.bld_blk_info_type_id%TYPE;
3171       l_attribute_category     VARCHAR2 (100);
3172       l_proc                   VARCHAR2 (72)
3173                                         := g_package || 'populate_attributes';
3174    BEGIN
3175       IF p_scope = 'DETAIL'
3176       THEN
3177          FOR MAP IN
3178             g_field_mappings_table.FIRST .. g_field_mappings_table.LAST
3179          LOOP
3180             IF (p_scope = 'DETAIL' AND p_new = 'Y')
3181             THEN
3182                l_att_cnt :=
3183                     NVL (hxc_generic_retrieval_pkg.t_detail_attributes.LAST,
3184                          0
3185                         )
3186                   + 1;
3187                l_bld_blk_info_type_id :=
3188                          p_attribute_table (p_cnt).detail_bld_blk_info_type_id;
3189             ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3190             THEN
3191                l_att_cnt :=
3192                     NVL
3193                        (hxc_generic_retrieval_pkg.t_old_detail_attributes.LAST,
3194                         0
3195                        )
3196                   + 1;
3197                l_bld_blk_info_type_id :=
3198                          p_attribute_table (p_cnt).detail_bld_blk_info_type_id;
3199             END IF;
3200 
3201             -- for each field mapping assign the value back to the
3202             -- attribute table
3203             IF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE_CATEGORY'
3204                )
3205             THEN
3206                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3207                                                         l_bld_blk_info_type_id
3208                   )
3209                THEN
3210                   -- WWB 3791698 - OIT to OTL migration fix to handle pre-pending of PAEXPITDFF
3211                   --               to existing contexts
3212                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3213                   THEN
3214                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3215                                                           p_building_block_id;
3216                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3217                         hxc_deposit_wrapper_utilities.get_dupdff_name
3218                            (p_attribute_table (p_cnt).detail_attribute_category
3219                            );
3220                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3221                                        g_field_mappings_table (MAP).field_name;
3222                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3223                                           g_field_mappings_table (MAP).CONTEXT;
3224                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3225                                          g_field_mappings_table (MAP).CATEGORY;
3226                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3227                   THEN
3228                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3229                                                                    (l_att_cnt).bb_id :=
3230                                                           p_building_block_id;
3231                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3232                                                                    (l_att_cnt).VALUE :=
3233                         hxc_deposit_wrapper_utilities.get_dupdff_name
3234                            (p_attribute_table (p_cnt).detail_attribute_category
3235                            );
3236                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3237                                                                     (l_att_cnt).field_name :=
3238                                        g_field_mappings_table (MAP).field_name;
3239                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3240                                                                     (l_att_cnt).CONTEXT :=
3241                                           g_field_mappings_table (MAP).CONTEXT;
3242                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3243                                                                     (l_att_cnt).CATEGORY :=
3244                                          g_field_mappings_table (MAP).CATEGORY;
3245                   END IF;
3246                END IF;
3247             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE1')
3248             THEN
3249                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3250                                                         l_bld_blk_info_type_id
3251                   )
3252                THEN
3253                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3254                   THEN
3255                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3256                                                           p_building_block_id;
3257                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3258                                   p_attribute_table (p_cnt).detail_attribute1;
3259                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3260                                       g_field_mappings_table (MAP).field_name;
3261                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3262                                          g_field_mappings_table (MAP).CONTEXT;
3263                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3264                                         g_field_mappings_table (MAP).CATEGORY;
3265                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3266                   THEN
3267                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3268                                                                    (l_att_cnt).bb_id :=
3269                                                           p_building_block_id;
3270                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3271                                                                    (l_att_cnt).VALUE :=
3272                                   p_attribute_table (p_cnt).detail_attribute1;
3273                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3274                                                                    (l_att_cnt).field_name :=
3275                                       g_field_mappings_table (MAP).field_name;
3276                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3277                                                                    (l_att_cnt).CONTEXT :=
3278                                          g_field_mappings_table (MAP).CONTEXT;
3279                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3280                                                                    (l_att_cnt).CATEGORY :=
3281                                         g_field_mappings_table (MAP).CATEGORY;
3282                   END IF;
3283                END IF;
3284             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE2')
3285             THEN
3286                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3287                                                         l_bld_blk_info_type_id
3288                   )
3289                THEN
3290                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3291                   THEN
3292                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3293                                                           p_building_block_id;
3294                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3295                                   p_attribute_table (p_cnt).detail_attribute2;
3296                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3297                                       g_field_mappings_table (MAP).field_name;
3298                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3299                                          g_field_mappings_table (MAP).CONTEXT;
3300                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3301                                         g_field_mappings_table (MAP).CATEGORY;
3302                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3303                   THEN
3304                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3305                                                                    (l_att_cnt).bb_id :=
3306                                                           p_building_block_id;
3307                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3308                                                                    (l_att_cnt).VALUE :=
3309                                   p_attribute_table (p_cnt).detail_attribute2;
3310                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3311                                                                    (l_att_cnt).field_name :=
3312                                       g_field_mappings_table (MAP).field_name;
3313                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3314                                                                    (l_att_cnt).CONTEXT :=
3315                                          g_field_mappings_table (MAP).CONTEXT;
3316                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3317                                                                    (l_att_cnt).CATEGORY :=
3318                                         g_field_mappings_table (MAP).CATEGORY;
3319                   END IF;
3320                END IF;
3321             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE3')
3322             THEN
3323                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3324                                                         l_bld_blk_info_type_id
3325                   )
3326                THEN
3327                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3328                   THEN
3329                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3330                                                           p_building_block_id;
3331                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3332                                   p_attribute_table (p_cnt).detail_attribute3;
3333                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3334                                       g_field_mappings_table (MAP).field_name;
3335                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3336                                          g_field_mappings_table (MAP).CONTEXT;
3337                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3338                                         g_field_mappings_table (MAP).CATEGORY;
3339                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3340                   THEN
3341                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3342                                                                    (l_att_cnt).bb_id :=
3343                                                           p_building_block_id;
3344                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3345                                                                    (l_att_cnt).VALUE :=
3346                                   p_attribute_table (p_cnt).detail_attribute3;
3347                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3348                                                                    (l_att_cnt).field_name :=
3349                                       g_field_mappings_table (MAP).field_name;
3350                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3351                                                                    (l_att_cnt).CONTEXT :=
3352                                          g_field_mappings_table (MAP).CONTEXT;
3353                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3354                                                                    (l_att_cnt).CATEGORY :=
3355                                         g_field_mappings_table (MAP).CATEGORY;
3356                   END IF;
3357                END IF;
3358             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE4')
3359             THEN
3360                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3361                                                         l_bld_blk_info_type_id
3362                   )
3363                THEN
3364                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3365                   THEN
3366                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3367                                                           p_building_block_id;
3368                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3369                                   p_attribute_table (p_cnt).detail_attribute4;
3370                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3371                                       g_field_mappings_table (MAP).field_name;
3372                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3373                                          g_field_mappings_table (MAP).CONTEXT;
3374                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3375                                         g_field_mappings_table (MAP).CATEGORY;
3376                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3377                   THEN
3378                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3379                                                                    (l_att_cnt).bb_id :=
3380                                                           p_building_block_id;
3381                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3382                                                                    (l_att_cnt).VALUE :=
3383                                   p_attribute_table (p_cnt).detail_attribute4;
3384                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3385                                                                    (l_att_cnt).field_name :=
3386                                       g_field_mappings_table (MAP).field_name;
3387                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3388                                                                    (l_att_cnt).CONTEXT :=
3389                                          g_field_mappings_table (MAP).CONTEXT;
3390                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3391                                                                    (l_att_cnt).CATEGORY :=
3392                                         g_field_mappings_table (MAP).CATEGORY;
3393                   END IF;
3394                END IF;
3395             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE5')
3396             THEN
3397                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3398                                                         l_bld_blk_info_type_id
3399                   )
3400                THEN
3401                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3402                   THEN
3403                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3404                                                           p_building_block_id;
3405                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3406                                   p_attribute_table (p_cnt).detail_attribute5;
3407                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3408                                       g_field_mappings_table (MAP).field_name;
3409                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3410                                          g_field_mappings_table (MAP).CONTEXT;
3411                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3412                                         g_field_mappings_table (MAP).CATEGORY;
3413                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3414                   THEN
3415                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3416                                                                    (l_att_cnt).bb_id :=
3417                                                           p_building_block_id;
3418                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3419                                                                    (l_att_cnt).VALUE :=
3420                                   p_attribute_table (p_cnt).detail_attribute5;
3421                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3422                                                                    (l_att_cnt).field_name :=
3423                                       g_field_mappings_table (MAP).field_name;
3424                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3425                                                                    (l_att_cnt).CONTEXT :=
3426                                          g_field_mappings_table (MAP).CONTEXT;
3427                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3428                                                                    (l_att_cnt).CATEGORY :=
3429                                         g_field_mappings_table (MAP).CATEGORY;
3430                   END IF;
3431                END IF;
3432             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE6')
3433             THEN
3434                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3435                                                         l_bld_blk_info_type_id
3436                   )
3437                THEN
3438                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3439                   THEN
3440                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3441                                                           p_building_block_id;
3442                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3443                                   p_attribute_table (p_cnt).detail_attribute6;
3444                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3445                                       g_field_mappings_table (MAP).field_name;
3446                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3447                                          g_field_mappings_table (MAP).CONTEXT;
3448                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3449                                         g_field_mappings_table (MAP).CATEGORY;
3450                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3451                   THEN
3452                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3453                                                                    (l_att_cnt).bb_id :=
3454                                                           p_building_block_id;
3455                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3456                                                                    (l_att_cnt).VALUE :=
3457                                   p_attribute_table (p_cnt).detail_attribute6;
3458                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3459                                                                    (l_att_cnt).field_name :=
3460                                       g_field_mappings_table (MAP).field_name;
3461                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3462                                                                    (l_att_cnt).CONTEXT :=
3463                                          g_field_mappings_table (MAP).CONTEXT;
3464                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3465                                                                    (l_att_cnt).CATEGORY :=
3466                                         g_field_mappings_table (MAP).CATEGORY;
3467                   END IF;
3468                END IF;
3469             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE7')
3470             THEN
3471                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3472                                                         l_bld_blk_info_type_id
3473                   )
3474                THEN
3475                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3476                   THEN
3477                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3478                                                           p_building_block_id;
3479                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3480                                   p_attribute_table (p_cnt).detail_attribute7;
3481                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3482                                       g_field_mappings_table (MAP).field_name;
3483                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3484                                          g_field_mappings_table (MAP).CONTEXT;
3485                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3486                                         g_field_mappings_table (MAP).CATEGORY;
3487                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3488                   THEN
3489                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3490                                                                    (l_att_cnt).bb_id :=
3491                                                           p_building_block_id;
3492                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3493                                                                    (l_att_cnt).VALUE :=
3494                                   p_attribute_table (p_cnt).detail_attribute7;
3495                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3496                                                                    (l_att_cnt).field_name :=
3497                                       g_field_mappings_table (MAP).field_name;
3498                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3499                                                                    (l_att_cnt).CONTEXT :=
3500                                          g_field_mappings_table (MAP).CONTEXT;
3501                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3502                                                                    (l_att_cnt).CATEGORY :=
3503                                         g_field_mappings_table (MAP).CATEGORY;
3504                   END IF;
3505                END IF;
3506             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE8')
3507             THEN
3508                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3509                                                         l_bld_blk_info_type_id
3510                   )
3511                THEN
3512                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3513                   THEN
3514                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3515                                                           p_building_block_id;
3516                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3517                                   p_attribute_table (p_cnt).detail_attribute8;
3518                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3519                                       g_field_mappings_table (MAP).field_name;
3520                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3521                                          g_field_mappings_table (MAP).CONTEXT;
3522                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3523                                         g_field_mappings_table (MAP).CATEGORY;
3524                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3525                   THEN
3526                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3527                                                                    (l_att_cnt).bb_id :=
3528                                                           p_building_block_id;
3529                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3530                                                                    (l_att_cnt).VALUE :=
3531                                   p_attribute_table (p_cnt).detail_attribute8;
3532                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3533                                                                    (l_att_cnt).field_name :=
3534                                       g_field_mappings_table (MAP).field_name;
3535                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3536                                                                    (l_att_cnt).CONTEXT :=
3537                                          g_field_mappings_table (MAP).CONTEXT;
3538                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3539                                                                    (l_att_cnt).CATEGORY :=
3540                                         g_field_mappings_table (MAP).CATEGORY;
3541                   END IF;
3542                END IF;
3543             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE9')
3544             THEN
3545                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3546                                                         l_bld_blk_info_type_id
3547                   )
3548                THEN
3549                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3550                   THEN
3551                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3552                                                           p_building_block_id;
3553                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3554                                   p_attribute_table (p_cnt).detail_attribute9;
3555                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3556                                       g_field_mappings_table (MAP).field_name;
3557                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3558                                          g_field_mappings_table (MAP).CONTEXT;
3559                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3560                                         g_field_mappings_table (MAP).CATEGORY;
3561                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3562                   THEN
3563                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3564                                                                    (l_att_cnt).bb_id :=
3565                                                           p_building_block_id;
3566                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3567                                                                    (l_att_cnt).VALUE :=
3568                                   p_attribute_table (p_cnt).detail_attribute9;
3569                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3570                                                                    (l_att_cnt).field_name :=
3571                                       g_field_mappings_table (MAP).field_name;
3572                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3573                                                                    (l_att_cnt).CONTEXT :=
3574                                          g_field_mappings_table (MAP).CONTEXT;
3575                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3576                                                                    (l_att_cnt).CATEGORY :=
3577                                         g_field_mappings_table (MAP).CATEGORY;
3578                   END IF;
3579                END IF;
3580             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE10')
3581             THEN
3582                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3583                                                         l_bld_blk_info_type_id
3584                   )
3585                THEN
3586                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3587                   THEN
3588                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3589                                                           p_building_block_id;
3590                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3591                                  p_attribute_table (p_cnt).detail_attribute10;
3592                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3593                                       g_field_mappings_table (MAP).field_name;
3594                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3595                                          g_field_mappings_table (MAP).CONTEXT;
3596                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3597                                         g_field_mappings_table (MAP).CATEGORY;
3598                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3599                   THEN
3600                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3601                                                                    (l_att_cnt).bb_id :=
3602                                                           p_building_block_id;
3603                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3604                                                                    (l_att_cnt).VALUE :=
3605                                  p_attribute_table (p_cnt).detail_attribute10;
3606                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3607                                                                    (l_att_cnt).field_name :=
3608                                       g_field_mappings_table (MAP).field_name;
3609                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3610                                                                    (l_att_cnt).CONTEXT :=
3611                                          g_field_mappings_table (MAP).CONTEXT;
3612                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3613                                                                    (l_att_cnt).CATEGORY :=
3614                                         g_field_mappings_table (MAP).CATEGORY;
3615                   END IF;
3616                END IF;
3617             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE11')
3618             THEN
3619                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3620                                                         l_bld_blk_info_type_id
3621                   )
3622                THEN
3623                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3624                   THEN
3625                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3626                                                           p_building_block_id;
3627                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3628                                  p_attribute_table (p_cnt).detail_attribute11;
3629                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3630                                       g_field_mappings_table (MAP).field_name;
3631                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3632                                          g_field_mappings_table (MAP).CONTEXT;
3633                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3634                                         g_field_mappings_table (MAP).CATEGORY;
3635                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3636                   THEN
3637                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3638                                                                    (l_att_cnt).bb_id :=
3639                                                           p_building_block_id;
3640                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3641                                                                    (l_att_cnt).VALUE :=
3642                                  p_attribute_table (p_cnt).detail_attribute11;
3643                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3644                                                                    (l_att_cnt).field_name :=
3645                                       g_field_mappings_table (MAP).field_name;
3646                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3647                                                                    (l_att_cnt).CONTEXT :=
3648                                          g_field_mappings_table (MAP).CONTEXT;
3649                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3650                                                                    (l_att_cnt).CATEGORY :=
3651                                         g_field_mappings_table (MAP).CATEGORY;
3652                   END IF;
3653                END IF;
3654             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE12')
3655             THEN
3656                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3657                                                         l_bld_blk_info_type_id
3658                   )
3659                THEN
3660                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3661                   THEN
3662                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3663                                                           p_building_block_id;
3664                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3665                                  p_attribute_table (p_cnt).detail_attribute12;
3666                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3667                                       g_field_mappings_table (MAP).field_name;
3668                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3669                                          g_field_mappings_table (MAP).CONTEXT;
3670                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3671                                         g_field_mappings_table (MAP).CATEGORY;
3672                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3673                   THEN
3674                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3675                                                                    (l_att_cnt).bb_id :=
3676                                                           p_building_block_id;
3677                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3678                                                                    (l_att_cnt).VALUE :=
3679                                  p_attribute_table (p_cnt).detail_attribute12;
3680                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3681                                                                    (l_att_cnt).field_name :=
3682                                       g_field_mappings_table (MAP).field_name;
3683                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3684                                                                    (l_att_cnt).CONTEXT :=
3685                                          g_field_mappings_table (MAP).CONTEXT;
3686                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3687                                                                    (l_att_cnt).CATEGORY :=
3688                                         g_field_mappings_table (MAP).CATEGORY;
3689                   END IF;
3690                END IF;
3691             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE13')
3692             THEN
3693                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3694                                                         l_bld_blk_info_type_id
3695                   )
3696                THEN
3697                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3698                   THEN
3699                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3700                                                           p_building_block_id;
3701                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3702                                  p_attribute_table (p_cnt).detail_attribute13;
3703                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3704                                       g_field_mappings_table (MAP).field_name;
3705                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3706                                          g_field_mappings_table (MAP).CONTEXT;
3707                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3708                                         g_field_mappings_table (MAP).CATEGORY;
3709                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3710                   THEN
3711                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3712                                                                    (l_att_cnt).bb_id :=
3713                                                           p_building_block_id;
3714                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3715                                                                    (l_att_cnt).VALUE :=
3716                                  p_attribute_table (p_cnt).detail_attribute13;
3717                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3718                                                                    (l_att_cnt).field_name :=
3719                                       g_field_mappings_table (MAP).field_name;
3720                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3721                                                                    (l_att_cnt).CONTEXT :=
3722                                          g_field_mappings_table (MAP).CONTEXT;
3723                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3724                                                                    (l_att_cnt).CATEGORY :=
3725                                         g_field_mappings_table (MAP).CATEGORY;
3726                   END IF;
3727                END IF;
3728             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE14')
3729             THEN
3730                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3731                                                         l_bld_blk_info_type_id
3732                   )
3733                THEN
3734                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3735                   THEN
3736                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3737                                                           p_building_block_id;
3738                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3739                                  p_attribute_table (p_cnt).detail_attribute14;
3740                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3741                                       g_field_mappings_table (MAP).field_name;
3742                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3743                                          g_field_mappings_table (MAP).CONTEXT;
3744                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3745                                         g_field_mappings_table (MAP).CATEGORY;
3746                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3747                   THEN
3748                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3749                                                                    (l_att_cnt).bb_id :=
3750                                                           p_building_block_id;
3751                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3752                                                                    (l_att_cnt).VALUE :=
3753                                  p_attribute_table (p_cnt).detail_attribute14;
3754                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3755                                                                    (l_att_cnt).field_name :=
3756                                       g_field_mappings_table (MAP).field_name;
3757                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3758                                                                    (l_att_cnt).CONTEXT :=
3759                                          g_field_mappings_table (MAP).CONTEXT;
3760                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3761                                                                    (l_att_cnt).CATEGORY :=
3762                                         g_field_mappings_table (MAP).CATEGORY;
3763                   END IF;
3764                END IF;
3765             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE15')
3766             THEN
3767                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3768                                                         l_bld_blk_info_type_id
3769                   )
3770                THEN
3771                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3772                   THEN
3773                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3774                                                           p_building_block_id;
3775                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3776                                  p_attribute_table (p_cnt).detail_attribute15;
3777                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3778                                       g_field_mappings_table (MAP).field_name;
3779                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3780                                          g_field_mappings_table (MAP).CONTEXT;
3781                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3782                                         g_field_mappings_table (MAP).CATEGORY;
3783                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3784                   THEN
3785                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3786                                                                    (l_att_cnt).bb_id :=
3787                                                           p_building_block_id;
3788                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3789                                                                    (l_att_cnt).VALUE :=
3790                                  p_attribute_table (p_cnt).detail_attribute15;
3791                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3792                                                                    (l_att_cnt).field_name :=
3793                                       g_field_mappings_table (MAP).field_name;
3794                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3795                                                                    (l_att_cnt).CONTEXT :=
3796                                          g_field_mappings_table (MAP).CONTEXT;
3797                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3798                                                                    (l_att_cnt).CATEGORY :=
3799                                         g_field_mappings_table (MAP).CATEGORY;
3800                   END IF;
3801                END IF;
3802             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE16')
3803             THEN
3804                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3805                                                         l_bld_blk_info_type_id
3806                   )
3807                THEN
3808                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3809                   THEN
3810                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3811                                                           p_building_block_id;
3812                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3813                                  p_attribute_table (p_cnt).detail_attribute16;
3814                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3815                                       g_field_mappings_table (MAP).field_name;
3816                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3817                                          g_field_mappings_table (MAP).CONTEXT;
3818                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3819                                         g_field_mappings_table (MAP).CATEGORY;
3820                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3821                   THEN
3822                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3823                                                                    (l_att_cnt).bb_id :=
3824                                                           p_building_block_id;
3825                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3826                                                                    (l_att_cnt).VALUE :=
3827                                  p_attribute_table (p_cnt).detail_attribute16;
3828                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3829                                                                    (l_att_cnt).field_name :=
3830                                       g_field_mappings_table (MAP).field_name;
3831                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3832                                                                    (l_att_cnt).CONTEXT :=
3833                                          g_field_mappings_table (MAP).CONTEXT;
3834                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3835                                                                    (l_att_cnt).CATEGORY :=
3836                                         g_field_mappings_table (MAP).CATEGORY;
3837                   END IF;
3838                END IF;
3839             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE17')
3840             THEN
3841                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3842                                                         l_bld_blk_info_type_id
3843                   )
3844                THEN
3845                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3846                   THEN
3847                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3848                                                           p_building_block_id;
3849                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3850                                  p_attribute_table (p_cnt).detail_attribute17;
3851                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3852                                       g_field_mappings_table (MAP).field_name;
3853                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3854                                          g_field_mappings_table (MAP).CONTEXT;
3855                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3856                                         g_field_mappings_table (MAP).CATEGORY;
3857                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3858                   THEN
3859                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3860                                                                    (l_att_cnt).bb_id :=
3861                                                           p_building_block_id;
3862                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3863                                                                    (l_att_cnt).VALUE :=
3864                                  p_attribute_table (p_cnt).detail_attribute17;
3865                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3866                                                                    (l_att_cnt).field_name :=
3867                                       g_field_mappings_table (MAP).field_name;
3868                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3869                                                                    (l_att_cnt).CONTEXT :=
3870                                          g_field_mappings_table (MAP).CONTEXT;
3871                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3872                                                                    (l_att_cnt).CATEGORY :=
3873                                         g_field_mappings_table (MAP).CATEGORY;
3874                   END IF;
3875                END IF;
3876             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE18')
3877             THEN
3878                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3879                                                         l_bld_blk_info_type_id
3880                   )
3881                THEN
3882                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3883                   THEN
3884                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3885                                                           p_building_block_id;
3886                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3887                                  p_attribute_table (p_cnt).detail_attribute18;
3888                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3889                                       g_field_mappings_table (MAP).field_name;
3890                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3891                                          g_field_mappings_table (MAP).CONTEXT;
3892                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3893                                         g_field_mappings_table (MAP).CATEGORY;
3894                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3895                   THEN
3896                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3897                                                                    (l_att_cnt).bb_id :=
3898                                                           p_building_block_id;
3899                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3900                                                                    (l_att_cnt).VALUE :=
3901                                  p_attribute_table (p_cnt).detail_attribute18;
3902                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3903                                                                    (l_att_cnt).field_name :=
3904                                       g_field_mappings_table (MAP).field_name;
3905                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3906                                                                    (l_att_cnt).CONTEXT :=
3907                                          g_field_mappings_table (MAP).CONTEXT;
3908                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3909                                                                    (l_att_cnt).CATEGORY :=
3910                                         g_field_mappings_table (MAP).CATEGORY;
3911                   END IF;
3912                END IF;
3913             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE19')
3914             THEN
3915                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3916                                                         l_bld_blk_info_type_id
3917                   )
3918                THEN
3919                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3920                   THEN
3921                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3922                                                           p_building_block_id;
3923                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3924                                  p_attribute_table (p_cnt).detail_attribute19;
3925                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3926                                       g_field_mappings_table (MAP).field_name;
3927                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3928                                          g_field_mappings_table (MAP).CONTEXT;
3929                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3930                                         g_field_mappings_table (MAP).CATEGORY;
3931                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3932                   THEN
3933                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3934                                                                    (l_att_cnt).bb_id :=
3935                                                           p_building_block_id;
3936                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3937                                                                    (l_att_cnt).VALUE :=
3938                                  p_attribute_table (p_cnt).detail_attribute19;
3939                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3940                                                                    (l_att_cnt).field_name :=
3941                                       g_field_mappings_table (MAP).field_name;
3942                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3943                                                                    (l_att_cnt).CONTEXT :=
3944                                          g_field_mappings_table (MAP).CONTEXT;
3945                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3946                                                                    (l_att_cnt).CATEGORY :=
3947                                         g_field_mappings_table (MAP).CATEGORY;
3948                   END IF;
3949                END IF;
3950             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE20')
3951             THEN
3952                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3953                                                         l_bld_blk_info_type_id
3954                   )
3955                THEN
3956                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3957                   THEN
3958                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3959                                                           p_building_block_id;
3960                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3961                                  p_attribute_table (p_cnt).detail_attribute20;
3962                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
3963                                       g_field_mappings_table (MAP).field_name;
3964                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
3965                                          g_field_mappings_table (MAP).CONTEXT;
3966                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
3967                                         g_field_mappings_table (MAP).CATEGORY;
3968                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
3969                   THEN
3970                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3971                                                                    (l_att_cnt).bb_id :=
3972                                                           p_building_block_id;
3973                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3974                                                                    (l_att_cnt).VALUE :=
3975                                  p_attribute_table (p_cnt).detail_attribute20;
3976                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3977                                                                    (l_att_cnt).field_name :=
3978                                       g_field_mappings_table (MAP).field_name;
3979                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3980                                                                    (l_att_cnt).CONTEXT :=
3981                                          g_field_mappings_table (MAP).CONTEXT;
3982                      hxc_generic_retrieval_pkg.t_old_detail_attributes
3983                                                                    (l_att_cnt).CATEGORY :=
3984                                         g_field_mappings_table (MAP).CATEGORY;
3985                   END IF;
3986                END IF;
3987             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE21')
3988             THEN
3989                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
3990                                                         l_bld_blk_info_type_id
3991                   )
3992                THEN
3993                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
3994                   THEN
3995                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
3996                                                           p_building_block_id;
3997                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
3998                                  p_attribute_table (p_cnt).detail_attribute21;
3999                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4000                                       g_field_mappings_table (MAP).field_name;
4001                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4002                                          g_field_mappings_table (MAP).CONTEXT;
4003                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4004                                         g_field_mappings_table (MAP).CATEGORY;
4005                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4006                   THEN
4007                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4008                                                                    (l_att_cnt).bb_id :=
4009                                                           p_building_block_id;
4010                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4011                                                                    (l_att_cnt).VALUE :=
4012                                  p_attribute_table (p_cnt).detail_attribute21;
4013                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4014                                                                    (l_att_cnt).field_name :=
4015                                       g_field_mappings_table (MAP).field_name;
4016                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4017                                                                    (l_att_cnt).CONTEXT :=
4018                                          g_field_mappings_table (MAP).CONTEXT;
4019                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4020                                                                    (l_att_cnt).CATEGORY :=
4021                                         g_field_mappings_table (MAP).CATEGORY;
4022                   END IF;
4023                END IF;
4024             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE22')
4025             THEN
4026                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4027                                                         l_bld_blk_info_type_id
4028                   )
4029                THEN
4030                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4031                   THEN
4032                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4033                                                           p_building_block_id;
4034                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4035                                  p_attribute_table (p_cnt).detail_attribute22;
4036                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4037                                       g_field_mappings_table (MAP).field_name;
4038                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4039                                          g_field_mappings_table (MAP).CONTEXT;
4040                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4041                                         g_field_mappings_table (MAP).CATEGORY;
4042                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4043                   THEN
4044                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4045                                                                    (l_att_cnt).bb_id :=
4046                                                           p_building_block_id;
4047                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4048                                                                    (l_att_cnt).VALUE :=
4049                                  p_attribute_table (p_cnt).detail_attribute22;
4050                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4051                                                                    (l_att_cnt).field_name :=
4052                                       g_field_mappings_table (MAP).field_name;
4053                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4054                                                                    (l_att_cnt).CONTEXT :=
4055                                          g_field_mappings_table (MAP).CONTEXT;
4056                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4057                                                                    (l_att_cnt).CATEGORY :=
4058                                         g_field_mappings_table (MAP).CATEGORY;
4059                   END IF;
4060                END IF;
4061             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE23')
4062             THEN
4063                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4064                                                         l_bld_blk_info_type_id
4065                   )
4066                THEN
4067                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4068                   THEN
4069                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4070                                                           p_building_block_id;
4071                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4072                                  p_attribute_table (p_cnt).detail_attribute23;
4073                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4074                                       g_field_mappings_table (MAP).field_name;
4075                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4076                                          g_field_mappings_table (MAP).CONTEXT;
4077                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4078                                         g_field_mappings_table (MAP).CATEGORY;
4079                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4080                   THEN
4081                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4082                                                                    (l_att_cnt).bb_id :=
4083                                                           p_building_block_id;
4084                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4085                                                                    (l_att_cnt).VALUE :=
4086                                  p_attribute_table (p_cnt).detail_attribute23;
4087                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4088                                                                    (l_att_cnt).field_name :=
4089                                       g_field_mappings_table (MAP).field_name;
4090                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4091                                                                    (l_att_cnt).CONTEXT :=
4092                                          g_field_mappings_table (MAP).CONTEXT;
4093                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4094                                                                    (l_att_cnt).CATEGORY :=
4095                                         g_field_mappings_table (MAP).CATEGORY;
4096                   END IF;
4097                END IF;
4098             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE24')
4099             THEN
4100                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4101                                                         l_bld_blk_info_type_id
4102                   )
4103                THEN
4104                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4105                   THEN
4106                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4107                                                           p_building_block_id;
4108                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4109                                  p_attribute_table (p_cnt).detail_attribute24;
4110                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4111                                       g_field_mappings_table (MAP).field_name;
4112                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4113                                          g_field_mappings_table (MAP).CONTEXT;
4114                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4115                                         g_field_mappings_table (MAP).CATEGORY;
4116                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4117                   THEN
4118                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4119                                                                    (l_att_cnt).bb_id :=
4120                                                           p_building_block_id;
4121                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4122                                                                    (l_att_cnt).VALUE :=
4123                                  p_attribute_table (p_cnt).detail_attribute24;
4124                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4125                                                                    (l_att_cnt).field_name :=
4126                                       g_field_mappings_table (MAP).field_name;
4127                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4128                                                                    (l_att_cnt).CONTEXT :=
4129                                          g_field_mappings_table (MAP).CONTEXT;
4130                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4131                                                                    (l_att_cnt).CATEGORY :=
4132                                         g_field_mappings_table (MAP).CATEGORY;
4133                   END IF;
4134                END IF;
4135             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE25')
4136             THEN
4137                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4138                                                         l_bld_blk_info_type_id
4139                   )
4140                THEN
4141                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4142                   THEN
4143                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4144                                                           p_building_block_id;
4145                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4146                                  p_attribute_table (p_cnt).detail_attribute25;
4147                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4148                                       g_field_mappings_table (MAP).field_name;
4149                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4150                                          g_field_mappings_table (MAP).CONTEXT;
4151                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4152                                         g_field_mappings_table (MAP).CATEGORY;
4153                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4154                   THEN
4155                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4156                                                                    (l_att_cnt).bb_id :=
4157                                                           p_building_block_id;
4158                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4159                                                                    (l_att_cnt).VALUE :=
4160                                  p_attribute_table (p_cnt).detail_attribute25;
4161                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4162                                                                    (l_att_cnt).field_name :=
4163                                       g_field_mappings_table (MAP).field_name;
4164                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4165                                                                    (l_att_cnt).CONTEXT :=
4166                                          g_field_mappings_table (MAP).CONTEXT;
4167                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4168                                                                    (l_att_cnt).CATEGORY :=
4169                                         g_field_mappings_table (MAP).CATEGORY;
4170                   END IF;
4171                END IF;
4172             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE26')
4173             THEN
4174                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4175                                                         l_bld_blk_info_type_id
4176                   )
4177                THEN
4178                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4179                   THEN
4180                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4181                                                           p_building_block_id;
4182                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4183                                  p_attribute_table (p_cnt).detail_attribute26;
4184                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4185                                       g_field_mappings_table (MAP).field_name;
4186                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4187                                          g_field_mappings_table (MAP).CONTEXT;
4188                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4189                                         g_field_mappings_table (MAP).CATEGORY;
4190                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4191                   THEN
4192                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4193                                                                    (l_att_cnt).bb_id :=
4194                                                           p_building_block_id;
4195                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4196                                                                    (l_att_cnt).VALUE :=
4197                                  p_attribute_table (p_cnt).detail_attribute26;
4198                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4199                                                                    (l_att_cnt).field_name :=
4200                                       g_field_mappings_table (MAP).field_name;
4201                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4202                                                                    (l_att_cnt).CONTEXT :=
4203                                          g_field_mappings_table (MAP).CONTEXT;
4204                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4205                                                                    (l_att_cnt).CATEGORY :=
4206                                         g_field_mappings_table (MAP).CATEGORY;
4207                   END IF;
4208                END IF;
4209             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE27')
4210             THEN
4211                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4212                                                         l_bld_blk_info_type_id
4213                   )
4214                THEN
4215                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4216                   THEN
4217                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4218                                                           p_building_block_id;
4219                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4220                                  p_attribute_table (p_cnt).detail_attribute27;
4221                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4222                                       g_field_mappings_table (MAP).field_name;
4223                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4224                                          g_field_mappings_table (MAP).CONTEXT;
4225                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4226                                         g_field_mappings_table (MAP).CATEGORY;
4227                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4228                   THEN
4229                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4230                                                                    (l_att_cnt).bb_id :=
4231                                                           p_building_block_id;
4232                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4233                                                                    (l_att_cnt).VALUE :=
4234                                  p_attribute_table (p_cnt).detail_attribute27;
4235                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4236                                                                    (l_att_cnt).field_name :=
4237                                       g_field_mappings_table (MAP).field_name;
4238                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4239                                                                    (l_att_cnt).CONTEXT :=
4240                                          g_field_mappings_table (MAP).CONTEXT;
4241                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4242                                                                    (l_att_cnt).CATEGORY :=
4243                                         g_field_mappings_table (MAP).CATEGORY;
4244                   END IF;
4245                END IF;
4246             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE28')
4247             THEN
4248                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4249                                                         l_bld_blk_info_type_id
4250                   )
4251                THEN
4252                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4253                   THEN
4254                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4255                                                           p_building_block_id;
4256                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4257                                  p_attribute_table (p_cnt).detail_attribute28;
4258                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4259                                       g_field_mappings_table (MAP).field_name;
4260                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4261                                          g_field_mappings_table (MAP).CONTEXT;
4262                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4263                                         g_field_mappings_table (MAP).CATEGORY;
4264                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4265                   THEN
4266                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4267                                                                    (l_att_cnt).bb_id :=
4268                                                           p_building_block_id;
4269                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4270                                                                    (l_att_cnt).VALUE :=
4271                                  p_attribute_table (p_cnt).detail_attribute28;
4272                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4273                                                                    (l_att_cnt).field_name :=
4274                                       g_field_mappings_table (MAP).field_name;
4275                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4276                                                                    (l_att_cnt).CONTEXT :=
4277                                          g_field_mappings_table (MAP).CONTEXT;
4278                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4279                                                                    (l_att_cnt).CATEGORY :=
4280                                         g_field_mappings_table (MAP).CATEGORY;
4281                   END IF;
4282                END IF;
4283             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE29')
4284             THEN
4285                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4286                                                         l_bld_blk_info_type_id
4287                   )
4288                THEN
4289                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4290                   THEN
4291                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4292                                                           p_building_block_id;
4293                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4294                                  p_attribute_table (p_cnt).detail_attribute29;
4295                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4296                                       g_field_mappings_table (MAP).field_name;
4297                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4298                                          g_field_mappings_table (MAP).CONTEXT;
4299                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4300                                         g_field_mappings_table (MAP).CATEGORY;
4301                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4302                   THEN
4303                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4304                                                                    (l_att_cnt).bb_id :=
4305                                                           p_building_block_id;
4306                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4307                                                                    (l_att_cnt).VALUE :=
4308                                  p_attribute_table (p_cnt).detail_attribute29;
4309                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4310                                                                    (l_att_cnt).field_name :=
4311                                       g_field_mappings_table (MAP).field_name;
4312                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4313                                                                    (l_att_cnt).CONTEXT :=
4314                                          g_field_mappings_table (MAP).CONTEXT;
4315                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4316                                                                    (l_att_cnt).CATEGORY :=
4317                                         g_field_mappings_table (MAP).CATEGORY;
4318                   END IF;
4319                END IF;
4320             ELSIF (g_field_mappings_table (MAP).ATTRIBUTE = 'ATTRIBUTE30')
4321             THEN
4322                IF (g_field_mappings_table (MAP).bld_blk_info_type_id =
4323                                                         l_bld_blk_info_type_id
4324                   )
4325                THEN
4326                   IF (p_scope = 'DETAIL' AND p_new = 'Y')
4327                   THEN
4328                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).bb_id :=
4329                                                           p_building_block_id;
4330                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).VALUE :=
4331                                  p_attribute_table (p_cnt).detail_attribute30;
4332                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).field_name :=
4333                                       g_field_mappings_table (MAP).field_name;
4334                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CONTEXT :=
4335                                          g_field_mappings_table (MAP).CONTEXT;
4336                      hxc_generic_retrieval_pkg.t_detail_attributes (l_att_cnt).CATEGORY :=
4337                                         g_field_mappings_table (MAP).CATEGORY;
4338                   ELSIF (p_scope = 'DETAIL' AND p_new = 'N')
4339                   THEN
4340                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4341                                                                    (l_att_cnt).bb_id :=
4342                                                           p_building_block_id;
4343                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4344                                                                    (l_att_cnt).VALUE :=
4345                                  p_attribute_table (p_cnt).detail_attribute30;
4346                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4347                                                                    (l_att_cnt).field_name :=
4348                                       g_field_mappings_table (MAP).field_name;
4349                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4350                                                                    (l_att_cnt).CONTEXT :=
4351                                          g_field_mappings_table (MAP).CONTEXT;
4352                      hxc_generic_retrieval_pkg.t_old_detail_attributes
4353                                                                    (l_att_cnt).CATEGORY :=
4354                                         g_field_mappings_table (MAP).CATEGORY;
4355                   END IF;
4356                END IF;
4357             END IF;
4358          END LOOP;
4359       END IF;                                           --  p_scope = 'DETAIL'
4360    END populate_attributes;
4361 
4362 -- private procedure
4363 --   query_it
4364 --
4365 -- description
4366 --   This is the heart of the retrieval process. It retrieves and sorts the time
4367 --   building blocks.
4368 --   Retrieval:
4369 --   The dynanmic SQL is parsed and executed and the dbms_sql arrays defined
4370 --   and initialised. Once all the rows have been fetched the data is moved into
4371 --   one PL/SQL table (see populate_query_table).
4372 --   Sorting:
4373 --   Since the bld blks are retrieved in one query there is some data repetition.
4374 --   We loop through all the rows returned and note when the bld blk id changes
4375 --   at the TIME, DAY and DETAIL scopes and then and only then copy the bld blk
4376 --   to the appropriate global PL/SQL table. At any time a bld blk is copied,
4377 --   any bld blks in the hierarchy above are also copied. The decision to
4378 --   copy a bld blk or not is based upon the max ovn column also populated in the
4379 --   query. For the incremental retrieval this is the ovn of the bld blk last transferred.
4380 --   If they are the same, we do nothing, if it is smaller than the actual ovn then
4381 --   the bld blk has changed and we must transfer. When the retrieval is not incremental
4382 --   then the function max ovn is replaced by the actual ovn + 1 such that we always
4383 --   transfer the bld blk.
4384 --
4385 -- parameters
4386 --   p_query   - the dynamic sql to be run
4387    PROCEDURE query_it (p_query IN VARCHAR2)
4388    IS
4389 --
4390 -- define local variables
4391 --
4392       l_proc                      VARCHAR2 (72);
4393       l_query_text                VARCHAR2 (32000)                 := p_query;
4394       l_copy_old                  VARCHAR2 (1)                         := 'N';
4395       l_count                     PLS_INTEGER;
4396       l_ind                       PLS_INTEGER;
4397       l_number_format 		  varchar2(2);
4398       l_att26    		  number;
4399 -- timecard scope building block local variables
4400       l_old_timecard_bb_id        hxc_time_building_blocks.time_building_block_id%TYPE
4401                                                                         := -1;
4402       l_old_day_bb_id             hxc_time_building_blocks.time_building_block_id%TYPE
4403                                                                         := -1;
4404       l_old_detail_bb_id          hxc_time_building_blocks.time_building_block_id%TYPE
4405                                                                         := -1;
4406 -- timecard scope attribute local variables
4407       l_old_timecard_ta_id        hxc_time_attributes.time_attribute_id%TYPE
4408                                                                         := -1;
4409       l_old_day_ta_id             hxc_time_attributes.time_attribute_id%TYPE
4410                                                                         := -1;
4411       l_old_detail_ta_id          hxc_time_attributes.time_attribute_id%TYPE
4412                                                                         := -1;
4413 -- tables and temporary table local variables
4414       t_attribute_field_name      tab_ta_field_name;
4415       t_attribute_value           tab_ta_attribute;
4416       l_gaz_index                 INTEGER;
4417 -- dynamic SQL local variables
4418       l_csr                       INTEGER;
4419       l_max_array_size            INTEGER;
4420       l_estimated_array_size      INTEGER                                := 0;
4421       l_rows_fetched              INTEGER;
4422       l_dummy                     INTEGER;
4423       l_timecard_copied           VARCHAR2 (1)                         := 'N';
4424       l_day_copied                VARCHAR2 (1)                         := 'N';
4425       l_detail_copied             VARCHAR2 (1)                         := 'N';
4426       l_time_att_copied           VARCHAR2 (1)                         := 'N';
4427       l_day_att_copied            VARCHAR2 (1)                         := 'N';
4428       l_detail_att_copied         VARCHAR2 (1)                         := 'N';
4429       l_bld_blks_to_transfer      VARCHAR2 (1)                         := 'N';
4430 
4431 -- table and variable for the time/day/detail bld blk info type registers
4432       TYPE t_bld_blk_info_type_id IS TABLE OF hxc_bld_blk_info_types.bld_blk_info_type_id%TYPE
4433          INDEX BY BINARY_INTEGER;
4434 
4435       t_time_bld_blk_info         t_bld_blk_info_type_id;
4436       t_day_bld_blk_info          t_bld_blk_info_type_id;
4437       t_detail_bld_blk_info       t_bld_blk_info_type_id;
4438       l_bld_blk_info_index        PLS_INTEGER;
4439       e_no_timecards              EXCEPTION;
4440       e_no_bld_blks_to_transfer   EXCEPTION;
4441       -- used in incremental when we fetched but no ovn diffs
4442       l_prefs                     hxc_generic_retrieval_utils.t_pref;
4443       l_ret_rules                 hxc_generic_retrieval_utils.t_ret_rule;
4444       l_rtr_outcomes              hxc_generic_retrieval_utils.t_rtr_outcome;
4445       l_errors                    hxc_generic_retrieval_utils.t_errors;
4446       l_timecard_retrieve         BOOLEAN;
4447       l_day_retrieve              BOOLEAN;
4448       l_error_flag                BOOLEAN;
4449       l_tc_locked                 BOOLEAN;
4450       l_tc_first_lock             BOOLEAN;
4451       l_range                     VARCHAR2 (15);
4452       l_already_multiplied        varchar2(1) := 'N';
4453       l_detail_index              number;
4454 
4455       -- Bug 7595581
4456       -- Retrieval Log
4457 
4458       l_detail_bld_blk_idx	  PLS_INTEGER;
4459       l_bb_skipped_reason	  VARCHAR2(80);
4460 
4461 -- OTL-Absences Integration (Bug 8779478)
4462       l_detail_attribute_category hxc_time_attributes.attribute_category%TYPE;  -- Absences
4463       abs_cnt			  PLS_INTEGER;					-- Absences
4464 
4465 
4466       CURSOR csr_how_big_is_htbb
4467       IS
4468          SELECT COUNT (*)
4469            FROM hxc_time_building_blocks
4470           WHERE SCOPE = 'TIMECARD';
4471 
4472     CURSOR get_session_number_format
4473     is
4474     SELECT value
4475     FROM nls_session_parameters
4476     WHERE parameter = 'NLS_NUMERIC_CHARACTERS';
4477 
4478       l_htbb_size                 NUMBER;
4479 
4480 
4481 
4482 -- define private procedures
4483 
4484 
4485      -- Bug 9701936
4486      -- Added this private procedure to be
4487      -- called at the end of each chunk to move all
4488      -- PENDING records to SKIPPED status.
4489 
4490      PROCEDURE skip_pending_records
4491      IS
4492 
4493        PRAGMA AUTONOMOUS_TRANSACTION;
4494 
4495      BEGIN
4496 
4497          UPDATE hxc_rdb_process_timecards
4498             SET stage = 'SKIPPED'
4499           WHERE ret_user_id = FND_GLOBAL.user_id
4500             AND request_id = FND_GLOBAL.conc_request_id
4501             AND process = g_params.p_process
4502             AND stage = 'PENDING';
4503 
4504          COMMIT;
4505 
4506      END skip_pending_records;
4507 
4508 
4509       -- private procedure
4510 --   copy_bld_blks
4511 --
4512 -- description
4513 --   Populates the global bld blks PL/SQL tables with the appropriate bld blk information
4514 --   Also maintains the global transaction detail PL/SQL table for each bld blk
4515 --
4516 -- parameters
4517 --   p_bld_blks_table   - PL/SQL table of all bld blk rows
4518 --   pscope    - scope of the bld blk to be copied
4519 --   p_copied     - copied flag used to prevent data duplication in tables
4520 --   p_cnt     - index for p_bld blks_table
4521 --   p_copy_old      - flag to indicate whether or not to maintain the 'old'
4522 --       - bld blks PL/SQL table
4523       PROCEDURE copy_bld_blks (
4524          p_bld_blks_table                   t_all_building_blocks,
4525          p_scope                            VARCHAR2,
4526          p_copied           IN OUT NOCOPY   VARCHAR2,
4527          p_cnt                              INTEGER,
4528          p_copy_old                         VARCHAR2,
4529          p_errors           IN OUT NOCOPY   hxc_generic_retrieval_utils.t_errors,
4530          p_error                            BOOLEAN
4531       )
4532       IS
4533          l_bld_blk_index       PLS_INTEGER;
4534          l_old_bld_blk_index   PLS_INTEGER;
4535          l_error_index         PLS_INTEGER;
4536          l_proc                VARCHAR2 (72) := g_package || 'copy_bld_blks';
4537       BEGIN
4538          IF (p_scope = 'TIME')
4539          THEN
4540             l_bld_blk_index :=
4541                    NVL (hxc_generic_retrieval_pkg.t_tx_time_bb_id.LAST, 0)
4542                    + 1;
4543          ELSIF (p_scope = 'DAY')
4544          THEN
4545             l_bld_blk_index :=
4546                     NVL (hxc_generic_retrieval_pkg.t_tx_day_bb_id.LAST, 0)
4547                     + 1;
4548          ELSIF (p_scope = 'DETAIL')
4549          THEN
4550             l_bld_blk_index :=
4551                  NVL (hxc_generic_retrieval_pkg.t_detail_bld_blks.LAST, 0)
4552                  + 1;
4553          END IF;
4554 
4555          l_error_index :=
4556                    NVL (hxc_generic_retrieval_pkg.t_tx_error_bb_id.LAST, 0)
4557                    + 1;
4558 
4559          IF (p_scope = 'TIME' AND p_copied = 'N')
4560          THEN
4561             hxc_generic_retrieval_pkg.t_time_bld_blks (t_bb (p_cnt).time_bb_id
4562                                                       ).start_time :=
4563                                                   t_bb (p_cnt).time_start_time;
4564             hxc_generic_retrieval_pkg.t_time_bld_blks (t_bb (p_cnt).time_bb_id).stop_time :=
4565                                                    t_bb (p_cnt).time_stop_time;
4566             hxc_generic_retrieval_pkg.t_time_bld_blks (t_bb (p_cnt).time_bb_id).comment_text :=
4567                                                 t_bb (p_cnt).time_comment_text;
4568 
4569             -- audit the transaction
4570             IF (NOT p_error)
4571             THEN
4572                hxc_generic_retrieval_pkg.t_tx_time_bb_id (l_bld_blk_index) :=
4573                                                       t_bb (p_cnt).time_bb_id;
4574                hxc_generic_retrieval_pkg.t_tx_time_bb_ovn (l_bld_blk_index) :=
4575                                                         t_bb (p_cnt).time_ovn;
4576                hxc_generic_retrieval_pkg.t_tx_time_status (l_bld_blk_index) :=
4577                                                                 'IN PROGRESS';
4578                hxc_generic_retrieval_pkg.t_tx_time_exception (l_bld_blk_index) :=
4579                                                                          NULL;
4580             ELSE
4581                hxc_generic_retrieval_pkg.t_tx_error_bb_id (l_error_index) :=
4582                                                       t_bb (p_cnt).time_bb_id;
4583                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn (l_error_index) :=
4584                                                         t_bb (p_cnt).time_ovn;
4585                hxc_generic_retrieval_pkg.t_tx_error_status (l_error_index) :=
4586                                                                      'ERRORS';
4587                hxc_generic_retrieval_pkg.t_tx_error_exception (l_error_index) :=
4588                   p_errors (t_bb (p_cnt).detail_resource_id).exception_description;
4589             END IF;
4590 
4591             p_copied := 'Y';
4592          ELSIF (p_scope = 'DAY' AND p_copied = 'N')
4593          THEN
4594             -- audit the transaction
4595             IF (NOT p_error)
4596             THEN
4597                hxc_generic_retrieval_pkg.t_tx_day_parent_id (l_bld_blk_index) :=
4598                                                       t_bb (p_cnt).time_bb_id;
4599                hxc_generic_retrieval_pkg.t_tx_day_bb_id (l_bld_blk_index) :=
4600                                                        t_bb (p_cnt).day_bb_id;
4601                hxc_generic_retrieval_pkg.t_tx_day_bb_ovn (l_bld_blk_index) :=
4602                                                          t_bb (p_cnt).day_ovn;
4603                hxc_generic_retrieval_pkg.t_tx_day_status (l_bld_blk_index) :=
4604                                                                 'IN PROGRESS';
4605                hxc_generic_retrieval_pkg.t_tx_day_exception (l_bld_blk_index) :=
4606                                                                          NULL;
4607             ELSE
4608                hxc_generic_retrieval_pkg.t_tx_error_bb_id (l_error_index) :=
4609                                                        t_bb (p_cnt).day_bb_id;
4610                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn (l_error_index) :=
4611                                                          t_bb (p_cnt).day_ovn;
4612                hxc_generic_retrieval_pkg.t_tx_error_status (l_error_index) :=
4613                                                                      'ERRORS';
4614                hxc_generic_retrieval_pkg.t_tx_error_exception (l_error_index) :=
4615                                                                          NULL;
4616             END IF;
4617 
4618             p_copied := 'Y';
4619          ELSIF (p_scope = 'DETAIL' AND p_copied = 'N')
4620          THEN
4621             IF (NOT p_error)
4622             THEN
4623                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).bb_id :=
4624                                                     t_bb (p_cnt).detail_bb_id;
4625                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).parent_bb_id :=
4626                                              t_bb (p_cnt).detail_parent_bb_id;
4627                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).resource_type :=
4628                                             t_bb (p_cnt).detail_resource_type;
4629                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).resource_id :=
4630                                               t_bb (p_cnt).detail_resource_id;
4631                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).comment_text :=
4632                                              t_bb (p_cnt).detail_comment_text;
4633                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).start_time :=
4634                                                   t_bb (p_cnt).day_start_time;
4635                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).stop_time :=
4636                                                    t_bb (p_cnt).day_stop_time;
4637                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).measure :=
4638                                                   t_bb (p_cnt).detail_measure;
4639                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).uom :=
4640                                                       t_bb (p_cnt).detail_uom;
4641 
4642                IF (t_bb (p_cnt).detail_type = 'RANGE')
4643                THEN
4644                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4645                                                              (l_bld_blk_index).start_time :=
4646                                                t_bb (p_cnt).detail_start_time;
4647                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4648                                                              (l_bld_blk_index).stop_time :=
4649                                                 t_bb (p_cnt).detail_stop_time;
4650                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4651                                                              (l_bld_blk_index).measure :=
4652                        (  t_bb (p_cnt).detail_stop_time
4653                         - t_bb (p_cnt).detail_start_time
4654                        )
4655                      * 24;
4656                   hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).uom :=
4657                                                                        'HOURS';
4658                END IF;
4659 
4660                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).SCOPE :=
4661                                                      t_bb (p_cnt).detail_scope;
4662                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).TYPE :=
4663                                                       t_bb (p_cnt).detail_type;
4664                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).deleted :=
4665                                                    t_bb (p_cnt).detail_deleted;
4666                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).ovn :=
4667                                                        t_bb (p_cnt).detail_ovn;
4668                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).timecard_bb_id :=
4669                                                        t_bb (p_cnt).time_bb_id;
4670                hxc_generic_retrieval_pkg.t_detail_bld_blks (l_bld_blk_index).timecard_ovn :=
4671                                                          t_bb (p_cnt).time_ovn;
4672                -- set the bld blks to transfer flag if any DETAIL bld blks to transfer
4673                l_bld_blks_to_transfer := 'Y';
4674 
4675 -- maintain arrays for old building block
4676                IF (p_copy_old = 'Y')
4677                THEN
4678                   l_old_bld_blk_index := NVL (t_old_detail_bb_id.LAST, 0) + 1;
4679                   t_old_detail_seq (l_old_bld_blk_index) :=
4680                                                           l_old_bld_blk_index;
4681                   t_old_detail_bb_id (l_old_bld_blk_index) :=
4682                                                     t_bb (p_cnt).detail_bb_id;
4683                   t_old_detail_ovn (l_old_bld_blk_index) :=
4684                                                   t_bb (p_cnt).detail_max_ovn;
4685                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4686                                                              (l_bld_blk_index).changed :=
4687                                                                           'Y';
4688                ELSE
4689                   hxc_generic_retrieval_pkg.t_detail_bld_blks
4690                                                              (l_bld_blk_index).changed :=
4691                                                                           'N';
4692                END IF;
4693             END IF;                                          -- if not p_error
4694 
4695             -- audit the transaction
4696             IF (NOT p_error)
4697             THEN
4698                hxc_generic_retrieval_pkg.t_tx_detail_parent_id
4699                                                              (l_bld_blk_index) :=
4700                                                        t_bb (p_cnt).day_bb_id;
4701                hxc_generic_retrieval_pkg.t_tx_detail_bb_id (l_bld_blk_index) :=
4702                                                     t_bb (p_cnt).detail_bb_id;
4703                hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn (l_bld_blk_index) :=
4704                                                       t_bb (p_cnt).detail_ovn;
4705                hxc_generic_retrieval_pkg.t_tx_detail_status (l_bld_blk_index) :=
4706                                                                 'IN PROGRESS';
4707                hxc_generic_retrieval_pkg.t_tx_detail_exception
4708                                                              (l_bld_blk_index) :=
4709                                                                          NULL;
4710             ELSE
4711                hxc_generic_retrieval_pkg.t_tx_error_bb_id (l_error_index) :=
4712                                                     t_bb (p_cnt).detail_bb_id;
4713                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn (l_error_index) :=
4714                                                       t_bb (p_cnt).detail_ovn;
4715                hxc_generic_retrieval_pkg.t_tx_error_status (l_error_index) :=
4716                                                                      'ERRORS';
4717                hxc_generic_retrieval_pkg.t_tx_error_exception (l_error_index) :=
4718                                                                          NULL;
4719             END IF;
4720 
4721             p_copied := 'Y';
4722          END IF;
4723       END copy_bld_blks;
4724 
4725 -- private function
4726 --   att_copied_before ?
4727 --
4728 -- description
4729 --   Polls the temporary attribute PL/SQL table to ensure that this attribute has not been copied
4730 --   already.
4731 --   Returns TRUE if copied before, FALSE, if not
4732 --
4733 -- parameters
4734 --   p_scope   - scope
4735 --   p_bld_blk_info_type_id - bld blk info type id
4736       FUNCTION att_copied_before (
4737          p_scope                  VARCHAR2,
4738          p_bld_blk_info_type_id   hxc_bld_blk_info_types.bld_blk_info_type_id%TYPE
4739       )
4740          RETURN BOOLEAN
4741 
4742       IS
4743       BEGIN
4744          IF p_scope = 'TIME'
4745          THEN
4746             IF t_time_bld_blk_info.COUNT <> 0
4747             THEN
4748                FOR x IN t_time_bld_blk_info.FIRST .. t_time_bld_blk_info.LAST
4749                LOOP
4750                   IF t_time_bld_blk_info (x) = p_bld_blk_info_type_id
4751                   THEN
4752                      RETURN TRUE;
4753                   END IF;
4754                END LOOP;
4755 
4756                RETURN FALSE;
4757             ELSE
4758                RETURN FALSE;
4759             END IF;
4760          ELSIF p_scope = 'DAY'
4761          THEN
4762             IF t_day_bld_blk_info.COUNT <> 0
4763             THEN
4764                FOR x IN t_day_bld_blk_info.FIRST .. t_day_bld_blk_info.LAST
4765                LOOP
4766                   IF t_day_bld_blk_info (x) = p_bld_blk_info_type_id
4767                   THEN
4768                      RETURN TRUE;
4769                   END IF;
4770                END LOOP;
4771 
4772                RETURN FALSE;
4773             ELSE
4774                RETURN FALSE;
4775             END IF;
4776          ELSIF p_scope = 'DETAIL'
4777          THEN
4778             IF t_detail_bld_blk_info.COUNT <> 0
4779             THEN
4780                FOR x IN
4781                   t_detail_bld_blk_info.FIRST .. t_detail_bld_blk_info.LAST
4782                LOOP
4783                   IF t_detail_bld_blk_info (x) = p_bld_blk_info_type_id
4784                   THEN
4785                      RETURN TRUE;
4786                   END IF;
4787                END LOOP;
4788 
4789                RETURN FALSE;
4790             ELSE
4791                RETURN FALSE;
4792             END IF;
4793          END IF;
4794       END att_copied_before;
4795 
4796    BEGIN                                                           -- query_it
4797       IF g_debug
4798       THEN
4799          l_proc := g_package || 'query_it';
4800          hr_utility.set_location ('Entering ' || l_proc, 10);
4801       END IF;
4802 
4803     OPEN get_session_number_format;
4804     FETCH get_session_number_format into l_number_format;
4805     CLOSE get_session_number_format;
4806 
4807       l_max_array_size := 100;
4808       l_rows_fetched := l_max_array_size;
4809 
4810       IF g_debug
4811       THEN
4812          hr_utility.set_location ('Processing ' || l_proc, 20);
4813       END IF;
4814 
4815       l_csr := DBMS_SQL.open_cursor;
4816 
4817       IF g_debug
4818       THEN
4819          hr_utility.set_location ('Processing ' || l_proc, 30);
4820       END IF;
4821 
4822       DBMS_SQL.parse (l_csr, l_query_text, DBMS_SQL.native);
4823 
4824 -- bind variables needed by all queries
4825       IF (g_params.p_process IN
4826              ('Projects Retrieval Process',
4827               'BEE Retrieval Process',
4828               'Apply Schedule Rules',
4829               'Purchasing Retrieval Process'
4830              )
4831          )
4832       THEN
4833          NULL;                 -- no more binds - bound in pop ret range blks
4834       ELSE
4835          DBMS_SQL.bind_variable (l_csr, ':p_lower_range', l_pkg_range_start);
4836          DBMS_SQL.bind_variable (l_csr, ':p_upper_range', l_pkg_range_stop);
4837 
4838          IF (g_params.p_incremental = 'Y')
4839          THEN
4840             DBMS_SQL.bind_variable (l_csr,
4841                                     ':p_process_id',
4842                                     g_retrieval_process_id
4843                                    );
4844          END IF;
4845 
4846          -- bind the start and end date parameters
4847          IF g_debug
4848          THEN
4849             hr_utility.set_location ('Processing ' || l_proc, 35);
4850          END IF;
4851 
4852          IF (    (    g_params.p_start_date IS NOT NULL
4853                   AND g_params.p_end_date IS NOT NULL
4854                  )
4855              AND (g_params.p_rerun_flag = 'N')
4856             )
4857          THEN
4858             DBMS_SQL.bind_variable (l_csr,
4859                                     ':p_start_date',
4860                                     g_params.p_start_date
4861                                    );
4862             DBMS_SQL.bind_variable (l_csr, ':p_end_date', g_params.p_end_date);
4863          END IF;
4864       END IF;
4865 
4866       IF g_debug
4867       THEN
4868          hr_utility.set_location ('Processing ' || l_proc, 37);
4869       END IF;
4870 
4871       IF (g_params.p_rerun_flag = 'Y')
4872       THEN
4873          DBMS_SQL.bind_variable (l_csr,
4874                                  ':p_transaction_code',
4875                                  g_params.p_transaction_code
4876                                 );
4877       END IF;
4878 
4879 -- define arrays for each item in the select list
4880       IF g_debug
4881       THEN
4882          hr_utility.set_location ('Processing ' || l_proc, 40);
4883       END IF;
4884 
4885       DBMS_SQL.define_array (c                => l_csr,
4886                              POSITION         => 1,
4887                              n_tab            => t_timecard_bb_id,
4888                              cnt              => l_max_array_size,
4889                              lower_bound      => 1
4890                             );
4891       DBMS_SQL.define_array (c                => l_csr,
4892                              POSITION         => 2,
4893                              n_tab            => t_timecard_ovn,
4894                              cnt              => l_max_array_size,
4895                              lower_bound      => 1
4896                             );
4897       DBMS_SQL.define_array (c                => l_csr,
4898                              POSITION         => 3,
4899                              n_tab            => t_day_bb_id,
4900                              cnt              => l_max_array_size,
4901                              lower_bound      => 1
4902                             );
4903       DBMS_SQL.define_array (c                => l_csr,
4904                              POSITION         => 4,
4905                              n_tab            => t_day_ovn,
4906                              cnt              => l_max_array_size,
4907                              lower_bound      => 1
4908                             );
4909       DBMS_SQL.define_array (c                => l_csr,
4910                              POSITION         => 5,
4911                              d_tab            => t_day_start_time,
4912                              cnt              => l_max_array_size,
4913                              lower_bound      => 1
4914                             );
4915       DBMS_SQL.define_array (c                => l_csr,
4916                              POSITION         => 6,
4917                              d_tab            => t_day_stop_time,
4918                              cnt              => l_max_array_size,
4919                              lower_bound      => 1
4920                             );
4921       DBMS_SQL.define_array (c                => l_csr,
4922                              POSITION         => 7,
4923                              n_tab            => t_detail_bb_id,
4924                              cnt              => l_max_array_size,
4925                              lower_bound      => 1
4926                             );
4927       DBMS_SQL.define_array (c                => l_csr,
4928                              POSITION         => 8,
4929                              n_tab            => t_detail_ovn,
4930                              cnt              => l_max_array_size,
4931                              lower_bound      => 1
4932                             );
4933       DBMS_SQL.define_array (c                => l_csr,
4934                              POSITION         => 9,
4935                              n_tab            => t_detail_parent_id,
4936                              cnt              => l_max_array_size,
4937                              lower_bound      => 1
4938                             );
4939       DBMS_SQL.define_array (c                => l_csr,
4940                              POSITION         => 10,
4941                              c_tab            => t_detail_resource_type,
4942                              cnt              => l_max_array_size,
4943                              lower_bound      => 1
4944                             );
4945       DBMS_SQL.define_array (c                => l_csr,
4946                              POSITION         => 11,
4947                              n_tab            => t_detail_resource_id,
4948                              cnt              => l_max_array_size,
4949                              lower_bound      => 1
4950                             );
4951       DBMS_SQL.define_array (c                => l_csr,
4952                              POSITION         => 12,
4953                              c_tab            => t_detail_comment_text,
4954                              cnt              => l_max_array_size,
4955                              lower_bound      => 1
4956                             );
4957       DBMS_SQL.define_array (c                => l_csr,
4958                              POSITION         => 13,
4959                              d_tab            => t_detail_start_time,
4960                              cnt              => l_max_array_size,
4961                              lower_bound      => 1
4962                             );
4963       DBMS_SQL.define_array (c                => l_csr,
4964                              POSITION         => 14,
4965                              d_tab            => t_detail_stop_time,
4966                              cnt              => l_max_array_size,
4967                              lower_bound      => 1
4968                             );
4969       DBMS_SQL.define_array (c                => l_csr,
4970                              POSITION         => 15,
4971                              n_tab            => t_detail_measure,
4972                              cnt              => l_max_array_size,
4973                              lower_bound      => 1
4974                             );
4975       DBMS_SQL.define_array (c                => l_csr,
4976                              POSITION         => 16,
4977                              c_tab            => t_detail_scope,
4978                              cnt              => l_max_array_size,
4979                              lower_bound      => 1
4980                             );
4981       DBMS_SQL.define_array (c                => l_csr,
4982                              POSITION         => 17,
4983                              c_tab            => t_detail_type,
4984                              cnt              => l_max_array_size,
4985                              lower_bound      => 1
4986                             );
4987       DBMS_SQL.define_array (c                => l_csr,
4988                              POSITION         => 18,
4989                              n_tab            => t_detail_ta_id,
4990                              cnt              => l_max_array_size,
4991                              lower_bound      => 1
4992                             );
4993       DBMS_SQL.define_array (c                => l_csr,
4994                              POSITION         => 19,
4995                              n_tab            => t_detail_bld_blk_info_type_id,
4996                              cnt              => l_max_array_size,
4997                              lower_bound      => 1
4998                             );
4999       DBMS_SQL.define_array (c                => l_csr,
5000                              POSITION         => 20,
5001                              c_tab            => t_detail_attribute1,
5002                              cnt              => l_max_array_size,
5003                              lower_bound      => 1
5004                             );
5005       DBMS_SQL.define_array (c                => l_csr,
5006                              POSITION         => 21,
5007                              c_tab            => t_detail_attribute2,
5008                              cnt              => l_max_array_size,
5009                              lower_bound      => 1
5010                             );
5011       DBMS_SQL.define_array (c                => l_csr,
5012                              POSITION         => 22,
5013                              c_tab            => t_detail_attribute3,
5014                              cnt              => l_max_array_size,
5015                              lower_bound      => 1
5016                             );
5017       DBMS_SQL.define_array (c                => l_csr,
5018                              POSITION         => 23,
5019                              c_tab            => t_detail_attribute4,
5020                              cnt              => l_max_array_size,
5021                              lower_bound      => 1
5022                             );
5023       DBMS_SQL.define_array (c                => l_csr,
5024                              POSITION         => 24,
5025                              c_tab            => t_detail_attribute5,
5026                              cnt              => l_max_array_size,
5027                              lower_bound      => 1
5028                             );
5029       DBMS_SQL.define_array (c                => l_csr,
5030                              POSITION         => 25,
5031                              c_tab            => t_detail_attribute6,
5032                              cnt              => l_max_array_size,
5033                              lower_bound      => 1
5034                             );
5035       DBMS_SQL.define_array (c                => l_csr,
5036                              POSITION         => 26,
5037                              c_tab            => t_detail_attribute7,
5038                              cnt              => l_max_array_size,
5039                              lower_bound      => 1
5040                             );
5041       DBMS_SQL.define_array (c                => l_csr,
5042                              POSITION         => 27,
5043                              c_tab            => t_detail_attribute8,
5044                              cnt              => l_max_array_size,
5045                              lower_bound      => 1
5046                             );
5047       DBMS_SQL.define_array (c                => l_csr,
5048                              POSITION         => 28,
5049                              c_tab            => t_detail_attribute9,
5050                              cnt              => l_max_array_size,
5051                              lower_bound      => 1
5052                             );
5053       DBMS_SQL.define_array (c                => l_csr,
5054                              POSITION         => 29,
5055                              c_tab            => t_detail_attribute10,
5056                              cnt              => l_max_array_size,
5057                              lower_bound      => 1
5058                             );
5059       DBMS_SQL.define_array (c                => l_csr,
5060                              POSITION         => 30,
5061                              c_tab            => t_detail_attribute11,
5062                              cnt              => l_max_array_size,
5063                              lower_bound      => 1
5064                             );
5065       DBMS_SQL.define_array (c                => l_csr,
5066                              POSITION         => 31,
5067                              c_tab            => t_detail_attribute12,
5068                              cnt              => l_max_array_size,
5069                              lower_bound      => 1
5070                             );
5071       DBMS_SQL.define_array (c                => l_csr,
5072                              POSITION         => 32,
5073                              c_tab            => t_detail_attribute13,
5074                              cnt              => l_max_array_size,
5075                              lower_bound      => 1
5076                             );
5077       DBMS_SQL.define_array (c                => l_csr,
5078                              POSITION         => 33,
5079                              c_tab            => t_detail_attribute14,
5080                              cnt              => l_max_array_size,
5081                              lower_bound      => 1
5082                             );
5083       DBMS_SQL.define_array (c                => l_csr,
5084                              POSITION         => 34,
5085                              c_tab            => t_detail_attribute15,
5086                              cnt              => l_max_array_size,
5087                              lower_bound      => 1
5088                             );
5089       DBMS_SQL.define_array (c                => l_csr,
5090                              POSITION         => 35,
5091                              c_tab            => t_detail_attribute16,
5092                              cnt              => l_max_array_size,
5093                              lower_bound      => 1
5094                             );
5095       DBMS_SQL.define_array (c                => l_csr,
5096                              POSITION         => 36,
5097                              c_tab            => t_detail_attribute17,
5098                              cnt              => l_max_array_size,
5099                              lower_bound      => 1
5100                             );
5101       DBMS_SQL.define_array (c                => l_csr,
5102                              POSITION         => 37,
5103                              c_tab            => t_detail_attribute18,
5104                              cnt              => l_max_array_size,
5105                              lower_bound      => 1
5106                             );
5107       DBMS_SQL.define_array (c                => l_csr,
5108                              POSITION         => 38,
5109                              c_tab            => t_detail_attribute19,
5110                              cnt              => l_max_array_size,
5111                              lower_bound      => 1
5112                             );
5113       DBMS_SQL.define_array (c                => l_csr,
5114                              POSITION         => 39,
5115                              c_tab            => t_detail_attribute20,
5116                              cnt              => l_max_array_size,
5117                              lower_bound      => 1
5118                             );
5119       DBMS_SQL.define_array (c                => l_csr,
5120                              POSITION         => 40,
5121                              c_tab            => t_detail_attribute21,
5122                              cnt              => l_max_array_size,
5123                              lower_bound      => 1
5124                             );
5125       DBMS_SQL.define_array (c                => l_csr,
5126                              POSITION         => 41,
5127                              c_tab            => t_detail_attribute22,
5128                              cnt              => l_max_array_size,
5129                              lower_bound      => 1
5130                             );
5131       DBMS_SQL.define_array (c                => l_csr,
5132                              POSITION         => 42,
5133                              c_tab            => t_detail_attribute23,
5134                              cnt              => l_max_array_size,
5135                              lower_bound      => 1
5136                             );
5137       DBMS_SQL.define_array (c                => l_csr,
5138                              POSITION         => 43,
5139                              c_tab            => t_detail_attribute24,
5140                              cnt              => l_max_array_size,
5141                              lower_bound      => 1
5142                             );
5143       DBMS_SQL.define_array (c                => l_csr,
5144                              POSITION         => 44,
5145                              c_tab            => t_detail_attribute25,
5146                              cnt              => l_max_array_size,
5147                              lower_bound      => 1
5148                             );
5149       DBMS_SQL.define_array (c                => l_csr,
5150                              POSITION         => 45,
5151                              c_tab            => t_detail_attribute26,
5152                              cnt              => l_max_array_size,
5153                              lower_bound      => 1
5154                             );
5155       DBMS_SQL.define_array (c                => l_csr,
5156                              POSITION         => 46,
5157                              c_tab            => t_detail_attribute27,
5158                              cnt              => l_max_array_size,
5159                              lower_bound      => 1
5160                             );
5161       DBMS_SQL.define_array (c                => l_csr,
5162                              POSITION         => 47,
5163                              c_tab            => t_detail_attribute28,
5164                              cnt              => l_max_array_size,
5165                              lower_bound      => 1
5166                             );
5167       DBMS_SQL.define_array (c                => l_csr,
5168                              POSITION         => 48,
5169                              c_tab            => t_detail_attribute29,
5170                              cnt              => l_max_array_size,
5171                              lower_bound      => 1
5172                             );
5173       DBMS_SQL.define_array (c                => l_csr,
5174                              POSITION         => 49,
5175                              c_tab            => t_detail_attribute30,
5176                              cnt              => l_max_array_size,
5177                              lower_bound      => 1
5178                             );
5179       DBMS_SQL.define_array (c                => l_csr,
5180                              POSITION         => 50,
5181                              d_tab            => t_detail_date_from,
5182                              cnt              => l_max_array_size,
5183                              lower_bound      => 1
5184                             );
5185       DBMS_SQL.define_array (c                => l_csr,
5186                              POSITION         => 51,
5187                              d_tab            => t_detail_date_to,
5188                              cnt              => l_max_array_size,
5189                              lower_bound      => 1
5190                             );
5191       DBMS_SQL.define_array (c                => l_csr,
5192                              POSITION         => 52,
5193                              c_tab            => t_detail_approval_status,
5194                              cnt              => l_max_array_size,
5195                              lower_bound      => 1
5196                             );
5197       DBMS_SQL.define_array (c                => l_csr,
5198                              POSITION         => 53,
5199                              n_tab            => t_detail_approval_style_id,
5200                              cnt              => l_max_array_size,
5201                              lower_bound      => 1
5202                             );
5203       DBMS_SQL.define_array (c                => l_csr,
5204                              POSITION         => 54,
5205                              c_tab            => t_detail_deleted,
5206                              cnt              => l_max_array_size,
5207                              lower_bound      => 1
5208                             );
5209       DBMS_SQL.define_array (c                => l_csr,
5210                              POSITION         => 55,
5211                              c_tab            => t_detail_attribute_category,
5212                              cnt              => l_max_array_size,
5213                              lower_bound      => 1
5214                             );
5215       DBMS_SQL.define_array (c                => l_csr,
5216                              POSITION         => 56,
5217                              n_tab            => t_timecard_max_ovn,
5218                              cnt              => l_max_array_size,
5219                              lower_bound      => 1
5220                             );
5221       DBMS_SQL.define_array (c                => l_csr,
5222                              POSITION         => 57,
5223                              n_tab            => t_day_max_ovn,
5224                              cnt              => l_max_array_size,
5225                              lower_bound      => 1
5226                             );
5227       DBMS_SQL.define_array (c                => l_csr,
5228                              POSITION         => 58,
5229                              n_tab            => t_detail_max_ovn,
5230                              cnt              => l_max_array_size,
5231                              lower_bound      => 1
5232                             );
5233       DBMS_SQL.define_array (c                => l_csr,
5234                              POSITION         => 59,
5235                              c_tab            => t_detail_uom,
5236                              cnt              => l_max_array_size,
5237                              lower_bound      => 1
5238                             );
5239       DBMS_SQL.define_array (c                => l_csr,
5240                              POSITION         => 60,
5241                              d_tab            => t_timecard_start_time,
5242                              cnt              => l_max_array_size,
5243                              lower_bound      => 1
5244                             );
5245       DBMS_SQL.define_array (c                => l_csr,
5246                              POSITION         => 61,
5247                              d_tab            => t_timecard_stop_time,
5248                              cnt              => l_max_array_size,
5249                              lower_bound      => 1
5250                             );
5251       DBMS_SQL.define_array (c                => l_csr,
5252                              POSITION         => 62,
5253                              c_tab            => t_timecard_comment_text,
5254                              cnt              => l_max_array_size,
5255                              lower_bound      => 1
5256                             );
5257       DBMS_SQL.define_array (c                => l_csr,
5258                              POSITION         => 63,
5259                              c_tab            => t_timecard_deleted,
5260                              cnt              => l_max_array_size,
5261                              lower_bound      => 1
5262                             );
5263 
5264       IF g_debug
5265       THEN
5266          hr_utility.set_location ('Processing ' || l_proc, 50);
5267       END IF;
5268 
5269       l_dummy := DBMS_SQL.EXECUTE (l_csr);
5270 
5271       IF g_debug
5272       THEN
5273          hr_utility.set_location ('Processing ' || l_proc, 60);
5274       END IF;
5275 
5276 -- loop to ensure we fetch all the rows
5277       WHILE (l_rows_fetched = l_max_array_size)
5278       LOOP
5279          l_rows_fetched := DBMS_SQL.fetch_rows (l_csr);
5280 
5281          IF (l_rows_fetched = 0 AND t_bb.COUNT = 0)
5282          THEN
5283             DBMS_SQL.close_cursor (l_csr);
5284             -- Bug 8888911
5285             -- Marking that this is an empty chunk.
5286             put_log('  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
5287             put_log('   This is an empty chunk : No records relevant for these resources ');
5288             put_log('  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
5289             IF g_debug
5290             THEN
5291                hr_utility.trace('This is an empty chunk ');
5292             END IF;
5293             RAISE e_no_timecards;
5294          END IF;
5295 
5296          DBMS_SQL.column_value (c             => l_csr,
5297                                 POSITION      => 1,
5298                                 n_tab         => t_timecard_bb_id
5299                                );
5300          DBMS_SQL.column_value (c             => l_csr,
5301                                 POSITION      => 2,
5302                                 n_tab         => t_timecard_ovn
5303                                );
5304          DBMS_SQL.column_value (c             => l_csr,
5305                                 POSITION      => 3,
5306                                 n_tab         => t_day_bb_id
5307                                );
5308          DBMS_SQL.column_value (c             => l_csr, POSITION => 4,
5309                                 n_tab         => t_day_ovn);
5310          DBMS_SQL.column_value (c             => l_csr,
5311                                 POSITION      => 5,
5312                                 d_tab         => t_day_start_time
5313                                );
5314          DBMS_SQL.column_value (c             => l_csr,
5315                                 POSITION      => 6,
5316                                 d_tab         => t_day_stop_time
5317                                );
5318          DBMS_SQL.column_value (c             => l_csr,
5319                                 POSITION      => 7,
5320                                 n_tab         => t_detail_bb_id
5321                                );
5322          DBMS_SQL.column_value (c             => l_csr,
5323                                 POSITION      => 8,
5324                                 n_tab         => t_detail_ovn
5325                                );
5326          DBMS_SQL.column_value (c             => l_csr,
5327                                 POSITION      => 9,
5328                                 n_tab         => t_detail_parent_id
5329                                );
5330          DBMS_SQL.column_value (c             => l_csr,
5331                                 POSITION      => 10,
5332                                 c_tab         => t_detail_resource_type
5333                                );
5334          DBMS_SQL.column_value (c             => l_csr,
5335                                 POSITION      => 11,
5336                                 n_tab         => t_detail_resource_id
5337                                );
5338          DBMS_SQL.column_value (c             => l_csr,
5339                                 POSITION      => 12,
5340                                 c_tab         => t_detail_comment_text
5341                                );
5342          DBMS_SQL.column_value (c             => l_csr,
5343                                 POSITION      => 13,
5344                                 d_tab         => t_detail_start_time
5345                                );
5346          DBMS_SQL.column_value (c             => l_csr,
5347                                 POSITION      => 14,
5348                                 d_tab         => t_detail_stop_time
5349                                );
5350          DBMS_SQL.column_value (c             => l_csr,
5351                                 POSITION      => 15,
5352                                 n_tab         => t_detail_measure
5353                                );
5354          DBMS_SQL.column_value (c             => l_csr,
5355                                 POSITION      => 16,
5356                                 c_tab         => t_detail_scope
5357                                );
5358          DBMS_SQL.column_value (c             => l_csr,
5359                                 POSITION      => 17,
5360                                 c_tab         => t_detail_type
5361                                );
5362          DBMS_SQL.column_value (c             => l_csr,
5363                                 POSITION      => 18,
5364                                 n_tab         => t_detail_ta_id
5365                                );
5366          DBMS_SQL.column_value (c             => l_csr,
5367                                 POSITION      => 19,
5368                                 n_tab         => t_detail_bld_blk_info_type_id
5369                                );
5370          DBMS_SQL.column_value (c             => l_csr,
5371                                 POSITION      => 20,
5372                                 c_tab         => t_detail_attribute1
5373                                );
5374          DBMS_SQL.column_value (c             => l_csr,
5375                                 POSITION      => 21,
5376                                 c_tab         => t_detail_attribute2
5377                                );
5378          DBMS_SQL.column_value (c             => l_csr,
5379                                 POSITION      => 22,
5380                                 c_tab         => t_detail_attribute3
5381                                );
5382          DBMS_SQL.column_value (c             => l_csr,
5383                                 POSITION      => 23,
5384                                 c_tab         => t_detail_attribute4
5385                                );
5386          DBMS_SQL.column_value (c             => l_csr,
5387                                 POSITION      => 24,
5388                                 c_tab         => t_detail_attribute5
5389                                );
5390          DBMS_SQL.column_value (c             => l_csr,
5391                                 POSITION      => 25,
5392                                 c_tab         => t_detail_attribute6
5393                                );
5394          DBMS_SQL.column_value (c             => l_csr,
5395                                 POSITION      => 26,
5396                                 c_tab         => t_detail_attribute7
5397                                );
5398          DBMS_SQL.column_value (c             => l_csr,
5399                                 POSITION      => 27,
5400                                 c_tab         => t_detail_attribute8
5401                                );
5402          DBMS_SQL.column_value (c             => l_csr,
5403                                 POSITION      => 28,
5404                                 c_tab         => t_detail_attribute9
5405                                );
5406          DBMS_SQL.column_value (c             => l_csr,
5407                                 POSITION      => 29,
5408                                 c_tab         => t_detail_attribute10
5409                                );
5410          DBMS_SQL.column_value (c             => l_csr,
5411                                 POSITION      => 30,
5412                                 c_tab         => t_detail_attribute11
5413                                );
5414          DBMS_SQL.column_value (c             => l_csr,
5415                                 POSITION      => 31,
5416                                 c_tab         => t_detail_attribute12
5417                                );
5418          DBMS_SQL.column_value (c             => l_csr,
5419                                 POSITION      => 32,
5420                                 c_tab         => t_detail_attribute13
5421                                );
5422          DBMS_SQL.column_value (c             => l_csr,
5423                                 POSITION      => 33,
5424                                 c_tab         => t_detail_attribute14
5425                                );
5426          DBMS_SQL.column_value (c             => l_csr,
5427                                 POSITION      => 34,
5428                                 c_tab         => t_detail_attribute15
5429                                );
5430          DBMS_SQL.column_value (c             => l_csr,
5431                                 POSITION      => 35,
5432                                 c_tab         => t_detail_attribute16
5433                                );
5434          DBMS_SQL.column_value (c             => l_csr,
5435                                 POSITION      => 36,
5436                                 c_tab         => t_detail_attribute17
5437                                );
5438          DBMS_SQL.column_value (c             => l_csr,
5439                                 POSITION      => 37,
5440                                 c_tab         => t_detail_attribute18
5441                                );
5442          DBMS_SQL.column_value (c             => l_csr,
5443                                 POSITION      => 38,
5444                                 c_tab         => t_detail_attribute19
5445                                );
5446          DBMS_SQL.column_value (c             => l_csr,
5447                                 POSITION      => 39,
5448                                 c_tab         => t_detail_attribute20
5449                                );
5450          DBMS_SQL.column_value (c             => l_csr,
5451                                 POSITION      => 40,
5452                                 c_tab         => t_detail_attribute21
5453                                );
5454          DBMS_SQL.column_value (c             => l_csr,
5455                                 POSITION      => 41,
5456                                 c_tab         => t_detail_attribute22
5457                                );
5458          DBMS_SQL.column_value (c             => l_csr,
5459                                 POSITION      => 42,
5460                                 c_tab         => t_detail_attribute23
5461                                );
5462          DBMS_SQL.column_value (c             => l_csr,
5463                                 POSITION      => 43,
5464                                 c_tab         => t_detail_attribute24
5465                                );
5466          DBMS_SQL.column_value (c             => l_csr,
5467                                 POSITION      => 44,
5468                                 c_tab         => t_detail_attribute25
5469                                );
5470          DBMS_SQL.column_value (c             => l_csr,
5471                                 POSITION      => 45,
5472                                 c_tab         => t_detail_attribute26
5473                                );
5474          DBMS_SQL.column_value (c             => l_csr,
5475                                 POSITION      => 46,
5476                                 c_tab         => t_detail_attribute27
5477                                );
5478          DBMS_SQL.column_value (c             => l_csr,
5479                                 POSITION      => 47,
5480                                 c_tab         => t_detail_attribute28
5481                                );
5482          DBMS_SQL.column_value (c             => l_csr,
5483                                 POSITION      => 48,
5484                                 c_tab         => t_detail_attribute29
5485                                );
5486          DBMS_SQL.column_value (c             => l_csr,
5487                                 POSITION      => 49,
5488                                 c_tab         => t_detail_attribute30
5489                                );
5490          DBMS_SQL.column_value (c             => l_csr,
5491                                 POSITION      => 50,
5492                                 d_tab         => t_detail_date_from
5493                                );
5494          DBMS_SQL.column_value (c             => l_csr,
5495                                 POSITION      => 51,
5496                                 d_tab         => t_detail_date_to
5497                                );
5498          DBMS_SQL.column_value (c             => l_csr,
5499                                 POSITION      => 52,
5500                                 c_tab         => t_detail_approval_status
5501                                );
5502          DBMS_SQL.column_value (c             => l_csr,
5503                                 POSITION      => 53,
5504                                 n_tab         => t_detail_approval_style_id
5505                                );
5506          DBMS_SQL.column_value (c             => l_csr,
5507                                 POSITION      => 54,
5508                                 c_tab         => t_detail_deleted
5509                                );
5510          DBMS_SQL.column_value (c             => l_csr,
5511                                 POSITION      => 55,
5512                                 c_tab         => t_detail_attribute_category
5513                                );
5514          DBMS_SQL.column_value (c             => l_csr,
5515                                 POSITION      => 56,
5516                                 n_tab         => t_timecard_max_ovn
5517                                );
5518          DBMS_SQL.column_value (c             => l_csr,
5519                                 POSITION      => 57,
5520                                 n_tab         => t_day_max_ovn
5521                                );
5522          DBMS_SQL.column_value (c             => l_csr,
5523                                 POSITION      => 58,
5524                                 n_tab         => t_detail_max_ovn
5525                                );
5526          DBMS_SQL.column_value (c             => l_csr,
5527                                 POSITION      => 59,
5528                                 c_tab         => t_detail_uom
5529                                );
5530          DBMS_SQL.column_value (c             => l_csr,
5531                                 POSITION      => 60,
5532                                 d_tab         => t_timecard_start_time
5533                                );
5534          DBMS_SQL.column_value (c             => l_csr,
5535                                 POSITION      => 61,
5536                                 d_tab         => t_timecard_stop_time
5537                                );
5538          DBMS_SQL.column_value (c             => l_csr,
5539                                 POSITION      => 62,
5540                                 c_tab         => t_timecard_comment_text
5541                                );
5542          DBMS_SQL.column_value (c             => l_csr,
5543                                 POSITION      => 63,
5544                                 c_tab         => t_timecard_deleted
5545                                );
5546 -- to make the data more manageable copy the arrays into PL/SQL tables
5547 -- and save space
5548          populate_query_table;
5549       END LOOP;
5550 
5551       DBMS_SQL.close_cursor (l_csr);
5552 
5553       IF g_debug
5554       THEN
5555          hr_utility.set_location ('Processing ' || l_proc, 110);
5556       END IF;
5557 
5558       IF (g_params.p_incremental = 'N')
5559       THEN
5560          -- need to populate resources table since max_ovn was not called
5561          FOR x IN t_bb.FIRST .. t_bb.LAST
5562          LOOP
5563             IF NOT (hxc_generic_retrieval_utils.g_resources.EXISTS
5564                                                    (t_bb (x).detail_resource_id
5565                                                    )
5566                    )
5567             THEN
5568                hxc_generic_retrieval_utils.g_resources
5569                                                   (t_bb (x).detail_resource_id
5570                                                   ).resource_id :=
5571                                                    t_bb (x).detail_resource_id;
5572                hxc_generic_retrieval_utils.g_resources
5573                                                    (t_bb (x).detail_resource_id
5574                                                    ).start_time :=
5575                                                         hr_general.end_of_time;
5576                hxc_generic_retrieval_utils.g_resources
5577                                                    (t_bb (x).detail_resource_id
5578                                                    ).stop_time :=
5579                                                       hr_general.start_of_time;
5580             END IF;
5581          END LOOP;
5582       END IF;
5583 
5584 -- initialise tables
5585       IF g_debug
5586       THEN
5587          hr_utility.TRACE ('Params to parse_resources......');
5588          hr_utility.TRACE ('Process id is '
5589                            || TO_CHAR (g_retrieval_process_id)
5590                           );
5591          hr_utility.TRACE (   'Time Recipient id is '
5592                            || TO_CHAR (g_retrieval_tr_id)
5593                           );
5594       END IF;
5595 
5596       l_prefs.DELETE;
5597       l_ret_rules.DELETE;
5598       l_rtr_outcomes.DELETE;
5599       hxc_generic_retrieval_utils.parse_resources
5600                                       (p_process_id        => g_retrieval_process_id,
5601                                        p_ret_tr_id         => g_retrieval_tr_id,
5602                                        p_prefs             => l_prefs,
5603                                        p_ret_rules         => l_ret_rules,
5604                                        p_rtr_outcomes      => l_rtr_outcomes,
5605                                        p_errors            => l_errors
5606                                       );
5607 
5608       IF g_debug
5609       THEN
5610          hr_utility.TRACE (' *********** - GLOBAL TABLE INFO ************ ');
5611       END IF;
5612 
5613       l_count := hxc_generic_retrieval_utils.g_resources.COUNT;
5614 
5615       IF g_debug
5616       THEN
5617          hr_utility.TRACE ('Resources         : ' || TO_CHAR (l_count));
5618       END IF;
5619 
5620       l_count := t_bb.COUNT;
5621 
5622       IF g_debug
5623       THEN
5624          hr_utility.TRACE ('master bld blks   : ' || TO_CHAR (l_count));
5625       END IF;
5626 
5627       l_count := l_prefs.COUNT;
5628 
5629       IF g_debug
5630       THEN
5631          hr_utility.TRACE ('Prefs             : ' || TO_CHAR (l_count));
5632       END IF;
5633 
5634       l_count := l_ret_rules.COUNT;
5635 
5636       IF g_debug
5637       THEN
5638          hr_utility.TRACE ('Retrieval Rules   : ' || TO_CHAR (l_count));
5639       END IF;
5640 
5641       l_count := l_rtr_outcomes.COUNT;
5642 
5643       IF g_debug
5644       THEN
5645          hr_utility.TRACE ('Ret Rule Outcomes : ' || TO_CHAR (l_count));
5646       END IF;
5647 
5648       l_count := l_errors.COUNT;
5649 
5650       IF g_debug
5651       THEN
5652          hr_utility.TRACE ('Errors : ' || TO_CHAR (l_count));
5653       END IF;
5654 
5655 -- now loop through the table and populate the building block table for those bld blks which have
5656 -- changed
5657       IF g_debug
5658       THEN
5659          hr_utility.TRACE ('');
5660          hr_utility.TRACE ('****** Populating Global PL/SQL tables *******');
5661          hr_utility.TRACE ('');
5662       END IF;
5663 
5664       FOR cnt IN t_bb.FIRST .. t_bb.LAST
5665       LOOP
5666 --if g_debug then
5667    -- hr_utility.set_location('Processing '||l_proc, 130);
5668 --end if;
5669 
5670          -- Intitialise timecard scope variables
5671          IF (t_bb (cnt).time_bb_id <> l_old_timecard_bb_id)
5672          THEN
5673             -- set old time card id and reset copied flag
5674 
5675             --if g_debug then
5676    -- hr_utility.trace('GAZ t bb is '||to_char(t_bb(cnt).time_bb_id));
5677 --end if;
5678             l_timecard_retrieve := TRUE;
5679             l_day_retrieve := TRUE;
5680             l_old_timecard_bb_id := t_bb (cnt).time_bb_id;
5681             l_timecard_copied := 'N';
5682             l_tc_locked := FALSE;
5683             l_tc_first_lock := TRUE;
5684 
5685             IF (l_errors.EXISTS (t_bb (cnt).detail_resource_id))
5686             THEN
5687                l_error_flag := TRUE;
5688             ELSE
5689                l_error_flag := FALSE;
5690             END IF;
5691 
5692             -- clear out table of copied bld blk info types for this bb_id
5693             t_time_bld_blk_info.DELETE;
5694          END IF;                                  -- timecard id changed check
5695 
5696 -- if g_debug then
5697    --hr_utility.set_location('Processing '||l_proc, 140);
5698 --end if;
5699 
5700          -- Initialise and maintain DAY scope variables
5701          IF (t_bb (cnt).day_bb_id <> l_old_day_bb_id)
5702          THEN
5703             -- set count and old bld blk id
5704             l_old_day_bb_id := t_bb (cnt).day_bb_id;
5705             l_day_copied := 'N';
5706             -- clear out table of copied bld blk info types for this bb_id
5707             t_day_bld_blk_info.DELETE;
5708          END IF;
5709 
5710 -- if g_debug then
5711    --hr_utility.set_location('Processing '||l_proc, 160);
5712 --end if;
5713 
5714          -- Maintain Detail building blocks
5715          IF (t_bb (cnt).detail_bb_id <> l_old_detail_bb_id)
5716          THEN
5717             -- set count and old time card id
5718 
5719             -- if g_debug then
5720    --hr_utility.trace('GAZ tbb DETAIL is '||to_char(t_bb(cnt).detail_bb_id));
5721 --end if;
5722             l_old_detail_bb_id := t_bb (cnt).detail_bb_id;
5723             l_detail_copied := 'N';
5724              l_already_multiplied := 'N'; --DAYS Vs HOURS
5725             -- clear out table of copied bld blk info types for this bb_id
5726             t_detail_bld_blk_info.DELETE;
5727             l_day_retrieve := TRUE;
5728 
5729             -- Do not transfer if deleted and never transferred prior
5730             -- ( WWB 3503607 GPM v115.102 )
5731 
5732             -- Bug 7595581
5733             -- Retrieval Log
5734 
5735             l_bb_skipped_reason := null;
5736             IF (    t_bb (cnt).detail_deleted = 'Y'
5737                 AND t_bb (cnt).detail_max_ovn = 0
5738                )
5739             THEN
5740                l_day_retrieve := FALSE;
5741 
5742                -- Not transferring the deleted entries, but then they might need an adj
5743                -- ustment if the processes are BEE retrieval and Apply Schedules and the
5744                -- preference for Rule evaluation is changed after it its transferred.
5745                -- Checking that up here.
5746                -- Bug 8366309
5747                -- Check preferences before adjusting the deleted entries.
5748 
5749                IF    ( g_params.p_process IN ('BEE Retrieval Process',
5750                                               'Apply Schedule Rules') )
5751                  AND (hxc_generic_retrieval_utils.chk_otm_pref( t_bb(cnt).detail_resource_id,
5752                                                                 t_bb(cnt).day_start_time,
5753                                                                 g_retrieval_process_id))
5754                  AND (hxc_generic_retrieval_utils.chk_need_adj( t_bb (cnt).time_bb_id,
5755                                                                 t_bb (cnt).time_ovn,
5756                                                                 t_bb (cnt).detail_resource_id,
5757                                                                 t_bb (cnt).day_start_time,
5758                                                                 t_bb (cnt).detail_bb_id,
5759                                                                 t_bb (cnt).detail_ovn, -- Bug 8366309
5760                                                                 'Y',                   -- Bug 8366309;  Deleted = 'Y'
5761                                                                 g_retrieval_process_id ) )
5762                THEN
5763                   IF g_debug
5764                   THEN
5765                      hr_utility.trace('Resource '||t_bb (cnt).detail_resource_id||
5766                     'had  a different rules evaluation pref and needs adj this time');
5767                   END IF;
5768                END IF;
5769 
5770             ELSE
5771 
5772                -- Absences starts
5773                -- OTL-Absences Integration (Bug 8779478)
5774 
5775                l_detail_attribute_category := null;
5776 
5777                abs_cnt := cnt;
5778 
5779                LOOP
5780                EXIT WHEN (t_bb (abs_cnt).detail_bb_id <> t_bb (cnt).detail_bb_id);
5781 
5782                     IF (t_bb (abs_cnt).detail_attribute_category like 'ELEMENT%') THEN
5783 			l_detail_attribute_category := t_bb (abs_cnt).detail_attribute_category   ;
5784 			EXIT;
5785                     ELSE
5786                         abs_cnt := abs_cnt + 1;
5787                         -- Bug 8892988
5788                         -- Added the below exit condition to get rid of
5789                         -- 1403 errors
5790                         IF NOT t_bb.EXISTS(abs_cnt)
5791                         THEN
5792                            EXIT;
5793                         END IF;
5794                     END IF;
5795 
5796                END LOOP;
5797 
5798                -- Absences ends
5799 
5800 
5801                hr_utility.TRACE ('about to call chk retrieve');
5802                hxc_generic_retrieval_utils.chk_retrieve
5803                             (p_resource_id            => t_bb (cnt).detail_resource_id,
5804                              p_bb_status              => t_bb (cnt).detail_approval_status,
5805                              p_bb_deleted             => t_bb (cnt).time_deleted,
5806                              p_bb_start_time          => t_bb (cnt).day_start_time,
5807                              p_bb_stop_time           => t_bb (cnt).day_stop_time,
5808                              p_bb_id                  => t_bb (cnt).detail_bb_id,
5809                              p_bb_ovn                 => t_bb (cnt).detail_ovn,
5810                              p_attribute_category     => l_detail_attribute_category,   -- Bug 8779478
5811                              p_process                => g_params.p_process,
5812                              p_prefs                  => l_prefs,
5813                              p_ret_rules              => l_ret_rules,
5814                              p_rtr_outcomes           => l_rtr_outcomes,
5815                              p_tc_bb_id               => t_bb (cnt).time_bb_id,
5816                              p_tc_bb_ovn              => t_bb (cnt).time_ovn,
5817                              p_timecard_retrieve      => l_timecard_retrieve,
5818                              p_day_retrieve           => l_day_retrieve,
5819                              p_tc_locked              => l_tc_locked,
5820                              p_tc_first_lock          => l_tc_first_lock,
5821                              p_bb_skipped_reason      => l_bb_skipped_reason   -- Bug 7595581
5822                             );
5823                hr_utility.TRACE ('after to call chk retrieve');
5824             END IF;                         -- chk deleted and not transferred
5825 
5826             -- if this detail block has not already been copied and the object version numbers
5827             -- are different then we need this building block and the day and time bld blks
5828 
5829             -- Bug 7595581
5830             -- Retrieval Log
5831 
5832             IF(l_bb_skipped_reason IS NULL)
5833             THEN
5834                         -- Bug 9657355
5835 	    		l_bb_skipped_reason := 'Block is deleted and was not transferred earlier';
5836 	    END IF;
5837 
5838 
5839             IF (   (    (l_detail_copied = 'N')
5840                     AND (t_bb (cnt).detail_ovn > t_bb (cnt).detail_max_ovn)
5841                     AND (l_day_retrieve)
5842                    )
5843                 OR (l_error_flag)
5844                )
5845             THEN
5846                -- maintain time bld blk table
5847 
5848 		-- Bug 7595581
5849                 -- Retrieval Log
5850 		g_rtr_detail_blks(t_bb(cnt).detail_bb_id).dummy := 'Y';
5851 
5852             /* -- only populate old DETAIL
5853 
5854                      IF ( t_bb(cnt).time_max_ovn <> 0 )
5855                      THEN
5856                         l_copy_old  := 'Y';
5857                      ELSE
5858                         l_copy_old  := 'N';
5859                      END IF;
5860                */
5861                copy_bld_blks (p_bld_blks_table      => t_bb,
5862                               p_scope               => 'TIME',
5863                               p_copied              => l_timecard_copied,
5864                               p_cnt                 => cnt,
5865                               p_copy_old            => 'N',
5866                               p_errors              => l_errors,
5867                               p_error               => l_error_flag
5868                              );
5869                -- maintain day bld blk table
5870 
5871                /* -- Only populate old DETAIL
5872 
5873                      IF ( t_bb(cnt).day_max_ovn <> 0 )
5874                      THEN
5875                         l_copy_old  := 'Y';
5876                      ELSE
5877                         l_copy_old  := 'N';
5878                      END IF;
5879                */
5880                copy_bld_blks (p_bld_blks_table      => t_bb,
5881                               p_scope               => 'DAY',
5882                               p_copied              => l_day_copied,
5883                               p_cnt                 => cnt,
5884                               p_copy_old            => 'N',
5885                               p_errors              => l_errors,
5886                               p_error               => l_error_flag
5887                              );
5888 
5889                IF (t_bb (cnt).detail_max_ovn <> 0)
5890                THEN
5891                   l_copy_old := 'Y';
5892                ELSE
5893                   l_copy_old := 'N';
5894                END IF;
5895 
5896                -- maintain detail bld blk table
5897                copy_bld_blks (p_bld_blks_table      => t_bb,
5898                               p_scope               => 'DETAIL',
5899                               p_copied              => l_detail_copied,
5900                               p_cnt                 => cnt,
5901                               p_copy_old            => l_copy_old,
5902                               p_errors              => l_errors,
5903                               p_error               => l_error_flag
5904                              );
5905 
5906 
5907 		-- Bug 7595581
5908                 -- Retrieval Log
5909 
5910 		ELSE
5911 		  IF(NOT (g_rtr_detail_blks.EXISTS(t_bb(cnt).detail_bb_id))) THEN
5912 				l_detail_bld_blk_idx := NVL (hxc_generic_retrieval_pkg.g_detail_skipped.LAST, 0) + 1;
5913 
5914 				hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).resource_id
5915 										:= t_bb(cnt).detail_resource_id;
5916 				hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).timecard_id
5917 										:= t_bb(cnt).time_bb_id;
5918 				hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).timecard_ovn
5919 										:= t_bb(cnt).time_ovn;
5920 				hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).bb_id
5921 										:= t_bb(cnt).detail_bb_id;
5922 				hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).ovn
5923 										:= t_bb(cnt).detail_ovn;
5924 				hxc_generic_retrieval_pkg.g_detail_skipped(l_detail_bld_blk_idx).description
5925 										:= l_bb_skipped_reason;
5926 
5927 		  END IF;
5928 
5929 
5930             END IF;                                               -- check ovn
5931          END IF;
5932 
5933          --***********DAYS Vs HOURS************
5934          IF g_params.p_process = 'Projects Retrieval Process' THEN
5935 	  l_detail_index := NVL (hxc_generic_retrieval_pkg.t_detail_bld_blks.LAST, 0);
5936 
5937 	 IF l_detail_index<> 0 THEN
5938 
5939 	  IF  hxc_generic_retrieval_pkg.t_detail_bld_blks(l_detail_index).bb_id
5940 		= t_bb(cnt).detail_bb_id  THEN
5941 
5942 		IF l_number_format = ',.'  THEN --EUROPEAN FORMAT
5943 		   l_att26 := to_number(replace(t_bb(cnt).detail_attribute26,'.',','));
5944 		ELSIF  l_number_format = '.,'  THEN --US FORMAT
5945 		   l_att26 := to_number(replace(t_bb(cnt).detail_attribute26,',','.'));
5946 		END IF;
5947 
5948 	      IF nvl(l_att26,1) <> 1 AND l_already_multiplied = 'N' THEN
5949 
5950 		hxc_generic_retrieval_pkg.t_detail_bld_blks(l_detail_index).measure :=
5951 		hxc_generic_retrieval_pkg.t_detail_bld_blks(l_detail_index).measure * l_att26;
5952 
5953 		l_already_multiplied := 'Y';
5954 
5955 	      END IF;
5956 
5957 	  END IF;
5958 	 END IF;
5959 	END IF;
5960         --***********DAYS Vs HOURS************
5961 
5962 -- Maintain Timecard Attribute rows
5963          IF (NOT l_error_flag)
5964          THEN
5965             IF (    l_day_retrieve
5966                 AND (t_bb (cnt).detail_ovn > t_bb (cnt).detail_max_ovn)
5967                )
5968             THEN
5969                -- Maintain Detail Attribute rows
5970 
5971                -- must not forget that there may not be any attributes for the detail scope
5972                -- hence r_csr_tbb.detail_time_attribute_id may be null
5973                IF (    (t_bb (cnt).detail_ta_id <> l_old_detail_ta_id)
5974                    AND (t_bb (cnt).detail_ta_id IS NOT NULL)
5975                   )
5976                THEN
5977                   -- set old time card time attribute id
5978                   l_old_detail_ta_id := t_bb (cnt).detail_ta_id;
5979 
5980                   IF (att_copied_before
5981                          (p_scope                     => 'DETAIL',
5982                           p_bld_blk_info_type_id      => t_bb (cnt).detail_bld_blk_info_type_id
5983                          )
5984                      )
5985                   THEN
5986                      l_detail_att_copied := 'Y';
5987                   ELSE
5988                      l_detail_att_copied := 'N';
5989                   END IF;
5990 
5991                   -- check to see if these are attributes for a bld blk that needs to be transferred
5992                   IF (l_detail_att_copied = 'N')
5993                   THEN
5994                      -- loop through the global field mappings table to map attribute value to field
5995                      -- name and populate the detail attribute tables
5996                      populate_attributes
5997                               (p_building_block_id      => t_bb (cnt).detail_bb_id,
5998                                p_attribute_table        => t_bb,
5999                                p_cnt                    => cnt,
6000                                p_scope                  => 'DETAIL',
6001                                p_new                    => 'Y'
6002                               );
6003                      l_detail_att_copied := 'Y';
6004                      l_bld_blk_info_index :=
6005                                         NVL (t_detail_bld_blk_info.LAST, 0)
6006                                         + 1;
6007                      t_detail_bld_blk_info (l_bld_blk_info_index) :=
6008                                         t_bb (cnt).detail_bld_blk_info_type_id;
6009                   END IF;
6010                END IF;
6011             END IF;                     -- l_day_retrieve and detail ovn check
6012          END IF;                                    -- IF ( NOT l_error_flag )
6013       END LOOP;                                                -- csr_tbb loop
6014 
6015 -- check to see if out of any of the timecards retrieved in the query were
6016 -- copied to the global PL/SQL tables
6017       IF (l_bld_blks_to_transfer = 'N')
6018       THEN
6019          RAISE e_no_bld_blks_to_transfer;
6020       ELSE
6021          hxc_generic_retrieval_pkg.g_no_timecards := FALSE;
6022          hxc_generic_retrieval_pkg.g_overall_no_timecards := FALSE;
6023       END IF;
6024 
6025       IF g_debug
6026       THEN
6027          hr_utility.TRACE (' *********** - GLOBAL TABLE INFO ************ ');
6028       END IF;
6029 
6030       l_count := hxc_generic_retrieval_pkg.t_detail_bld_blks.COUNT;
6031 
6032       IF g_debug
6033       THEN
6034          hr_utility.TRACE ('DETAIL bld blks       : ' || TO_CHAR (l_count));
6035       END IF;
6036 
6037       l_count := hxc_generic_retrieval_pkg.t_detail_attributes.COUNT;
6038 
6039       IF g_debug
6040       THEN
6041          hr_utility.TRACE ('DETAIL attributes     : ' || TO_CHAR (l_count));
6042       END IF;
6043 
6044       l_count := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT;
6045 
6046       IF g_debug
6047       THEN
6048          hr_utility.TRACE ('DETAIL txd count is ' || TO_CHAR (l_count));
6049       END IF;
6050 
6051       l_count := hxc_generic_retrieval_pkg.t_tx_error_bb_id.COUNT;
6052 
6053       IF g_debug
6054       THEN
6055          hr_utility.TRACE ('ERROR txd count is ' || TO_CHAR (l_count));
6056       END IF;
6057 
6058 -- delete the table
6059       t_bb.DELETE;
6060 
6061       IF g_debug
6062       THEN
6063          hr_utility.set_location ('Leaving ' || l_proc, 200);
6064       END IF;
6065    EXCEPTION
6066       WHEN e_no_timecards
6067       THEN
6068          hxc_generic_retrieval_utils.g_resources.DELETE;
6069 
6070          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
6071          THEN
6072             audit_transaction
6073                          (p_mode                        => 'I'       -- Insert
6074                                                               ,
6075                           p_transaction_process_id      => g_retrieval_process_id,
6076                           p_status                      => 'WARNINGS',
6077                           p_description                 => 'HXC_0012_GNRET_NO_TIMECARDS'
6078                          );
6079          END IF;
6080 
6081          -- Bug 9701936
6082          -- Added this call to move PENDING records to SKIPPED Status
6083          skip_pending_records;
6084 
6085          fnd_message.set_name ('HXC', 'HXC_0012_GNRET_NO_TIMECARDS');
6086          fnd_message.raise_error;
6087       WHEN e_no_bld_blks_to_transfer
6088       THEN
6089          t_bb.DELETE;
6090          hxc_generic_retrieval_utils.g_resources.DELETE;
6091 
6092          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
6093          THEN
6094             audit_transaction
6095                          (p_mode                        => 'I'       -- Insert
6096                                                               ,
6097                           p_transaction_process_id      => g_retrieval_process_id,
6098                           p_status                      => 'WARNINGS',
6099                           p_description                 => 'HXC_0013_GNRET_NO_BLD_BLKS'
6100                          );
6101          ELSIF (l_errors.COUNT <> 0)
6102          THEN
6103             -- Must maintain the errors WWB 3517746
6104             audit_transaction
6105                          (p_mode                        => 'I'       -- Insert
6106                                                               ,
6107                           p_transaction_process_id      => g_retrieval_process_id,
6108                           p_status                      => 'WARNINGS',
6109                           p_description                 => 'HXC_0013_GNRET_NO_BLD_BLKS'
6110                          );
6111          END IF;
6112 
6113          fnd_message.set_name ('HXC', 'HXC_0013_GNRET_NO_BLD_BLKS');
6114          fnd_message.raise_error;
6115       WHEN OTHERS
6116       THEN
6117          -- Bug 9394444
6118          hr_utility.trace(dbms_utility.format_error_backtrace);
6119          audit_transaction
6120                          (p_mode                        => 'I'       -- Insert
6121                                                               ,
6122                           p_transaction_process_id      => g_retrieval_process_id,
6123                           p_status                      => 'WARNINGS',
6124                           p_description                 => SUBSTR (SQLERRM,
6125                                                                    1,
6126                                                                    2000
6127                                                                   )
6128                          );
6129          RAISE;
6130    END query_it;
6131 
6132 -- private procedure
6133 --   query_old_timecard
6134 --
6135 -- description
6136 --   this queries the bld blk last transferred.
6137 --   we populate a temporary table with the bld blk id and ovn
6138 --   of the last transferred bld blk and then bulk collect
6139 --
6140 -- parameters
6141 --   none
6142    PROCEDURE query_old_timecard
6143    IS
6144       PRAGMA AUTONOMOUS_TRANSACTION;
6145 --
6146 -- define local variables
6147 --
6148       l_proc                       VARCHAR2 (100);
6149 
6150       CURSOR gaz_chk_tmp_table
6151       IS
6152          SELECT 'x'
6153            FROM hxc_tmp_bld_blks;
6154 
6155       CURSOR csr_get_old_detail_bld_blks
6156       IS
6157          SELECT   /*+ ORDERED  INDEX(TBB) INDEX(DAY) USE_NL(TBB, DAY) */
6158                   tbb.time_building_block_id, tbb.object_version_number,
6159                   tbb.parent_building_block_id, tbb.resource_type,
6160                   tbb.resource_id, tbb.comment_text,
6161                   DECODE (tbb.TYPE,
6162                           'MEASURE', DAY.start_time,
6163                           tbb.start_time
6164                          ),
6165                   DECODE (tbb.TYPE, 'MEASURE', DAY.stop_time, tbb.stop_time),
6166                   DECODE (tbb.TYPE,
6167                           'MEASURE', tbb.measure,
6168                           (tbb.stop_time - tbb.start_time
6169                           ) * 24
6170                          ),
6171                   tbb.SCOPE, tbb.TYPE,
6172                   DECODE (tbb.TYPE, 'MEASURE', tbb.unit_of_measure, 'HOURS'),
6173                   tbb.date_from, tbb.date_to, tbb.approval_status,
6174                   tbb.approval_style_id
6175              FROM hxc_tmp_bld_blks tmp,
6176                   hxc_time_building_blocks tbb,
6177                   hxc_time_building_blocks DAY
6178             WHERE tbb.time_building_block_id = tmp.time_building_block_id
6179               AND tbb.object_version_number = tmp.time_building_block_ovn
6180               AND DAY.time_building_block_id = tbb.parent_building_block_id
6181               AND DAY.object_version_number = tbb.parent_building_block_ovn
6182          ORDER BY tmp.seq;
6183 
6184       CURSOR csr_get_old_attributes
6185       IS
6186          SELECT   /*+ ORDERED  INDEX(TAU) INDEX(TA) USE_NL(TAU, TA) */
6187                   tmp.time_building_block_id, ta.bld_blk_info_type_id,
6188                   ta.attribute_category, ta.attribute1, ta.attribute2,
6189                   ta.attribute3, ta.attribute4, ta.attribute5, ta.attribute6,
6190                   ta.attribute7, ta.attribute8, ta.attribute9, ta.attribute10,
6191                   ta.attribute11, ta.attribute12, ta.attribute13,
6192                   ta.attribute14, ta.attribute15, ta.attribute16,
6193                   ta.attribute17, ta.attribute18, ta.attribute19,
6194                   ta.attribute20, ta.attribute21, ta.attribute22,
6195                   ta.attribute23, ta.attribute24, ta.attribute25,
6196                   ta.attribute26, ta.attribute27, ta.attribute28,
6197                   ta.attribute29, ta.attribute30
6198              FROM hxc_tmp_bld_blks tmp,
6199                   hxc_time_attribute_usages tau,
6200                   hxc_time_attributes ta
6201             WHERE tau.time_building_block_id = tmp.time_building_block_id
6202               AND tau.time_building_block_ovn = tmp.time_building_block_ovn
6203               AND ta.time_attribute_id = tau.time_attribute_id
6204          ORDER BY tmp.seq;
6205 
6206       l_index                      PLS_INTEGER;
6207       l_dummy                      VARCHAR2 (1);
6208 
6209 -- bulk collect collections
6210       TYPE t_old_bld_blk_bb_id IS TABLE OF hxc_time_building_blocks.time_building_block_id%TYPE
6211          INDEX BY BINARY_INTEGER;
6212 
6213       TYPE t_old_bld_blk_bb_ovn IS TABLE OF hxc_time_building_blocks.object_version_number%TYPE
6214          INDEX BY BINARY_INTEGER;
6215 
6216       TYPE t_old_bld_blk_parent_id IS TABLE OF hxc_time_building_blocks.parent_building_block_id%TYPE
6217          INDEX BY BINARY_INTEGER;
6218 
6219       TYPE t_old_bld_blk_resource_type IS TABLE OF hxc_time_building_blocks.resource_type%TYPE
6220          INDEX BY BINARY_INTEGER;
6221 
6222       TYPE t_old_bld_blk_resource_id IS TABLE OF hxc_time_building_blocks.resource_id%TYPE
6223          INDEX BY BINARY_INTEGER;
6224 
6225       TYPE t_old_bld_blk_comment_text IS TABLE OF hxc_time_building_blocks.comment_text%TYPE
6226          INDEX BY BINARY_INTEGER;
6227 
6228       TYPE t_old_bld_blk_start_time IS TABLE OF hxc_time_building_blocks.start_time%TYPE
6229          INDEX BY BINARY_INTEGER;
6230 
6231       TYPE t_old_bld_blk_stop_time IS TABLE OF hxc_time_building_blocks.stop_time%TYPE
6232          INDEX BY BINARY_INTEGER;
6233 
6234       TYPE t_old_bld_blk_measure IS TABLE OF hxc_time_building_blocks.measure%TYPE
6235          INDEX BY BINARY_INTEGER;
6236 
6237       TYPE t_old_bld_blk_scope IS TABLE OF hxc_time_building_blocks.SCOPE%TYPE
6238          INDEX BY BINARY_INTEGER;
6239 
6240       TYPE t_old_bld_blk_type IS TABLE OF hxc_time_building_blocks.TYPE%TYPE
6241          INDEX BY BINARY_INTEGER;
6242 
6243       TYPE t_old_bld_blk_uom IS TABLE OF hxc_time_building_blocks.unit_of_measure%TYPE
6244          INDEX BY BINARY_INTEGER;
6245 
6246       TYPE t_old_bld_blk_date_from IS TABLE OF hxc_time_building_blocks.date_from%TYPE
6247          INDEX BY BINARY_INTEGER;
6248 
6249       TYPE t_old_bld_blk_date_to IS TABLE OF hxc_time_building_blocks.date_to%TYPE
6250          INDEX BY BINARY_INTEGER;
6251 
6252       TYPE t_old_bld_blk_app_status IS TABLE OF hxc_time_building_blocks.approval_status%TYPE
6253          INDEX BY BINARY_INTEGER;
6254 
6255       TYPE t_old_bld_blk_app_style_id IS TABLE OF hxc_time_building_blocks.approval_style_id%TYPE
6256          INDEX BY BINARY_INTEGER;
6257 
6258       TYPE t_old_bld_blk_bb_info_type_id IS TABLE OF hxc_time_attributes.bld_blk_info_type_id%TYPE
6259          INDEX BY BINARY_INTEGER;
6260 
6261       TYPE t_old_bld_blk_att_cat IS TABLE OF hxc_time_attributes.attribute_category%TYPE
6262          INDEX BY BINARY_INTEGER;
6263 
6264       TYPE t_old_bld_blk_attribute1 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6265          INDEX BY BINARY_INTEGER;
6266 
6267       TYPE t_old_bld_blk_attribute2 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6268          INDEX BY BINARY_INTEGER;
6269 
6270       TYPE t_old_bld_blk_attribute3 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6271          INDEX BY BINARY_INTEGER;
6272 
6273       TYPE t_old_bld_blk_attribute4 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6274          INDEX BY BINARY_INTEGER;
6275 
6276       TYPE t_old_bld_blk_attribute5 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6277          INDEX BY BINARY_INTEGER;
6278 
6279       TYPE t_old_bld_blk_attribute6 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6280          INDEX BY BINARY_INTEGER;
6281 
6282       TYPE t_old_bld_blk_attribute7 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6283          INDEX BY BINARY_INTEGER;
6284 
6285       TYPE t_old_bld_blk_attribute8 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6286          INDEX BY BINARY_INTEGER;
6287 
6288       TYPE t_old_bld_blk_attribute9 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6289          INDEX BY BINARY_INTEGER;
6290 
6291       TYPE t_old_bld_blk_attribute10 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6292          INDEX BY BINARY_INTEGER;
6293 
6294       TYPE t_old_bld_blk_attribute11 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6295          INDEX BY BINARY_INTEGER;
6296 
6297       TYPE t_old_bld_blk_attribute12 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6298          INDEX BY BINARY_INTEGER;
6299 
6300       TYPE t_old_bld_blk_attribute13 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6301          INDEX BY BINARY_INTEGER;
6302 
6303       TYPE t_old_bld_blk_attribute14 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6304          INDEX BY BINARY_INTEGER;
6305 
6306       TYPE t_old_bld_blk_attribute15 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6307          INDEX BY BINARY_INTEGER;
6308 
6309       TYPE t_old_bld_blk_attribute16 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6310          INDEX BY BINARY_INTEGER;
6311 
6312       TYPE t_old_bld_blk_attribute17 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6313          INDEX BY BINARY_INTEGER;
6314 
6315       TYPE t_old_bld_blk_attribute18 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6316          INDEX BY BINARY_INTEGER;
6317 
6318       TYPE t_old_bld_blk_attribute19 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6319          INDEX BY BINARY_INTEGER;
6320 
6321       TYPE t_old_bld_blk_attribute20 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6322          INDEX BY BINARY_INTEGER;
6323 
6324       TYPE t_old_bld_blk_attribute21 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6325          INDEX BY BINARY_INTEGER;
6326 
6327       TYPE t_old_bld_blk_attribute22 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6328          INDEX BY BINARY_INTEGER;
6329 
6330       TYPE t_old_bld_blk_attribute23 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6331          INDEX BY BINARY_INTEGER;
6332 
6333       TYPE t_old_bld_blk_attribute24 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6334          INDEX BY BINARY_INTEGER;
6335 
6336       TYPE t_old_bld_blk_attribute25 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6337          INDEX BY BINARY_INTEGER;
6338 
6339       TYPE t_old_bld_blk_attribute26 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6340          INDEX BY BINARY_INTEGER;
6341 
6342       TYPE t_old_bld_blk_attribute27 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6343          INDEX BY BINARY_INTEGER;
6344 
6345       TYPE t_old_bld_blk_attribute28 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6346          INDEX BY BINARY_INTEGER;
6347 
6348       TYPE t_old_bld_blk_attribute29 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6349          INDEX BY BINARY_INTEGER;
6350 
6351       TYPE t_old_bld_blk_attribute30 IS TABLE OF hxc_time_attributes.attribute1%TYPE
6352          INDEX BY BINARY_INTEGER;
6353 
6354       t_old_bb_id                  t_old_bld_blk_bb_id;
6355       t_old_bb_ovn                 t_old_bld_blk_bb_ovn;
6356       t_old_att_bb_id              t_old_bld_blk_bb_id;
6357       t_old_parent_id              t_old_bld_blk_parent_id;
6358       t_old_resource_type          t_old_bld_blk_resource_type;
6359       t_old_resource_id            t_old_bld_blk_resource_id;
6360       t_old_comment_text           t_old_bld_blk_comment_text;
6361       t_old_start_time             t_old_bld_blk_start_time;
6362       t_old_stop_time              t_old_bld_blk_stop_time;
6363       t_old_measure                t_old_bld_blk_measure;
6364       t_old_scope                  t_old_bld_blk_scope;
6365       t_old_type                   t_old_bld_blk_type;
6366       t_old_uom                    t_old_bld_blk_uom;
6367       t_old_date_from              t_old_bld_blk_date_from;
6368       t_old_date_to                t_old_bld_blk_date_to;
6369       t_old_approval_status        t_old_bld_blk_app_status;
6370       t_old_approval_style_id      t_old_bld_blk_app_style_id;
6371       t_old_bld_blk_info_type_id   t_old_bld_blk_bb_info_type_id;
6372       t_old_attribute_category     t_old_bld_blk_att_cat;
6373       t_old_attribute1             t_old_bld_blk_attribute1;
6374       t_old_attribute2             t_old_bld_blk_attribute2;
6375       t_old_attribute3             t_old_bld_blk_attribute3;
6376       t_old_attribute4             t_old_bld_blk_attribute4;
6377       t_old_attribute5             t_old_bld_blk_attribute5;
6378       t_old_attribute6             t_old_bld_blk_attribute6;
6379       t_old_attribute7             t_old_bld_blk_attribute7;
6380       t_old_attribute8             t_old_bld_blk_attribute8;
6381       t_old_attribute9             t_old_bld_blk_attribute9;
6382       t_old_attribute10            t_old_bld_blk_attribute10;
6383       t_old_attribute11            t_old_bld_blk_attribute11;
6384       t_old_attribute12            t_old_bld_blk_attribute12;
6385       t_old_attribute13            t_old_bld_blk_attribute13;
6386       t_old_attribute14            t_old_bld_blk_attribute14;
6387       t_old_attribute15            t_old_bld_blk_attribute15;
6388       t_old_attribute16            t_old_bld_blk_attribute16;
6389       t_old_attribute17            t_old_bld_blk_attribute17;
6390       t_old_attribute18            t_old_bld_blk_attribute18;
6391       t_old_attribute19            t_old_bld_blk_attribute19;
6392       t_old_attribute20            t_old_bld_blk_attribute20;
6393       t_old_attribute21            t_old_bld_blk_attribute21;
6394       t_old_attribute22            t_old_bld_blk_attribute22;
6395       t_old_attribute23            t_old_bld_blk_attribute23;
6396       t_old_attribute24            t_old_bld_blk_attribute24;
6397       t_old_attribute25            t_old_bld_blk_attribute25;
6398       t_old_attribute26            t_old_bld_blk_attribute26;
6399       t_old_attribute27            t_old_bld_blk_attribute27;
6400       t_old_attribute28            t_old_bld_blk_attribute28;
6401       t_old_attribute29            t_old_bld_blk_attribute29;
6402       t_old_attribute30            t_old_bld_blk_attribute30;
6403       l_range_increment            NUMBER                        := 100;
6404       l_lower_range                PLS_INTEGER;
6405       l_upper_range                PLS_INTEGER;
6406       l_bb_index                   PLS_INTEGER;
6407       l_already_multiplied         varchar2(1) := 'N';
6408       l_detail_index               number := 0;
6409       l_old_detail_bb_id           number := -1;
6410       l_number_format              varchar2(2);
6411       l_att26			   number;
6412    BEGIN
6413 -- populate temporary table for detail scope
6414       l_index := t_old_detail_bb_id.COUNT;
6415 
6416       IF g_debug
6417       THEN
6418          l_proc := g_package || 'query_old_timecard';
6419          hr_utility.set_location ('Processing ' || l_proc, 180);
6420       END IF;
6421 
6422       IF (l_index <> 0)
6423       THEN
6424          l_lower_range := t_old_detail_bb_id.FIRST;
6425          l_upper_range :=
6426             LEAST (t_old_detail_bb_id.LAST,
6427                    l_lower_range + l_range_increment);
6428 
6429          WHILE l_lower_range <= t_old_detail_bb_id.LAST
6430          LOOP
6431             FORALL x IN l_lower_range .. l_upper_range
6432                INSERT INTO hxc_tmp_bld_blks
6433                            (seq, time_building_block_id,
6434                             time_building_block_ovn
6435                            )
6436                     VALUES (t_old_detail_seq (x), t_old_detail_bb_id (x),
6437                             t_old_detail_ovn (x)
6438                            );
6439 
6440             IF g_debug
6441             THEN
6442                hr_utility.set_location ('Processing ' || l_proc, 190);
6443             END IF;
6444 
6445             OPEN csr_get_old_detail_bld_blks;
6446 
6447             FETCH csr_get_old_detail_bld_blks
6448             BULK COLLECT INTO t_old_bb_id, t_old_bb_ovn, t_old_parent_id,
6449                    t_old_resource_type, t_old_resource_id, t_old_comment_text,
6450                    t_old_start_time, t_old_stop_time, t_old_measure,
6451                    t_old_scope, t_old_type, t_old_uom, t_old_date_from,
6452                    t_old_date_to, t_old_approval_status,
6453                    t_old_approval_style_id;
6454 
6455             CLOSE csr_get_old_detail_bld_blks;
6456 
6457             IF g_debug
6458             THEN
6459                hr_utility.set_location ('Processing ' || l_proc, 200);
6460             END IF;
6461 
6462             OPEN csr_get_old_attributes;
6463 
6464             FETCH csr_get_old_attributes
6465             BULK COLLECT INTO t_old_att_bb_id, t_old_bld_blk_info_type_id,
6466                    t_old_attribute_category, t_old_attribute1,
6467                    t_old_attribute2, t_old_attribute3, t_old_attribute4,
6468                    t_old_attribute5, t_old_attribute6, t_old_attribute7,
6469                    t_old_attribute8, t_old_attribute9, t_old_attribute10,
6470                    t_old_attribute11, t_old_attribute12, t_old_attribute13,
6471                    t_old_attribute14, t_old_attribute15, t_old_attribute16,
6472                    t_old_attribute17, t_old_attribute18, t_old_attribute19,
6473                    t_old_attribute20, t_old_attribute21, t_old_attribute22,
6474                    t_old_attribute23, t_old_attribute24, t_old_attribute25,
6475                    t_old_attribute26, t_old_attribute27, t_old_attribute28,
6476                    t_old_attribute29, t_old_attribute30;
6477 
6478             CLOSE csr_get_old_attributes;
6479 
6480             IF g_debug
6481             THEN
6482                hr_utility.set_location (   'gaz - old att table is '
6483                                         || TO_CHAR (t_old_att_bb_id.COUNT),
6484                                         999
6485                                        );
6486             END IF;
6487 
6488 -- commit and in doing so clear out temp table
6489             COMMIT;
6490 
6491 -- gaz - test to make sure tmp table is defined correctly in case
6492             OPEN gaz_chk_tmp_table;
6493 
6494             FETCH gaz_chk_tmp_table
6495              INTO l_dummy;
6496 
6497             IF gaz_chk_tmp_table%FOUND
6498             THEN
6499                CLOSE gaz_chk_tmp_table;
6500 
6501                fnd_message.set_name ('HXC', 'HXC_TMP_BLD_BLKS_NOT_TMP');
6502                fnd_message.raise_error;
6503             END IF;
6504 
6505             CLOSE gaz_chk_tmp_table;
6506 
6507 -- populate old bld blk PL/SQL table
6508             IF g_debug
6509             THEN
6510                hr_utility.set_location ('Processing ' || l_proc, 210);
6511             END IF;
6512 	    l_detail_index := l_lower_range-1;	--DAYS Vs HOURS
6513             l_bb_index := l_lower_range;
6514 
6515             FOR x IN t_old_bb_id.FIRST .. t_old_bb_id.LAST
6516             LOOP
6517                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).bb_id :=
6518                                                               t_old_bb_id (x);
6519                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).ovn :=
6520                                                              t_old_bb_ovn (x);
6521                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).parent_bb_id :=
6522                                                           t_old_parent_id (x);
6523                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).resource_type :=
6524                                                       t_old_resource_type (x);
6525                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).resource_id :=
6526                                                         t_old_resource_id (x);
6527                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).comment_text :=
6528                                                        t_old_comment_text (x);
6529                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).start_time :=
6530                                                          t_old_start_time (x);
6531                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).stop_time :=
6532                                                           t_old_stop_time (x);
6533                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).measure :=
6534                                                             t_old_measure (x);
6535                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).SCOPE :=
6536                                                               t_old_scope (x);
6537                hxc_generic_retrieval_pkg.t_old_detail_bld_blks (l_bb_index).TYPE :=
6538                                                                t_old_type (x);
6539                l_bb_index := l_bb_index + 1;
6540             END LOOP;
6541 
6542             IF g_debug
6543             THEN
6544                hr_utility.set_location ('Processing ' || l_proc, 220);
6545             END IF;
6546 
6547             l_index := hxc_generic_retrieval_pkg.t_old_detail_bld_blks.COUNT;
6548 
6549             IF g_debug
6550             THEN
6551                hr_utility.set_location
6552                                (   'gaz GLOBAL old DETAIL bld blk count is '
6553                                 || TO_CHAR (l_index),
6554                                 999
6555                                );
6556             END IF;
6557 
6558             l_index := hxc_generic_retrieval_pkg.t_old_detail_attributes.COUNT;
6559 
6560             IF g_debug
6561             THEN
6562                hr_utility.set_location (   'gaz time att count is '
6563                                         || TO_CHAR (l_index),
6564                                         999
6565                                        );
6566             END IF;
6567 
6568             IF (t_old_att_bb_id.COUNT <> 0)
6569             THEN
6570                IF g_debug
6571                THEN
6572                   hr_utility.set_location ('Processing ' || l_proc, 230);
6573                END IF;
6574 
6575                FOR x IN t_old_att_bb_id.FIRST .. t_old_att_bb_id.LAST
6576                LOOP
6577                   t_bb (x).detail_bb_id := t_old_att_bb_id (x);
6578                   t_bb (x).detail_bld_blk_info_type_id :=
6579                                                t_old_bld_blk_info_type_id (x);
6580                   t_bb (x).detail_attribute_category :=
6581                                                  t_old_attribute_category (x);
6582                   t_bb (x).detail_attribute1 := t_old_attribute1 (x);
6583                   t_bb (x).detail_attribute2 := t_old_attribute2 (x);
6584                   t_bb (x).detail_attribute3 := t_old_attribute3 (x);
6585                   t_bb (x).detail_attribute4 := t_old_attribute4 (x);
6586                   t_bb (x).detail_attribute5 := t_old_attribute5 (x);
6587                   t_bb (x).detail_attribute6 := t_old_attribute6 (x);
6588                   t_bb (x).detail_attribute7 := t_old_attribute7 (x);
6589                   t_bb (x).detail_attribute8 := t_old_attribute8 (x);
6590                   t_bb (x).detail_attribute9 := t_old_attribute9 (x);
6591                   t_bb (x).detail_attribute10 := t_old_attribute10 (x);
6592                   t_bb (x).detail_attribute11 := t_old_attribute11 (x);
6593                   t_bb (x).detail_attribute12 := t_old_attribute12 (x);
6594                   t_bb (x).detail_attribute13 := t_old_attribute13 (x);
6595                   t_bb (x).detail_attribute14 := t_old_attribute14 (x);
6596                   t_bb (x).detail_attribute15 := t_old_attribute15 (x);
6597                   t_bb (x).detail_attribute16 := t_old_attribute16 (x);
6598                   t_bb (x).detail_attribute17 := t_old_attribute17 (x);
6599                   t_bb (x).detail_attribute18 := t_old_attribute18 (x);
6600                   t_bb (x).detail_attribute19 := t_old_attribute19 (x);
6601                   t_bb (x).detail_attribute20 := t_old_attribute20 (x);
6602                   t_bb (x).detail_attribute21 := t_old_attribute21 (x);
6603                   t_bb (x).detail_attribute22 := t_old_attribute22 (x);
6604                   t_bb (x).detail_attribute23 := t_old_attribute23 (x);
6605                   t_bb (x).detail_attribute24 := t_old_attribute24 (x);
6606                   t_bb (x).detail_attribute25 := t_old_attribute25 (x);
6607                   t_bb (x).detail_attribute26 := t_old_attribute26 (x);
6608                   t_bb (x).detail_attribute27 := t_old_attribute27 (x);
6609                   t_bb (x).detail_attribute28 := t_old_attribute28 (x);
6610                   t_bb (x).detail_attribute29 := t_old_attribute29 (x);
6611                   t_bb (x).detail_attribute30 := t_old_attribute30 (x);
6612 
6613                   --********DAYS Vs HOURS*******
6614                  IF g_params.p_process = 'Projects Retrieval Process' THEN
6615 		  IF (t_bb (x).detail_bb_id <> l_old_detail_bb_id) then
6616 			l_old_detail_bb_id := t_bb (x).detail_bb_id;
6617 			l_already_multiplied := 'N';
6618 			l_detail_index :=l_detail_index+1;
6619 		  END IF;
6620 
6621 		  IF l_detail_index BETWEEN hxc_generic_retrieval_pkg.t_old_detail_bld_blks.FIRST
6622 		      AND hxc_generic_retrieval_pkg.t_old_detail_bld_blks.LAST
6623 		  THEN
6624 
6625 		     IF  hxc_generic_retrieval_pkg.t_old_detail_bld_blks(l_detail_index).bb_id =
6626 				t_bb(x).detail_bb_id THEN
6627 
6628 			IF l_number_format = ',.'  THEN --EUROPEAN FORMAT
6629 			   l_att26 := to_number(replace(t_bb(x).detail_attribute26,'.',','));
6630 		        ELSIF  l_number_format = '.,'  THEN --US FORMAT
6631 			   l_att26 := to_number(replace(t_bb(x).detail_attribute26,',','.'));
6632 			END IF;
6633 			 IF NVL(l_att26,1) <> 1 AND l_already_multiplied = 'N' THEN
6634 
6635 			hxc_generic_retrieval_pkg.t_old_detail_bld_blks(l_detail_index).measure :=
6636 			hxc_generic_retrieval_pkg.t_old_detail_bld_blks(l_detail_index).measure *
6637 			l_att26;
6638 
6639 			l_already_multiplied := 'Y';
6640 
6641 			 END IF;
6642 		     END IF;
6643 
6644 		  END IF;
6645 		 END IF;
6646 		  --********DAYS VS HOURS*******
6647 
6648 
6649                END LOOP;
6650 
6651                l_index := hxc_generic_retrieval_pkg.t_bb.COUNT;
6652 
6653                IF g_debug
6654                THEN
6655                   hr_utility.set_location (   'gaz t bb count is '
6656                                            || TO_CHAR (l_index),
6657                                            999
6658                                           );
6659                END IF;
6660 
6661                IF g_debug
6662                THEN
6663                   hr_utility.set_location ('Processing ' || l_proc, 240);
6664                END IF;
6665 
6666                FOR x IN t_bb.FIRST .. t_bb.LAST
6667                LOOP
6668                   populate_attributes
6669                                 (p_building_block_id      => t_bb (x).detail_bb_id,
6670                                  p_attribute_table        => t_bb,
6671                                  p_cnt                    => x,
6672                                  p_scope                  => 'DETAIL',
6673                                  p_new                    => 'N'
6674                                 );
6675                END LOOP;
6676             END IF;                          -- ( t_old_att_bb_id.COUNT <> 0 )
6677 
6678             IF g_debug
6679             THEN
6680                hr_utility.set_location ('Processing ' || l_proc, 250);
6681             END IF;
6682 
6683 -- truncate temporary tables and delete arrays and table
6684             t_bb.DELETE;
6685             t_old_bb_id.DELETE;
6686             t_old_att_bb_id.DELETE;
6687             t_old_parent_id.DELETE;
6688             t_old_resource_type.DELETE;
6689             t_old_resource_id.DELETE;
6690             t_old_comment_text.DELETE;
6691             t_old_start_time.DELETE;
6692             t_old_stop_time.DELETE;
6693             t_old_measure.DELETE;
6694             t_old_scope.DELETE;
6695             t_old_type.DELETE;
6696             t_old_uom.DELETE;
6697             t_old_date_from.DELETE;
6698             t_old_date_to.DELETE;
6699             t_old_approval_status.DELETE;
6700             t_old_approval_style_id.DELETE;
6701             t_old_bld_blk_info_type_id.DELETE;
6702             t_old_attribute1.DELETE;
6703             t_old_attribute2.DELETE;
6704             t_old_attribute3.DELETE;
6705             t_old_attribute4.DELETE;
6706             t_old_attribute5.DELETE;
6707             t_old_attribute6.DELETE;
6708             t_old_attribute7.DELETE;
6709             t_old_attribute8.DELETE;
6710             t_old_attribute9.DELETE;
6711             t_old_attribute10.DELETE;
6712             t_old_attribute11.DELETE;
6713             t_old_attribute12.DELETE;
6714             t_old_attribute13.DELETE;
6715             t_old_attribute14.DELETE;
6716             t_old_attribute15.DELETE;
6717             t_old_attribute16.DELETE;
6718             t_old_attribute17.DELETE;
6719             t_old_attribute18.DELETE;
6720             t_old_attribute19.DELETE;
6721             t_old_attribute20.DELETE;
6722             t_old_attribute21.DELETE;
6723             t_old_attribute22.DELETE;
6724             t_old_attribute23.DELETE;
6725             t_old_attribute24.DELETE;
6726             t_old_attribute25.DELETE;
6727             t_old_attribute26.DELETE;
6728             t_old_attribute27.DELETE;
6729             t_old_attribute28.DELETE;
6730             t_old_attribute29.DELETE;
6731             t_old_attribute30.DELETE;
6732             l_lower_range := l_upper_range + 1;
6733             l_upper_range :=
6734                LEAST (l_upper_range + l_range_increment,
6735                       t_old_detail_bb_id.LAST
6736                      );
6737          END LOOP;           -- while l_lower_range <= t_old_detail_bb_id.LAST
6738 
6739          IF g_debug
6740          THEN
6741             hr_utility.set_location ('Processing ' || l_proc, 260);
6742          END IF;
6743       END IF;                                           -- IF ( l_index <> 0 )
6744 --if g_debug then
6745    -- hr_utility.set_location('Processing '||l_proc, 270);
6746 --end if;
6747    END query_old_timecard;
6748 
6749 --
6750 -- procedure
6751 --   execute_retrieval_process
6752 --
6753 -- description
6754 --   this is the main procedure for the retrieval process. The basic process
6755 --   flow is as follows
6756 --
6757 --       check the retrieval process is registered
6758 --       (chk_retrieval_process)
6759 --          |
6760 --       check no other retrieval running
6761 --    (check_concurrency_ok)
6762 --       |
6763 --              audit the transaction header
6764 --                      |
6765 --    get the field mappings for this retrieval process
6766 --    and populate global PL/SQL table
6767 --    (get_field_mappings)
6768 --       |
6769 --    parse the user defined WHERE clause
6770 --    (parse_it)
6771 --       |
6772 --    build the dynamic SQL query based on parameters passed
6773 --    (build_query)
6774 --       |
6775 --    execute the query
6776 --    (query_it)
6777 --       |
6778 --    populate the transaction tables
6779 --    (audit_transaction)
6780 --          |
6781 --    query the old time card if appropriate
6782 --    (query_old_timecard)
6783 --
6784 --
6785 --
6786 -- parameters
6787 --   p_process    - name of the process registered in hxc_retrieval_processes
6788 --   p_transaction_code - user defined transaction code used for rerun
6789 --   p_start_date - start date of the retrieval window
6790 --   p_end_date      - end date of the retrieval window
6791 --   p_incremental   - incremental (Y/N)
6792 --   p_rerun_flag - rerun flag (Y/N)
6793 --   p_where_clause  - user specified where clause
6794 --   p_scope      - driving scope - which bld blk scope we drive the date window
6795 --   p_clusive    - INclusive or EXclusive dates in the date window
6796 --         (i.e. INclude or EXClude bld blks which do not completely
6797 --                         fit in the date window)
6798 --
6799    PROCEDURE execute_retrieval_process (
6800       p_process            IN   hxc_retrieval_processes.NAME%TYPE,
6801       p_transaction_code   IN   VARCHAR2,
6802       p_start_date         IN   DATE DEFAULT NULL,
6803       p_end_date           IN   DATE DEFAULT NULL,
6804       p_incremental        IN   VARCHAR2 DEFAULT 'Y',
6805       p_rerun_flag         IN   VARCHAR2 DEFAULT 'N',
6806       p_where_clause       IN   VARCHAR2,
6807       p_scope              IN   VARCHAR2 DEFAULT 'DAY',
6808       p_clusive            IN   VARCHAR2 DEFAULT 'EX',
6809       p_unique_params      IN   VARCHAR2 DEFAULT NULL,
6810       p_since_date         IN   VARCHAR2 DEFAULT NULL
6811    )
6812    IS
6813 -- debug local variables
6814       l_debug                      VARCHAR2 (1);
6815       l_gaz_cnt                    PLS_INTEGER;
6816       l_gaz_att                    PLS_INTEGER;
6817       loop_ok                      BOOLEAN                            := TRUE;
6818       l_message_table              hxc_message_table_type;
6819       l_boolean                    BOOLEAN;
6820       l_bld_blks                   hxc_generic_retrieval_pkg.t_building_blocks;
6821       l_atts                       hxc_generic_retrieval_pkg.t_time_attribute;
6822       l_att_index                  PLS_INTEGER                          := -1;
6823 
6824       CURSOR csr_debug
6825       IS
6826          SELECT 'Y'
6827            FROM hxc_debug
6828           WHERE process = 'RETRIEVAL' AND TRUNC (debug_date) =
6829                                                               TRUNC (SYSDATE);
6830 
6831       l_sql                        VARCHAR2 (2000);
6832       l_since_date                 VARCHAR2 (100);
6833       l_proc                       VARCHAR2 (72)
6834                                   := g_package || 'execute_retrieval_process';
6835       l_mapping_id                 hxc_mappings.mapping_id%TYPE       := NULL;
6836       l_ret_id                     hxc_retrieval_processes.retrieval_process_id%TYPE;
6837       e_retrieval_not_registered   EXCEPTION;
6838       e_process_already_running    EXCEPTION;
6839       l_where_clause_blk           VARCHAR2 (2000);
6840       l_where_clause_att           VARCHAR2 (2000);
6841       l_dynamic_query              VARCHAR2 (32000);
6842       l_transaction_id             NUMBER (15);
6843 
6844 -- define private functions and procedures
6845 
6846       -- private function
6847 --   build_query
6848 --
6849 -- description
6850 --   This function builds the dynamic query based on the parameters passed
6851 --   to the retrieval API.
6852 --   The query is broken down into its component forms of SELECT, FROM, WHERE
6853 --   and ORDER BY. The WHERE predicates are further broken down into timecard
6854 --   scopes. There are two SELECT portions, one for incremental and one for
6855 --   non incremental
6856 -- l_incremental_select
6857 -- l_select
6858 --   There are three FROMs, one for the rerun retrieval, one for the non incremental
6859 --   and one for the incremental
6860 -- l_from
6861 --      l_incremental_from
6862 --      l_rerun
6863 --   Since we also control which scope of building block we are interested
6864 --   in the time window restricting upon the WHERE is broken down into
6865 --   bld blks scopes. Furthermore, within this the user is able to specify
6866 --   whether or not the date range is INclusive or EXclusive of time bld
6867 --   blks
6868 -- l_time
6869 -- l_time_ex
6870 -- l_time_in
6871 -- l_day
6872 -- l_day_ex
6873 -- l_day_in
6874 -- l_detail
6875 -- l_detail_ex
6876 -- l_detail_in
6877 --   Finally the order by which currently is static.
6878 -- l_order_by
6879 --
6880 -- Parameters
6881 --   p_where_clause - the recipient API defined where clause
6882       FUNCTION build_query (
6883          p_where_clause_blk   VARCHAR2,
6884          p_where_clause_att   VARCHAR2
6885       )
6886          RETURN VARCHAR2
6887       IS
6888          l_hint                  VARCHAR2 (170)
6889             := '
6890 SELECT /*+ ordered use_nl( tbb
6891              detail_block detail_usage detail_att
6892              day_block timecard_block
6893              detail_max_ovn ) */ ';
6894          l_incremental_select    VARCHAR2 (1860)
6895             := '
6896 	timecard_block.time_building_block_id
6897 ,	timecard_block.object_version_number
6898 ,	day_block.time_building_block_id
6899 ,	day_block.object_version_number
6900 ,	day_block.start_time
6901 ,	day_block.stop_time
6902 ,	detail_block.time_building_block_id
6903 ,	detail_block.object_version_number
6904 ,	detail_block.parent_building_block_id
6905 ,	detail_block.resource_type
6906 ,	detail_block.resource_id
6907 ,	detail_block.comment_text
6908 ,	detail_block.start_time
6909 ,	detail_block.stop_time
6910 ,	detail_block.measure
6911 ,	detail_block.scope
6912 ,	detail_block.type
6913 ,	detail_att.time_attribute_id
6914 ,	detail_att.bld_blk_info_type_id
6915 ,	detail_att.attribute1
6916 ,	detail_att.attribute2
6917 ,	detail_att.attribute3
6918 ,	detail_att.attribute4
6919 ,	detail_att.attribute5
6920 ,	detail_att.attribute6
6921 ,	detail_att.attribute7
6922 ,	detail_att.attribute8
6923 ,	detail_att.attribute9
6924 ,	detail_att.attribute10
6925 ,	detail_att.attribute11
6926 ,	detail_att.attribute12
6927 ,	detail_att.attribute13
6928 ,	detail_att.attribute14
6929 ,	detail_att.attribute15
6930 ,	detail_att.attribute16
6931 ,	detail_att.attribute17
6932 ,	detail_att.attribute18
6933 ,	detail_att.attribute19
6934 ,	detail_att.attribute20
6935 ,	detail_att.attribute21
6936 ,	detail_att.attribute22
6937 ,	detail_att.attribute23
6938 ,	detail_att.attribute24
6939 ,	detail_att.attribute25
6940 ,	detail_att.attribute26
6941 ,	detail_att.attribute27
6942 ,	detail_att.attribute28
6943 ,	detail_att.attribute29
6944 ,	detail_att.attribute30
6945 ,	detail_block.date_from
6946 ,	detail_block.date_to
6947 ,	detail_block.approval_status
6948 ,	detail_block.approval_style_id
6949 ,	DECODE ( detail_block.date_to, hr_general.end_of_time, ''N'', ''Y'' )
6950 ,	detail_att.attribute_category
6951 ,       1
6952 ,       1
6953 ,       NVL(detail_max_ovn.max_ovn, 0)
6954 ,	detail_block.unit_of_measure
6955 ,	timecard_block.start_time
6956 ,	timecard_block.stop_time
6957 ,       timecard_block.comment_text
6958 ,	DECODE ( timecard_block.date_to, hr_general.end_of_time, ''N'', ''Y'' ) ';
6959          l_select                VARCHAR2 (1945)
6960             := '
6961 SELECT /*+ ordered use_nl(
6962              detail_block detail_usage detail_att
6963              day_block timecard_block
6964              detail_max_ovn ) */
6965 	timecard_block.time_building_block_id
6966 ,	timecard_block.object_version_number
6967 ,	day_block.time_building_block_id
6968 ,	day_block.object_version_number
6969 ,	day_block.start_time
6970 ,	day_block.stop_time
6971 ,	detail_block.time_building_block_id
6972 ,	detail_block.object_version_number
6973 ,	detail_block.parent_building_block_id
6974 ,	detail_block.resource_type
6975 ,	detail_block.resource_id
6976 ,	detail_block.comment_text
6977 ,	detail_block.start_time
6978 ,	detail_block.stop_time
6979 ,	detail_block.measure
6980 ,	detail_block.scope
6981 ,	detail_block.type
6982 ,	detail_att.time_attribute_id
6983 ,	detail_att.bld_blk_info_type_id
6984 ,	detail_att.attribute1
6985 ,	detail_att.attribute2
6986 ,	detail_att.attribute3
6987 ,	detail_att.attribute4
6988 ,	detail_att.attribute5
6989 ,	detail_att.attribute6
6990 ,	detail_att.attribute7
6991 ,	detail_att.attribute8
6992 ,	detail_att.attribute9
6993 ,	detail_att.attribute10
6994 ,	detail_att.attribute11
6995 ,	detail_att.attribute12
6996 ,	detail_att.attribute13
6997 ,	detail_att.attribute14
6998 ,	detail_att.attribute15
6999 ,	detail_att.attribute16
7000 ,	detail_att.attribute17
7001 ,	detail_att.attribute18
7002 ,	detail_att.attribute19
7003 ,	detail_att.attribute20
7004 ,	detail_att.attribute21
7005 ,	detail_att.attribute22
7006 ,	detail_att.attribute23
7007 ,	detail_att.attribute24
7008 ,	detail_att.attribute25
7009 ,	detail_att.attribute26
7010 ,	detail_att.attribute27
7011 ,	detail_att.attribute28
7012 ,	detail_att.attribute29
7013 ,	detail_att.attribute30
7014 ,	detail_block.date_from
7015 ,	detail_block.date_to
7016 ,	detail_block.approval_status
7017 ,	detail_block.approval_style_id
7018 ,	DECODE ( detail_block.date_to, hr_general.end_of_time, ''N'', ''Y'' )
7019 ,	detail_att.attribute_category
7020 ,       1
7021 ,       1
7022 ,	detail_block.object_version_number -1
7023 ,	detail_block.unit_of_measure
7024 ,	timecard_block.start_time
7025 ,	timecard_block.stop_time
7026 ,       timecard_block.comment_text
7027 ,	DECODE ( timecard_block.date_to, hr_general.end_of_time, ''N'', ''Y'' ) ';
7028          l_from                  VARCHAR2 (200)
7029             := '
7030 FROM
7031 	hxc_time_building_blocks	timecard_block
7032 ,	hxc_time_building_blocks	day_block
7033 ,	Hxc_time_building_blocks	detail_block
7034 ,	Hxc_time_attribute_usages	detail_usage
7035 ,	Hxc_time_attributes		detail_att';
7036          l_inline_view_range     VARCHAR2 (800)
7037             := '
7038 FROM
7039 	(select /*+ no_merge ordered */
7040         time_building_block_id,
7041 	object_version_number
7042 from 	Hxc_latest_details tbb_latest
7043 where	tbb_latest.resource_id BETWEEN :p_lower_range and :p_upper_range
7044 and     tbb_latest.approval_status <> ''ERROR''
7045 AND	NOT EXISTS (select ''x''
7046 			FROM	hxc_transaction_details txd
7047 			,	hxc_transactions tx
7048 			WHERE	tx.transaction_process_id	= :p_process_id
7049 			AND	tx.type				= ''RETRIEVAL''
7050 			AND	tx.status			= ''SUCCESS''
7051 			AND	tx.transaction_id		= txd.transaction_id
7052 			AND	txd.status			= ''SUCCESS''
7053 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
7054 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
7055 		)
7056 
7057 ';
7058 -- Bug 9394444
7059 
7060          l_inline_view_range_pa     VARCHAR2 (800)
7061             := '
7062 FROM
7063 	(select /*+ no_merge ordered */
7064         time_building_block_id,
7065 	object_version_number
7066 from 	Hxc_pa_latest_details tbb_latest
7067 where	tbb_latest.resource_id BETWEEN :p_lower_range and :p_upper_range
7068 and     tbb_latest.approval_status <> ''ERROR''
7069 AND	NOT EXISTS (select ''x''
7070 			FROM	hxc_transaction_details txd
7071 			,	hxc_transactions tx
7072 			WHERE	tx.transaction_process_id	= :p_process_id
7073 			AND	tx.type				= ''RETRIEVAL''
7074 			AND	tx.status			= ''SUCCESS''
7075 			AND	tx.transaction_id		= txd.transaction_id
7076 			AND	txd.status			= ''SUCCESS''
7077 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
7078 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
7079 		)
7080 ';
7081 
7082          l_inline_view_range_pay     VARCHAR2 (800)
7083             := '
7084 FROM
7085 	(select /*+ no_merge ordered */
7086         time_building_block_id,
7087 	object_version_number
7088 from 	Hxc_pay_latest_details tbb_latest
7089 where	tbb_latest.resource_id BETWEEN :p_lower_range and :p_upper_range
7090 and     tbb_latest.approval_status <> ''ERROR''
7091 AND	NOT EXISTS (select ''x''
7092 			FROM	hxc_transaction_details txd
7093 			,	hxc_transactions tx
7094 			WHERE	tx.transaction_process_id	= :p_process_id
7095 			AND	tx.type				= ''RETRIEVAL''
7096 			AND	tx.status			= ''SUCCESS''
7097 			AND	tx.transaction_id		= txd.transaction_id
7098 			AND	txd.status			= ''SUCCESS''
7099 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
7100 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
7101 		)
7102 ';
7103 
7104 
7105 
7106          l_inline_view           VARCHAR2 (2000)
7107 	             := '
7108 	 FROM
7109 	 	(select /*+ no_merge ordered */
7110 	         tbb_latest.time_building_block_id,
7111 	 	tbb_latest.object_version_number
7112 	 from 	hxc_retrieval_ranges rr,
7113 	         hxc_retrieval_range_resources rrr,
7114 	         hxc_latest_details tbb_latest
7115 	 where	rr.retrieval_range_id = :p_rr_id AND
7116 	         rr.retrieval_range_id = rrr.retrieval_range_id AND
7117 	         tbb_latest.resource_id = rrr.resource_id AND
7118 	         tbb_latest.last_update_date > :p_since_date
7119 	         AND tbb_latest.approval_status <> ''ERROR''
7120 	 AND	NOT EXISTS (select ''x''
7121 	 			FROM	hxc_transaction_details txd
7122 	 			,	hxc_transactions tx
7123 	 			WHERE	tx.transaction_process_id	= :p_process_id
7124 	 			AND	tx.type				= ''RETRIEVAL''
7125 	 			AND	tx.status			= ''SUCCESS''
7126 	 			AND	tx.transaction_id		= txd.transaction_id
7127 	 			AND	txd.status			= ''SUCCESS''
7128 	 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
7129 	 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
7130 	 		)
7131 ';
7132 -- Bug 9394444
7133          l_inline_view_pa           VARCHAR2 (2000)
7134 	             := '
7135 	 FROM
7136 	 	(select /*+ no_merge ordered */
7137 	         tbb_latest.time_building_block_id,
7138 	 	tbb_latest.object_version_number
7139 	 from 	hxc_retrieval_ranges rr,
7140 	         hxc_retrieval_range_resources rrr,
7141 	         hxc_pa_latest_details tbb_latest
7142 	 where	rr.retrieval_range_id = :p_rr_id AND
7143 	         rr.retrieval_range_id = rrr.retrieval_range_id AND
7144 	         tbb_latest.resource_id = rrr.resource_id AND
7145 	         tbb_latest.last_update_date > :p_since_date
7146 	         AND tbb_latest.approval_status <> ''ERROR''
7147 	 AND	NOT EXISTS (select ''x''
7148 	 			FROM	hxc_transaction_details txd
7149 	 			,	hxc_transactions tx
7150 	 			WHERE	tx.transaction_process_id	= :p_process_id
7151 	 			AND	tx.type				= ''RETRIEVAL''
7152 	 			AND	tx.status			= ''SUCCESS''
7153 	 			AND	tx.transaction_id		= txd.transaction_id
7154 	 			AND	txd.status			= ''SUCCESS''
7155 	 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
7156 	 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
7157 	 		)
7158 ';
7159 
7160          l_inline_view_pay           VARCHAR2 (2000)
7161 	             := '
7162 	 FROM
7163 	 	(select /*+ no_merge ordered */
7164 	         tbb_latest.time_building_block_id,
7165 	 	tbb_latest.object_version_number
7166 	 from 	hxc_retrieval_ranges rr,
7167 	         hxc_retrieval_range_resources rrr,
7168 	         hxc_pay_latest_details tbb_latest
7169 	 where	rr.retrieval_range_id = :p_rr_id AND
7170 	         rr.retrieval_range_id = rrr.retrieval_range_id AND
7171 	         tbb_latest.resource_id = rrr.resource_id AND
7172 	         tbb_latest.last_update_date > :p_since_date
7173 	         AND tbb_latest.approval_status <> ''ERROR''
7174 	 AND	NOT EXISTS (select ''x''
7175 	 			FROM	hxc_transaction_details txd
7176 	 			,	hxc_transactions tx
7177 	 			WHERE	tx.transaction_process_id	= :p_process_id
7178 	 			AND	tx.type				= ''RETRIEVAL''
7179 	 			AND	tx.status			= ''SUCCESS''
7180 	 			AND	tx.transaction_id		= txd.transaction_id
7181 	 			AND	txd.status			= ''SUCCESS''
7182 	 		AND	txd.time_building_block_id	= tbb_latest.time_building_block_id
7183 	 		AND     txd.time_building_block_ovn     = tbb_latest.object_version_number
7184 	 		)
7185 ';
7186 
7187 
7188          l_noloop_from           VARCHAR2 (250)
7189             := '
7190  ) tbb
7191 ,	Hxc_time_building_blocks        detail_block
7192 ,	Hxc_time_attribute_usages	detail_usage
7193 ,	Hxc_time_attributes		detail_att
7194 ,	hxc_time_building_blocks	day_block
7195 ,	hxc_time_building_blocks	timecard_block
7196 ,	hxc_max_ovn			detail_max_ovn';
7197          l_incremental_from      VARCHAR2 (400)
7198             := '
7199 FROM
7200         hxc_retrieval_range_blks        tbb
7201 ,	Hxc_time_building_blocks        detail_block
7202 ,	Hxc_time_attribute_usages	detail_usage
7203 ,	Hxc_time_attributes		detail_att
7204 ,	hxc_time_building_blocks	day_block
7205 ,	hxc_time_building_blocks	timecard_block
7206 ,	hxc_latest_details    hld
7207 ,	hxc_max_ovn			detail_max_ovn';
7208          l_time                  VARCHAR2 (400)
7209             := '
7210 WHERE
7211         timecard_block.scope = ''TIMECARD'' AND
7212         timecard_block.approval_status <> ''ERROR'' AND
7213         timecard_block.object_version_number = (
7214                 SELECT  /*+ no_unnest */ MAX ( tovn.object_version_number )
7215                 FROM    hxc_time_building_blocks tovn
7216                 WHERE   tovn.time_building_block_id = timecard_block.time_building_block_id ) ';
7217 -- Bug 9394444
7218          l_incremental_from_pa      VARCHAR2 (400)
7219             := '
7220 FROM
7221         hxc_retrieval_range_blks        tbb
7222 ,	Hxc_time_building_blocks        detail_block
7223 ,	Hxc_time_attribute_usages	detail_usage
7224 ,	Hxc_time_attributes		detail_att
7225 ,	hxc_time_building_blocks	day_block
7226 ,	hxc_time_building_blocks	timecard_block
7227 ,	hxc_pa_latest_details    hld
7228 ,	hxc_max_ovn			detail_max_ovn';
7229 
7230          l_incremental_from_pay      VARCHAR2 (400)
7231             := '
7232 FROM
7233         hxc_retrieval_range_blks        tbb
7234 ,	Hxc_time_building_blocks        detail_block
7235 ,	Hxc_time_attribute_usages	detail_usage
7236 ,	Hxc_time_attributes		detail_att
7237 ,	hxc_time_building_blocks	day_block
7238 ,	hxc_time_building_blocks	timecard_block
7239 ,	hxc_pay_latest_details    hld
7240 ,	hxc_max_ovn			detail_max_ovn';
7241 
7242 
7243 
7244          l_time_ex               VARCHAR2 (560)
7245             := '
7246 WHERE
7247         timecard_block.scope = ''TIMECARD'' AND
7248         timecard_block.approval_status <> ''ERROR'' AND
7249         timecard_block.object_version_number = (
7250                 SELECT   /*+ no_unnest */ MAX ( tovn.object_version_number )
7251                 FROM    hxc_time_building_blocks tovn
7252                 WHERE   tovn.time_building_block_id = timecard_block.time_building_block_id )
7253 AND
7254         timecard_block.start_time
7255         BETWEEN :p_start_date AND :p_end_date AND
7256         timecard_block.stop_time
7257         BETWEEN :p_start_date AND :p_end_date ';
7258          l_time_in               VARCHAR2 (650)
7259             := '
7260 WHERE
7261         timecard_block.scope = ''TIMECARD'' AND
7262         timecard_block.approval_status <> ''ERROR'' AND
7263         timecard_block.object_version_number = (
7264                 SELECT   /*+ no_unnest */ MAX ( tovn.object_version_number )
7265 		FROM    hxc_time_building_blocks tovn
7266                 WHERE   tovn.time_building_block_id = timecard_block.time_building_block_id )
7267         AND
7268         :p_start_date   <=      timecard_block.stop_time   AND
7269         :p_end_date     >=      timecard_block.start_time ';
7270          l_day                   VARCHAR2 (600)
7271             := '
7272 AND
7273         day_block.parent_building_block_id
7274                                 = timecard_block.time_building_block_id AND
7275         day_block.scope         = ''DAY'' AND
7276         day_block.approval_status <> ''ERROR'' AND
7277         day_block.object_version_number = (
7278                 SELECT  /*+ no_unnest */ MAX ( dyovn.object_version_number )
7279 		FROM    hxc_time_building_blocks dyovn
7280                 WHERE   dyovn.time_building_block_id = day_block.time_building_block_id ) ';
7281          l_detail                VARCHAR2 (350)
7282             := '
7283 AND
7284         detail_block.parent_building_block_id  = day_block.time_building_block_id
7285 AND
7286         detail_usage.time_building_block_id  = detail_block.time_building_block_id AND
7287         detail_usage.time_building_block_ovn = detail_block.object_version_number
7288 AND
7289         detail_att.time_attribute_id = detail_usage.time_attribute_id';
7290          l_inline_day_ex         VARCHAR2 (200)
7291             := '
7292 AND
7293         tbb_latest.start_time
7294         BETWEEN :p_start_date AND :p_end_date	AND
7295         tbb_latest.stop_time
7296         BETWEEN :p_start_date AND :p_end_date ';
7297          l_inline_day_in         VARCHAR2 (200)
7298             := '
7299 AND
7300         :p_start_date <= tbb_latest.stop_time	AND
7301         :p_end_date   >= tbb_latest.start_time ';
7302          l_rerun                 VARCHAR2 (1100)
7303             := '
7304 FROM
7305 	hxc_time_attributes		detail_att
7306 ,	hxc_time_attribute_usages	detail_usage
7307 ,	hxc_time_building_blocks	detail_block
7308 ,	hxc_time_building_blocks	day_block
7309 ,	hxc_time_attributes		timecard_att
7310 ,	hxc_transaction_details		txd
7311 ,	hxc_transactions		tx
7312 WHERE
7313 	tx.transaction_code	= :p_transaction_code
7314 AND
7315 	txd.transaction_id	= tx.transaction_id
7316 AND
7317 	timecard_block.time_building_block_id	= txd.time_building_block_id	AND
7318 	timecard_block.object_version_number	= txd.time_building_block_ovn	AND
7319 	timecard_block.scope 	= ''TIMECARD''
7320 AND
7321 	day_block.parent_building_block_id
7322 				= timecard_block.time_building_block_id AND
7323 	day_block.scope		= ''DAY''	AND
7324 	day_block.time_building_block_id	= txd.time_building_block_id	AND
7325 	day_block.object_version_number		= txd.time_building_block_ovn
7326 AND
7327 	detail_block.parent_building_block_id	= day_block.time_building_block_id AND
7328 	detail_block.scope			= ''DETAIL'' AND
7329 	detail_block.time_building_block_id	= txd.time_building_block_id	AND
7330 	detail_block.object_version_number	= txd.time_building_block_ovn';
7331 -- GPM v115.41
7332          /*l_not_exists            VARCHAR2 (500)
7333             := '
7334  AND
7335     detail_max_ovn.time_building_block_id(+) = detail_block.time_building_block_id
7336 AND
7337 	detail_block.time_building_block_id = tbb.time_building_block_id AND
7338 	detail_block.object_version_number  = tbb.object_version_number';*/
7339 
7340 	l_not_exists            VARCHAR2 (500)
7341 		             := '
7342 		  AND
7343 		     detail_max_ovn.time_building_block_id(+) = detail_block.time_building_block_id
7344 		 AND
7345 		 	detail_block.time_building_block_id = tbb.time_building_block_id AND
7346 		 	detail_block.object_version_number  = tbb.object_version_number
7347 		 	AND( ( detail_block.start_time IS NOT NULL AND detail_block.stop_time IS NOT NULL )
7348 		 	OR (detail_block.measure IS NOT NULL))
7349 	';
7350 
7351          l_latest_double_check   VARCHAR2 (400)
7352             := ' AND detail_block.time_building_block_id = hld.time_building_block_id
7353                  AND detail_block.object_version_number  = hld.object_version_number';
7354          l_order_by              VARCHAR2 (200)
7355             := '
7356 ORDER BY
7357         timecard_block.resource_id
7358 ,	timecard_block.start_time
7359 ,       timecard_block.time_building_block_id
7360 ,       day_block.start_time
7361 ,	detail_block.time_building_block_id';
7362          l_time_store_query      VARCHAR2 (32000);
7363          l_inline_day            VARCHAR2 (200)   := ' ';
7364          l_app_set               VARCHAR2 (200);
7365       BEGIN                                                     -- build query
7366 
7367          -- Bug 9394444
7368          IF g_params.p_process = 'Projects Retrieval Process'
7369           AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PA')
7370           AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
7371          THEN
7372                l_inline_view := l_inline_view_pa;
7373                l_incremental_from     := l_incremental_from_pa;
7374          ELSIF g_params.p_process IN ('BEE Retrieval Process','Apply Schedule Rules')
7375            AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
7376                 AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PAY')
7377          THEN
7378                l_inline_view := l_inline_view_pay;
7379                l_incremental_from     := l_incremental_from_pay;
7380          END IF;
7381 
7382 --Elp changes sonarasi 14-Mar-2003
7383 --A string of application set ids like (1,2,3,5) etc are obtained for the corresponding time
7384 --recipient id of the application. As per ELP changes, the Application Set Id for the detail,
7385 --day and timecard scopes are added in hxc_time_building_blocks table. Here we retrieve only
7386 --blocks that the Retrieval Application is interested in. So we just add to the where clause
7387 --to compare if the detail building block's application set id is within the list of
7388 --application set ids generated for the corresponding time recipient.
7389          l_app_set :=
7390                     g_app_set_id_string (g_retrieval_tr_id).app_set_id_string;
7391 
7392 --Elp changes sonarasi over
7393          IF (g_params.p_rerun_flag = 'Y')
7394          THEN
7395             l_time_store_query := l_select || l_rerun || l_order_by;
7396          ELSIF (g_params.p_start_date IS NULL AND g_params.p_end_date IS NULL
7397                )
7398          THEN
7399             l_time_store_query := l_time || l_day || l_detail;
7400          ELSIF (g_params.p_scope = 'TIME')
7401          THEN
7402             IF (g_params.p_clusive = 'EX')
7403             THEN
7404                l_time_store_query := l_time_ex || l_day || l_detail;
7405             ELSIF (g_params.p_clusive = 'IN')
7406             THEN
7407                l_time_store_query := l_time_in || l_day || l_detail;
7408             ELSE
7409                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
7410                fnd_message.raise_error;
7411             END IF;
7412          ELSIF (g_params.p_scope = 'DAY')
7413          THEN
7414             IF (g_params.p_clusive = 'EX')
7415             THEN
7416                l_time_store_query := l_time || l_day || l_detail;
7417                l_inline_day := l_inline_day_ex;
7418             ELSIF (g_params.p_clusive = 'IN')
7419             THEN
7420                l_time_store_query := l_time || l_day || l_detail;
7421                l_inline_day := l_inline_day_in;
7422             ELSE
7423                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
7424                fnd_message.raise_error;
7425             END IF;
7426          ELSIF (g_params.p_scope = 'DETAIL')
7427          THEN
7428             IF (g_params.p_clusive = 'EX')
7429             THEN
7430                l_time_store_query := l_time || l_day || l_detail;
7431                l_inline_day := l_inline_day_ex;
7432             ELSIF (g_params.p_clusive = 'IN')
7433             THEN
7434                l_time_store_query := l_time || l_day || l_detail;
7435                l_inline_day := l_inline_day_in;
7436             ELSE
7437                fnd_message.set_name ('HXC', 'HXC_0014_GNRET_INVLD_P_CLUSIVE');
7438                fnd_message.raise_error;
7439             END IF;
7440          ELSE
7441             fnd_message.set_name ('HXC', 'HXC_0015_GNRET_INVLD_P_SCOPE');
7442             fnd_message.raise_error;
7443          END IF;
7444 
7445          IF (g_params.p_rerun_flag = 'N')
7446          THEN
7447             IF (g_params.p_incremental = 'Y')
7448             THEN
7449                IF (g_params.p_process IN
7450                             ('BEE Retrieval Process', 'Apply Schedule Rules')
7451                   )
7452                THEN
7453                   -- since the Transfer from OTL to BEE default where is a resource id filter
7454                   -- there is no need to include this in this query since it has already been
7455                   -- applied to populate the hxc retrieval range resource table
7456                   l_time_store_query :=
7457                         l_hint
7458                      || l_incremental_select
7459                      || l_incremental_from
7460                      || l_time_store_query
7461                      || l_not_exists
7462                      || l_latest_double_check
7463                      || l_order_by;
7464                ELSIF (g_params.p_process IN
7465                          ('Purchasing Retrieval Process',
7466                           'Projects Retrieval Process'
7467                          )
7468                      )
7469                THEN
7470                   -- Applications whose default where does not filter on person and LOOP
7471                   l_time_store_query :=
7472                         l_hint
7473                      || l_incremental_select
7474                      || l_incremental_from
7475                      || l_time_store_query
7476                      || p_where_clause_blk
7477                      || p_where_clause_att
7478                      || l_not_exists
7479                      || l_latest_double_check
7480                      || l_order_by;
7481                ELSIF (g_params.p_process IN ('Maintenance Retrieval Process')
7482                      )
7483                THEN
7484                   -- Applications which do not LOOP
7485                   l_time_store_query :=
7486                         l_hint
7487                      || l_incremental_select
7488                      || l_inline_view_range
7489                      || l_inline_day
7490                      || l_app_set
7491                      || p_where_clause_blk
7492                      || l_noloop_from
7493                      || l_time_store_query
7494                      || p_where_clause_att
7495                      || l_not_exists
7496                      || l_order_by;
7497                ELSE
7498                   fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7499                   fnd_message.set_token ('PROCEDURE', 'Integration catch');
7500                   fnd_message.set_token ('STEP', ': whereclause');
7501                   fnd_message.raise_error;
7502                END IF;
7503             ELSE
7504                l_time_store_query :=
7505                      l_select
7506                   || l_from
7507                   || l_time_store_query
7508                   || l_app_set
7509                   || p_where_clause_blk
7510                   || p_where_clause_att
7511                   || l_order_by;
7512             END IF;
7513          END IF;
7514 
7515          RETURN l_time_store_query;
7516       END build_query;
7517 
7518       FUNCTION check_concurrency_ok (
7519          p_process_id          NUMBER,
7520          p_retrieval_process   VARCHAR2,
7521          p_where_clause        VARCHAR2,
7522          p_unique_params       VARCHAR2
7523       )
7524          RETURN BOOLEAN
7525       IS
7526          CURSOR chk_transaction
7527          IS
7528             SELECT transaction_id
7529               FROM hxc_transactions tx
7530              WHERE transaction_process_id = p_process_id
7531                AND status = 'IN PROGRESS';
7532 
7533          CURSOR csr_chk_where_clause (
7534             p_transaction_id   NUMBER,
7535             p_where_clause     VARCHAR2,
7536             p_unique_params    VARCHAR2
7537          )
7538          IS
7539             SELECT 'x'
7540               FROM hxc_retrieval_ranges rr
7541              WHERE rr.transaction_id = p_transaction_id
7542                AND (   rr.where_clause = p_where_clause
7543                     OR (p_where_clause IS NULL AND rr.where_clause IS NULL)
7544                    )
7545                AND (   rr.unique_params = p_unique_params
7546                     OR (p_unique_params IS NULL AND rr.unique_params IS NULL
7547                        )
7548                    );
7549 
7550          CURSOR csr_chk_range_exists (p_transaction_id NUMBER)
7551          IS
7552             SELECT TO_CHAR (SYSDATE, 'HH24:MI:SS DD-MON-YY')
7553               FROM hxc_retrieval_ranges
7554              WHERE transaction_id = p_transaction_id;
7555 
7556          l_transaction_id   hxc_transactions.transaction_id%TYPE;
7557          l_bee_ok           VARCHAR2 (1);
7558          l_cnt              PLS_INTEGER                            := 0;
7559          l_no_ranges        BOOLEAN                                := TRUE;
7560          l_dummy            VARCHAR2 (20);
7561       BEGIN                                            -- check concurrency ok
7562          IF g_debug
7563          THEN
7564             hr_utility.TRACE (   'in check concurrency - process id is   '
7565                               || TO_CHAR (p_process_id)
7566                              );
7567             hr_utility.TRACE (   'in check concurrency - retrieval id is '
7568                               || p_retrieval_process
7569                              );
7570             hr_utility.TRACE (   'in check concurrency - where clause is '
7571                               || SUBSTR (p_where_clause, 1, 300)
7572                              );
7573          END IF;
7574 
7575          OPEN chk_transaction;
7576 
7577          FETCH chk_transaction
7578           INTO l_transaction_id;
7579 
7580          CLOSE chk_transaction;
7581 
7582 -- if another process is running check to see if the transfer batch size is
7583 -- set otherwise the processes will conflict
7584          IF g_debug
7585          THEN
7586             hr_utility.TRACE ('l running is ' || TO_CHAR (l_transaction_id));
7587          END IF;
7588 
7589          IF (p_retrieval_process = 'Projects Retrieval Process')
7590          THEN
7591             RETURN TRUE;
7592          END IF;
7593 
7594 -- check the unique params
7595          IF (    p_retrieval_process IN
7596                             ('Apply Schedule Rules', 'BEE Retrieval Process')
7597              AND l_transaction_id IS NOT NULL
7598             )
7599          THEN
7600             IF g_debug
7601             THEN
7602                hr_utility.TRACE ('Checking BEE');
7603             END IF;
7604 
7605             -- make sure that ranges have been inserted already by the IN PROGRESS
7606             -- process
7607             WHILE l_no_ranges
7608             LOOP
7609                IF g_debug
7610                THEN
7611                   hr_utility.TRACE ('looking for ranges');
7612                END IF;
7613 
7614                OPEN csr_chk_range_exists (l_transaction_id);
7615 
7616                FETCH csr_chk_range_exists
7617                 INTO l_dummy;
7618 
7619                IF (csr_chk_range_exists%NOTFOUND)
7620                THEN
7621                   IF g_debug
7622                   THEN
7623                      hr_utility.TRACE (   'No ranges yet for '
7624                                        || TO_CHAR (l_transaction_id)
7625                                       );
7626                   END IF;
7627 
7628                   l_cnt := l_cnt + 1;
7629 
7630                   IF (l_cnt > 100000)
7631                   THEN
7632                      fnd_message.set_name ('HXC', 'HXC_RET_NO_RANGES');
7633                      fnd_message.set_token ('TERM_TIME', l_dummy);
7634                      fnd_message.raise_error;
7635                   END IF;
7636                ELSE
7637                   IF g_debug
7638                   THEN
7639                      hr_utility.TRACE ('found ranges');
7640                   END IF;
7641 
7642                   l_no_ranges := FALSE;
7643                END IF;
7644 
7645                CLOSE csr_chk_range_exists;
7646             END LOOP;
7647 
7648             OPEN csr_chk_where_clause (p_transaction_id      => l_transaction_id,
7649                                        p_where_clause        => p_where_clause,
7650                                        p_unique_params       => p_unique_params
7651                                       );
7652 
7653             FETCH csr_chk_where_clause
7654              INTO l_bee_ok;
7655 
7656             CLOSE csr_chk_where_clause;
7657 
7658             IF g_debug
7659             THEN
7660                hr_utility.TRACE ('l bee ok is ' || l_bee_ok);
7661             END IF;
7662          END IF;
7663 
7664          IF (   (    l_transaction_id IS NOT NULL
7665                  AND p_retrieval_process NOT IN
7666                             ('Apply Schedule Rules', 'BEE Retrieval Process')
7667                 )
7668              OR (l_transaction_id IS NOT NULL AND l_bee_ok IS NULL)
7669             )
7670          THEN
7671             IF g_debug
7672             THEN
7673                hr_utility.TRACE ('FALSE');
7674             END IF;
7675 
7676             RETURN FALSE;
7677          ELSE
7678             IF g_debug
7679             THEN
7680                hr_utility.TRACE ('TRUE');
7681             END IF;
7682 
7683             RETURN TRUE;
7684          END IF;
7685       END check_concurrency_ok;
7686 
7687 -- private procedure
7688 --   chk_a_and_r_overlap
7689 --
7690 -- description
7691 --   Archive and Restore validation to check if the date params
7692 --   include any Archive and Restore period.
7693 --   Writes message to the log
7694 --
7695 -- parameters
7696 --   p_start_date, p_end_date
7697       PROCEDURE check_a_and_r_overlap (p_start_date DATE, p_end_date DATE)
7698       IS
7699          CURSOR chk_a_and_r_overlap (p_start_date DATE, p_end_date DATE)
7700          IS
7701             SELECT 'x'
7702               FROM hxc_data_sets hds
7703              WHERE hds.start_date <= p_end_date
7704                AND hds.end_date >= p_start_date
7705                AND hds.status IN
7706                       ('OFF_LINE', 'RESTORE_IN_PROGRESS',
7707                        'BACKUP_IN_PROGRESS');
7708 
7709          l_message_text   VARCHAR2 (2000);
7710          l_start_date     DATE := NVL (p_start_date, hr_general.start_of_time);
7711          l_end_date       DATE     := NVL (p_end_date, hr_general.end_of_time);
7712       BEGIN
7713          IF g_debug
7714          THEN
7715             hr_utility.TRACE ('Entering chk_a_and_r_overlap');
7716          END IF;
7717 
7718          OPEN chk_a_and_r_overlap (l_start_date, l_end_date);
7719 
7720          FETCH chk_a_and_r_overlap
7721           INTO l_message_text;
7722 
7723          IF (chk_a_and_r_overlap%FOUND)
7724          THEN
7725             fnd_message.set_name ('HXC', 'HXC_RET_ARCHIVE_DATA');
7726             l_message_text := SUBSTR (fnd_message.get (), 1, 2000);
7727             -- Bug 9173209
7728             -- Retrieval Log adjustment
7729             fnd_file.put_line (fnd_file.LOG,'  '||l_message_text);
7730          END IF;
7731 
7732          CLOSE chk_a_and_r_overlap;
7733 
7734          IF g_debug
7735          THEN
7736             hr_utility.TRACE ('Leaving chk_a_and_r_overlap');
7737          END IF;
7738       END check_a_and_r_overlap;
7739 
7740 -- private procedure
7741 --   get_field_mappings
7742 --
7743 -- description
7744 --   Retrieves the mapping components for a given mapping_id
7745 --   and populates the Global PL/SQL table g_field_mappings
7746 --   table
7747 --
7748 -- parameters
7749 --   p_mapping_id   - mapping_id
7750       FUNCTION get_field_mappings (p_mapping_id hxc_mappings.mapping_id%TYPE)
7751          RETURN t_field_mappings
7752       IS
7753 --
7754          l_mapping_record   r_field_mappings;
7755          l_mappings_table   t_field_mappings;
7756 
7757 --
7758          CURSOR csr_get_mappings
7759          IS
7760             SELECT   mpc.bld_blk_info_type_id, UPPER (mpc.field_name),
7761                      mpc.SEGMENT, bbit.bld_blk_info_type CONTEXT,
7762                      bbitu.building_block_category CATEGORY
7763                 FROM hxc_bld_blk_info_type_usages bbitu,
7764                      hxc_bld_blk_info_types bbit,
7765                      hxc_mapping_components mpc,
7766                      hxc_mapping_comp_usages mcu,
7767                      hxc_mappings MAP
7768                WHERE MAP.mapping_id = p_mapping_id
7769                  AND mcu.mapping_id = MAP.mapping_id
7770                  AND mpc.mapping_component_id = mcu.mapping_component_id
7771                  AND bbit.bld_blk_info_type_id = mpc.bld_blk_info_type_id
7772                  AND bbitu.bld_blk_info_type_id = bbit.bld_blk_info_type_id
7773             ORDER BY 1, 2, 3;
7774 
7775          l_table_index      NUMBER           := 0;
7776          l_proc             VARCHAR2 (72);
7777       BEGIN                                              -- get field mappings
7778          IF g_debug
7779          THEN
7780             l_proc := g_package || 'get_field_mappings';
7781             hr_utility.set_location ('Entering ' || l_proc, 10);
7782          END IF;
7783 
7784          OPEN csr_get_mappings;
7785 
7786          FETCH csr_get_mappings
7787           INTO l_mapping_record;
7788 
7789          IF csr_get_mappings%NOTFOUND
7790          THEN
7791             fnd_message.set_name ('HXC', 'HXC_0016_GNRET_NO_MAPPINGS');
7792             fnd_message.raise_error;
7793 
7794             CLOSE csr_get_mappings;
7795          END IF;
7796 
7797          LOOP
7798             IF g_debug
7799             THEN
7800                hr_utility.set_location ('Processing ' || l_proc, 20);
7801             END IF;
7802 
7803             l_table_index := l_table_index + 1;
7804             l_mappings_table (l_table_index) := l_mapping_record;
7805 
7806             FETCH csr_get_mappings
7807              INTO l_mapping_record;
7808 
7809             EXIT WHEN csr_get_mappings%NOTFOUND;
7810          END LOOP;
7811 
7812          CLOSE csr_get_mappings;
7813 
7814          IF g_debug
7815          THEN
7816             hr_utility.set_location ('Leaving ' || l_proc, 30);
7817          END IF;
7818 
7819          RETURN l_mappings_table;
7820       END get_field_mappings;
7821 
7822       PROCEDURE maintain_globals
7823       IS
7824       BEGIN
7825          g_conc_request_id := fnd_profile.VALUE ('CONC_REQUEST_ID');
7826 
7827          IF g_debug
7828          THEN
7829             hr_utility.TRACE ('Conc Req ID is ' || TO_CHAR (g_conc_request_id)
7830                              );
7831          END IF;
7832 
7833          -- Bug 9173209
7834          -- Retrieval Log adjustment
7835          fnd_file.put_line (fnd_file.LOG,
7836                             '  Conc Req ID is '
7837                             || TO_CHAR (g_conc_request_id)
7838                            );
7839 
7840          g_params.p_process := NULL;
7841          g_params.p_transaction_code := NULL;
7842          g_params.p_incremental := NULL;
7843          g_params.p_rerun_flag := NULL;
7844          g_params.p_where_clause := NULL;
7845          g_params.p_scope := NULL;
7846          g_params.p_clusive := NULL;
7847          g_params.p_unique_params := NULL;
7848          g_transaction_id := NULL;
7849          hxc_generic_retrieval_pkg.t_detail_bld_blks.DELETE;
7850          hxc_generic_retrieval_pkg.t_old_detail_bld_blks.DELETE;
7851          hxc_generic_retrieval_pkg.t_detail_attributes.DELETE;
7852          hxc_generic_retrieval_pkg.t_old_detail_attributes.DELETE;
7853          hxc_generic_retrieval_pkg.t_time_bld_blks.DELETE;
7854          t_old_detail_seq.DELETE;
7855          t_old_detail_bb_id.DELETE;
7856          t_old_detail_ovn.DELETE;
7857          hxc_generic_retrieval_pkg.t_tx_time_bb_id.DELETE;
7858          hxc_generic_retrieval_pkg.t_tx_time_bb_ovn.DELETE;
7859          hxc_generic_retrieval_pkg.t_tx_time_transaction_id.DELETE;
7860          hxc_generic_retrieval_pkg.t_tx_time_status.DELETE;
7861          hxc_generic_retrieval_pkg.t_tx_time_exception.DELETE;
7862          hxc_generic_retrieval_pkg.t_tx_day_bb_id.DELETE;
7863          hxc_generic_retrieval_pkg.t_tx_day_parent_id.DELETE;
7864          hxc_generic_retrieval_pkg.t_tx_day_bb_ovn.DELETE;
7865          hxc_generic_retrieval_pkg.t_tx_day_transaction_id.DELETE;
7866          hxc_generic_retrieval_pkg.t_tx_day_status.DELETE;
7867          hxc_generic_retrieval_pkg.t_tx_day_exception.DELETE;
7868          hxc_generic_retrieval_pkg.t_tx_detail_bb_id.DELETE;
7869          hxc_generic_retrieval_pkg.t_tx_detail_parent_id.DELETE;
7870          hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn.DELETE;
7871          hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.DELETE;
7872          hxc_generic_retrieval_pkg.t_tx_detail_status.DELETE;
7873          hxc_generic_retrieval_pkg.t_tx_detail_exception.DELETE;
7874          -- Bug 9494444
7875          -- Added some new global tables, so deleting those also
7876          -- here.
7877          hxc_generic_retrieval_pkg.t_detail_rec_lines.DELETE;
7878          hxc_generic_retrieval_pkg.t_old_detail_rec_lines.DELETE;
7879          hxc_generic_retrieval_pkg.g_old_bb_ids.DELETE;
7880          hxc_generic_retrieval_pkg.t_bb.DELETE;
7881          hxc_generic_retrieval_pkg.g_no_timecards := TRUE;
7882          hxc_generic_retrieval_utils.g_resources.DELETE;
7883 
7884 	 -- Bug 7595581
7885 	 -- Retrieval Log
7886 
7887 	 hxc_generic_retrieval_pkg.g_detail_skipped.DELETE;
7888 
7889          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
7890          THEN
7891             g_retrieval_process_id := NULL;
7892             g_retrieval_tr_id := NULL;
7893             g_field_mappings_table.DELETE;
7894          END IF;
7895       END maintain_globals;
7896 
7897 -- private function get_valid_app_sets
7898 -- (added for ELP related changes to the retrieval process 14-Mar-2003 sonarasi)
7899 --
7900 -- description
7901 -- This function is used to return a string of valid application set ids for a given
7902 -- time recipient. If the process is 'Apply Schedule Rules' or 'BEE Retrieval Process'
7903 -- then we have an additional requirement. i,e the list of application set ids for
7904 -- hr time recipient needs to be added to the list.
7905 -- Parameters
7906 --  p_retrieval_process : The Retrieval Process Name
7907 --  p_retrieval_tr_id   : The time recipient id of the application.
7908       FUNCTION get_valid_app_sets (
7909          p_retrieval_process   hxc_retrieval_processes.NAME%TYPE,
7910          p_retrieval_tr_id     NUMBER
7911       )
7912          RETURN VARCHAR2
7913       IS
7914          CURSOR c_application_set_id (
7915             p_ret_tr_id_1   NUMBER,
7916             p_ret_tr_id_2   NUMBER
7917          )
7918          IS
7919             SELECT DISTINCT application_set_id
7920                        FROM hxc_application_set_comps_v
7921                       WHERE time_recipient_id IN
7922                                               (p_ret_tr_id_1, p_ret_tr_id_2);
7923 
7924          CURSOR csr_get_tr_id (p_application_id NUMBER)
7925          IS
7926             SELECT tr.time_recipient_id
7927               FROM hxc_time_recipients tr
7928              WHERE tr.application_id = p_application_id;
7929 
7930          l_application_set_id_string   VARCHAR2 (200)                   := '';
7931          l_ret_tr_id                   NUMBER            := p_retrieval_tr_id;
7932          l_hr_tr                       hxc_time_recipients.time_recipient_id%TYPE;
7933          l_ret_tr_id_1                 NUMBER            := p_retrieval_tr_id;
7934          l_ret_tr_id_2                 NUMBER                         := NULL;
7935       BEGIN
7936 -- if the process is BEE retrieval process then we need to add the application set ids of
7937 -- corresponding to hr time recipient id also.
7938          IF (p_retrieval_process IN
7939                             ('Apply Schedule Rules', 'BEE Retrieval Process')
7940             )
7941          THEN
7942             OPEN csr_get_tr_id (800);
7943 
7944             FETCH csr_get_tr_id
7945              INTO l_hr_tr;
7946 
7947             IF (csr_get_tr_id%NOTFOUND)
7948             THEN
7949                CLOSE csr_get_tr_id;
7950 
7951                fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
7952                fnd_message.set_token ('PROCEDURE', l_proc);
7953                fnd_message.set_token ('STEP', 'no HR Time Recipient ID');
7954                fnd_message.raise_error;
7955             END IF;
7956 
7957             CLOSE csr_get_tr_id;
7958 
7959             l_ret_tr_id_2 := l_hr_tr;
7960          END IF;
7961 
7962          FOR l_rec IN c_application_set_id (l_ret_tr_id_1, l_ret_tr_id_2)
7963          LOOP
7964             l_application_set_id_string :=
7965                l_application_set_id_string || ',' || l_rec.application_set_id;
7966          END LOOP;
7967 
7968          l_application_set_id_string :=
7969                ' AND
7970 tbb_latest.application_set_id IN ('
7971             || SUBSTR (l_application_set_id_string, 2)
7972             || ')';
7973          RETURN l_application_set_id_string;
7974       END get_valid_app_sets;
7975    BEGIN                                          -- execute retrieval process
7976 -- this is to handle the case where the OTLR and BEE are processed in
7977 -- the loop
7978       g_debug := hr_utility.debug_enabled;
7979 
7980       IF (    g_params.p_process <> p_process
7981           AND hxc_generic_retrieval_pkg.g_in_loop
7982          )
7983       THEN
7984          -- reset global looping variables
7985          hxc_generic_retrieval_pkg.g_in_loop := FALSE;
7986          hxc_generic_retrieval_pkg.g_last_chunk := FALSE;
7987          hxc_generic_retrieval_pkg.g_no_timecards := TRUE;
7988          hxc_generic_retrieval_pkg.g_overall_no_timecards := TRUE;
7989       END IF;
7990 
7991       -- Bug 9173209
7992       -- Retrieval Log adjustment
7993       put_log('  ');
7994       put_log('  ');
7995       fnd_file.put_line (fnd_file.LOG,
7996                             fnd_date.date_to_canonical (SYSDATE)
7997                          || ' ******** OTL Processing Starts ******'
7998                         );
7999       put_log('##------------------------------------------------------## ');
8000       put_log(' Retrieval Process: '||UPPER(p_process));
8001       put_log('##------------------------------------------------------## ');
8002 
8003       -- Bug 9394444
8004       -- Added the following comments for the Retrieval Log
8005       put_log(' ');
8006       put_log(' ');
8007 
8008       IF p_process = 'Projects Retrieval Process'
8009        AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PA')
8010        AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
8011       THEN
8012           put_log('Process is running on Upgraded Mode ');
8013       ELSIF p_process IN ('BEE Retrieval Process','Apply Schedule Rules')
8014         AND hxc_upgrade_pkg.performance_upgrade_complete('RETRIEVAL_PAY')
8015         AND NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
8016       THEN
8017           put_log('Process is running on Upgraded Mode ');
8018       ELSIF NVL(FND_PROFILE.VALUE('HXC_USE_UPGRADED_RETRIEVAL_PROCESS'),'N') = 'Y'
8019       THEN
8020           put_log('Process is not running on Upgraded Mode because one or more ');
8021           put_log('Upgrade processes are not complete.  ');
8022       END IF;
8023 
8024       put_log(' ');
8025       put_log(' ');
8026 
8027       maintain_globals;
8028 
8029       IF (    hxc_generic_retrieval_pkg.g_in_loop
8030           AND hxc_generic_retrieval_pkg.g_last_chunk
8031          )
8032       THEN
8033          -- do nothing, this is the last iteration, we are in a loop and the last chunk
8034          -- has already been processed
8035          NULL;
8036       ELSE
8037          g_params.p_process := p_process;
8038          g_params.p_transaction_code := p_transaction_code;
8039          g_params.p_incremental := p_incremental;
8040          g_params.p_rerun_flag := p_rerun_flag;
8041          g_params.p_where_clause := p_where_clause;
8042          g_params.p_scope := p_scope;
8043          g_params.p_clusive := p_clusive;
8044          g_params.p_unique_params := p_unique_params;
8045          g_params.transfer_batch_size :=
8046                                fnd_profile.VALUE ('HXC_RETRIEVAL_BATCH_SIZE');
8047          g_params.retrieval_options :=
8048                     NVL (fnd_profile.VALUE ('HXC_RETRIEVAL_OPTIONS'), 'BOTH');
8049 
8050          IF (p_since_date IS NULL)
8051          THEN
8052             -- then get value from the profile option
8053             l_since_date :=
8054                NVL (SUBSTR (fnd_profile.VALUE ('HXC_RETRIEVAL_CHANGES_DATE'),
8055                             1,
8056                             3
8057                            ),
8058                     60
8059                    );
8060 
8061             BEGIN
8062                SELECT TO_NUMBER (l_since_date)
8063                  INTO l_since_date
8064                  FROM DUAL;
8065             EXCEPTION
8066                WHEN OTHERS
8067                THEN
8068                   l_since_date := 60;
8069             END;
8070 
8071             g_params.since_date := SYSDATE - TO_NUMBER (l_since_date);
8072          ELSE
8073             g_params.since_date :=
8074                               TO_DATE (p_since_date, 'RRRR/MM/DD HH24:MI:SS');
8075          END IF;
8076 
8077          IF g_debug
8078          THEN
8079             hr_utility.TRACE (   'final since date is '
8080                               || TO_CHAR (g_params.since_date,
8081                                           'hh24:mi:ss dd-mon-yy'
8082                                          )
8083                              );
8084          END IF;
8085 
8086          IF (p_start_date IS NOT NULL AND p_end_date IS NOT NULL)
8087          THEN
8088             g_params.p_start_date := TRUNC (p_start_date);
8089             g_params.p_end_date :=
8090                TO_DATE (   TO_CHAR (TRUNC (p_end_date), 'DD/MM/YYYY')
8091                         || ' 23:59:59',
8092                         'DD/MM/YYYY HH24:MI:SS'
8093                        );
8094             g_params.l_using_dates := TRUE;
8095          ELSIF (p_start_date IS NOT NULL AND p_end_date IS NULL)
8096          THEN
8097             g_params.p_start_date := TRUNC (p_start_date);
8098             g_params.p_end_date :=
8099                TO_DATE (   TO_CHAR (TRUNC (hr_general.end_of_time),
8100                                     'DD/MM/YYYY'
8101                                    )
8102                         || ' 23:59:59',
8103                         'DD/MM/YYYY HH24:MI:SS'
8104                        );
8105             g_params.l_using_dates := TRUE;
8106          ELSIF (p_start_date IS NULL AND p_end_date IS NOT NULL)
8107          THEN
8108             g_params.p_start_date := hr_general.start_of_time;
8109             g_params.p_end_date :=
8110                TO_DATE (   TO_CHAR (TRUNC (p_end_date), 'DD/MM/YYYY')
8111                         || ' 23:59:59',
8112                         'DD/MM/YYYY HH24:MI:SS'
8113                        );
8114             g_params.l_using_dates := TRUE;
8115          ELSE
8116             g_params.p_start_date := NULL;
8117             g_params.p_end_date := NULL;
8118             g_params.l_using_dates := FALSE;
8119          END IF;
8120 
8121 -- check archived and restore over lap
8122          IF (    (NOT hxc_generic_retrieval_pkg.g_in_loop)
8123              AND (   (    g_params.retrieval_options = 'BOTH'
8124                       AND NOT g_params.p_process = 'BEE Retrieval Process'
8125                      )
8126                   OR (    g_params.retrieval_options = 'BEE'
8127                       AND g_params.p_process = 'BEE Retrieval Process'
8128                      )
8129                   OR (    g_params.retrieval_options = 'OTLR'
8130                       AND g_params.p_process = 'Apply Schedule Rules'
8131                      )
8132                   OR (g_params.p_process NOT IN
8133                             ('BEE Retrieval Process', 'Apply Schedule Rules')
8134                      )
8135                  )
8136             )
8137          THEN
8138             -- only want to do this once for the first loop since the params
8139             -- do not change for each loop and once for the Transfer Time from OTL to BEE
8140             check_a_and_r_overlap (g_params.p_start_date,
8141                                    g_params.p_end_date);
8142          END IF;
8143 
8144 -- check to see if we want to turn trace on
8145          OPEN csr_debug;
8146 
8147          FETCH csr_debug
8148           INTO l_debug;
8149 
8150          CLOSE csr_debug;
8151 
8152          IF l_debug = 'Y'
8153          THEN
8154             glb_debug := TRUE;
8155 
8156             IF g_debug
8157             THEN
8158                hr_utility.trace_on
8159                               (trace_mode              => NULL,
8160                                session_identifier      => NVL
8161                                                              (p_transaction_code,
8162                                                               'RETRIEVAL'
8163                                                              )
8164                               );
8165             END IF;
8166          END IF;
8167 
8168          IF g_debug
8169          THEN
8170             hr_utility.set_location ('Entering ' || l_proc, 10);
8171          END IF;
8172 
8173          IF (   g_params.p_transaction_code LIKE 'GAZ%'
8174              OR g_params.p_transaction_code IS NULL
8175             )
8176          THEN
8177             NULL;
8178 --l_alter_session := 'alter session set sql_trace TRUE';
8179 
8180          --execute immediate l_alter_session;
8181          END IF;
8182 
8183          IF g_debug
8184          THEN
8185             hr_utility.TRACE ('****  Retrieval Params are.... ****');
8186             hr_utility.TRACE ('');
8187             hr_utility.TRACE ('Process is          :' || g_params.p_process);
8188             hr_utility.TRACE (   'Transaction code is :'
8189                               || g_params.p_transaction_code
8190                              );
8191             hr_utility.TRACE ('Start Date is       :' || g_params.p_start_date);
8192             hr_utility.TRACE ('End Date is         :' || g_params.p_end_date);
8193             hr_utility.TRACE ('Incremental is      :'
8194                               || g_params.p_incremental
8195                              );
8196             hr_utility.TRACE ('Rerun Flag is       :' || g_params.p_rerun_flag);
8197             hr_utility.TRACE (   'Where Clause is     :'
8198                               || SUBSTR (g_params.p_where_clause, 1, 200)
8199                              );
8200             hr_utility.TRACE (SUBSTR (g_params.p_where_clause, 201, 200));
8201             hr_utility.TRACE (SUBSTR (g_params.p_where_clause, 401, 200));
8202             hr_utility.TRACE ('Scope is            :' || g_params.p_scope);
8203             hr_utility.TRACE ('Clusive is          :' || g_params.p_clusive);
8204             hr_utility.TRACE ('');
8205             hr_utility.TRACE ('****  Retrieval LOOPING GLOBALS are.... ****');
8206          END IF;
8207 
8208          IF (g_in_loop)
8209          THEN
8210             IF g_debug
8211             THEN
8212                hr_utility.TRACE ('G_IN_LOOP is TRUE');
8213             END IF;
8214          ELSE
8215             IF g_debug
8216             THEN
8217                hr_utility.TRACE ('G_IN_LOOP is FALSE');
8218             END IF;
8219          END IF;
8220 
8221          IF (g_last_chunk)
8222          THEN
8223             IF g_debug
8224             THEN
8225                hr_utility.TRACE ('G_LAST_CHUNK is TRUE');
8226             END IF;
8227          ELSE
8228             IF g_debug
8229             THEN
8230                hr_utility.TRACE ('G_LAST_CHUNK is FALSE');
8231             END IF;
8232          END IF;
8233 
8234          IF (g_no_timecards)
8235          THEN
8236             IF g_debug
8237             THEN
8238                hr_utility.TRACE ('G_NO_TIMECARDS is TRUE');
8239             END IF;
8240          ELSE
8241             IF g_debug
8242             THEN
8243                hr_utility.TRACE ('G_NO_TIMECARDS is FALSE');
8244             END IF;
8245          END IF;
8246 
8247          IF (g_overall_no_timecards)
8248          THEN
8249             IF g_debug
8250             THEN
8251                hr_utility.TRACE ('G_OVERALL_NO_TIMECARDS is TRUE');
8252             END IF;
8253          ELSE
8254             IF g_debug
8255             THEN
8256                hr_utility.TRACE ('G_OVERALL_NO_TIMECARDS is FALSE');
8257             END IF;
8258          END IF;
8259 
8260          IF g_debug
8261          THEN
8262             hr_utility.TRACE (   'l_range_start is '
8263                               || TO_CHAR (l_pkg_range_start)
8264                              );
8265             hr_utility.TRACE ('l_range_stop is ' || TO_CHAR (l_pkg_range_stop));
8266          END IF;
8267 
8268          IF (NOT hxc_generic_retrieval_pkg.g_in_loop)
8269          THEN
8270             -- check that the process is registered and return the mapping id
8271             -- and retrieval_process id
8272             chk_retrieval_process
8273                            (p_retrieval_process         => p_process,
8274                             p_retrieval_process_id      => g_retrieval_process_id,
8275                             p_retrieval_tr_id           => g_retrieval_tr_id,
8276                             p_mapping_id                => l_mapping_id
8277                            );
8278 
8279             IF g_debug
8280             THEN
8281                hr_utility.set_location ('Processing ' || l_proc, 20);
8282             END IF;
8283 
8284             -- check to see if mapping_id exists and thus retrieval process registered
8285             IF (l_mapping_id IS NULL)
8286             THEN
8287                RAISE e_retrieval_not_registered;
8288             END IF;
8289 
8290 -- now check to see if this retrieval is already running
8291 -- only need to do this if NOT the 'Projects Retrieval Process'
8292             IF g_debug
8293             THEN
8294                hr_utility.set_location ('Processing ' || l_proc, 30);
8295             END IF;
8296 
8297             IF (g_params.p_process = 'Apply Schedule Rules')
8298             THEN
8299                SELECT rp.retrieval_process_id
8300                  INTO l_ret_id
8301                  FROM hxc_retrieval_processes rp
8302                 WHERE rp.NAME = 'BEE Retrieval Process';
8303 
8304                -- check to see that the last retrieval completed normally
8305                hxc_generic_retrieval_utils.RECOVERY
8306                                       (p_process_id      => g_retrieval_process_id,
8307                                        p_process         => p_process
8308                                       );
8309 
8310                IF NOT check_concurrency_ok
8311                                   (p_process_id             => g_retrieval_process_id,
8312                                    p_retrieval_process      => g_params.p_process,
8313                                    p_where_clause           => g_params.p_where_clause,
8314                                    p_unique_params          => g_params.p_unique_params
8315                                   )
8316                THEN
8317                   RAISE e_process_already_running;
8318                END IF;
8319 
8320                IF (g_params.retrieval_options = 'BOTH')
8321                THEN
8322                   hxc_generic_retrieval_utils.RECOVERY
8323                                         (p_process_id      => l_ret_id,
8324                                          p_process         => 'BEE Retrieval Process'
8325                                         );
8326 
8327                   -- check that the BEE Retrieval isn't also running
8328                   IF NOT check_concurrency_ok
8329                               (p_process_id             => l_ret_id,
8330                                p_retrieval_process      => 'BEE Retrieval Process',
8331                                p_where_clause           => g_params.p_where_clause,
8332                                p_unique_params          => g_params.p_unique_params
8333                               )
8334                   THEN
8335                      RAISE e_process_already_running;
8336                   END IF;
8337                END IF;
8338             ELSIF (g_params.p_process = 'BEE Retrieval Process')
8339             THEN
8340                -- check the HXC_RETRIEVAL_OPTIONS profile value
8341                IF (g_params.retrieval_options = 'BEE')
8342                THEN
8343                   -- Apply Schedule Rules was not called
8344                   hxc_generic_retrieval_utils.RECOVERY
8345                                      (p_process_id      => g_retrieval_process_id,
8346                                       p_process         => p_process
8347                                      );
8348 
8349                   IF NOT check_concurrency_ok
8350                                   (p_process_id             => g_retrieval_process_id,
8351                                    p_retrieval_process      => g_params.p_process,
8352                                    p_where_clause           => g_params.p_where_clause,
8353                                    p_unique_params          => g_params.p_unique_params
8354                                   )
8355                   THEN
8356                      RAISE e_process_already_running;
8357                   END IF;
8358                ELSE
8359                   -- we have already checked the BEE Retrieval when the process
8360                   -- started and cleaned up if appropriate
8361                   NULL;
8362                END IF;
8363             ELSE
8364                hxc_generic_retrieval_utils.RECOVERY
8365                                      (p_process_id      => g_retrieval_process_id,
8366                                       p_process         => p_process
8367                                      );
8368 
8369                IF NOT check_concurrency_ok
8370                                   (p_process_id             => g_retrieval_process_id,
8371                                    p_retrieval_process      => g_params.p_process,
8372                                    p_where_clause           => g_params.p_where_clause,
8373                                    p_unique_params          => g_params.p_unique_params
8374                                   )
8375                THEN
8376                   RAISE e_process_already_running;
8377                END IF;
8378             END IF;
8379          END IF;     -- IF ( NOT hxc_generic_retrieval_process_pkg.G_IN_LOOP )
8380 
8381 -- audit the transaction (header)
8382          audit_transaction
8383                           (p_mode                        => 'I'      -- Insert
8384                                                                ,
8385                            p_transaction_process_id      => g_retrieval_process_id,
8386                            p_status                      => 'IN PROGRESS',
8387                            p_description                 => ''
8388                           );
8389 
8390          IF g_debug
8391          THEN
8392             hr_utility.set_location ('Processing ' || l_proc, 40);
8393          END IF;
8394 
8395          IF NOT hxc_generic_retrieval_pkg.g_in_loop
8396          THEN
8397 --Elp changes sonarasi 14-Mar-2003
8398 --Now that we have the time recipient id, let us find out the application set id string.
8399 --We call the get_valid_app_sets function to get the application set id string
8400 --However we do a check here to see if the application set id string has already been
8401 --obtained..Only if it is not obtained do we hit the database to find it.
8402 --Note : g_app_set_id_string is indexed on g_retrieval_tr_id
8403             IF NOT (g_app_set_id_string.EXISTS (g_retrieval_tr_id))
8404             THEN
8405                g_app_set_id_string (g_retrieval_tr_id).app_set_id_string :=
8406                   get_valid_app_sets (p_retrieval_process      => p_process,
8407                                       p_retrieval_tr_id        => g_retrieval_tr_id
8408                                      );
8409             END IF;
8410 
8411 --Elp changes sonarasi over
8412 
8413             --  get the field mappings associated with the mapping id
8414 --  This populates the global table g_field_mappings_table
8415             g_field_mappings_table :=
8416                              get_field_mappings (p_mapping_id      => l_mapping_id);
8417          END IF;                    -- NOT hxc_generic_retrieval_pkg.G_IN_LOOP
8418 
8419 -- parse the where clause and build the final query for execution
8420          l_where_clause_blk := LTRIM (RTRIM (p_where_clause));
8421          l_where_clause_att := LTRIM (RTRIM (p_where_clause));
8422          parse_it (p_where_clause_blk      => l_where_clause_blk,
8423                    p_where_clause_att      => l_where_clause_att
8424                   );
8425          l_where_clause_blk := replace_timecard_string (l_where_clause_blk);
8426 
8427          IF g_debug
8428          THEN
8429             hr_utility.set_location ('Processing ' || l_proc, 60);
8430          END IF;
8431 
8432          l_dynamic_query :=
8433             build_query (p_where_clause_blk      => l_where_clause_blk,
8434                          p_where_clause_att      => l_where_clause_att
8435                         );
8436 
8437          IF g_debug
8438          THEN
8439             hr_utility.set_location ('Processing ' || l_proc, 70);
8440          END IF;
8441 
8442 -- lets see the query
8443          insert_query (l_dynamic_query, 'QUERY');
8444          maintain_chunks (p_where_clause => p_where_clause);
8445          populate_ret_range_blks;
8446          populate_max_ovn (p_where_clause => p_where_clause);
8447 
8448 -- get the bulding blocks
8449 -- execute the query, populate the tables
8450          IF (hxc_generic_retrieval_pkg.g_in_loop)
8451          THEN
8452             IF g_debug
8453             THEN
8454                hr_utility.set_location ('Processing ' || l_proc, 71);
8455             END IF;
8456 
8457             WHILE (hxc_generic_retrieval_pkg.g_no_timecards)
8458             LOOP
8459                IF g_debug
8460                THEN
8461                   hr_utility.set_location ('Processing ' || l_proc, 72);
8462                END IF;
8463 
8464                BEGIN
8465                   query_it (p_query => l_dynamic_query);
8466                EXCEPTION
8467                   WHEN OTHERS
8468                   THEN
8469                      -- Bug 9394444
8470                      hr_utility.trace(dbms_utility.format_error_backtrace);
8471                      IF g_debug
8472                      THEN
8473                         hr_utility.TRACE (   'query EXCEPTION is '
8474                                           || SUBSTR (SQLERRM, 1, 60)
8475                                          );
8476                         hr_utility.TRACE (   'query EXCEPTION is '
8477                                           || SUBSTR (SQLERRM, 61, 120)
8478                                          );
8479                         hr_utility.TRACE (   'query EXCEPTION is '
8480                                           || SUBSTR (SQLERRM, 121, 180)
8481                                          );
8482                         hr_utility.TRACE (   'query EXCEPTION is '
8483                                           || SUBSTR (SQLERRM, 181, 240)
8484                                          );
8485                      END IF;
8486 
8487                      IF (    (   SQLERRM LIKE
8488                                       'ORA-20001: HXC_0013_GNRET_NO_BLD_BLKS%'
8489                               OR SQLERRM LIKE
8490                                      'ORA-20001: HXC_0012_GNRET_NO_TIMECARDS%'
8491                              )
8492                          AND (NOT hxc_generic_retrieval_pkg.g_last_chunk)
8493                         )
8494                      THEN
8495                         IF g_debug
8496                         THEN
8497                            hr_utility.set_location ('Processing ' || l_proc,
8498                                                     73
8499                                                    );
8500                         END IF;
8501 
8502                         -- Bug 8888911
8503                         -- Mark the exception to the log.
8504                         put_log('  ==================================================================================');
8505                         put_log('   There are no valid records for this set of resources to the recipient application');
8506                         put_log('  ===================================================================================');
8507                         IF g_detail_skipped.COUNT > 0
8508                         THEN
8509                             put_log('  ---- The following records were considered and are skipped for the below reason ----  ');
8510                         END IF;
8511 
8512                         maintain_chunks (p_where_clause => p_where_clause);
8513                         populate_ret_range_blks;
8514                         populate_max_ovn (p_where_clause => p_where_clause);
8515                      ELSIF (   SQLERRM LIKE
8516                                       'ORA-20001: HXC_0013_GNRET_NO_BLD_BLKS%'
8517                             OR SQLERRM LIKE
8518                                      'ORA-20001: HXC_0012_GNRET_NO_TIMECARDS%'
8519                            )
8520                      THEN
8521                         IF g_debug
8522                         THEN
8523                            hr_utility.set_location ('Processing ' || l_proc,
8524                                                     74
8525                                                    );
8526                         END IF;
8527 
8528                         IF (hxc_generic_retrieval_pkg.g_overall_no_timecards
8529                            )
8530                         THEN
8531                            IF g_debug
8532                            THEN
8533                               hr_utility.set_location ('Processing ' || l_proc,
8534                                                        75
8535                                                       );
8536                            END IF;
8537 
8538                            -- this is the last chunk and there have been no timecards
8539                            fnd_message.raise_error;
8540                            -- GPM v115.41
8541                            EXIT;
8542                         ELSE
8543                            -- last chunk and there were timecards but just not in this
8544                            -- this iteration
8545                            EXIT;
8546                         END IF;
8547                      ELSE
8548                         IF g_debug
8549                         THEN
8550                            hr_utility.set_location ('Processing ' || l_proc,
8551                                                     76
8552                                                    );
8553                         END IF;
8554 
8555                         audit_transaction
8556                            (p_mode                        => 'I'     -- Insert
8557                                                                 ,
8558                             p_transaction_process_id      => g_retrieval_process_id,
8559                             p_status                      => 'ERRORS',
8560                             p_description                 => SUBSTR (SQLERRM,
8561                                                                      1,
8562                                                                      2000
8563                                                                     )
8564                            );
8565                         RAISE;
8566                      END IF;
8567                END;
8568             END LOOP;
8569          ELSE
8570             IF g_debug
8571             THEN
8572                hr_utility.set_location ('Processing ' || l_proc, 77);
8573             END IF;
8574 
8575             query_it (p_query => l_dynamic_query);
8576          END IF;
8577 
8578          IF g_debug
8579          THEN
8580             hr_utility.set_location ('Processing ' || l_proc, 80);
8581          END IF;
8582 
8583          IF (NOT hxc_generic_retrieval_pkg.g_last_chunk)
8584          THEN
8585             IF (g_params.p_incremental = 'Y')
8586             THEN
8587                query_old_timecard;
8588             END IF;
8589          END IF;          -- IF ( NOT hxc_generic_retrieval_pkg.G_LAST_CHUNK )
8590 
8591          IF g_debug
8592          THEN
8593             hr_utility.set_location ('Processing ' || l_proc, 100);
8594          END IF;
8595       END IF;
8596 
8597 -- ( hxc_generic_retrieval_pkg.G_IN_LOOP AND hxc_generic_retrieval_pkg.G_LAST_CHUNK );
8598 
8599       -- before we pass control to the recipient application check to make sure the conc
8600 -- process has not been terminated
8601 
8602       -- Bug 9173209
8603       -- Retrieval Log adjustment
8604       fnd_file.put_line (fnd_file.LOG,
8605                             '  '||fnd_date.date_to_canonical (SYSDATE)
8606                          || ' > SKIPPED Blocks COUNT > '
8607                          || hxc_generic_retrieval_pkg.g_detail_skipped.COUNT
8608                         );
8609 
8610       IF (hxc_generic_retrieval_pkg.g_detail_skipped.COUNT > 0)
8611       THEN
8612 
8613            -- Bug 9458888
8614            -- Used for Retrieval Dashboard Process Tab
8615            l_skipped_tc_id := VARCHARTAB();
8616            l_skipped_bb_id := VARCHARTAB();
8617            l_skipped_bb_ovn := VARCHARTAB();
8618            l_skipped_desc := VARCHARTAB();
8619            l_index := 0;
8620 
8621          fnd_file.put_line
8622                          (fnd_file.LOG,
8623                              '  '||fnd_date.date_to_canonical (SYSDATE)
8624                           || ' > ******* Printing SKIPPED Detail Blocks *******'
8625                          );
8626 
8627 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8628 
8629 	fnd_file.put_line(fnd_file.log, '     RESOURCE ID   '
8630 				     || '     TIMECARD      '
8631 				     || '     DETAIL        '
8632 				     || '     REMARKS       ');
8633 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8634 
8635 	FOR i IN hxc_generic_retrieval_pkg.g_detail_skipped.FIRST .. hxc_generic_retrieval_pkg.g_detail_skipped.LAST
8636 	LOOP
8637 
8638 	fnd_file.put_line(fnd_file.log, '     '
8639 	    ||hxc_generic_retrieval_pkg.g_detail_skipped(i).resource_id
8640 	    || '           '
8641 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id
8642 	    || ' ['
8643 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_ovn
8644 	    || ']          '
8645 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).bb_id
8646 	    || ' ['
8647 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).ovn
8648 	    || ']          '
8649 	    || hxc_generic_retrieval_pkg.g_detail_skipped(i).description);
8650 
8651 	    -- Bug 9458888
8652 
8653 	    g_temp_tc_list(i) := hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id;
8654 
8655            l_skipped_tc_id.EXTEND(1);
8656            l_skipped_bb_id.EXTEND(1);
8657            l_skipped_bb_ovn.EXTEND(1);
8658            l_skipped_desc.EXTEND(1);
8659            l_index := l_index + 1;
8660 
8661            l_skipped_tc_id(l_index) := hxc_generic_retrieval_pkg.g_detail_skipped(i).timecard_id;
8662            l_skipped_bb_id(l_index) := hxc_generic_retrieval_pkg.g_detail_skipped(i).bb_id;
8663            l_skipped_bb_ovn(l_index) := hxc_generic_retrieval_pkg.g_detail_skipped(i).ovn;
8664            l_skipped_desc(l_index) := hxc_generic_retrieval_pkg.g_detail_skipped(i).description;
8665 
8666 
8667 	END LOOP;
8668 
8669 	-- Bug 9458888
8670 	update_rdb_status(g_temp_tc_list,
8671 	                  'PENDING',
8672 	                  'SKIPPED');
8673 
8674         g_temp_tc_list.DELETE;
8675 
8676         FORALL i IN l_skipped_tc_id.FIRST..l_skipped_tc_id.LAST
8677              INSERT INTO hxc_rdb_process_details
8678                   ( timecard_id,
8679                     detail_id,
8680                     detail_ovn,
8681                     skipped_reason,
8682                     skip_level,
8683                     ret_user_id,
8684                     request_id,
8685                     process)
8686              VALUES ( l_skipped_tc_id(i),
8687                       l_skipped_bb_id (i),
8688                       l_skipped_bb_ovn(i),
8689                       l_skipped_desc(i),
8690                       'OTL_PROC',
8691                       FND_GLOBAL.user_ID,
8692                       FND_GLOBAL.conc_request_id,
8693                       g_params.p_process);
8694 
8695 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8696 
8697     END IF;
8698       fnd_file.put_line
8699                 (fnd_file.LOG,
8700                     '  '||fnd_date.date_to_canonical (SYSDATE)
8701                  || ' > Blocks COUNT being passed to RECIPIENT APPLICATION > '
8702                  || hxc_generic_retrieval_pkg.t_detail_bld_blks.COUNT
8703                 );
8704 
8705       IF (hxc_generic_retrieval_pkg.t_detail_bld_blks.COUNT > 0)
8706       THEN
8707            -- Bug 9458888
8708            l_skipped_tc_id := VARCHARTAB();
8709            l_skipped_bb_id := VARCHARTAB();
8710            l_skipped_bb_ovn := VARCHARTAB();
8711            l_skipped_desc := VARCHARTAB();
8712            l_index := 0;
8713 
8714          fnd_file.put_line
8715              (fnd_file.LOG,
8716                  '  '||fnd_date.date_to_canonical (SYSDATE)
8717               || ' > ******* Passing the following blocks for RETRIEVAL *******'
8718              );
8719 
8720 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8721 	fnd_file.put_line(fnd_file.log, '     RESOURCE ID   '
8722 				     || '     TIMECARD      '
8723 				     || '     DETAIL        ');
8724 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8725 
8726 	FOR i IN hxc_generic_retrieval_pkg.t_detail_bld_blks.FIRST .. hxc_generic_retrieval_pkg.t_detail_bld_blks.LAST
8727 	LOOP
8728 
8729 	fnd_file.put_line(fnd_file.log, '     '
8730 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).resource_id
8731 	    || '          '
8732 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_bb_id
8733 	    || ' ['
8734 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_ovn
8735 	    || ']        '
8736 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).bb_id
8737 	    || ' ['
8738 	    || hxc_generic_retrieval_pkg.t_detail_bld_blks(i).ovn
8739 	    || '] ');
8740 
8741            l_skipped_tc_id.EXTEND(1);
8742            l_skipped_bb_id.EXTEND(1);
8743            l_skipped_bb_ovn.EXTEND(1);
8744            l_skipped_desc.EXTEND(1);
8745            l_index := l_index + 1;
8746 
8747            l_skipped_tc_id(l_index) := hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_bb_id;
8748            l_skipped_bb_id(l_index) := hxc_generic_retrieval_pkg.t_detail_bld_blks(i).bb_id;
8749            l_skipped_bb_ovn(l_index) := hxc_generic_retrieval_pkg.t_detail_bld_blks(i).ovn;
8750            l_skipped_desc(l_index) := NULL ;
8751 
8752 	   g_temp_tc_list(i) := hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_bb_id;
8753 
8754            -- Bug 9494444
8755            -- The below tables record all the actual details that are getting retrieved
8756            --  old or new, but not just deleted entries.  This is for Payroll application
8757            --  where the batch details are plugged in these tables later.
8758            t_detail_rec_lines(i).bb_id :=  hxc_generic_retrieval_pkg.t_detail_bld_blks(i).bb_id;
8759            t_detail_rec_lines(i).ovn   :=  hxc_generic_retrieval_pkg.t_detail_bld_blks(i).ovn;
8760 
8761            -- Bug 9747820
8762            -- Store the timecard ids of each building block id
8763            g_timecards_array(hxc_generic_retrieval_pkg.t_detail_bld_blks(i).bb_id)
8764                                  := hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_bb_id;
8765 
8766            -- Store the latest OVN of each timecard id.
8767            IF NOT g_tc_ovn_array.EXISTS(g_timecards_array(t_detail_bld_blks(i).bb_id))
8768               OR g_tc_ovn_array(g_timecards_array(t_detail_bld_blks(i).bb_id))
8769                    < hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_ovn
8770            THEN
8771               g_tc_ovn_array((g_timecards_array(t_detail_bld_blks(i).bb_id)))
8772                                    := hxc_generic_retrieval_pkg.t_detail_bld_blks(i).timecard_ovn;
8773            END IF;
8774 
8775 	END LOOP;
8776 
8777         -- Bug 9494444
8778         -- The below tables record all the old bb id ovns going out for retro adjustments.
8779         -- Used by Payroll application later when the actual batch details are plugged into these
8780         -- tables.
8781         IF t_old_detail_bld_blks.COUNT > 0
8782   	THEN
8783   	   l_index := t_old_detail_bld_blks.FIRST;
8784   	   LOOP
8785   	      t_old_detail_rec_lines(l_index).bb_id := t_old_detail_bld_blks(l_index).bb_id;
8786   	      t_old_detail_rec_lines(l_index).ovn   := t_old_detail_bld_blks(l_index).ovn;
8787   	      g_old_bb_ids(t_old_detail_bld_blks(l_index).bb_id) := t_old_detail_bld_blks(l_index).bb_id;
8788   	      l_index := t_old_detail_bld_blks.NEXT(l_index);
8789   	      EXIT WHEN NOT t_old_detail_bld_blks.EXISTS(l_index);
8790   	   END LOOP;
8791   	END IF;
8792 
8793 
8794 	-- Bug 9458888
8795 	update_rdb_status(g_temp_tc_list,
8796 	                  'PENDING',
8797 	                  'PROCESSING');
8798 	update_rdb_status(g_temp_tc_list,
8799 	                  'SKIPPED',
8800 	                  'PROCESSING_PARTIAL');
8801 	g_temp_tc_list.DELETE;
8802 
8803          FORALL i IN l_skipped_tc_id.FIRST..l_skipped_tc_id.LAST
8804              INSERT INTO hxc_rdb_process_details
8805                   ( timecard_id,
8806                     detail_id,
8807                     detail_ovn,
8808                     skipped_reason,
8809                     skip_level,
8810                     ret_user_id,
8811                     request_id,
8812                     process)
8813              VALUES ( l_skipped_tc_id(i),
8814                       l_skipped_bb_id (i),
8815                       l_skipped_bb_ovn(i),
8816                       l_skipped_desc(i),
8817                       'OTL_PROC',
8818                       FND_GLOBAL.user_ID,
8819                       FND_GLOBAL.conc_request_id,
8820                       g_params.p_process);
8821 
8822 
8823 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
8824 
8825 	END IF;
8826 
8827 
8828 
8829 
8830 
8831       IF (hxc_generic_retrieval_utils.chk_terminated (g_conc_request_id))
8832       THEN
8833          fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
8834          fnd_message.set_token ('PROCEDURE', 'Generic Retrieval');
8835          fnd_message.set_token ('STEP', ': Process Terminated');
8836          fnd_message.raise_error;
8837       END IF;
8838    EXCEPTION
8839       WHEN e_retrieval_not_registered
8840       THEN
8841          fnd_message.set_name ('HXC', 'HXC_0011_GNRET_NOT_REGISTERED');
8842          fnd_message.raise_error;
8843       WHEN e_process_already_running
8844       THEN
8845          fnd_message.set_name ('HXC', 'HXC_0017_GNRET_PROCESS_RUNNING');
8846          fnd_message.raise_error;
8847       WHEN e_no_ranges
8848       THEN
8849          fnd_message.set_name ('HXC', 'HXC_0012_GNRET_NO_TIMECARDS');
8850          fnd_message.raise_error;
8851       WHEN OTHERS
8852       THEN
8853          -- Bug 9394444
8854          hr_utility.trace(dbms_utility.format_error_backtrace);
8855          audit_transaction
8856                          (p_mode                        => 'I'       -- Insert
8857                                                               ,
8858                           p_transaction_process_id      => g_retrieval_process_id,
8859                           p_status                      => 'ERRORS',
8860                           p_description                 => SUBSTR (SQLERRM,
8861                                                                    1,
8862                                                                    2000
8863                                                                   )
8864                          );
8865 -- now we need to unlock any TCs which were locked
8866          hxc_lock_api.release_lock
8867             (p_row_lock_id              => NULL,
8868              p_process_locker_type      => hxc_generic_retrieval_pkg.g_lock_type,
8869              p_transaction_lock_id      => hxc_generic_retrieval_pkg.g_transaction_id,
8870              p_released_success         => l_boolean
8871             );
8872          RAISE;
8873 --
8874    END execute_retrieval_process;
8875 
8876 -- private procedure
8877 --    delete_retrieval_ranges
8878 --
8879 -- description
8880 --    Deletes retrieval_ranges which is filled up by each retrieval process id
8881 --    Gets called when the transaction is updated with either 'SUCESS' or 'DELETE'
8882 --    from update_transaction_status
8883 --    Deletes based on concurrent process id which is unique for each process
8884 --    Ref. Bug 5669202
8885   PROCEDURE delete_retrieval_ranges (p_transaction_id IN hxc_transactions.transaction_id%TYPE)
8886   IS
8887   PRAGMA AUTONOMOUS_TRANSACTION;
8888   BEGIN
8889 
8890        DELETE FROM HXC_RETRIEVAL_RANGE_RESOURCES
8891        WHERE RETRIEVAL_RANGE_ID IN
8892            ( SELECT RETRIEVAL_RANGE_ID
8893              FROM HXC_RETRIEVAL_RANGES
8894              WHERE CONC_REQUEST_ID = g_conc_request_id
8895 	     AND   TRANSACTION_ID = p_transaction_id);
8896 
8897        DELETE FROM HXC_RETRIEVAL_RANGES
8898        WHERE  CONC_REQUEST_ID = g_conc_request_id
8899        AND    TRANSACTION_ID = p_transaction_id;
8900 
8901        COMMIT;
8902   END delete_retrieval_ranges;
8903 
8904 -- public procedure
8905 --   update_transaction_status
8906 --
8907 -- description
8908 --   Wrapper process such that audit transaction can be called externally.
8909 --   Updates the transactions for the retrieval once the recipient API has
8910 --   processed all the time bld blks. This procedure is called from the
8911 --   recipient API. The retrieval has already populated a global PL/SQL table
8912 --   with transaction details for each bld blk. The recipient API will have
8913 --   maintained this table appropriately. All this process does is
8914 --   update the transaction bulk bound (for performance) and maintain the
8915 --   transaction header records. unless of course the retrieval is being
8916 --   rolled back in which case all the detail records are deleted.
8917 --
8918 -- Parameters
8919 --   p_process - retrieval process name
8920 --   p_status  - the status of the overall retrieval
8921 --   p_exception_description - exception description
8922 --   p_rollback - is the retrieval being rolled back
8923    PROCEDURE update_transaction_status (
8924       p_process                 hxc_retrieval_processes.NAME%TYPE,
8925       p_status                  hxc_transactions.status%TYPE,
8926       p_exception_description   hxc_transactions.exception_description%TYPE,
8927       p_rollback                BOOLEAN DEFAULT FALSE
8928    )
8929    IS
8930 -- going to call the chk_retrieval_process procedure - do not need mapping id
8931       l_process_id            hxc_retrieval_processes.retrieval_process_id%TYPE;
8932       l_mapping_id            hxc_mappings.mapping_id%TYPE;
8933       l_tx_id                 hxc_transactions.transaction_id%TYPE;
8934       l_proc                  VARCHAR2 (72);
8935       l_time_max              INTEGER;
8936       l_day_max               INTEGER;
8937       l_detail_max            INTEGER;
8938       l_error_max             INTEGER;
8939       l_lock_ind              PLS_INTEGER;
8940       l_message_table         hxc_message_table_type;
8941       l_boolean               BOOLEAN;
8942       l_temp_transaction_id   t_transaction_id;
8943       l_ranges_to_process     number;
8944 
8945 
8946       -- Bug 9494444
8947       -- A whole set of types and variables declared here, used for
8948       -- taking the snapshot of the records used by the retrieval.
8949       TYPE VARCHARTAB IS TABLE OF VARCHAR2(500);
8950       TYPE DATETAB    IS TABLE OF DATE;
8951       TYPE NUMTAB     IS TABLE OF NUMBER;
8952 
8953       t_l_resource_id                NUMTAB ;
8954       t_l_time_building_block_id     NUMTAB ;
8955       t_l_approval_status            VARCHARTAB ;
8956       t_l_start_time                 DATETAB ;
8957       t_l_stop_time                  DATETAB ;
8958       t_l_org_id                     NUMTAB ;
8959       t_l_business_group_id          NUMTAB ;
8960       t_l_timecard_id                NUMTAB ;
8961       t_l_attribute1                 VARCHARTAB ;
8962       t_l_attribute2                 VARCHARTAB ;
8963       t_l_attribute3                 VARCHARTAB ;
8964       t_l_measure                    NUMTAB ;
8965       t_l_object_version_number      NUMTAB ;
8966       -- Bug 12919783
8967       t_l_application_set_id         NUMTAB;
8968 
8969 
8970 
8971       l_resource_id                  NUMTAB     := NUMTAB()  ;
8972       l_time_building_block_id       NUMTAB     := NUMTAB() ;
8973       l_approval_status              VARCHARTAB := VARCHARTAB() ;
8974       -- Bug 12919783
8975       l_application_set_id           NUMTAB     := NUMTAB();
8976       l_start_time                   DATETAB    := DATETAB() ;
8977       l_stop_time                    DATETAB    := DATETAB() ;
8978       l_org_id                       NUMTAB     := NUMTAB() ;
8979       l_business_group_id            NUMTAB     := NUMTAB() ;
8980       l_timecard_id                  NUMTAB     := NUMTAB() ;
8981       l_attribute1                   VARCHARTAB := VARCHARTAB() ;
8982       l_attribute2                   VARCHARTAB := VARCHARTAB() ;
8983       l_attribute3                   VARCHARTAB := VARCHARTAB() ;
8984       l_measure                      NUMTAB     := NUMTAB() ;
8985       l_object_version_number        NUMTAB     := NUMTAB() ;
8986 
8987       l_counter     BINARY_INTEGER := 0;
8988 
8989       l_old_tbb       NUMTAB;
8990       l_exists_tbb    NUMBERTABLE;
8991       l_index         BINARY_INTEGER := 0;
8992 
8993       l_rec_bb_id     NUMTAB := NUMTAB();
8994       l_rec_ovn       NUMTAB := NUMTAB();
8995       l_rec_id        NUMTAB := NUMTAB();
8996       l_batch_id      NUMTAB := NUMTAB();
8997 
8998 
8999       -- Bug 9701936
9000       -- Added these tables to effectively process Success and Error status
9001       -- details.
9002       l_success_tc    NUMTABLE;
9003       l_error_tc      NUMTABLE;
9004 
9005       i  BINARY_INTEGER;
9006 
9007       -- Bug 12919783
9008       l_rlbk_elig_tc1  NUMTABLE;
9009       l_rlbk_elig_tc2  NUMTABLE;
9010 
9011 
9012 
9013    BEGIN
9014       g_debug := hr_utility.debug_enabled;
9015 
9016       IF g_debug
9017       THEN
9018          l_proc := g_package || 'update_transaction_status';
9019          hr_utility.TRACE ('In Update Transaction Status');
9020       END IF;
9021 
9022 -- get the process id
9023       chk_retrieval_process (p_retrieval_process         => p_process,
9024                              p_retrieval_process_id      => l_process_id,
9025                              p_retrieval_tr_id           => g_retrieval_tr_id,
9026                              p_mapping_id                => l_mapping_id
9027                             );
9028 
9029 -- now call the audit transaction appropriately
9030       IF g_debug
9031       THEN
9032          hr_utility.set_location ('Processing ' || l_proc, 110);
9033       END IF;
9034 
9035       -- Bug 6914381
9036       -- If any transaction resulted in error, there is no need to
9037       -- do a reversal entry.  Hence delete the same record from
9038       -- HXC_BEE_PREF_ADJ_LINES.
9039       -- Do it only for Xfer time from OTL to BEE.
9040 
9041       IF g_params.p_process IN ('BEE Retrieval Process', 'Apply Schedule Rules')
9042       THEN
9043          IF hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT > 0
9044          THEN
9045             FORALL i IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST..
9046                                 hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9047 
9048                 DELETE FROM hxc_bee_pref_adj_lines
9049                    WHERE detail_bb_id = t_tx_detail_bb_id(i)
9050                      AND batch_source = DECODE(g_params.p_process,
9051                                               'BEE Retrieval Process', 'OTM',
9052                                               'Apply Schedule Rules' , 'Time Store')
9053                      AND t_tx_detail_status(i) = 'ERRORS'                         ;
9054          END IF;
9055       END IF;
9056 
9057 
9058 
9059       IF (p_status = 'ERRORS')
9060       THEN
9061          -- call audit transaction
9062          -- we want to commit these transactions for audit purposes
9063          -- before the process rolls them back
9064          audit_transaction (p_mode                        => 'U'     -- update
9065                                                                 ,
9066                             p_transaction_process_id      => l_process_id,
9067                             p_status                      => p_status,
9068                             p_description                 => p_exception_description,
9069                             p_rollback                    => p_rollback
9070                            );
9071       ELSE
9072          -- retrieval was successful - do the same work as audit_transaction except
9073          -- allow the recipient application commit the data.
9074          l_time_max := hxc_generic_retrieval_pkg.t_tx_time_bb_id.COUNT;
9075          l_day_max := hxc_generic_retrieval_pkg.t_tx_day_bb_id.COUNT;
9076          l_detail_max := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT;
9077          l_error_max := hxc_generic_retrieval_pkg.t_tx_error_bb_id.COUNT;
9078 
9079          OPEN csr_get_tx_id;
9080 
9081          FETCH csr_get_tx_id
9082           INTO l_tx_id;
9083 
9084          CLOSE csr_get_tx_id;
9085 
9086          INSERT INTO hxc_transactions
9087                      (transaction_id, transaction_process_id,
9088                       transaction_date, TYPE, status,
9089                       exception_description
9090                      )
9091               VALUES (l_tx_id, l_process_id,
9092                       SYSDATE, 'RETRIEVAL_STATUS_UPDATE', p_status,
9093                       p_exception_description
9094                      );
9095 
9096          UPDATE hxc_transactions
9097             SET status = p_status,
9098                 exception_description = p_exception_description
9099           WHERE transaction_id = hxc_generic_retrieval_pkg.g_transaction_id;
9100 
9101          IF NOT p_rollback
9102          THEN
9103             IF g_debug
9104             THEN
9105                hr_utility.set_location ('Processing ' || l_proc, 130);
9106             END IF;
9107 
9108 -- check to see if any tx time details
9109             IF l_time_max <> 0
9110             THEN
9111 -- now let's bulk fetch all the transaction detail id
9112                OPEN csr_get_tx_detail_id (l_time_max);
9113 
9114                FETCH csr_get_tx_detail_id
9115                BULK COLLECT INTO l_temp_transaction_id;
9116 
9117                CLOSE csr_get_tx_detail_id;
9118 
9119                hxc_generic_retrieval_pkg.t_tx_time_transaction_id :=
9120                                                         l_temp_transaction_id;
9121 
9122                IF g_debug
9123                THEN
9124                   hr_utility.set_location ('Processing ' || l_proc, 50);
9125                END IF;
9126 
9127                FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_time_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_time_transaction_id.LAST
9128                   INSERT INTO hxc_transaction_details
9129                               (transaction_detail_id,
9130                                time_building_block_id,
9131                                time_building_block_ovn,
9132                                transaction_id,
9133                                status,
9134                                exception_description
9135                               )
9136                        VALUES (hxc_generic_retrieval_pkg.t_tx_time_transaction_id
9137                                                                     (tx_detail),
9138                                hxc_generic_retrieval_pkg.t_tx_time_bb_id
9139                                                                     (tx_detail),
9140                                hxc_generic_retrieval_pkg.t_tx_time_bb_ovn
9141                                                                     (tx_detail),
9142                                hxc_generic_retrieval_pkg.g_transaction_id,
9143                                hxc_generic_retrieval_pkg.t_tx_time_status
9144                                                                     (tx_detail),
9145                                hxc_generic_retrieval_pkg.t_tx_time_exception
9146                                                                     (tx_detail)
9147                               );
9148             END IF;                                         -- l_time_max <> 0
9149 
9150 -- check to see if any tx day details
9151             IF l_day_max <> 0
9152             THEN
9153 -- now let's bulk fetch all the transaction detail id
9154                OPEN csr_get_tx_detail_id (l_day_max);
9155 
9156                FETCH csr_get_tx_detail_id
9157                BULK COLLECT INTO l_temp_transaction_id;
9158 
9159                CLOSE csr_get_tx_detail_id;
9160 
9161                hxc_generic_retrieval_pkg.t_tx_day_transaction_id :=
9162                                                         l_temp_transaction_id;
9163 
9164                IF g_debug
9165                THEN
9166                   hr_utility.set_location ('Processing ' || l_proc, 60);
9167                END IF;
9168 
9169                FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_day_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_day_transaction_id.LAST
9170                   INSERT INTO hxc_transaction_details
9171                               (transaction_detail_id,
9172                                time_building_block_id,
9173                                time_building_block_ovn,
9174                                transaction_id,
9175                                status,
9176                                exception_description
9177                               )
9178                        VALUES (hxc_generic_retrieval_pkg.t_tx_day_transaction_id
9179                                                                     (tx_detail),
9180                                hxc_generic_retrieval_pkg.t_tx_day_bb_id
9181                                                                     (tx_detail),
9182                                hxc_generic_retrieval_pkg.t_tx_day_bb_ovn
9183                                                                     (tx_detail),
9184                                hxc_generic_retrieval_pkg.g_transaction_id,
9185                                hxc_generic_retrieval_pkg.t_tx_day_status
9186                                                                     (tx_detail),
9187                                hxc_generic_retrieval_pkg.t_tx_day_exception
9188                                                                     (tx_detail)
9189                               );
9190             END IF;                                          -- l_day_max <> 0
9191 
9192 -- check to see if any tx detail details
9193             IF l_detail_max <> 0
9194             THEN
9195 -- now let's bulk fetch all the transaction detail id
9196                OPEN csr_get_tx_detail_id (l_detail_max);
9197 
9198                FETCH csr_get_tx_detail_id
9199                BULK COLLECT INTO l_temp_transaction_id;
9200 
9201                CLOSE csr_get_tx_detail_id;
9202 
9203                hxc_generic_retrieval_pkg.t_tx_detail_transaction_id :=
9204                                                         l_temp_transaction_id;
9205 
9206                IF g_debug
9207                THEN
9208                   hr_utility.set_location ('Processing ' || l_proc, 70);
9209                END IF;
9210 
9211                FORALL tx_detail IN hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.LAST
9212                   INSERT INTO hxc_transaction_details
9213                               (transaction_detail_id,
9214                                time_building_block_id,
9215                                time_building_block_ovn,
9216                                transaction_id,
9217                                status,
9218                                exception_description
9219                               )
9220                        VALUES (hxc_generic_retrieval_pkg.t_tx_detail_transaction_id
9221                                                                     (tx_detail),
9222                                hxc_generic_retrieval_pkg.t_tx_detail_bb_id
9223                                                                     (tx_detail),
9224                                hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn
9225                                                                     (tx_detail),
9226                                hxc_generic_retrieval_pkg.g_transaction_id,
9227                                hxc_generic_retrieval_pkg.t_tx_detail_status
9228                                                                     (tx_detail),
9229                                hxc_generic_retrieval_pkg.t_tx_detail_exception
9230                                                                     (tx_detail)
9231                               );
9232 
9233 
9234                -- Bug 9747820
9235                -- If there are any ERROR status bb id, delete those particular
9236                -- timecards from the list.
9237 
9238                IF hxc_generic_retrieval_pkg.t_tx_detail_bb_id.COUNT >0
9239                THEN
9240                   i := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST;
9241                   LOOP
9242                      IF hxc_generic_retrieval_pkg.t_tx_detail_status(i) = 'ERRORS'
9243                      THEN
9244                         g_tc_ovn_array.DELETE(g_timecards_array(hxc_generic_retrieval_pkg.t_tx_detail_bb_id(i)));
9245                         g_timecards_array.DELETE(hxc_generic_retrieval_pkg.t_tx_detail_bb_id(i));
9246                      END IF;
9247                      i := hxc_generic_retrieval_pkg.t_tx_detail_bb_id.NEXT(i);
9248                      EXIT WHEN NOT hxc_generic_retrieval_pkg.t_tx_detail_bb_id.EXISTS(i);
9249                   END LOOP;
9250                END IF;
9251 
9252                -- Bug 9394444
9253                -- In case the transactions are SUCCESS, we need to delete from
9254                -- the tables maintaining these.
9255                -- This has to be done irrespective of whether Upgraded process
9256                -- is chosen or not.
9257 
9258                -- Bug 9494444
9259                -- Added code to return the relevant values for the mirror retrieval
9260                -- tables.
9261                IF g_params.p_process = 'Projects Retrieval Process'
9262                THEN
9263                    FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST ..
9264                                       hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9265                         DELETE FROM hxc_pa_latest_details
9266                               WHERE time_building_block_id = hxc_generic_retrieval_pkg.t_tx_detail_bb_id(tx_error)
9267                                AND hxc_generic_retrieval_pkg.t_tx_detail_status
9268                                                                     (tx_error) = 'SUCCESS'
9269                          RETURNING
9270                                  resource_id,
9271                                  time_building_block_id,
9272                                  approval_status,
9273                                  start_time,
9274                                  stop_time,
9275                                  org_id,
9276                                  business_group_id,
9277                                  timecard_id,
9278                                  attribute1,
9279                                  attribute2,
9280                                  attribute3,
9281                                  measure,
9282                                  object_version_number
9283                          BULK
9284                           COLLECT INTO
9285                                 t_l_resource_id,
9286                                 t_l_time_building_block_id,
9287                                 t_l_approval_status,
9288                                 t_l_start_time,
9289                                 t_l_stop_time,
9290                                 t_l_org_id,
9291                                 t_l_business_group_id,
9292                                 t_l_timecard_id,
9293                                 t_l_attribute1,
9294                                 t_l_attribute2,
9295                                 t_l_attribute3,
9296                                 t_l_measure,
9297                                 t_l_object_version_number;
9298 
9299                    -- If there are any successful deletes from hxc_pa_latest_details
9300                    -- move them to HXC_RET_PA_LATEST_DETAILS
9301                    -- Keep recording whichever bb ids are updated.
9302 
9303                    IF t_l_resource_id.COUNT > 0
9304                    THEN
9305 
9306                        -- Bug 11797402
9307                        -- Hint specified
9308                        FORALL i IN t_l_time_building_block_id.FIRST..t_l_time_building_block_id.LAST
9309                             UPDATE /*+ INDEX(ret HXC_RET_PA_LATEST_DETAILS_FK1) */
9310                                    hxc_ret_pa_latest_details ret
9311                                SET old_attribute1 = attribute1,
9312                                    old_attribute2 = attribute2,
9313                                    old_attribute3 = attribute3,
9314                                    old_measure    = measure,
9315                                    old_ovn        = object_version_number,
9316                                    old_pei_id     = pei_id,
9317                                    old_exp_group  = exp_group,
9318                                    pei_id         = NULL,
9319                                    exp_group      = NULL,
9320                                    measure        = t_l_measure(i),
9321                                    attribute1     = t_l_attribute1(i),
9322                                    attribute2     = t_l_attribute2(i),
9323                                    attribute3     = t_l_attribute3(i),
9324                                    object_version_number = t_l_object_version_number(i),
9325                                    business_group_id = t_l_business_group_id(i),
9326                                    org_id     = t_l_org_id(i),
9327                                    approval_status = t_l_approval_status(i),
9328                                    old_request_id = request_id,
9329                                    request_id = FND_GLOBAL.conc_request_id
9330                              WHERE time_building_block_id = t_l_time_building_block_id(i)
9331                            RETURNING time_building_block_id
9332                                 BULK COLLECT INTO l_old_tbb;
9333 
9334                        IF l_old_tbb.COUNT > 0
9335                        THEN
9336                           FOR i IN l_old_tbb.FIRST..l_old_tbb.LAST
9337                           LOOP
9338                              l_exists_tbb(l_old_tbb(i)) := l_old_tbb(i);
9339                           END LOOP;
9340                        END IF;
9341 
9342 
9343                        -- Remove the above updated bb ids from the tables, to avoid any
9344                        -- errors in the following insert.
9345                        FOR i IN t_l_time_building_block_id.FIRST..t_l_time_building_block_id.LAST
9346                        LOOP
9347                           IF NOT l_exists_tbb.EXISTS(t_l_time_building_block_id(i))
9348                             -- If this also exists in the retro list of building blocks,
9349                             -- this was retrieved earlier, but missed the update above.
9350                             -- Do not insert such a record into the table, because it should
9351                             -- have been an UPDATE.
9352                             AND NOT g_old_bb_ids.EXISTS(t_l_time_building_block_id(i))
9353                           THEN
9354                                 l_counter := l_counter+1;
9355                                 l_resource_id  .EXTEND(1) ;
9356                                 l_time_building_block_id  .EXTEND(1) ;
9357                                 l_approval_status  .EXTEND(1) ;
9358                                 l_start_time  .EXTEND(1) ;
9359                                 l_stop_time  .EXTEND(1) ;
9360                                 l_org_id  .EXTEND(1) ;
9361                                 l_business_group_id  .EXTEND(1) ;
9362                                 l_timecard_id  .EXTEND(1) ;
9363                                 l_attribute1  .EXTEND(1) ;
9364                                 l_attribute2  .EXTEND(1) ;
9365                                 l_attribute3  .EXTEND(1) ;
9366                                 l_measure  .EXTEND(1) ;
9367                                 l_object_version_number .EXTEND(1) ;
9368 
9369                                 l_resource_id  (l_counter) := 		t_l_resource_id(i);
9370                                 l_time_building_block_id  (l_counter) := 	    t_l_time_building_block_id(i);
9371                                 l_approval_status  (l_counter) := 	    t_l_approval_status(i);
9372                                 l_start_time  (l_counter) := 		    t_l_start_time(i);
9373                                 l_stop_time  (l_counter) := 		    t_l_stop_time(i);
9374                                 l_org_id  (l_counter) := 			    t_l_org_id(i);
9375                                 l_business_group_id  (l_counter) := 	    t_l_business_group_id(i);
9376                                 l_timecard_id  (l_counter) := 		    t_l_timecard_id(i);
9377                                 l_attribute1  (l_counter) := 		    t_l_attribute1(i);
9378                                 l_attribute2  (l_counter) := 		    t_l_attribute2(i);
9379                                 l_attribute3  (l_counter) := 		    t_l_attribute3(i);
9380                                 l_measure  (l_counter) := 		    t_l_measure(i);
9381                                 l_object_version_number (l_counter) := 	    t_l_object_version_number (i);
9382 
9383                           END IF;
9384                        END LOOP;
9385 
9386 
9387                        -- Insert the records which are new into the table.
9388                        FORALL i IN l_time_building_block_id.FIRST..l_time_building_block_id.LAST
9389                           INSERT INTO hxc_ret_pa_latest_details
9390                                      (resource_id,
9391                                       time_building_block_id,
9392                                       approval_status,
9393                                       start_time,
9394                                       stop_time,
9395                                       org_id,
9396                                       business_group_id,
9397                                       timecard_id,
9398                                       attribute1,
9399                                       attribute2,
9400                                       attribute3,
9401                                       measure,
9402                                       object_version_number,
9403                                       request_id
9404                                       )
9405                              VALUES     (
9406                                           l_resource_id(i),
9407                                           l_time_building_block_id(i),
9408                                           l_approval_status(i),
9409                                           l_start_time(i),
9410                                           l_stop_time(i),
9411                                           l_org_id(i),
9412                                           l_business_group_id(i),
9413                                           l_timecard_id(i),
9414                                           l_attribute1(i),
9415                                           l_attribute2(i),
9416                                           l_attribute3(i),
9417                                           l_measure(i),
9418                                           l_object_version_number(i),
9419                                           FND_GLOBAL.conc_request_id);
9420 
9421 
9422                    END IF;
9423 
9424 
9425                    -- Bug 9458888
9426 
9427                    g_temp_tc_list.DELETE;
9428 
9429                    -- Bug 9626621
9430                    -- There were two deletes in place of one happening here, making
9431                    -- the RETURNING INTO table go empty.
9432 
9433 
9434                    -- Bug 9701936
9435                    -- Made some modifications in the DELETE and UPDATE below.
9436 
9437 
9438                    FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST ..
9439                                       hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9440                         DELETE FROM hxc_rdb_process_details
9441                               WHERE detail_id   = hxc_generic_retrieval_pkg.t_tx_detail_bb_id(tx_error)
9442                                AND hxc_generic_retrieval_pkg.t_tx_detail_status
9443                                                                     (tx_error) = 'SUCCESS'
9444                                 AND request_id  = FND_GLOBAL.CONC_REQUEST_ID
9445                                 AND ret_user_id = FND_global.user_id
9446                                 AND process     = g_params.p_process
9447                           RETURNING timecard_id
9448                                BULK
9449                             COLLECT INTO l_success_tc ;
9450 
9451                    -- Picking up unique timecard ids.
9452                    l_success_tc := SET(l_success_tc);
9453 
9454 
9455                    -- Bug : 9948863
9456                    FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST ..
9457                                       hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9458                         UPDATE hxc_rdb_process_details
9459                            SET skip_level = 'REC_PROC',
9460                                skipped_reason = SUBSTR(hxc_generic_retrieval_pkg.t_tx_detail_exception
9461                                                                     (tx_error),1,149)
9462                               WHERE detail_id = hxc_generic_retrieval_pkg.t_tx_detail_bb_id(tx_error)
9463                                AND hxc_generic_retrieval_pkg.t_tx_detail_status
9464                                                                     (tx_error) = 'ERRORS'
9465                                AND request_id = FND_GLOBAL.CONC_REQUEST_ID
9466                                AND ret_user_id = FND_global.user_id
9467                                AND process = g_params.p_process
9468                          RETURNING timecard_id
9469                               BULK
9470                            COLLECT INTO l_error_tc ;
9471 
9472                    -- Picking up unique timecard ids.
9473                    l_error_tc := SET(l_error_tc);
9474 
9475 
9476                    -- Now we have two Nested tables one of the successful details' timecard_ids
9477                    -- and one of the errored details' timecard id.
9478                    -- Using the below SET operations, passing the relevant records to the
9479                    -- update procedure to mark the relevant statuses.
9480 
9481                    -- All Success
9482                    update_rdb_status((l_success_tc MULTISET EXCEPT l_error_tc),
9483                                       'PROCESSING',
9484                                       'PROCESSED');
9485 
9486                    -- All Success, but skipped some earlier
9487                    update_rdb_status((l_success_tc MULTISET EXCEPT l_error_tc),
9488                                       'PROCESSING_PARTIAL',
9489                                       'PROCESSED_PARTIALLY');
9490 
9491                    -- All Errors
9492                    update_rdb_status((l_error_tc MULTISET EXCEPT l_success_tc),
9493                                      'PROCESSING',
9494                                      'ERRORED');
9495 
9496                    -- All Errors, but skipped some earlier
9497                    update_rdb_status((l_error_tc MULTISET EXCEPT l_success_tc),
9498                                      'PROCESSING_PARTIAL',
9499                                      'ERRORED');
9500 
9501                    -- Some errors
9502                    update_rdb_status((l_error_tc MULTISET INTERSECT l_success_tc),
9503                                      'PROCESSING',
9504                                      'PROCESSED_PARTIALLY');
9505 
9506                    -- Some errors, but skipped some earlier
9507                    update_rdb_status((l_error_tc MULTISET INTERSECT l_success_tc),
9508                                      'PROCESSING_PARTIAL',
9509                                      'PROCESSED_PARTIALLY');
9510 
9511 
9512 
9513 
9514                END IF;
9515 
9516                IF g_params.p_process IN ( 'BEE Retrieval Process','Apply Schedule Rules')
9517                THEN
9518                    g_temp_tc_list.DELETE;
9519 
9520                    -- Similar processing like projects above.
9521                    -- Bug 12919783
9522                    FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST ..
9523                                       hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9524                         DELETE FROM hxc_pay_latest_details
9525                               WHERE time_building_block_id = hxc_generic_retrieval_pkg.t_tx_detail_bb_id(tx_error)
9526                                AND hxc_generic_retrieval_pkg.t_tx_detail_status
9527                                                                     (tx_error) = 'SUCCESS'
9528                          RETURNING
9529                                  resource_id,
9530                                  time_building_block_id,
9531                                  approval_status,
9532                                  start_time,
9533                                  stop_time,
9534                                  org_id,
9535                                  business_group_id,
9536                                  timecard_id,
9537                                  attribute1,
9538                                  attribute2,
9539                                  attribute3,
9540                                  measure,
9541                                  object_version_number,
9542                                  application_set_id
9543                            BULK COLLECT INTO
9544                                 t_l_resource_id,
9545                                 t_l_time_building_block_id,
9546                                 t_l_approval_status,
9547                                 t_l_start_time,
9548                                 t_l_stop_time,
9549                                 t_l_org_id,
9550                                 t_l_business_group_id,
9551                                 t_l_timecard_id,
9552                                 t_l_attribute1,
9553                                 t_l_attribute2,
9554                                 t_l_attribute3,
9555                                 t_l_measure,
9556                                 t_l_object_version_number,
9557                                 t_l_application_set_id;
9558 
9559                    IF t_l_resource_id.COUNT > 0
9560                    THEN
9561 
9562                      -- Bug 12919783
9563                      -- We are not updating if it is an OTLR timecard, just inserting
9564                      IF g_params.p_process = 'Apply Schedule Rules'
9565                      THEN
9566 
9567                         FORALL i IN t_l_time_building_block_id.FIRST..t_l_time_building_block_id.LAST
9568                             UPDATE hxc_ret_pay_latest_details
9569                                SET old_attribute1 = attribute1,
9570                                    old_attribute2 = attribute2,
9571                                    old_attribute3 = attribute3,
9572                                    old_measure    = measure,
9573                                    old_ovn        = object_version_number,
9574                                    measure = t_l_measure(i),
9575                                    attribute1 = t_l_attribute1(i),
9576                                    attribute2 = t_l_attribute2(i),
9577                                    attribute3 = t_l_attribute3(i),
9578                                    object_version_number = t_l_object_version_number(i),
9579                                    business_group_id = t_l_business_group_id(i),
9580                                    org_id     = t_l_org_id(i),
9581                                    approval_status = t_l_approval_status(i),
9582                                    old_request_id  = request_id,
9583                                    old_batch_id    = batch_id,
9584                                    request_id      = FND_global.conc_request_id,
9585                                    application_set_id = t_l_application_set_id(i)
9586                              WHERE time_building_block_id = t_l_time_building_block_id(i)
9587                                AND old_batch_id IS NULL
9588                          RETURNING time_building_block_id
9589                               BULK COLLECT INTO l_old_tbb;
9590 
9591                       ELSE
9592 
9593                          FORALL i IN t_l_time_building_block_id.FIRST..t_l_time_building_block_id.LAST
9594                              UPDATE hxc_ret_pay_latest_details
9595                                 SET old_attribute1 = attribute1,
9596                                     old_attribute2 = attribute2,
9597                                     old_attribute3 = attribute3,
9598                                     old_measure    = measure,
9599                                     old_ovn        = object_version_number,
9600                                     measure = t_l_measure(i),
9601                                     attribute1 = t_l_attribute1(i),
9602                                     attribute2 = t_l_attribute2(i),
9603                                     attribute3 = t_l_attribute3(i),
9604                                     object_version_number = t_l_object_version_number(i),
9605                                     business_group_id = t_l_business_group_id(i),
9606                                     org_id     = t_l_org_id(i),
9607                                     approval_status = t_l_approval_status(i),
9608                                     old_request_id  = request_id,
9609                                     old_batch_id    = batch_id,
9610                                     request_id      = FND_global.conc_request_id,
9611                                     application_set_id = t_l_application_set_id(i)
9612                               WHERE time_building_block_id = t_l_time_building_block_id(i)
9613                           RETURNING time_building_block_id
9614                                BULK COLLECT INTO l_old_tbb;
9615 
9616                        END IF;
9617 
9618                        IF l_old_tbb.COUNT > 0
9619                        THEN
9620                           FOR i IN l_old_tbb.FIRST..l_old_tbb.LAST
9621                           LOOP
9622                              l_exists_tbb(l_old_tbb(i)) := l_old_tbb(i);
9623                           END LOOP;
9624                        END IF;
9625 
9626 
9627                        -- Bug 12919783
9628                        -- For OTLR process, we are not updating any already transferred detail
9629                        -- we would just insert new records for such cases.
9630                        FOR i IN t_l_time_building_block_id.FIRST..t_l_time_building_block_id.LAST
9631                        LOOP
9632                           IF  (NOT l_exists_tbb.EXISTS(t_l_time_building_block_id(i))
9633                                AND NOT g_old_bb_ids.EXISTS(t_l_time_building_block_id(i))
9634                                AND g_params.p_process = 'BEE Retrieval Process'
9635                                )
9636                             OR (NOT l_exists_tbb.EXISTS(t_l_time_building_block_id(i))
9637                                AND g_params.p_process = 'Apply Schedule Rules'
9638                                )
9639 
9640                           THEN
9641                                 l_counter := l_counter+1;
9642                                 l_resource_id  .EXTEND(1) ;
9643                                 l_time_building_block_id  .EXTEND(1) ;
9644                                 l_approval_status  .EXTEND(1) ;
9645                                 l_start_time  .EXTEND(1) ;
9646                                 l_stop_time  .EXTEND(1) ;
9647                                 l_org_id  .EXTEND(1) ;
9648                                 l_business_group_id  .EXTEND(1) ;
9649                                 l_timecard_id  .EXTEND(1) ;
9650                                 l_attribute1  .EXTEND(1) ;
9651                                 l_attribute2  .EXTEND(1) ;
9652                                 l_attribute3  .EXTEND(1) ;
9653                                 l_measure  .EXTEND(1) ;
9654                                 l_object_version_number .EXTEND(1) ;
9655                                 l_application_set_id.EXTEND(1) ;
9656 
9657                                 l_resource_id  (l_counter) := 		    t_l_resource_id(i);
9658                                 l_time_building_block_id  (l_counter) :=    t_l_time_building_block_id(i);
9659                                 l_approval_status  (l_counter) := 	    t_l_approval_status(i);
9660                                 l_start_time  (l_counter) := 		    t_l_start_time(i);
9661                                 l_stop_time  (l_counter) := 		    t_l_stop_time(i);
9662                                 l_org_id  (l_counter) := 		    t_l_org_id(i);
9663                                 l_business_group_id  (l_counter) := 	    t_l_business_group_id(i);
9664                                 l_timecard_id  (l_counter) := 		    t_l_timecard_id(i);
9665                                 l_attribute1  (l_counter) := 		    t_l_attribute1(i);
9666                                 l_attribute2  (l_counter) := 		    t_l_attribute2(i);
9667                                 l_attribute3  (l_counter) := 		    t_l_attribute3(i);
9668                                 l_measure  (l_counter) := 		    t_l_measure(i);
9669                                 l_object_version_number (l_counter) := 	    t_l_object_version_number (i);
9670                                 l_application_set_id(l_counter) := t_l_application_set_id(i);
9671 
9672                           END IF;
9673                        END LOOP;
9674 
9675 
9676                        FORALL i IN l_time_building_block_id.FIRST..l_time_building_block_id.LAST
9677                           INSERT INTO hxc_ret_pay_latest_details
9678                                (resource_id,
9679                                 time_building_block_id,
9680                                 approval_status,
9681                                 start_time,
9682                                 stop_time,
9683                                 org_id,
9684                                 business_group_id,
9685                                 timecard_id,
9686                                 attribute1,
9687                                 attribute2,
9688                                 attribute3,
9689                                 measure,
9690                                 object_version_number,
9691                                 request_id,
9692                                 application_set_id
9693                                 )
9694                             VALUES     (
9695                                     l_resource_id(i),
9696                                     l_time_building_block_id(i),
9697                                     l_approval_status(i),
9698                                     l_start_time(i),
9699                                     l_stop_time(i),
9700                                     l_org_id(i),
9701                                     l_business_group_id(i),
9702                                     l_timecard_id(i),
9703                                     l_attribute1(i),
9704                                     l_attribute2(i),
9705                                     l_attribute3(i),
9706                                     l_measure(i),
9707                                     l_object_version_number(i),
9708                                     FND_GLOBAL.conc_request_id,
9709                                     l_application_set_id(i));
9710 
9711                     -- Bug 12919783
9712                     -- HXC_RET_PAY_DETAILS is our Dump to hold all retrievals done ever
9713                     --  Insert all the records there.
9714                     FORALL i IN t_l_time_building_block_id.FIRST..t_l_time_building_block_id.LAST
9715                           INSERT INTO hxc_ret_pay_details
9716                                (resource_id,
9717                                 time_building_block_id,
9718                                 approval_status,
9719                                 start_time,
9720                                 stop_time,
9721                                 org_id,
9722                                 business_group_id,
9723                                 timecard_id,
9724                                 attribute1,
9725                                 attribute2,
9726                                 attribute3,
9727                                 measure,
9728                                 object_version_number,
9729                                 request_id
9730                                 )
9731                             VALUES     (
9732                                     t_l_resource_id(i),
9733                                     t_l_time_building_block_id(i),
9734                                     t_l_approval_status(i),
9735                                     t_l_start_time(i),
9736                                     t_l_stop_time(i),
9737                                     t_l_org_id(i),
9738                                     t_l_business_group_id(i),
9739                                     t_l_timecard_id(i),
9740                                     t_l_attribute1(i),
9741                                     t_l_attribute2(i),
9742                                     t_l_attribute3(i),
9743                                     t_l_measure(i),
9744                                     t_l_object_version_number(i),
9745                                     FND_GLOBAL.conc_request_id);
9746 
9747 
9748                        -- This is payroll specific code.
9749                        -- Picking up the batch id information back on to the table.
9750                        l_counter := 0;
9751                        IF t_detail_rec_lines.COUNT > 0
9752                        THEN
9753                           l_index := t_detail_rec_lines.FIRST;
9754                           LOOP
9755                              l_counter := l_counter + 1;
9756                              l_rec_bb_id.EXTEND(1);
9757                              l_rec_ovn.EXTEND(1);
9758                              l_rec_id.EXTEND(1);
9759                              l_batch_id.EXTEND(1);
9760 
9761                              l_rec_bb_id(l_counter) := t_detail_rec_lines(l_index).bb_id;
9762                              l_rec_ovn(l_counter) := t_detail_rec_lines(l_index).ovn;
9763                              l_rec_id(l_counter) := t_detail_rec_lines(l_index).rec_id;
9764                              l_batch_id(l_counter) := t_detail_rec_lines(l_index).batch_id;
9765 
9766                              l_index := t_detail_rec_lines.NEXT(l_index);
9767 
9768                              EXIT WHEN NOT t_detail_rec_lines.EXISTS(l_index);
9769                           END LOOP;
9770 
9771 
9772                           FORALL i IN l_rec_bb_id.FIRST..l_rec_bb_id.LAST
9773                             UPDATE hxc_ret_pay_latest_details
9774                                SET old_pbl_id = pbl_id,
9775                                    pbl_id = l_rec_id(i),
9776                                    batch_id = l_batch_id(i)
9777                              WHERE time_building_block_id = l_rec_bb_id(i)
9778                                AND object_version_number  = l_rec_ovn(i);
9779 
9780                           -- Bug 12919783
9781                           FORALL i IN l_rec_bb_id.FIRST..l_rec_bb_id.LAST
9782                             UPDATE hxc_ret_pay_details
9783                                SET pbl_id = l_rec_id(i),
9784                                    batch_id = l_batch_id(i)
9785                              WHERE time_building_block_id = l_rec_bb_id(i)
9786                                AND object_version_number  = l_rec_ovn(i);
9787 
9788                          BEGIN
9789                              l_batch_id := SET(l_batch_id);
9790                              FORALL i IN l_batch_id.FIRST..l_batch_id.LAST SAVE EXCEPTIONS
9791                                INSERT INTO hxc_pay_trans_code_all
9792                                    ( transaction_code,
9793                                      batch_id,
9794                                      request_id)
9795                                   VALUES ( g_params.p_transaction_code,
9796                                            l_batch_id(i),
9797                                            FND_GLOBAL.conc_request_id);
9798                             EXCEPTION
9799                                WHEN OTHERS
9800                                THEN
9801                                    NULL;
9802                           END;
9803 
9804                        END IF;
9805 
9806                        l_counter := 0;
9807                        l_rec_bb_id := NUMTAB();
9808                        l_rec_ovn := NUMTAB();
9809                        l_rec_id := NUMTAB();
9810                        l_batch_id := NUMTAB();
9811                        IF t_old_detail_rec_lines.COUNT > 0
9812                        THEN
9813                           l_index := t_old_detail_rec_lines.FIRST;
9814                           LOOP
9815                              l_counter := l_counter + 1;
9816                              l_rec_bb_id.EXTEND(1);
9817                              l_rec_ovn.EXTEND(1);
9818                              l_rec_id.EXTEND(1);
9819                              l_batch_id.EXTEND(1);
9820 
9821                              l_rec_bb_id(l_counter) := t_old_detail_rec_lines(l_index).bb_id;
9822                              l_rec_ovn(l_counter) := t_old_detail_rec_lines(l_index).ovn;
9823                              l_rec_id(l_counter) := t_old_detail_rec_lines(l_index).rec_id;
9824                              l_batch_id(l_counter) := t_old_detail_rec_lines(l_index).batch_id;
9825 
9826                              l_index := t_old_detail_rec_lines.NEXT(l_index);
9827 
9828                              EXIT WHEN NOT t_old_detail_rec_lines.EXISTS(l_index);
9829                           END LOOP;
9830 
9831 
9832                           FORALL i IN l_rec_bb_id.FIRST..l_rec_bb_id.LAST
9833                             UPDATE hxc_ret_pay_latest_details
9834                                SET retro_pbl_id = l_rec_id(i),
9835                                    retro_batch_id = l_batch_id(i)
9836                              WHERE time_building_block_id = l_rec_bb_id(i)
9837                                AND old_ovn  = l_rec_ovn(i);
9838 
9839                           -- Bug 12919783
9840                           FORALL i IN l_rec_bb_id.FIRST..l_rec_bb_id.LAST
9841                             UPDATE hxc_ret_pay_details
9842                                SET retro_pbl_id = l_rec_id(i),
9843                                    retro_batch_id = l_batch_id(i),
9844                                    old_ovn = l_rec_ovn(i)
9845                              WHERE time_building_block_id = l_rec_bb_id(i)
9846                                AND request_id = FND_GLOBAL.conc_request_id ;
9847 
9848                           BEGIN
9849                              l_batch_id := SET(l_batch_id);
9850                              FORALL i IN l_batch_id.FIRST..l_batch_id.LAST SAVE EXCEPTIONS
9851                                 INSERT INTO hxc_pay_trans_code_all
9852                                     ( transaction_code,
9853                                       batch_id,
9854                                       request_id)
9855                                  VALUES ( g_params.p_transaction_code,
9856                                           l_batch_id(i),
9857                                           FND_GLOBAL.conc_request_id);
9858                             EXCEPTION
9859                                 WHEN OTHERS
9860                                 THEN
9861                                      NULL;
9862                           END;
9863 
9864 
9865                        END IF;
9866 
9867 
9868 
9869                END IF;
9870 
9871 
9872                    -- Bug 9701936
9873                    -- Follows the same logic as Projects Application above.
9874 
9875                    FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST ..
9876                                       hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9877                         DELETE FROM hxc_rdb_process_details
9878                               WHERE detail_id   = hxc_generic_retrieval_pkg.t_tx_detail_bb_id(tx_error)
9879                                AND hxc_generic_retrieval_pkg.t_tx_detail_status
9880                                                                     (tx_error) = 'SUCCESS'
9881                                 AND request_id  = FND_GLOBAL.CONC_REQUEST_ID
9882                                 AND ret_user_id = FND_global.user_id
9883                                 AND process     = g_params.p_process
9884                           RETURNING timecard_id
9885                                BULK
9886                             COLLECT INTO l_success_tc ;
9887 
9888                    l_success_tc := SET(l_success_tc);
9889 
9890                    -- Bug 12919783
9891                    -- Marking Latest Retrievals for Rollback
9892 
9893                    -- Bug 13814489
9894                    -- Added the below IF.
9895                    IF l_success_tc.COUNT > 0
9896                    THEN
9897 
9898                        FORALL rlbk IN l_success_tc.FIRST..l_success_tc.LAST
9899                          UPDATE hxc_ld_rollback_timecards_all
9900                             SET request_id = FND_Global.conc_request_id
9901                           WHERE timecard_id = l_success_tc(rlbk)
9902                            RETURNING timecard_id BULK COLLECT INTO l_rlbk_elig_tc1;
9903 
9904                        l_rlbk_elig_tc2 := l_success_tc MULTISET EXCEPT l_rlbk_elig_tc1;
9905 
9906                        FORALL rlbk IN l_rlbk_elig_tc2.FIRST..l_rlbk_elig_tc2.LAST
9907                          INSERT INTO hxc_ld_rollback_timecards_all
9908                            (timecard_id, request_id)
9909                           VALUES (l_rlbk_elig_tc2(rlbk),FND_GLOBAL.conc_request_id);
9910 
9911                    END IF;
9912 
9913                    -- Bug : 9948863
9914                    FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_detail_bb_id.FIRST ..
9915                                       hxc_generic_retrieval_pkg.t_tx_detail_bb_id.LAST
9916                         UPDATE hxc_rdb_process_details
9917                            SET skip_level     = 'REC_PROC',
9918                                skipped_reason = SUBSTR(hxc_generic_retrieval_pkg.t_tx_detail_exception
9919                                                                     (tx_error),1,149)
9920                               WHERE detail_id   = hxc_generic_retrieval_pkg.t_tx_detail_bb_id(tx_error)
9921                                AND hxc_generic_retrieval_pkg.t_tx_detail_status
9922                                                                     (tx_error) = 'ERRORS'
9923                                AND request_id   = FND_GLOBAL.CONC_REQUEST_ID
9924                                AND ret_user_id  = FND_global.user_id
9925                                AND process      = g_params.p_process
9926                          RETURNING timecard_id
9927                               BULK
9928                            COLLECT INTO l_error_tc ;
9929 
9930 
9931                      l_error_tc := SET(l_error_tc);
9932 
9933                      -- All Success
9934                      update_rdb_status((l_success_tc MULTISET EXCEPT l_error_tc),
9935                                       'PROCESSING',
9936                                       'PROCESSED');
9937 
9938                      -- All Success, but skipped some earlier
9939                      update_rdb_status((l_success_tc MULTISET EXCEPT l_error_tc),
9940                                       'PROCESSING_PARTIAL',
9941                                       'PROCESSED_PARTIALLY');
9942 
9943                      -- All Errors
9944                      update_rdb_status((l_error_tc MULTISET EXCEPT l_success_tc),
9945                                       'PROCESSING',
9946                                       'ERRORED');
9947                      -- All Errors, but skipped some earlier
9948                      update_rdb_status((l_error_tc MULTISET EXCEPT l_success_tc),
9949                                       'PROCESSING_PARTIAL',
9950                                       'ERRORED');
9951 
9952                      -- Some errors
9953                      update_rdb_status((l_error_tc MULTISET INTERSECT l_success_tc),
9954                                       'PROCESSING',
9955                                       'PROCESSED_PARTIALLY');
9956 
9957                      -- Some errors, but skipped some earlier
9958                      update_rdb_status((l_error_tc MULTISET INTERSECT l_success_tc),
9959                                       'PROCESSING_PARTIAL',
9960                                       'PROCESSED_PARTIALLY');
9961 
9962 
9963                END IF;
9964 
9965 
9966 
9967 
9968                IF g_debug
9969                THEN
9970                   hr_utility.set_location ('Processing ' || l_proc, 75);
9971                END IF;
9972             END IF;                                       -- l_detail_max <> 0
9973 
9974             IF g_debug
9975             THEN
9976                hr_utility.set_location ('Processing ' || l_proc, 80);
9977             END IF;
9978 
9979             IF l_error_max <> 0
9980             THEN
9981                IF g_debug
9982                THEN
9983                   hr_utility.set_location ('Processing ' || l_proc, 85);
9984                END IF;
9985 
9986 -- now let's bulk fetch all the transaction detail id
9987                OPEN csr_get_tx_detail_id (l_error_max);
9988 
9989                FETCH csr_get_tx_detail_id
9990                BULK COLLECT INTO l_temp_transaction_id;
9991 
9992                CLOSE csr_get_tx_detail_id;
9993 
9994                hxc_generic_retrieval_pkg.t_tx_error_transaction_id :=
9995                                                          l_temp_transaction_id;
9996 
9997                IF g_debug
9998                THEN
9999                   hr_utility.set_location ('Processing ' || l_proc, 90);
10000                END IF;
10001 
10002                FORALL tx_error IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
10003                   INSERT INTO hxc_transaction_details
10004                               (transaction_detail_id,
10005                                time_building_block_id,
10006                                time_building_block_ovn,
10007                                transaction_id,
10008                                status,
10009                                exception_description
10010                               )
10011                        VALUES (hxc_generic_retrieval_pkg.t_tx_error_transaction_id
10012                                                                      (tx_error),
10013                                hxc_generic_retrieval_pkg.t_tx_error_bb_id
10014                                                                      (tx_error),
10015                                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn
10016                                                                      (tx_error),
10017                                hxc_generic_retrieval_pkg.g_transaction_id,
10018                                hxc_generic_retrieval_pkg.t_tx_error_status
10019                                                                      (tx_error),
10020                                hxc_generic_retrieval_pkg.t_tx_error_exception
10021                                                                      (tx_error)
10022                               );
10023 -- given we are only going to do this once and the recipient app does not need
10024 -- to maintain these statuses we can delete the arrays
10025                hxc_generic_retrieval_pkg.t_tx_error_transaction_id.DELETE;
10026                hxc_generic_retrieval_pkg.t_tx_error_bb_id.DELETE;
10027                hxc_generic_retrieval_pkg.t_tx_error_bb_ovn.DELETE;
10028                hxc_generic_retrieval_pkg.t_tx_error_status.DELETE;
10029                hxc_generic_retrieval_pkg.t_tx_error_exception.DELETE;
10030 
10031                IF g_debug
10032                THEN
10033                   hr_utility.set_location ('Processing ' || l_proc, 100);
10034                END IF;
10035             END IF;                                        -- l_error_max <> 0
10036          END IF;                                                 -- p_rollback
10037 
10038          IF g_debug
10039          THEN
10040             hr_utility.set_location ('Processing ' || l_proc, 170);
10041          END IF;
10042 
10043          -- need to clean up the hxc retrieval ranges table if the process
10044          -- has errored.
10045          IF (p_status = 'ERRORS')
10046          THEN
10047             UPDATE hxc_retrieval_ranges
10048                SET transaction_id = -1
10049              WHERE retrieval_process_id = l_process_id AND transaction_id = -1;
10050          END IF;
10051       END IF;                                           -- p_status = 'ERRORS'
10052 
10053 -- now we need to unlock any TCs which were locked
10054       hxc_lock_api.release_lock
10055          (p_row_lock_id              => NULL,
10056           p_process_locker_type      => hxc_generic_retrieval_pkg.g_lock_type,
10057           p_transaction_lock_id      => hxc_generic_retrieval_pkg.g_transaction_id,
10058           p_released_success         => l_boolean
10059          );
10060 
10061 	--bug 5669202
10062 
10063 
10064       -- Bug 9747820
10065       -- Added the below construct to process transferred to
10066       -- column.
10067       IF g_debug
10068       THEN
10069          hr_utility.trace(' About to process transferred to ');
10070 
10071          IF g_tc_ovn_array.COUNT > 0
10072          THEN
10073          i := g_tc_ovn_array.FIRST;
10074          LOOP
10075             hr_utility.trace(i);
10076             hr_utility.trace(g_tc_ovn_array(i));
10077             hr_utility.trace(l_process_id);
10078             i := g_tc_ovn_array.NEXT(i);
10079             EXIT WHEN NOT g_tc_ovn_array.EXISTS(i);
10080          END LOOP;
10081          END IF;
10082 
10083       END IF;
10084 
10085       IF g_tc_ovn_array.COUNT > 0
10086       THEN
10087          i := g_tc_ovn_array.FIRST;
10088          LOOP
10089             -- Call the procedure passing timecard id, ovn and process id
10090             -- to populate the columns.
10091             hxc_timecard_summary_pkg.update_transferred_to(i,
10092                                                            g_tc_ovn_array(i),
10093                                                            l_process_id );
10094             i := g_tc_ovn_array.NEXT(i);
10095             EXIT WHEN NOT g_tc_ovn_array.EXISTS(i);
10096          END LOOP;
10097       END IF;
10098 
10099       -- Processing is done, so delete the table.
10100       g_tc_ovn_array.DELETE;
10101 
10102 
10103 	IF ((p_status = 'SUCCESS' OR p_status = 'ERRORS') AND l_process_id <> -1)
10104 	-- DO NOT DELETE FOR 'IN PROGRESS' TRANSACTIONS
10105         THEN
10106                IF g_debug
10107                THEN
10108                        hr_utility.TRACE ('g_conc_request_id is ' || g_conc_request_id);
10109                END IF;
10110 
10111                delete_retrieval_ranges (hxc_generic_retrieval_pkg.g_transaction_id);
10112 
10113                IF g_debug
10114                THEN
10115                        hr_utility.set_location ('Processing ' || l_proc, 200);
10116                END IF;
10117         ELSE
10118                IF g_debug
10119                THEN
10120                        hr_utility.set_location ('Processing ' || l_proc, 250);
10121                END IF;
10122         END IF;
10123 
10124       IF (hxc_generic_retrieval_utils.chk_terminated
10125                                          (fnd_profile.VALUE ('CONC_REQUEST_ID')
10126                                          )
10127          )
10128       THEN
10129          fnd_message.set_name ('PAY', 'HR_6153_ALL_PROCEDURE_FAIL');
10130          fnd_message.set_token ('PROCEDURE', 'Generic Retrieval');
10131          fnd_message.set_token ('STEP', ': Process Terminated');
10132          fnd_message.raise_error;
10133 
10134       END IF;
10135 
10136       fnd_file.put_line
10137                    (fnd_file.LOG,
10138                        '  '||fnd_date.date_to_canonical (SYSDATE)
10139                     || ' > Blocks COUNT of TRANSACTION DETAILS > '
10140                     || hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.COUNT
10141                    );
10142 
10143       IF (hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.COUNT > 0)
10144       THEN
10145          fnd_file.put_line
10146             (fnd_file.LOG,
10147                 '  '||fnd_date.date_to_canonical (SYSDATE)
10148              || ' > ******* Details Recevied from the RECIPIENT APPLICATION *******'
10149             );
10150 
10151 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
10152 	fnd_file.put_line(fnd_file.log, '     DETAIL      '
10153 				     || '     TRANSACTON ID      '
10154 				     || '     STATUS        '
10155 				     || '     DESCRIPTION       ');
10156 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
10157 
10158 	FOR i IN hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_detail_transaction_id.LAST
10159 	LOOP
10160 
10161 	fnd_file.put_line(fnd_file.log,
10162 	     '     '
10163 	    || hxc_generic_retrieval_pkg.t_tx_detail_bb_id(i)
10164 	    || ' ['
10165 	    || hxc_generic_retrieval_pkg.t_tx_detail_bb_ovn(i)
10166 	    || ']       '
10167 	    || hxc_generic_retrieval_pkg.t_tx_detail_transaction_id(i)
10168 	    || '        '
10169 	    || hxc_generic_retrieval_pkg.t_tx_detail_status(i)
10170 	    || '        '
10171 	    || hxc_generic_retrieval_pkg.t_tx_detail_exception(i));
10172 
10173 	END LOOP;
10174 
10175 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
10176 
10177 	END IF;
10178 
10179       fnd_file.put_line
10180                     (fnd_file.LOG,
10181                         '  '||fnd_date.date_to_canonical (SYSDATE)
10182                      || ' > ERRORed BLOCK count > '
10183                      || hxc_generic_retrieval_pkg.t_tx_error_transaction_id.COUNT
10184                     );
10185 
10186       IF (hxc_generic_retrieval_pkg.t_tx_error_transaction_id.COUNT > 0)
10187       THEN
10188          fnd_file.put_line
10189                       (fnd_file.LOG,
10190                           '  '||fnd_date.date_to_canonical (SYSDATE)
10191                        || ' > ******* The following blocks are in ERROR *******'
10192                       );
10193 
10194 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
10195 	fnd_file.put_line(fnd_file.log, '     DETAIL      '
10196 				     || '     TRANSACTON ID      '
10197 				     || '     STATUS        '
10198 				     || '     DESCRIPTION       ');
10199 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
10200 
10201 	FOR i IN hxc_generic_retrieval_pkg.t_tx_error_transaction_id.FIRST .. hxc_generic_retrieval_pkg.t_tx_error_transaction_id.LAST
10202 	LOOP
10203 
10204 	fnd_file.put_line(fnd_file.log,
10205 	    '    '
10206 	    || hxc_generic_retrieval_pkg.t_tx_error_bb_id(i)
10207 	    || ' ['
10208 	    || hxc_generic_retrieval_pkg.t_tx_error_bb_ovn(i)
10209 	    || ']       '
10210 	    || hxc_generic_retrieval_pkg.t_tx_error_transaction_id(i)
10211 	    || '        '
10212 	    || hxc_generic_retrieval_pkg.t_tx_error_status(i)
10213 	    || '        '
10214 	    || hxc_generic_retrieval_pkg.t_tx_error_exception(i));
10215 
10216 	END LOOP;
10217 
10218 	fnd_file.put_line(fnd_file.log, '  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
10219 
10220 
10221       END IF;
10222 
10223       IF g_debug
10224       THEN
10225          hr_utility.TRACE ('Leaving Update Transaction Status');
10226       END IF;
10227    END update_transaction_status;
10228 
10229 
10230   -- Bug 8888911
10231   -- Added this new function call so that writing on to FND_FILE.LOG is easy.
10232   -- It is known that put_log is not grammar friendly, but since we are going to use
10233   -- this one quite a lot, one which is short is easier to write.
10234   PROCEDURE put_log(p_text   IN VARCHAR2)
10235   IS
10236 
10237   BEGIN
10238        FND_FILE.PUT_LINE(FND_FILE.LOG,p_text);
10239        IF g_debug
10240        THEN
10241           hr_utility.trace(p_text);
10242        END IF;
10243   END put_log;
10244 
10245 -- Bug 9458888
10246 -- Added for Retrieval Dashboard Process tab to update
10247 -- In progress and processing timecards.
10248 PROCEDURE update_rdb_status ( p_tc_list  NUMBERTABLE,
10249                               p_from_status   VARCHAR2,
10250                               p_to_status     VARCHAR2)
10251 IS
10252 
10253     PRAGMA AUTONOMOUS_TRANSACTION;
10254 
10255     TYPE NUMTAB IS TABLE OF NUMBER;
10256     l_tctab    NUMTAB;
10257     i  BINARY_INTEGER;
10258     l_index  BINARY_INTEGER := 0;
10259 
10260 BEGIN
10261 
10262      l_tctab := NUMTAB();
10263      IF p_tc_list.COUNT > 0
10264      THEN
10265          i :=p_tc_list.FIRST;
10266          LOOP
10267             l_tctab.EXTEND(1);
10268             l_index := l_index + 1;
10269             l_tctab(l_index) := p_tc_list(i);
10270             i := p_tc_list.NEXT(i);
10271             EXIT WHEN NOT p_tc_list.EXISTS(i);
10272          END LOOP;
10273      END IF;
10274 
10275      l_tctab := SET(l_tctab);
10276 
10277      FORALL i IN l_tctab.FIRST..l_tctab.LAST
10278         UPDATE hxc_rdb_process_timecards
10279            SET stage = p_to_status
10280          WHERE timecard_id = l_tctab(i)
10281            AND stage = p_from_status
10282            AND process = g_params.p_process;
10283 
10284      COMMIT;
10285 
10286 END update_rdb_status;
10287 
10288 
10289 -- Bug 9701936
10290 -- Added this overloaded function to take in a
10291 -- Nested Table of numbers.  Has only the updates required.
10292 
10293 PROCEDURE update_rdb_status ( p_tc_list  NUMTABLE,
10294                               p_from_status   VARCHAR2,
10295                               p_to_status     VARCHAR2)
10296 IS
10297 
10298     PRAGMA AUTONOMOUS_TRANSACTION;
10299 
10300 
10301 BEGIN
10302 
10303      IF p_tc_list.COUNT = 0
10304      THEN
10305         RETURN;
10306      END IF;
10307 
10308      FORALL i IN p_tc_list.FIRST..p_tc_list.LAST
10309         UPDATE hxc_rdb_process_timecards
10310            SET stage = p_to_status
10311          WHERE timecard_id = p_tc_list(i)
10312            AND stage = p_from_status
10313            AND process = g_params.p_process;
10314 
10315      COMMIT;
10316 
10317 END update_rdb_status;
10318 
10319 
10320 
10321 END hxc_generic_retrieval_pkg;